DrillThroughDefinitionDialog.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. *
  5. * IBM Cognos Products: BI UI Commons
  6. *
  7. * Copyright IBM Corp. 2018, 2019
  8. *
  9. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. */
  11. define(['../../lib/@waca/core-client/js/core-client/ui/dialogs/GenericViewDialog', './DrillThroughDefinitionView', '../../DynamicFileLoader', '../../widgets/livewidget/nls/StringResources', 'underscore'], function (BaseDialog, DrillThroughDefinitionView, DynamicFileLoader, StringResources, _) {
  12. /**
  13. * Create a drill through definition dialog.
  14. * @param - options
  15. */
  16. var DrillThroughDefinitionDialog = BaseDialog.extend({
  17. init: function init(options) {
  18. this.applicationName = options.applicationName;
  19. this.boardName = options.boardName;
  20. this.name = options.name || options.targetName;
  21. this.targetName = options.targetName;
  22. this.type = options.type;
  23. this.entryId = options.id;
  24. this.assetId = options.assetId;
  25. this.modelRefs = options.modelRefs;
  26. this.controller = options.controller;
  27. this.scope = options.scope;
  28. this.ownerId = options.ownerId;
  29. this.perspective = options.perspective;
  30. this.isLoading = options.isLoading;
  31. this.mappings = options.mappings;
  32. this.columnLabels = options.columnLabels;
  33. this.columnLabelValues = _.map(this.columnLabels, function (column) {
  34. return column.label;
  35. });
  36. this.rowSize = this.mappings && this.mappings.length;
  37. this.handlers = options.handlers || {};
  38. this.iconsFeature = options.iconsFeature || {};
  39. this.handlers = _.extend(this.handlers, {
  40. getRow: this._getRow.bind(this),
  41. onValueSelected: this._onValueSelected.bind(this),
  42. onScopeChange: this._onScopeChange.bind(this),
  43. onNameChange: this._onNameChange.bind(this),
  44. onCloseDialog: this._onCloseDialog.bind(this),
  45. onBack: this._onBack.bind(this)
  46. });
  47. var dialogOptions = {
  48. 'buttons': [{
  49. 'text': StringResources.get('dlg_apply'),
  50. 'handler': this.apply.bind(this),
  51. 'type': 'primary',
  52. 'defaultId': 'apply_button'
  53. }, {
  54. 'handler': this.cancel.bind(this),
  55. 'defaultId': 'cancel'
  56. }],
  57. 'showHeader': false,
  58. 'viewClass': DrillThroughDefinitionView,
  59. 'id': 'dtTitleText',
  60. 'viewOptions': {
  61. 'applicationName': this.applicationName,
  62. 'handlers': this.handlers,
  63. 'rowSize': this.rowSize,
  64. 'name': this.name,
  65. 'sourceName': options.sourceName,
  66. 'boardName': this.boardName,
  67. 'targetName': this.targetName,
  68. 'scope': this.scope,
  69. 'isLoading': this.isLoading,
  70. 'type': this.type,
  71. 'perspective': this.perspective,
  72. 'iconsFeature': this.iconsFeature
  73. }
  74. };
  75. DrillThroughDefinitionDialog.inherited('init', this, [dialogOptions]);
  76. },
  77. /**
  78. * Called when the apply button is clicked
  79. */
  80. apply: function apply() {
  81. var spec = {
  82. name: this.name,
  83. targetName: this.targetName,
  84. type: this.type,
  85. id: this.entryId, //This may be undefined for 'add new target'
  86. assetId: this.assetId,
  87. modelRefs: this.modelRefs,
  88. mappings: this.mappings,
  89. scope: this.scope,
  90. ownerId: this.ownerId,
  91. perspective: this.perspective
  92. };
  93. if (!this.handlers.canApply(spec)) {
  94. DynamicFileLoader.load(['dashboard-analytics/lib/@waca/core-client/js/core-client/ui/dialogs/MessageBox']).then(function (Modules) {
  95. var MessageBox = Modules[0];
  96. var title = StringResources.get('drillthrough_definitionDuplicateDrillTargetErrorTitle');
  97. var displayMessage = StringResources.get('drillthrough_definitionMessage', { name: spec.name });
  98. var msgBox = new MessageBox('error', title, displayMessage);
  99. msgBox.open();
  100. });
  101. } else {
  102. DrillThroughDefinitionDialog.inherited('ok', this, arguments);
  103. this.hide();
  104. this.handlers.onApply(spec);
  105. }
  106. },
  107. setFocus: function setFocus() {
  108. this._container().find('.dialogButton.primary')[0].focus();
  109. },
  110. /**
  111. * Returns the row information as consumed by the view
  112. * @param index index of row
  113. */
  114. _getRow: function _getRow(index) {
  115. var param = this.mappings[index];
  116. var mapTo = param.mapTo;
  117. var selectedIndex = -1;
  118. if (mapTo && this.columnLabels && this.columnLabels.length) {
  119. for (var i = 0; i < this.columnLabels.length; i++) {
  120. if (mapTo === this.columnLabels[i].columnId) {
  121. selectedIndex = i;
  122. break;
  123. }
  124. }
  125. }
  126. return {
  127. caption: param.name,
  128. state: {
  129. selectedIndex: selectedIndex,
  130. values: this.columnLabelValues
  131. }
  132. };
  133. },
  134. /**
  135. * Handler for when a mapped value is selected
  136. * @param entryIndex Mapping index
  137. * @param mapToIndex label index mapped to
  138. */
  139. _onValueSelected: function _onValueSelected(entryIndex, mapToIndex) {
  140. var entryItem = this.mappings[entryIndex];
  141. if (mapToIndex === -1) {
  142. entryItem.mapTo = null;
  143. } else {
  144. entryItem.mapTo = this.columnLabels[mapToIndex].columnId;
  145. }
  146. },
  147. /**
  148. * Handler for when the scope state of the drill entry has changed
  149. * @param state of scope for the drill entry
  150. */
  151. _onScopeChange: function _onScopeChange(state) {
  152. this.scope = state;
  153. },
  154. /**
  155. * Handler for when the name of the drill through entry has changed
  156. * @param name of the drill entry
  157. */
  158. _onNameChange: function _onNameChange(name) {
  159. this.name = name;
  160. },
  161. /**
  162. * Handler for when the user click the close dialog
  163. */
  164. _onCloseDialog: function _onCloseDialog() {
  165. this.cancel();
  166. },
  167. /**
  168. * Handler for when the user click the back button
  169. */
  170. _onBack: function _onBack() {
  171. this.cancel();
  172. if (this.handlers.back) {
  173. this.handlers.back();
  174. }
  175. },
  176. update: function update(options) {
  177. this.columnLabels = options.columnLabels || this.columnLabels;
  178. this.mappings = options.mappings || this.mappings;
  179. this.rowSize = this.mappings ? this.mappings.length : this.rowSize;
  180. this.targetName = options.targetName || this.targetName;
  181. if (!options.isLoading) {
  182. this.columnLabelValues = _.map(this.columnLabels, function (column) {
  183. return column.label;
  184. });
  185. }
  186. this.view.update({ rowSize: this.rowSize, isLoading: options.isLoading, targetName: this.targetName });
  187. }
  188. });
  189. return DrillThroughDefinitionDialog;
  190. });
  191. //# sourceMappingURL=DrillThroughDefinitionDialog.js.map