MultipleColumnsNavigationDialog.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2016, 2021
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['../../../lib/@waca/dashboard-common/dist/ui/dialogs/CommonSelectItemsDialog', './SelectItemsNavigationDialog', 'jquery', 'underscore', 'text!../templates/MultipleColumnNavigation.html', '../../../lib/@waca/dashboard-common/dist/ui/NextView', '../nls/StringResources', 'doT'], function (View, SelectItemsDialog, $, _, MultipleColumnNavigation, NextView, stringResources, dot) {
  8. var MultipleColumnsNavigationDialog = View.extend({
  9. events: {
  10. 'primaryaction .itemRow': '_selectItem',
  11. 'keydown .itemRow': '_moveFocus'
  12. },
  13. _possibleItems: [],
  14. _eventHandler: null,
  15. _currentIndex: null,
  16. _currentElementSelected: null,
  17. _selectedDrillGroup: null,
  18. _nextView: null,
  19. _templateArray: [],
  20. init: function init(options) {
  21. MultipleColumnsNavigationDialog.inherited('init', this, arguments);
  22. this._possibleItems = options.state.possibleItems;
  23. this._templateArray = [];
  24. this._eventHandler = options.state.eventHandler;
  25. },
  26. render: function render() {
  27. this._renderDataItems();
  28. this.dotTemplate = dot.template(MultipleColumnNavigation);
  29. var sHtml = this.dotTemplate({ array: this._templateArray });
  30. this.$el.html(sHtml);
  31. this._setFocus();
  32. },
  33. _renderDataItems: function _renderDataItems() {
  34. var dataItemIds = _.keys(this._possibleItems);
  35. for (var i = 0; i < dataItemIds.length; i++) {
  36. this._templateArray.push({ columnId: dataItemIds[i], label: this._possibleItems[dataItemIds[i]][0].dataItem.getLabel() });
  37. }
  38. },
  39. _selectItem: function _selectItem(evt) {
  40. this._currentElementSelected = $(evt.currentTarget);
  41. var currentSelectedItem = $(evt.currentTarget).attr('data');
  42. var selectedItemInfo = this._possibleItems[currentSelectedItem];
  43. var selectViewOptions = {
  44. state: {
  45. possibleItems: selectedItemInfo,
  46. eventHandler: this._eventHandler,
  47. currentSelectedItem: currentSelectedItem
  48. }
  49. };
  50. var selectItems = new SelectItemsDialog(selectViewOptions);
  51. selectItems = selectItems.render();
  52. var nextViewOptions = {
  53. previousView: this.$el.closest('.toolbarPopoverContent'),
  54. nextView: selectItems,
  55. title: stringResources.get('navigateTitle')
  56. };
  57. this._nextView = new NextView(nextViewOptions);
  58. this._nextView = this._nextView.render();
  59. var contianer = this.$el.closest('.popover-content');
  60. contianer.append(this._nextView.$el);
  61. },
  62. _setFocus: function _setFocus() {
  63. this.$el.find('.itemRow').attr('tabindex', '-1');
  64. this.$el.find('.itemRow:first').attr('tabindex', '0');
  65. },
  66. handleSelection: function handleSelection(selectedItem) {
  67. var item = $('<div></div>').addClass('itemRow').attr('data', selectedItem[0].id);
  68. $('<div></div>').addClass('text').text(selectedItem[0].label).appendTo(item);
  69. $('<div class="rightArrow"><span class="wfg_rightarrow"></span></div>').appendTo(item);
  70. this._currentElementSelected.replaceWith(item);
  71. this._possibleItems[this._currentIndex].dataItemId = selectedItem[0].id;
  72. this._eventHandler.handleSelection(selectedItem);
  73. },
  74. changeDrillGroup: function changeDrillGroup(drillGroupId, dataItemId) {
  75. this._selectedDrillGroup = drillGroupId;
  76. this._eventHandler.changeDrillGroup(drillGroupId, dataItemId);
  77. },
  78. remove: function remove() {
  79. MultipleColumnsNavigationDialog.inherited('remove', this, arguments);
  80. if (this._nextView) {
  81. this._nextView.remove();
  82. }
  83. }
  84. });
  85. return MultipleColumnsNavigationDialog;
  86. });
  87. //# sourceMappingURL=MultipleColumnsNavigationDialog.js.map