123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Watson Analytics (C) Copyright IBM Corp. 2018
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *
- */
- 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) {
- //@todo: Endor add support for multiple data sources
- var _validSourceId = function _validSourceId(sources, id) {
- if (_.isArray(sources)) {
- for (var index = 0; index < sources.length; index++) {
- if (sources[index] === id) {
- return true;
- }
- }
- }
- return false;
- };
- /**
- * Creates a view UI for the manage drill through dialog
- */
- var DrillThroughManageView = View.extend({
- templateString: Template,
- events: {
- 'primaryaction .edit': '_onEdit',
- 'primaryaction .delete': '_onDelete',
- 'primaryaction .visDT-ManageView-add': '_onAddNewTarget'
- },
- init: function init(options) {
- DrillThroughManageView.inherited('init', this, arguments);
- options = options || {};
- this.handlers = options.handlers;
- if (!this.handlers) {
- throw new Error('Handlers must be provided to manage drill through definitions');
- }
- this.content = options.content;
- this.dashboard = options.dashboard;
- this.drillThroughModelApi = options.drillThroughModelApi;
- },
- render: function render(bEnableOkButton) {
- var addAnotherJumpTo = StringResources.get('drillthrough_manageAddAnotherTarget');
- var entries = this.drillThroughModelApi.getDrillDefinitionEntries(this.content);
- var visualizationAPI = this.content.getFeature('Visualization');
- var dataSource = visualizationAPI.getDataSource();
- var sourceId = dataSource.getId();
- var jumpToEntries = [];
- var iconsFeature = this.dashboard.getFeature('Icons');
- var reportIcon = iconsFeature.getIcon('reportIcon');
- var dashboardIcon = iconsFeature.getIcon('dashboardIcon');
- var storyIcon = iconsFeature.getIcon('storyIcon');
- var editIcon = iconsFeature.getIcon('common-edit');
- var removeIcon = iconsFeature.getIcon('remove');
- var addNewIcon = iconsFeature.getIcon('addNew');
- _.each(entries, function (entry) {
- if (_validSourceId(entry.getModelRefs(), sourceId)) {
- jumpToEntries.push({
- getIcon: function getIcon() {
- var iconMap = {
- authoring: reportIcon.id,
- story: storyIcon.id,
- dashboard: dashboardIcon.id
- };
- return iconMap[entry.getPerspective()];
- },
- getId: function getId() {
- return entry.getId();
- },
- getName: function getName() {
- return entry.getName();
- },
- editJumpTo: StringResources.get('drillthrough_manageJumpPaths_edit', { name: entry.getName() }),
- removeJumpTo: StringResources.get('drillthrough_manageJumpPaths_delete', { name: entry.getName() })
- });
- }
- });
- var sHtml = this.dotTemplate({
- entries: jumpToEntries,
- editIcon: editIcon.id,
- removeIcon: removeIcon.id,
- addNewIcon: addNewIcon.id,
- addNewTarget: {
- getId: function getId() {
- return 'addNewTarget';
- },
- getName: function getName() {
- return addAnotherJumpTo;
- }
- }
- });
- this.$el.empty().html(sHtml);
- this._updateText();
- this.handlers.enableOk(!!bEnableOkButton);
- },
- _onEdit: function _onEdit(event) {
- var id = this._getId(event);
- return id ? this.handlers.onEdit(this.content, id, this._getEditDrillThroughModelOptions()) : Promise.reject('Invalid drill through target');
- },
- _onDelete: function _onDelete(event) {
- var id = this._getId(event);
- var drillTarget = id ? this.drillThroughModelApi.getDrillDefinitionEntry(id) : null;
- if (drillTarget) {
- var confirmDlg = new ConfirmationDialog('confirmDeleteDrillTarget', StringResources.get('drillthrough_manageConfirmeDeleteDrillTargetTitle'), StringResources.get('drillthrough_manageConfirmeDeleteDrillTarget', {
- name: drillTarget.getName()
- }));
- confirmDlg.confirm(function () {
- this.handlers.onDelete(id, this._getEditDrillThroughModelOptions());
- }.bind(this));
- } else {
- throw new Error('Invalid drill through target');
- }
- },
- _onAddNewTarget: function _onAddNewTarget() {
- return this.handlers.onCreate(this.content, this._getEditDrillThroughModelOptions());
- },
- _getItem: function _getItem(event) {
- var $target = $(event.currentTarget);
- return $target.closest('.visDT-ManageView-item-container');
- },
- _getId: function _getId(event) {
- var $ancestor = this._getItem(event);
- return $ancestor.length > 0 ? $ancestor[0].getAttribute('data-id') : null;
- },
- _getEditDrillThroughModelOptions: function _getEditDrillThroughModelOptions() {
- return {
- undoRedoOptions: {
- silent: true
- },
- callback: this.render.bind(this, true)
- };
- },
- setFocus: function setFocus() {
- this.$el.focus();
- this._updateText();
- },
- _updateText: function _updateText() {
- this.$el.find('.visDT-ManageView-item.visDT-ManageView-item-target').each(function (index, elem) {
- ContentFormatter.middleShortenString(elem);
- });
- }
- });
- return DrillThroughManageView;
- });
- //# sourceMappingURL=DrillThroughManageView.js.map
|