123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- *
- * IBM Cognos Products: BI UI Commons
- *
- * Copyright IBM Corp. 2018, 2019
- *
- * 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/dialogs/GenericViewDialog', './DrillThroughDefinitionView', '../../DynamicFileLoader', '../../widgets/livewidget/nls/StringResources', 'underscore'], function (BaseDialog, DrillThroughDefinitionView, DynamicFileLoader, StringResources, _) {
- /**
- * Create a drill through definition dialog.
- * @param - options
- */
- var DrillThroughDefinitionDialog = BaseDialog.extend({
- init: function init(options) {
- this.applicationName = options.applicationName;
- this.boardName = options.boardName;
- this.name = options.name || options.targetName;
- this.targetName = options.targetName;
- this.type = options.type;
- this.entryId = options.id;
- this.assetId = options.assetId;
- this.modelRefs = options.modelRefs;
- this.controller = options.controller;
- this.scope = options.scope;
- this.ownerId = options.ownerId;
- this.perspective = options.perspective;
- this.isLoading = options.isLoading;
- this.mappings = options.mappings;
- this.columnLabels = options.columnLabels;
- this.columnLabelValues = _.map(this.columnLabels, function (column) {
- return column.label;
- });
- this.rowSize = this.mappings && this.mappings.length;
- this.handlers = options.handlers || {};
- this.iconsFeature = options.iconsFeature || {};
- this.handlers = _.extend(this.handlers, {
- getRow: this._getRow.bind(this),
- onValueSelected: this._onValueSelected.bind(this),
- onScopeChange: this._onScopeChange.bind(this),
- onNameChange: this._onNameChange.bind(this),
- onCloseDialog: this._onCloseDialog.bind(this),
- onBack: this._onBack.bind(this)
- });
- var dialogOptions = {
- 'buttons': [{
- 'text': StringResources.get('dlg_apply'),
- 'handler': this.apply.bind(this),
- 'type': 'primary',
- 'defaultId': 'apply_button'
- }, {
- 'handler': this.cancel.bind(this),
- 'defaultId': 'cancel'
- }],
- 'showHeader': false,
- 'viewClass': DrillThroughDefinitionView,
- 'id': 'dtTitleText',
- 'viewOptions': {
- 'applicationName': this.applicationName,
- 'handlers': this.handlers,
- 'rowSize': this.rowSize,
- 'name': this.name,
- 'sourceName': options.sourceName,
- 'boardName': this.boardName,
- 'targetName': this.targetName,
- 'scope': this.scope,
- 'isLoading': this.isLoading,
- 'type': this.type,
- 'perspective': this.perspective,
- 'iconsFeature': this.iconsFeature
- }
- };
- DrillThroughDefinitionDialog.inherited('init', this, [dialogOptions]);
- },
- /**
- * Called when the apply button is clicked
- */
- apply: function apply() {
- var spec = {
- name: this.name,
- targetName: this.targetName,
- type: this.type,
- id: this.entryId, //This may be undefined for 'add new target'
- assetId: this.assetId,
- modelRefs: this.modelRefs,
- mappings: this.mappings,
- scope: this.scope,
- ownerId: this.ownerId,
- perspective: this.perspective
- };
- if (!this.handlers.canApply(spec)) {
- DynamicFileLoader.load(['dashboard-analytics/lib/@waca/core-client/js/core-client/ui/dialogs/MessageBox']).then(function (Modules) {
- var MessageBox = Modules[0];
- var title = StringResources.get('drillthrough_definitionDuplicateDrillTargetErrorTitle');
- var displayMessage = StringResources.get('drillthrough_definitionMessage', { name: spec.name });
- var msgBox = new MessageBox('error', title, displayMessage);
- msgBox.open();
- });
- } else {
- DrillThroughDefinitionDialog.inherited('ok', this, arguments);
- this.hide();
- this.handlers.onApply(spec);
- }
- },
- setFocus: function setFocus() {
- this._container().find('.dialogButton.primary')[0].focus();
- },
- /**
- * Returns the row information as consumed by the view
- * @param index index of row
- */
- _getRow: function _getRow(index) {
- var param = this.mappings[index];
- var mapTo = param.mapTo;
- var selectedIndex = -1;
- if (mapTo && this.columnLabels && this.columnLabels.length) {
- for (var i = 0; i < this.columnLabels.length; i++) {
- if (mapTo === this.columnLabels[i].columnId) {
- selectedIndex = i;
- break;
- }
- }
- }
- return {
- caption: param.name,
- state: {
- selectedIndex: selectedIndex,
- values: this.columnLabelValues
- }
- };
- },
- /**
- * Handler for when a mapped value is selected
- * @param entryIndex Mapping index
- * @param mapToIndex label index mapped to
- */
- _onValueSelected: function _onValueSelected(entryIndex, mapToIndex) {
- var entryItem = this.mappings[entryIndex];
- if (mapToIndex === -1) {
- entryItem.mapTo = null;
- } else {
- entryItem.mapTo = this.columnLabels[mapToIndex].columnId;
- }
- },
- /**
- * Handler for when the scope state of the drill entry has changed
- * @param state of scope for the drill entry
- */
- _onScopeChange: function _onScopeChange(state) {
- this.scope = state;
- },
- /**
- * Handler for when the name of the drill through entry has changed
- * @param name of the drill entry
- */
- _onNameChange: function _onNameChange(name) {
- this.name = name;
- },
- /**
- * Handler for when the user click the close dialog
- */
- _onCloseDialog: function _onCloseDialog() {
- this.cancel();
- },
- /**
- * Handler for when the user click the back button
- */
- _onBack: function _onBack() {
- this.cancel();
- if (this.handlers.back) {
- this.handlers.back();
- }
- },
- update: function update(options) {
- this.columnLabels = options.columnLabels || this.columnLabels;
- this.mappings = options.mappings || this.mappings;
- this.rowSize = this.mappings ? this.mappings.length : this.rowSize;
- this.targetName = options.targetName || this.targetName;
- if (!options.isLoading) {
- this.columnLabelValues = _.map(this.columnLabels, function (column) {
- return column.label;
- });
- }
- this.view.update({ rowSize: this.rowSize, isLoading: options.isLoading, targetName: this.targetName });
- }
- });
- return DrillThroughDefinitionDialog;
- });
- //# sourceMappingURL=DrillThroughDefinitionDialog.js.map
|