PersonalTab.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2015, 2018
  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/glass/app/ContentView', 'bi/admin/nls/StringResource', 'bi/commons/ui/properties/PropertyUIControl'], function (_, Q, ContentView, StringResource, PropertyUIControl) {
  9. 'use strict'; //NOSONAR: meant to be strict
  10. var PersonalTab = ContentView.extend({
  11. /**
  12. @paran options.el {node} - container dom node
  13. **/
  14. init: function init(options) {
  15. PersonalTab.inherited('init', this, arguments);
  16. _.extend(this, options);
  17. },
  18. _toggleBiDiDropdownEnabled: function _toggleBiDiDropdownEnabled() {
  19. var dropdown = this.$el.find('select.v_baseTextDirection');
  20. var dropdownRow = dropdown.closest('.propertyRow');
  21. if (dropdown.attr('disabled')) {
  22. dropdown.removeAttr('disabled');
  23. dropdownRow.removeClass('disabled');
  24. } else {
  25. dropdown.attr('disabled', 'disabled');
  26. dropdownRow.addClass('disabled');
  27. }
  28. },
  29. _shouldShowHidden: function _shouldShowHidden(obj) {
  30. return _.find(obj.options, function (item) {
  31. return item.name === 'showHiddenObjects';
  32. });
  33. },
  34. _shouldUseA11y: function _shouldUseA11y(obj) {
  35. return _.find(obj.options, function (item) {
  36. return item.name === 'http:\/\/developer.cognos.com\/ceba\/constants\/systemOptionEnum#accessibilityFeatures';
  37. });
  38. },
  39. _shouldBidiEnabled: function _shouldBidiEnabled(obj) {
  40. return _.find(obj.options, function (item) {
  41. return item.name === 'http:\/\/developer.cognos.com\/ceba\/constants\/biDirectionalOptionEnum#biDirectionalFeaturesEnabled';
  42. });
  43. },
  44. _getTextDir: function _getTextDir(obj) {
  45. return _.find(obj.options, function (item) {
  46. return item.name === 'http:\/\/developer.cognos.com\/ceba\/constants\/biDirectionalOptionEnum#baseTextDirection';
  47. });
  48. },
  49. render: function render() {
  50. //NOSONAR
  51. var deferred = Q.defer();
  52. var productLocalesPromise = this.glassContext.services.config.getProductLocales();
  53. var contentLocalesPromise = this.glassContext.services.config.getContentLocales();
  54. var timeZonesPromise = this.glassContext.services.config.getTimeZones();
  55. var serverLocalePromise = this._getServerLocale();
  56. Promise.all([productLocalesPromise, contentLocalesPromise, timeZonesPromise, serverLocalePromise]).then(function (responses) {
  57. var productLocals = responses[0];
  58. var contentLocals = responses[1];
  59. var timeZones = responses[2]; // check write permission
  60. var obj = this.objectInfo;
  61. this.writable = obj.permissions && obj.permissions.indexOf('write') > -1 ? true : false;
  62. var textDirs = this.glassContext.services.config._getBaseTextDirections();
  63. var showHidden = this._shouldShowHidden(obj);
  64. var useA11y = this._shouldUseA11y(obj);
  65. var bidiEnabled = this._shouldBidiEnabled(obj);
  66. bidiEnabled = bidiEnabled ? bidiEnabled : {
  67. value: false
  68. };
  69. var textDir = this._getTextDir(obj);
  70. obj.contentLocale = obj.contentLocale ? obj.contentLocale : this.serverLocale;
  71. obj.productLocale = obj.productLocale ? obj.productLocale : this.serverLocale;
  72. obj.timeZoneID = obj.timeZoneID ? obj.timeZoneID : "America/New_York";
  73. var timezoneOpts = _.map(timeZones, function (label, value) {
  74. return {
  75. 'label': label,
  76. 'value': value,
  77. 'selected': this.objectInfo.timeZoneID === value
  78. };
  79. }.bind(this));
  80. var textDirOpts = _.map(textDirs, function (label, value) {
  81. var actValue = 'http:\/\/developer.cognos.com\/ceba\/constants\/baseTextDirectionEnum#' + value;
  82. var currentVal = textDir ? textDir.value : "";
  83. return {
  84. 'label': label,
  85. 'value': actValue,
  86. 'selected': currentVal === actValue
  87. };
  88. }.bind(this));
  89. var reportFormatsOpts = _.map(this.glassContext.services.config._getFormats(), function (label, value) {
  90. return {
  91. 'label': label,
  92. 'value': value,
  93. 'selected': this.objectInfo.format === value
  94. };
  95. }.bind(this));
  96. var productLocalOpts = _.map(productLocals, function (label, value) {
  97. return {
  98. 'label': label,
  99. 'value': value,
  100. 'selected': this.objectInfo.productLocale === value
  101. };
  102. }.bind(this));
  103. var contentLocalOpts = _.map(contentLocals, function (label, value) {
  104. return {
  105. 'label': label,
  106. 'value': value,
  107. 'selected': this.objectInfo.contentLocale === value
  108. };
  109. }.bind(this));
  110. this._oPropertyUIControl = new PropertyUIControl({
  111. 'el': this.$el,
  112. 'glassContext': this.glassContext,
  113. 'slideout': this.slideout,
  114. 'items': [{
  115. 'name': 'showHiddenObjects',
  116. 'label': StringResource.get('showHiddenObjects'),
  117. 'checked': showHidden ? showHidden.value : false,
  118. 'type': 'CheckBox',
  119. 'disabled': !this.writable
  120. }, {
  121. 'type': 'Separator'
  122. }, {
  123. 'name': 'format',
  124. 'label': StringResource.get('reportFormat'),
  125. 'options': reportFormatsOpts,
  126. 'type': 'DropDown',
  127. 'readOnly': !this.writable
  128. }, {
  129. 'type': 'Separator'
  130. }, {
  131. 'name': 'http://developer.cognos.com/ceba/constants/systemOptionEnum#accessibilityFeatures',
  132. 'label': StringResource.get('useAccessibilityFeatures'),
  133. 'checked': useA11y ? useA11y.value : false,
  134. 'type': 'CheckBox',
  135. 'disabled': !this.writable
  136. }, {
  137. 'label': StringResource.get('regionalOptions'),
  138. 'type': 'SectionLabel'
  139. }, {
  140. 'name': 'timeZoneID',
  141. 'label': StringResource.get('timeZoneID'),
  142. 'options': timezoneOpts,
  143. 'parentEl': this.slideout.$el,
  144. 'type': 'DropDown',
  145. 'position': 'left',
  146. 'readOnly': !this.writable
  147. }, {
  148. 'type': 'Separator'
  149. }, {
  150. 'name': 'productLocale',
  151. 'label': StringResource.get('productLocale'),
  152. 'options': productLocalOpts,
  153. 'parentEl': this.slideout.$el,
  154. 'type': 'DropDown',
  155. 'position': 'left',
  156. 'readOnly': !this.writable
  157. }, {
  158. 'type': 'Separator'
  159. }, {
  160. 'name': 'contentLocale',
  161. 'label': StringResource.get('contentLocale'),
  162. 'options': contentLocalOpts,
  163. 'parentEl': this.slideout.$el,
  164. 'type': 'DropDown',
  165. 'position': 'left',
  166. 'readOnly': !this.writable
  167. }, {
  168. 'type': 'Separator'
  169. }, {
  170. 'name': 'biDirectionalFeaturesEnabled',
  171. 'label': StringResource.get('biDirectionalFeaturesEnabled'),
  172. 'checked': bidiEnabled.value,
  173. 'type': 'CheckBox',
  174. 'disabled': !this.writable,
  175. 'onChange': this._toggleBiDiDropdownEnabled.bind(this)
  176. }, {
  177. 'type': 'Separator'
  178. }, {
  179. 'name': 'baseTextDirection',
  180. 'label': StringResource.get('baseTextDirection'),
  181. 'options': textDirOpts,
  182. 'type': 'DropDown',
  183. 'disabled': !bidiEnabled.value,
  184. 'readOnly': !this.writable
  185. }]
  186. });
  187. this._oPropertyUIControl.render().then(function () {
  188. deferred.resolve(this);
  189. }.bind(this));
  190. }.bind(this), deferred.reject);
  191. return deferred.promise;
  192. },
  193. _getServerLocale: function _getServerLocale() {
  194. var deferred = $.Deferred();
  195. var ajaxService = this.glassContext.services.ajax;
  196. var url = 'v1/configuration/keys/serverLocale';
  197. ajaxService.ajax({
  198. 'dataType': 'json',
  199. 'type': 'GET',
  200. 'url': url
  201. }).then(function (result) {
  202. this.serverLocale = result.serverLocale;
  203. deferred.resolve(this.serverLocale);
  204. }.bind(this));
  205. return deferred.promise();
  206. },
  207. onClose: function onClose() {
  208. return this._oPropertyUIControl.onClose();
  209. },
  210. getModifiedProperties: function getModifiedProperties() {
  211. return this._oPropertyUIControl.getModifiedProperties();
  212. }
  213. });
  214. return PersonalTab;
  215. });