123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2016, 2017
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['q', 'jquery', 'underscore', 'bi/admin/nls/StringResource', 'bi/commons/ui/core/Class', 'bi/commons/ui/ButtonBar', 'bi/commons/ui/SlideoutHeaderView', 'bi/commons/ui/StandardLayoutView', 'bi/glass/utils/ClassFactory'], function (Q, $, _, StringResource, Class, ButtonBar, SlideoutHeaderView, StandardLayoutView, classFactory) {
- var BasePerspectiveListView = Class.extend({
- previewDialogModule: 'bi/glass/common/ui/PreviewDialog',
- APPLY_BUTTON_ID: 'applySelection',
- PREVIEW_BUTTON_ID: 'previewPerspective',
- init: function init(options) {
- BasePerspectiveListView.inherited('init', this, arguments);
- _.extend(this, options);
- this._contentView = this._getNewStandardLayoutView();
- this._header = this._getNewSlideoutHeaderView({
- title: this.title,
- slideout: this.slideout
- });
- this._contentView.headerView = this._header;
- this._footer = this._getNewButtonBar({
- buttons: [{
- 'id': this.PREVIEW_BUTTON_ID,
- 'label': StringResource.get('preview'),
- 'onSelect': this._showPreview.bind(this)
- }, {
- 'id': this.APPLY_BUTTON_ID,
- 'label': StringResource.get('apply'),
- 'onSelect': this._applyPerspective.bind(this)
- }]
- });
- this._contentView.footerView = this._footer;
- this._selectionChanged = this._selectionChanged.bind(this);
- },
- _getNewStandardLayoutView: function _getNewStandardLayoutView(options) {
- return new StandardLayoutView(options);
- },
- _getNewSlideoutHeaderView: function _getNewSlideoutHeaderView(options) {
- return new SlideoutHeaderView(options);
- },
- _getNewButtonBar: function _getNewButtonBar(options) {
- return new ButtonBar(options);
- },
- _applyPerspective: function _applyPerspective() {
- var currentSelection = this._getCurrentSelection();
- if (currentSelection && _.isFunction(this.onApplyCallback)) {
- if (currentSelection.name === BasePerspectiveListView.DEFAULT) {
- currentSelection.value = null;
- }
- this.onApplyCallback(currentSelection);
- }
- ;
- },
- _showPreview: function _showPreview() {
- var currentSelection = this._getCurrentSelection();
- if (currentSelection) {
- return Q(this._getPreviewMap(currentSelection)).then(function (map) {
- var dialogOptions = {
- glassContext: this.glassContext,
- urlMap: map
- };
- return classFactory.instantiate(this.previewDialogModule, dialogOptions).then(function (dialog) {
- dialog.open();
- }.bind(this));
- }.bind(this)).fail(function () {
- this.glassContext.appController.showToast(StringResource.get('previewDialogFailed'), {
- type: 'error'
- });
- return Q.reject();
- }.bind(this));
- } else {
- this.glassContext.appController.showToast(StringResource.get('invalidPerspective'), {
- type: 'error'
- });
- return Q.reject();
- }
- },
- _getPreviewMap: function _getPreviewMap(currentSelection) {
- var map;
- if (currentSelection.value !== undefined) {
- if (currentSelection.name === BasePerspectiveListView.DEFAULT) {
- // getDefaultHome returns a Promise which will be resolved to the map
- map = this._getDefaultHome();
- } else {
- map = currentSelection.value.content || {};
- map.perspective = currentSelection.value.perspective;
- }
- } else {
- map = {
- 'perspective': currentSelection.name
- };
- }
- return map;
- },
- _getListSpec: function _getListSpec() {
- return {
- 'defaultSort': [1, 'asc'],
- 'getData': this._getPerspectives.bind(this),
- 'columns': this._getListColumnSpecification(),
- 'a11yLabel': this.title,
- 'glassContext': this.glassContext,
- 'selectCallback': this._selectionChanged.bind(this)
- };
- },
- _getListColumnSpecification: function _getListColumnSpecification() {
- return [{
- 'module': 'bi/content_apps/common/ui/list_columns/RadioButtons'
- }, {
- 'module': 'bacontentnav/common/ui/list_columns/Text',
- 'propertyName': 'name',
- '_bNavigable': true,
- 'label': StringResource.get('name'),
- 'scope': 'row'
- }];
- },
- _getCurrentSelection: function _getCurrentSelection() {
- var selection;
- if (this._body && _.isFunction(this._body.getCurrentSelection)) {
- selection = this._body.getCurrentSelection();
- }
- return selection;
- },
- _selectionChanged: function _selectionChanged() {
- var currentSelection = this._getCurrentSelection();
- if (currentSelection.name) {
- this._footer.enableAllButtons();
- } else {
- this._footer.disableAllButtons();
- }
- },
- _getDefaultHome: function _getDefaultHome() {
- return this.glassContext.services.ajax.ajax({
- 'type': 'GET',
- 'url': 'v1/system_profile_settings'
- }).then(function (response) {
- return response.defaultHome;
- });
- },
- remove: function remove() {
- this._contentView.remove();
- },
- render: function render() {
- return this._contentView.render();
- }
- });
- BasePerspectiveListView.DEFAULT = StringResource.get('default');
- return BasePerspectiveListView;
- });
|