123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2015, 2018
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', 'q', 'bi/glass/app/ContentView', 'bi/admin/nls/StringResource', 'bi/commons/ui/properties/PropertyUIControl'], function (_, Q, ContentView, StringResource, PropertyUIControl) {
- 'use strict'; //NOSONAR: meant to be strict
- var PersonalTab = ContentView.extend({
- /**
- @paran options.el {node} - container dom node
- **/
- init: function init(options) {
- PersonalTab.inherited('init', this, arguments);
- _.extend(this, options);
- },
- _toggleBiDiDropdownEnabled: function _toggleBiDiDropdownEnabled() {
- var dropdown = this.$el.find('select.v_baseTextDirection');
- var dropdownRow = dropdown.closest('.propertyRow');
- if (dropdown.attr('disabled')) {
- dropdown.removeAttr('disabled');
- dropdownRow.removeClass('disabled');
- } else {
- dropdown.attr('disabled', 'disabled');
- dropdownRow.addClass('disabled');
- }
- },
- _shouldShowHidden: function _shouldShowHidden(obj) {
- return _.find(obj.options, function (item) {
- return item.name === 'showHiddenObjects';
- });
- },
- _shouldUseA11y: function _shouldUseA11y(obj) {
- return _.find(obj.options, function (item) {
- return item.name === 'http:\/\/developer.cognos.com\/ceba\/constants\/systemOptionEnum#accessibilityFeatures';
- });
- },
- _shouldBidiEnabled: function _shouldBidiEnabled(obj) {
- return _.find(obj.options, function (item) {
- return item.name === 'http:\/\/developer.cognos.com\/ceba\/constants\/biDirectionalOptionEnum#biDirectionalFeaturesEnabled';
- });
- },
- _getTextDir: function _getTextDir(obj) {
- return _.find(obj.options, function (item) {
- return item.name === 'http:\/\/developer.cognos.com\/ceba\/constants\/biDirectionalOptionEnum#baseTextDirection';
- });
- },
- render: function render() {
- //NOSONAR
- var deferred = Q.defer();
- var productLocalesPromise = this.glassContext.services.config.getProductLocales();
- var contentLocalesPromise = this.glassContext.services.config.getContentLocales();
- var timeZonesPromise = this.glassContext.services.config.getTimeZones();
- var serverLocalePromise = this._getServerLocale();
- Promise.all([productLocalesPromise, contentLocalesPromise, timeZonesPromise, serverLocalePromise]).then(function (responses) {
- var productLocals = responses[0];
- var contentLocals = responses[1];
- var timeZones = responses[2]; // check write permission
- var obj = this.objectInfo;
- this.writable = obj.permissions && obj.permissions.indexOf('write') > -1 ? true : false;
- var textDirs = this.glassContext.services.config._getBaseTextDirections();
- var showHidden = this._shouldShowHidden(obj);
- var useA11y = this._shouldUseA11y(obj);
- var bidiEnabled = this._shouldBidiEnabled(obj);
- bidiEnabled = bidiEnabled ? bidiEnabled : {
- value: false
- };
- var textDir = this._getTextDir(obj);
- obj.contentLocale = obj.contentLocale ? obj.contentLocale : this.serverLocale;
- obj.productLocale = obj.productLocale ? obj.productLocale : this.serverLocale;
- obj.timeZoneID = obj.timeZoneID ? obj.timeZoneID : "America/New_York";
- var timezoneOpts = _.map(timeZones, function (label, value) {
- return {
- 'label': label,
- 'value': value,
- 'selected': this.objectInfo.timeZoneID === value
- };
- }.bind(this));
- var textDirOpts = _.map(textDirs, function (label, value) {
- var actValue = 'http:\/\/developer.cognos.com\/ceba\/constants\/baseTextDirectionEnum#' + value;
- var currentVal = textDir ? textDir.value : "";
- return {
- 'label': label,
- 'value': actValue,
- 'selected': currentVal === actValue
- };
- }.bind(this));
- var reportFormatsOpts = _.map(this.glassContext.services.config._getFormats(), function (label, value) {
- return {
- 'label': label,
- 'value': value,
- 'selected': this.objectInfo.format === value
- };
- }.bind(this));
- var productLocalOpts = _.map(productLocals, function (label, value) {
- return {
- 'label': label,
- 'value': value,
- 'selected': this.objectInfo.productLocale === value
- };
- }.bind(this));
- var contentLocalOpts = _.map(contentLocals, function (label, value) {
- return {
- 'label': label,
- 'value': value,
- 'selected': this.objectInfo.contentLocale === value
- };
- }.bind(this));
- this._oPropertyUIControl = new PropertyUIControl({
- 'el': this.$el,
- 'glassContext': this.glassContext,
- 'slideout': this.slideout,
- 'items': [{
- 'name': 'showHiddenObjects',
- 'label': StringResource.get('showHiddenObjects'),
- 'checked': showHidden ? showHidden.value : false,
- 'type': 'CheckBox',
- 'disabled': !this.writable
- }, {
- 'type': 'Separator'
- }, {
- 'name': 'format',
- 'label': StringResource.get('reportFormat'),
- 'options': reportFormatsOpts,
- 'type': 'DropDown',
- 'readOnly': !this.writable
- }, {
- 'type': 'Separator'
- }, {
- 'name': 'http://developer.cognos.com/ceba/constants/systemOptionEnum#accessibilityFeatures',
- 'label': StringResource.get('useAccessibilityFeatures'),
- 'checked': useA11y ? useA11y.value : false,
- 'type': 'CheckBox',
- 'disabled': !this.writable
- }, {
- 'label': StringResource.get('regionalOptions'),
- 'type': 'SectionLabel'
- }, {
- 'name': 'timeZoneID',
- 'label': StringResource.get('timeZoneID'),
- 'options': timezoneOpts,
- 'parentEl': this.slideout.$el,
- 'type': 'DropDown',
- 'position': 'left',
- 'readOnly': !this.writable
- }, {
- 'type': 'Separator'
- }, {
- 'name': 'productLocale',
- 'label': StringResource.get('productLocale'),
- 'options': productLocalOpts,
- 'parentEl': this.slideout.$el,
- 'type': 'DropDown',
- 'position': 'left',
- 'readOnly': !this.writable
- }, {
- 'type': 'Separator'
- }, {
- 'name': 'contentLocale',
- 'label': StringResource.get('contentLocale'),
- 'options': contentLocalOpts,
- 'parentEl': this.slideout.$el,
- 'type': 'DropDown',
- 'position': 'left',
- 'readOnly': !this.writable
- }, {
- 'type': 'Separator'
- }, {
- 'name': 'biDirectionalFeaturesEnabled',
- 'label': StringResource.get('biDirectionalFeaturesEnabled'),
- 'checked': bidiEnabled.value,
- 'type': 'CheckBox',
- 'disabled': !this.writable,
- 'onChange': this._toggleBiDiDropdownEnabled.bind(this)
- }, {
- 'type': 'Separator'
- }, {
- 'name': 'baseTextDirection',
- 'label': StringResource.get('baseTextDirection'),
- 'options': textDirOpts,
- 'type': 'DropDown',
- 'disabled': !bidiEnabled.value,
- 'readOnly': !this.writable
- }]
- });
- this._oPropertyUIControl.render().then(function () {
- deferred.resolve(this);
- }.bind(this));
- }.bind(this), deferred.reject);
- return deferred.promise;
- },
- _getServerLocale: function _getServerLocale() {
- var deferred = $.Deferred();
- var ajaxService = this.glassContext.services.ajax;
- var url = 'v1/configuration/keys/serverLocale';
- ajaxService.ajax({
- 'dataType': 'json',
- 'type': 'GET',
- 'url': url
- }).then(function (result) {
- this.serverLocale = result.serverLocale;
- deferred.resolve(this.serverLocale);
- }.bind(this));
- return deferred.promise();
- },
- onClose: function onClose() {
- return this._oPropertyUIControl.onClose();
- },
- getModifiedProperties: function getModifiedProperties() {
- return this._oPropertyUIControl.getModifiedProperties();
- }
- });
- return PersonalTab;
- });
|