| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 | "use strict";/** * Licensed Materials - Property of IBM * IBM Cognos Products: Cognos Analytics * Copyright IBM Corp. 2016, 2018 * US Government Users Restricted Rights - Use, duplication or disclosure * restricted by GSA ADP Schedule Contract with IBM Corp. */define(['underscore', 'q', 'jquery', 'bi/glass/app/ContentView', 'bi/glass/app/services/ConfigService', 'bi/glass/api/Url', 'bi/admin/nls/StringResource', 'bi/commons/ui/properties/PropertyUIControl', 'bi/admin/multitenancy/services/TenantsCustomizationService'], function (_, Q, $, View, Config, Url, StringResource, PropertyUIControl, TenantsCustomizationService) {  'use strict'; //NOSONAR: meant to be strict  var ViewsTab = View.extend({    init: function init(options) {      ViewsTab.inherited('init', this, arguments);      $.extend(this, options);      this.glassContext = options.glassContext;      this.tenantsCustomizationService = this._getNewTenantsCustomizationService({        glassContext: this.glassContext      });      this._url = this._getNewUrl();    },    _getNewUrl: function _getNewUrl(options) {      return new Url(options);    },    _getNewTenantsCustomizationService: function _getNewTenantsCustomizationService(options) {      return new TenantsCustomizationService(options);    },    _getNewPropertyUIControl: function _getNewPropertyUIControl(spec) {      return new PropertyUIControl(spec);    },    render: function render() {      var loginProm = this._getDefaultLogin();      var welcomeProm;      if (this.isPortalAdmin && this.tenantID) {        welcomeProm = this.tenantsCustomizationService.getCustomizations(this.tenantID).then(function (resolve) {          var deferred = Q.defer();          deferred.resolve(resolve.ui_homePage);          return deferred.promise;        });      } else {        welcomeProm = this._getDefaultHome();      }      return Promise.all([welcomeProm, loginProm]).then(function (defaults) {        var defaultHome = defaults[0];        var defaultLogin = defaults[1];        var aControls = [];        this.currentHome = defaultHome;        this.currentLogin = defaultLogin;        return this.getHomeViewValue(defaultHome).then(function (homeViewValue) {          this.currentHomeViewValue = homeViewValue;          aControls.push({            'type': 'SingleLineValue',            'name': 'welcomePage',            'label': StringResource.get('homePage'),            'value': homeViewValue,            'editCallback': function () {              this.homePageSlideout = this.glassContext.appController.showSlideOut({                parent: this.slideout,                width: '400px',                label: StringResource.get('homePage'),                content: {                  module: 'bi/admin/system/HomePerspectiveListView',                  glassContext: this.glassContext,                  title: StringResource.get('homePage'),                  currentValue: this.currentHome,                  homeViewValue: this.currentHomeViewValue,                  onApplyCallback: this.isPortalAdmin && this.tenantID ? this.applyHomeForTenant.bind(this) : this.applyHome.bind(this),                  global: true                }              });            }.bind(this)          });          if (this.isSysAdmin) {            aControls.push({              'type': 'SingleLineValue',              'name': 'loginPage',              'label': StringResource.get('signInPage'),              'value': defaultLogin,              'editCallback': function () {                this.loginPageSlideout = this.glassContext.appController.showSlideOut({                  parent: this.slideout,                  width: '400px',                  label: StringResource.get('signInPage'),                  content: {                    module: 'bi/admin/system/LoginPerspectiveListView',                    glassContext: this.glassContext,                    title: StringResource.get('signInPage'),                    currentValue: this.currentLogin,                    onApplyCallback: this.applyLoginPerspective.bind(this)                  }                });              }.bind(this)            });          }          this._oPropertyUIControl = this._getNewPropertyUIControl({            'el': this.$el,            'glassContext': this.glassContext,            'items': aControls          });          return this._oPropertyUIControl.render();        }.bind(this));      }.bind(this));    },    getHomeViewValue: function getHomeViewValue(defaultHome) {      return Promise.try(function () {        if (_.isUndefined(defaultHome.content)) {          return defaultHome.perspective;        } else {          return this._getGlobalHomeViewValue(defaultHome);        }      }.bind(this));    },    _getTenantedHomeViewValue: function _getTenantedHomeViewValue(resolve) {      this.tenantsCustomizationService.getCustomizations(this.tenantID).then(function (data) {        resolve(data.ui_homePage);      });    },    _getGlobalHomeViewValue: function _getGlobalHomeViewValue(defaultHome) {      return this._url.getObjInfoFromContent(this.glassContext, defaultHome.content, ['defaultName']).then(function (object) {        return object.defaultName;      }).catch(function (err) {        this.logger.error(err);        return StringResource.get('unavailable');      }.bind(this));    },    applyHomeForTenant: function applyHomeForTenant(selection) {      return this.tenantsCustomizationService.setHomePage(this.tenantID, selection.value).then(function (result) {        this._tenantCustomizations = result;        this.currentHome = selection.value;        this.currentHomeViewValue = selection.name;        this._oPropertyUIControl.getProperty('welcomePage').setValue(selection.name);        this.homePageSlideout.hide();        this.glassContext.appController.showToast(StringResource.get('defaultHomeViewSet'));      }.bind(this), function () {        this.glassContext.appController.showToast(StringResource.get('defaultHomeViewError'), {          type: 'error'        });      }.bind(this));    },    applyHome: function applyHome(selection) {      var defaultHomeObj = {        'ui_homePage': selection.value      };      return this.glassContext.services.ajax.ajax({        'contentType': 'application/json',        'type': 'PUT',        'url': 'v1/system_profile_settings',        'data': JSON.stringify(defaultHomeObj)      }).then(function () {        this._oPropertyUIControl.getProperty('welcomePage').setValue(selection.name);        this.currentHome = selection.value;        this.currentHomeViewValue = selection.name;        this.homePageSlideout.hide();        this.glassContext.appController.showToast(StringResource.get('defaultHomeViewSet'));      }.bind(this), function () {        this.glassContext.appController.showToast(StringResource.get('defaultHomeViewError'), {          type: 'error'        });      }.bind(this));    },    applyLoginPerspective: function applyLoginPerspective(selection) {      var defaultLoginObj = {        'ui_loginPage': selection.name      };      return this.glassContext.services.ajax.ajax({        'contentType': 'application/json',        'type': 'PUT',        'url': 'v1/system_profile_settings',        'data': JSON.stringify(defaultLoginObj)      }).then(function () {        this._oPropertyUIControl.getProperty('loginPage').setValue(selection.name);        this.currentLogin = selection.name;        this.loginPageSlideout.hide();        this.glassContext.appController.showToast(StringResource.get('defaultLoginViewSet'));      }.bind(this), function () {        this.glassContext.appController.showToast(StringResource.get('defaultLoginViewError'), {          type: 'error'        });      }.bind(this));    },    _getDefaultLogin: function _getDefaultLogin() {      return this.glassContext.services.ajax.ajax({        'type': 'GET',        'url': 'v1/system_profile_settings'      }).then(function (response) {        if (!response.ui_loginPage) {          return this.glassContext.services.config.getDefaultLogin();        }        return response.ui_loginPage;      }.bind(this));    },    _getDefaultHome: function _getDefaultHome() {      return this.glassContext.services.ajax.ajax({        'type': 'GET',        'url': 'v1/system_profile_settings'      }).then(function (response) {        if (!response.ui_homePage) {          return this.glassContext.services.config.getDefaultHome();        }        return response.ui_homePage;      }.bind(this));    },    remove: function remove() {      ViewsTab.inherited('remove', this, arguments);      this._oPropertyUIControl.remove();    }  });  return ViewsTab;});
 |