123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2017
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', 'q', 'bi/commons/ui/core/Class', 'bi/admin/nls/StringResource', 'bi/commons/ui/properties/PropertyUIControl'], function (_, Q, Class, StringResource, PropertyUIControl) {
- 'use strict'; //NOSONAR: meant to be strict
- var RegionalOptionsModule = Class.extend({
- /**
- @paran options.el {node} - container dom node
- **/
- items: {},
- init: function init(options) {
- RegionalOptionsModule.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');
- }
- },
- getRegionalOptions: function getRegionalOptions(options) {
- //NOSONAR
- 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();
- return Promise.all([productLocalesPromise, contentLocalesPromise, timeZonesPromise, serverLocalePromise]).then(function (response) {
- //NOSONAR
- var productLocals = response[0];
- var contentLocals = response[1];
- var timeZones = response[2]; // check write permission
- var obj = options;
- var textDirs = this.glassContext.services.config._getBaseTextDirections();
- obj.biDirectionalFeaturesEnabled = obj.biDirectionalFeaturesEnabled && obj.biDirectionalFeaturesEnabled === true ? true : false;
- obj.baseTextDirection = obj.baseTextDirection ? obj.baseTextDirection : 'AUTO';
- 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': obj.timeZoneID === value
- };
- }.bind(this));
- var textDirOpts = _.map(textDirs, function (label, value) {
- return {
- 'label': label,
- 'value': value,
- 'selected': value === obj.baseTextDirection
- };
- }.bind(this));
- var productLocalOpts = _.map(productLocals, function (label, value) {
- return {
- 'label': label,
- 'value': value,
- 'selected': obj.productLocale === value
- };
- }.bind(this));
- var contentLocalOpts = _.map(contentLocals, function (label, value) {
- return {
- 'label': label,
- 'value': value,
- 'selected': obj.contentLocale === value
- };
- }.bind(this));
- return this.items = [{
- 'name': 'timeZoneID',
- 'label': StringResource.get('timeZoneID'),
- 'options': timezoneOpts,
- 'parentEl': this.slideout.$el,
- 'type': 'DropDown',
- 'position': 'left'
- }, {
- 'type': 'Separator'
- }, {
- 'name': 'productLocale',
- 'label': StringResource.get('productLocale'),
- 'options': productLocalOpts,
- 'parentEl': this.slideout.$el,
- 'type': 'DropDown',
- 'position': 'left'
- }, {
- 'type': 'Separator'
- }, {
- 'name': 'contentLocale',
- 'label': StringResource.get('contentLocale'),
- 'options': contentLocalOpts,
- 'parentEl': this.slideout.$el,
- 'type': 'DropDown',
- 'position': 'left'
- }, {
- 'type': 'Separator'
- }, {
- 'name': 'biDirectionalFeaturesEnabled',
- 'label': StringResource.get('biDirectionalFeaturesEnabled'),
- 'checked': obj.biDirectionalFeaturesEnabled,
- 'type': 'CheckBox',
- 'onChange': this._toggleBiDiDropdownEnabled.bind(this)
- }, {
- 'type': 'Separator'
- }, {
- 'name': 'baseTextDirection',
- 'label': StringResource.get('baseTextDirection'),
- 'options': textDirOpts,
- 'type': 'DropDown',
- 'disabled': !obj.biDirectionalFeaturesEnabled
- }];
- }.bind(this));
- },
- _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();
- }
- });
- return RegionalOptionsModule;
- });
|