DrillThroughManageView.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Watson Analytics (C) Copyright IBM Corp. 2018
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. *
  7. */
  8. define(['../../../lib/@waca/core-client/js/core-client/ui/core/View', '../../../lib/@waca/core-client/js/core-client/utils/ContentFormatter', '../../../lib/@waca/core-client/js/core-client/ui/dialogs/ConfirmationDialog', 'doT', 'underscore', 'jquery', 'text!../../templates/DrillThroughManage.html', '../../../widgets/livewidget/nls/StringResources'], function (View, ContentFormatter, ConfirmationDialog, doT, _, $, Template, StringResources) {
  9. //@todo: Endor add support for multiple data sources
  10. var _validSourceId = function _validSourceId(sources, id) {
  11. if (_.isArray(sources)) {
  12. for (var index = 0; index < sources.length; index++) {
  13. if (sources[index] === id) {
  14. return true;
  15. }
  16. }
  17. }
  18. return false;
  19. };
  20. /**
  21. * Creates a view UI for the manage drill through dialog
  22. */
  23. var DrillThroughManageView = View.extend({
  24. templateString: Template,
  25. events: {
  26. 'primaryaction .edit': '_onEdit',
  27. 'primaryaction .delete': '_onDelete',
  28. 'primaryaction .visDT-ManageView-add': '_onAddNewTarget'
  29. },
  30. init: function init(options) {
  31. DrillThroughManageView.inherited('init', this, arguments);
  32. options = options || {};
  33. this.handlers = options.handlers;
  34. if (!this.handlers) {
  35. throw new Error('Handlers must be provided to manage drill through definitions');
  36. }
  37. this.content = options.content;
  38. this.dashboard = options.dashboard;
  39. this.drillThroughModelApi = options.drillThroughModelApi;
  40. },
  41. render: function render(bEnableOkButton) {
  42. var addAnotherJumpTo = StringResources.get('drillthrough_manageAddAnotherTarget');
  43. var entries = this.drillThroughModelApi.getDrillDefinitionEntries(this.content);
  44. var visualizationAPI = this.content.getFeature('Visualization');
  45. var dataSource = visualizationAPI.getDataSource();
  46. var sourceId = dataSource.getId();
  47. var jumpToEntries = [];
  48. var iconsFeature = this.dashboard.getFeature('Icons');
  49. var reportIcon = iconsFeature.getIcon('reportIcon');
  50. var dashboardIcon = iconsFeature.getIcon('dashboardIcon');
  51. var storyIcon = iconsFeature.getIcon('storyIcon');
  52. var editIcon = iconsFeature.getIcon('common-edit');
  53. var removeIcon = iconsFeature.getIcon('remove');
  54. var addNewIcon = iconsFeature.getIcon('addNew');
  55. _.each(entries, function (entry) {
  56. if (_validSourceId(entry.getModelRefs(), sourceId)) {
  57. jumpToEntries.push({
  58. getIcon: function getIcon() {
  59. var iconMap = {
  60. authoring: reportIcon.id,
  61. story: storyIcon.id,
  62. dashboard: dashboardIcon.id
  63. };
  64. return iconMap[entry.getPerspective()];
  65. },
  66. getId: function getId() {
  67. return entry.getId();
  68. },
  69. getName: function getName() {
  70. return entry.getName();
  71. },
  72. editJumpTo: StringResources.get('drillthrough_manageJumpPaths_edit', { name: entry.getName() }),
  73. removeJumpTo: StringResources.get('drillthrough_manageJumpPaths_delete', { name: entry.getName() })
  74. });
  75. }
  76. });
  77. var sHtml = this.dotTemplate({
  78. entries: jumpToEntries,
  79. editIcon: editIcon.id,
  80. removeIcon: removeIcon.id,
  81. addNewIcon: addNewIcon.id,
  82. addNewTarget: {
  83. getId: function getId() {
  84. return 'addNewTarget';
  85. },
  86. getName: function getName() {
  87. return addAnotherJumpTo;
  88. }
  89. }
  90. });
  91. this.$el.empty().html(sHtml);
  92. this._updateText();
  93. this.handlers.enableOk(!!bEnableOkButton);
  94. },
  95. _onEdit: function _onEdit(event) {
  96. var id = this._getId(event);
  97. return id ? this.handlers.onEdit(this.content, id, this._getEditDrillThroughModelOptions()) : Promise.reject('Invalid drill through target');
  98. },
  99. _onDelete: function _onDelete(event) {
  100. var id = this._getId(event);
  101. var drillTarget = id ? this.drillThroughModelApi.getDrillDefinitionEntry(id) : null;
  102. if (drillTarget) {
  103. var confirmDlg = new ConfirmationDialog('confirmDeleteDrillTarget', StringResources.get('drillthrough_manageConfirmeDeleteDrillTargetTitle'), StringResources.get('drillthrough_manageConfirmeDeleteDrillTarget', {
  104. name: drillTarget.getName()
  105. }));
  106. confirmDlg.confirm(function () {
  107. this.handlers.onDelete(id, this._getEditDrillThroughModelOptions());
  108. }.bind(this));
  109. } else {
  110. throw new Error('Invalid drill through target');
  111. }
  112. },
  113. _onAddNewTarget: function _onAddNewTarget() {
  114. return this.handlers.onCreate(this.content, this._getEditDrillThroughModelOptions());
  115. },
  116. _getItem: function _getItem(event) {
  117. var $target = $(event.currentTarget);
  118. return $target.closest('.visDT-ManageView-item-container');
  119. },
  120. _getId: function _getId(event) {
  121. var $ancestor = this._getItem(event);
  122. return $ancestor.length > 0 ? $ancestor[0].getAttribute('data-id') : null;
  123. },
  124. _getEditDrillThroughModelOptions: function _getEditDrillThroughModelOptions() {
  125. return {
  126. undoRedoOptions: {
  127. silent: true
  128. },
  129. callback: this.render.bind(this, true)
  130. };
  131. },
  132. setFocus: function setFocus() {
  133. this.$el.focus();
  134. this._updateText();
  135. },
  136. _updateText: function _updateText() {
  137. this.$el.find('.visDT-ManageView-item.visDT-ManageView-item-target').each(function (index, elem) {
  138. ContentFormatter.middleShortenString(elem);
  139. });
  140. }
  141. });
  142. return DrillThroughManageView;
  143. });
  144. //# sourceMappingURL=DrillThroughManageView.js.map