"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; });