RegionalOptionsModule.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2017
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['underscore', 'q', 'bi/commons/ui/core/Class', 'bi/admin/nls/StringResource', 'bi/commons/ui/properties/PropertyUIControl'], function (_, Q, Class, StringResource, PropertyUIControl) {
  9. 'use strict'; //NOSONAR: meant to be strict
  10. var RegionalOptionsModule = Class.extend({
  11. /**
  12. @paran options.el {node} - container dom node
  13. **/
  14. items: {},
  15. init: function init(options) {
  16. RegionalOptionsModule.inherited('init', this, arguments);
  17. _.extend(this, options);
  18. },
  19. _toggleBiDiDropdownEnabled: function _toggleBiDiDropdownEnabled() {
  20. var dropdown = this.$el.find('select.v_baseTextDirection');
  21. var dropdownRow = dropdown.closest('.propertyRow');
  22. if (dropdown.attr('disabled')) {
  23. dropdown.removeAttr('disabled');
  24. dropdownRow.removeClass('disabled');
  25. } else {
  26. dropdown.attr('disabled', 'disabled');
  27. dropdownRow.addClass('disabled');
  28. }
  29. },
  30. getRegionalOptions: function getRegionalOptions(options) {
  31. //NOSONAR
  32. var productLocalesPromise = this.glassContext.services.config.getProductLocales();
  33. var contentLocalesPromise = this.glassContext.services.config.getContentLocales();
  34. var timeZonesPromise = this.glassContext.services.config.getTimeZones();
  35. var serverLocalePromise = this._getServerLocale();
  36. return Promise.all([productLocalesPromise, contentLocalesPromise, timeZonesPromise, serverLocalePromise]).then(function (response) {
  37. //NOSONAR
  38. var productLocals = response[0];
  39. var contentLocals = response[1];
  40. var timeZones = response[2]; // check write permission
  41. var obj = options;
  42. var textDirs = this.glassContext.services.config._getBaseTextDirections();
  43. obj.biDirectionalFeaturesEnabled = obj.biDirectionalFeaturesEnabled && obj.biDirectionalFeaturesEnabled === true ? true : false;
  44. obj.baseTextDirection = obj.baseTextDirection ? obj.baseTextDirection : 'AUTO';
  45. obj.contentLocale = obj.contentLocale ? obj.contentLocale : this.serverLocale;
  46. obj.productLocale = obj.productLocale ? obj.productLocale : this.serverLocale;
  47. obj.timeZoneID = obj.timeZoneID ? obj.timeZoneID : "America/New_York";
  48. var timezoneOpts = _.map(timeZones, function (label, value) {
  49. return {
  50. 'label': label,
  51. 'value': value,
  52. 'selected': obj.timeZoneID === value
  53. };
  54. }.bind(this));
  55. var textDirOpts = _.map(textDirs, function (label, value) {
  56. return {
  57. 'label': label,
  58. 'value': value,
  59. 'selected': value === obj.baseTextDirection
  60. };
  61. }.bind(this));
  62. var productLocalOpts = _.map(productLocals, function (label, value) {
  63. return {
  64. 'label': label,
  65. 'value': value,
  66. 'selected': obj.productLocale === value
  67. };
  68. }.bind(this));
  69. var contentLocalOpts = _.map(contentLocals, function (label, value) {
  70. return {
  71. 'label': label,
  72. 'value': value,
  73. 'selected': obj.contentLocale === value
  74. };
  75. }.bind(this));
  76. return this.items = [{
  77. 'name': 'timeZoneID',
  78. 'label': StringResource.get('timeZoneID'),
  79. 'options': timezoneOpts,
  80. 'parentEl': this.slideout.$el,
  81. 'type': 'DropDown',
  82. 'position': 'left'
  83. }, {
  84. 'type': 'Separator'
  85. }, {
  86. 'name': 'productLocale',
  87. 'label': StringResource.get('productLocale'),
  88. 'options': productLocalOpts,
  89. 'parentEl': this.slideout.$el,
  90. 'type': 'DropDown',
  91. 'position': 'left'
  92. }, {
  93. 'type': 'Separator'
  94. }, {
  95. 'name': 'contentLocale',
  96. 'label': StringResource.get('contentLocale'),
  97. 'options': contentLocalOpts,
  98. 'parentEl': this.slideout.$el,
  99. 'type': 'DropDown',
  100. 'position': 'left'
  101. }, {
  102. 'type': 'Separator'
  103. }, {
  104. 'name': 'biDirectionalFeaturesEnabled',
  105. 'label': StringResource.get('biDirectionalFeaturesEnabled'),
  106. 'checked': obj.biDirectionalFeaturesEnabled,
  107. 'type': 'CheckBox',
  108. 'onChange': this._toggleBiDiDropdownEnabled.bind(this)
  109. }, {
  110. 'type': 'Separator'
  111. }, {
  112. 'name': 'baseTextDirection',
  113. 'label': StringResource.get('baseTextDirection'),
  114. 'options': textDirOpts,
  115. 'type': 'DropDown',
  116. 'disabled': !obj.biDirectionalFeaturesEnabled
  117. }];
  118. }.bind(this));
  119. },
  120. _getServerLocale: function _getServerLocale() {
  121. var deferred = $.Deferred();
  122. var ajaxService = this.glassContext.services.ajax;
  123. var url = 'v1/configuration/keys/serverLocale';
  124. ajaxService.ajax({
  125. 'dataType': 'json',
  126. 'type': 'GET',
  127. 'url': url
  128. }).then(function (result) {
  129. this.serverLocale = result.serverLocale;
  130. deferred.resolve(this.serverLocale);
  131. }.bind(this));
  132. return deferred.promise();
  133. }
  134. });
  135. return RegionalOptionsModule;
  136. });