123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- "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(['doT', 'underscore', 'bi/commons/ui/View', 'bacontentnav/ui/widgets/FileSelector', 'bi/commons/ui/content/SingleSelectListControl', 'baglass/utils/Utils', 'baglass/api/Url', 'bi/admin/nls/StringResource', 'text!bi/admin/system/templates/SetHomePageTemplate.html', 'text!bi/commons/ui/template/RadioButton.html', 'bacontentnav/utils/ContentStoreObject'], function (dot, _, View, FileSelector, SingleSelectListControl, Utils, Url, StringResource, SetHomePageTemplate, RadioButton, ContentStoreObject) {
- 'use strict'; //NOSONAR
- var SetHomePageView = View.extend({
- init: function init(options) {
- SetHomePageView.inherited('init', this, arguments);
- _.extend(this, options);
- this.listControl = this._getNewSingleSelectListControl(this.listSpec);
- this.selectorID = _.uniqueId();
- this._url = this._getNewURL();
- this._selectedObjectData = null;
- },
- _getNewSingleSelectListControl: function _getNewSingleSelectListControl(spec) {
- return new SingleSelectListControl(spec);
- },
- _getNewURL: function _getNewURL() {
- return new Url();
- },
- _getNewFileSelector: function _getNewFileSelector(options) {
- return new FileSelector(options);
- },
- render: function render() {
- var getDataDfd = this._getHomePageTypes();
- var templateOptions = {
- options: [{
- name: 'cmObject',
- label: StringResource.get('selectDashboardOrReport')
- }, {
- name: 'perspective',
- label: StringResource.get('selectView')
- }]
- };
- var $Html = $(dot.template(SetHomePageTemplate)(templateOptions));
- for (var i = 0; i < templateOptions.options.length; i++) {
- $Html.find('.homeSelect.' + templateOptions.options[i].name).append(dot.template(RadioButton)({
- label: templateOptions.options[i].label,
- index: i,
- id: this.selectorID,
- controlOnLeft: true
- }));
- }
- this.$el.append($Html);
- this.$el.find('.homeSelect .roundButton').on('primaryaction', this._handleClickSelect.bind(this));
- this.$el.find('.cmObject .roundButton').attr("aria-label", StringResource.get('selectDashboardOrReport'));
- this.$el.find('.perspective .roundButton').attr("aria-label", StringResource.get('selectView'));
- this.listControl.$el = this.$el.find('.injectView.perspective');
- return getDataDfd.then(function (aHomePageTypes) {
- this.fileSelector = this._getNewFileSelector({
- $el: this.$el.find('.injectView.cmObject'),
- placeholder: StringResource.get('name'),
- title: StringResource.get('selectDashboardOrReport'),
- openDialogOptions: {
- 'glassContext': this.glassContext,
- 'typesToOpen': aHomePageTypes,
- 'multiSelect': false,
- 'onOpenCallback': this._setContentPath.bind(this),
- 'dialogTitle': StringResource.get('selectDashboardOrReport'),
- 'primaryBtnText': StringResource.get('select'),
- 'teamContentOnly': true
- }
- });
- return this.fileSelector.render();
- }.bind(this)).then(this.listControl.render.bind(this.listControl)).then(function () {
- if (this.currentValue && this.currentValue.content) {
- return this._url.getObjInfoFromContent(this.glassContext, this.currentValue.content, ['defaultName', 'ancestors']);
- }
- }.bind(this)).catch(this.logger.error.bind(this.logger)).then(this._initSelection.bind(this));
- },
- _handleClickSelect: function _handleClickSelect(event) {
- this._select(event.currentTarget);
- event.stopPropagation();
- return false;
- },
- _select: function _select(rowNode) {
- var $rowNode = $(rowNode);
- this._uncheckCurrentSelection();
- $rowNode.attr('aria-checked', 'true');
- $rowNode.addClass('checked');
- if ($rowNode.parent().hasClass('cmObject')) {
- this._enableFileSelector(true);
- this._enablePerspectiveList(false);
- } else if ($rowNode.parent().hasClass('perspective')) {
- this._enableFileSelector(false);
- this._enablePerspectiveList(true);
- }
- if (this._selectionChanged) {
- this._selectionChanged();
- }
- },
- _uncheckCurrentSelection: function _uncheckCurrentSelection() {
- var $currentFocusedRow = this.$el.find('.homeSelect .roundButton.checked');
- $currentFocusedRow.removeClass('checked');
- $currentFocusedRow.attr('aria-checked', 'false');
- },
- _enableFileSelector: function _enableFileSelector(enable) {
- if (enable) {
- this.fileSelector.enable();
- } else {
- this.fileSelector.disable();
- }
- },
- _enablePerspectiveList: function _enablePerspectiveList(enable) {
- this.listControl.$el.removeClass('disable');
- if (!enable) {
- this.listControl.$el.addClass('disable');
- }
- },
- _getHomePageTypes: function _getHomePageTypes() {
- return Promise.resolve(['exploration', 'report', 'reportView', 'package']);
- },
- _setContentPath: function _setContentPath(selectedObject) {
- this._selectedObjectData = selectedObject[0];
- this._setFileSelectorLabel(selectedObject[0]);
- return this._getUrlMap(selectedObject).then(function (urlMap) {
- this.currentValue = {};
- this.currentValue.perspective = urlMap.perspective;
- this.currentValue.content = urlMap;
- if (this._selectionChanged) {
- this._selectionChanged();
- }
- }.bind(this), this.logger.error.bind(this.logger));
- },
- _initSelection: function _initSelection(objectInfo) {
- var $selectedRadio;
- if (_.isUndefined(this.currentValue.content)) {
- $selectedRadio = this.$el.find('.homeSelect.perspective .roundButton');
- } else {
- $selectedRadio = this.$el.find('.homeSelect.cmObject .roundButton');
- this._setFileSelectorLabel(objectInfo);
- }
- this._select($selectedRadio);
- },
- _setFileSelectorLabel: function _setFileSelectorLabel(objectInfo) {
- var path = objectInfo ? ContentStoreObject.getLocation(objectInfo, true) : StringResource.get('unavailable');
- this.fileSelector.setValue(path);
- },
- getCurrentSelection: function getCurrentSelection() {
- var currentSelection = {
- 'name': '',
- 'value': null
- };
- if (this.isPerspective()) {
- var selectedPerspective = this.listControl.getCurrentSelection();
- if (selectedPerspective) {
- currentSelection = {
- 'name': selectedPerspective.name,
- 'value': {
- perspective: selectedPerspective.name
- }
- };
- }
- } else if (this._selectedObjectData) {
- currentSelection = {
- 'name': this._selectedObjectData.defaultName,
- 'value': this.currentValue
- };
- }
- return currentSelection;
- },
- isPerspective: function isPerspective() {
- var $currentFocusedRow = this.$el.find('.homeSelect .roundButton.checked');
- return $currentFocusedRow.parent().hasClass('perspective');
- },
- _getUrlMap: function _getUrlMap(selectedObject) {
- return Utils.getSharedResourceActionController(this.glassContext, selectedObject[0].type).then(function (module) {
- var context = this.glassContext.addToOptions({
- target: {
- activeObject: {
- aSelectedContext: selectedObject
- }
- },
- options: selectedObject
- });
- var publicContext = {
- urlMap: {
- objRef: selectedObject[0].id,
- type: selectedObject[0].type
- },
- mode: Url.DYNAMIC
- };
- if (selectedObject[0].defaultScreenTip === 'story') {
- publicContext.urlMap.mode = 'story';
- }
- _.extend(publicContext, context);
- return this._url.getUrlMap(module, this.glassContext, publicContext);
- }.bind(this));
- }
- });
- SetHomePageView.NOT_SUPPORTED_TYPE = 'The object type is not supported: ';
- return SetHomePageView;
- });
|