PagePropertiesProvider.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Business Analytics (C) Copyright IBM Corp. 2019, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['../../../app/nls/StringResources', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../lib/@waca/dashboard-common/dist/api/PropertiesProviderAPI', '../util/IconList', 'underscore'], function (StringResources, APIFactory, PropertiesProviderAPI, IconList, _) {
  9. var PageProperties = function () {
  10. function PageProperties(options) {
  11. _classCallCheck(this, PageProperties);
  12. this.dashboard = options.dashboardAPI;
  13. this.content = options.content;
  14. this.content.getFeature('Properties').registerProvider(this.getAPI());
  15. this._icons = options.features['Dashboard.Icons'];
  16. }
  17. PageProperties.prototype.getAPI = function getAPI() {
  18. return APIFactory.createAPI(this, [PropertiesProviderAPI]);
  19. };
  20. PageProperties.prototype._isTopLevelPage = function _isTopLevelPage() {
  21. return !this.content.getContainer();
  22. };
  23. PageProperties.prototype.getPropertyList = function getPropertyList() {
  24. var _this = this;
  25. if (this._isTopLevelPage()) {
  26. return [];
  27. }
  28. var restoreMasterStyling = function restoreMasterStyling() {
  29. var transaction = _this.dashboard.getFeature('Transaction');
  30. var transactionToken = transaction.startTransaction();
  31. _this.content.setPropertyValue('tabTextColor', 'transparent', transactionToken);
  32. _this.content.setPropertyValue('tabSelectedLineColor', 'transparent', transactionToken);
  33. _this.content.setPropertyValue('tabBackgroundColor', 'transparent', transactionToken);
  34. _this.content.setPropertyValue('tabIconColor', 'transparent', transactionToken);
  35. transaction.endTransaction(transactionToken);
  36. _this.dashboard.triggerDashboardEvent('properties:refreshChild', {
  37. content: _this.content,
  38. focusSelector: '.clickCallback_left_0_tabRestoreDefaults'
  39. });
  40. };
  41. var translationService = this.dashboard.getFeature('TranslationService');
  42. return [{
  43. id: 'title',
  44. getPropertyValue: function getPropertyValue() {
  45. var layoutModel = _this.getLayoutModel();
  46. return layoutModel.get('title');
  47. },
  48. setPropertyValue: function setPropertyValue(value) {
  49. var layoutModel = _this.getLayoutModel();
  50. if (layoutModel) {
  51. layoutModel.set({ title: value }, {
  52. payloadData: { skipUndoRedo: true }
  53. });
  54. }
  55. },
  56. editor: {
  57. sectionId: 'page.titleSection',
  58. uiControl: {
  59. type: 'InputLabel',
  60. label: StringResources.get('propTabTitle'),
  61. ariaLabel: StringResources.get('propTabTitle'),
  62. handleReturnKey: true,
  63. appendTranslationIcon: translationService.appendTranslationIcon.bind(translationService)
  64. }
  65. }
  66. }, {
  67. id: 'tabTextColor',
  68. getPropertyValue: function getPropertyValue() {
  69. var layoutModel = _this.getLayoutModel();
  70. return layoutModel.get('tabTextColor');
  71. },
  72. setPropertyValue: function setPropertyValue(value, transactionToken) {
  73. _this._changeTabColor('tabTextColor', value, transactionToken);
  74. },
  75. editor: {
  76. sectionId: 'page.titleSection',
  77. uiControl: {
  78. type: 'ColorPicker',
  79. label: StringResources.get('propTabTextColor'),
  80. ariaLabel: StringResources.get('propTabTextColor'),
  81. paletteType: 'DashboardColorSet',
  82. open: false,
  83. showHexValue: true,
  84. addButton: true,
  85. onChange: function onChange(propertyName) {
  86. var propertyValueInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  87. _this.content.setPropertyValue(propertyName, propertyValueInfo.name);
  88. }
  89. }
  90. }
  91. }, {
  92. id: 'tabIcon',
  93. getPropertyValue: function getPropertyValue() {
  94. var layoutModel = _this.getLayoutModel();
  95. var icon = layoutModel.get('tabIcon');
  96. if (icon && icon !== 'transparent') {
  97. return _this._icons.getIcon(icon).id;
  98. } else {
  99. return 'transparent';
  100. }
  101. },
  102. setPropertyValue: function setPropertyValue(value) {
  103. var layoutModel = _this.getLayoutModel();
  104. if (layoutModel) {
  105. // Transform string to object if input is string
  106. var iconList = IconList.getTabIcons(_this._icons);
  107. if (typeof value === 'string') {
  108. value = _.find(iconList, function (icon) {
  109. return icon.value === value;
  110. });
  111. value = value || iconList[0]; // the first element is the transparent option
  112. }
  113. layoutModel.set({ tabIcon: value.name }, {
  114. payloadData: { skipUndoRedo: true }
  115. });
  116. }
  117. },
  118. editor: {
  119. sectionId: 'page.tabIconArea',
  120. uiControl: {
  121. type: 'CollapsiblePicker',
  122. label: StringResources.get('propTabIcon'),
  123. ariaLabel: StringResources.get('propTabIcon'),
  124. selectedName: this.getLayoutModel().get('tabIcon'),
  125. placeholder: {
  126. name: 'transparent',
  127. label: StringResources.get('no_icon'),
  128. type: 'string',
  129. value: 'transparent'
  130. },
  131. contentSize: 'small',
  132. items: IconList.getTabIcons(this._icons)
  133. }
  134. }
  135. }, {
  136. id: 'tabIconColor',
  137. getPropertyValue: function getPropertyValue() {
  138. var layoutModel = _this.getLayoutModel();
  139. return layoutModel.get('tabIconColor');
  140. },
  141. setPropertyValue: function setPropertyValue(value, transactionToken) {
  142. _this._changeTabColor('tabIconColor', value, transactionToken);
  143. },
  144. editor: {
  145. sectionId: 'page.tabIconArea',
  146. uiControl: {
  147. type: 'ColorPicker',
  148. label: StringResources.get('propTabIconColor'),
  149. ariaLabel: StringResources.get('propTabIconColor'),
  150. paletteType: 'DashboardColorSet',
  151. open: false,
  152. showHexValue: true,
  153. addButton: true,
  154. onChange: function onChange(propertyName) {
  155. var propertyValueInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  156. _this.content.setPropertyValue(propertyName, propertyValueInfo.name);
  157. }
  158. }
  159. }
  160. }, {
  161. id: 'tabSelectedLineColor',
  162. getPropertyValue: function getPropertyValue() {
  163. var layoutModel = _this.getLayoutModel();
  164. return layoutModel.get('tabSelectedLineColor');
  165. },
  166. setPropertyValue: function setPropertyValue(value, transactionToken) {
  167. _this._changeTabColor('tabSelectedLineColor', value, transactionToken);
  168. },
  169. editor: {
  170. sectionId: 'page.titleBackground',
  171. uiControl: {
  172. type: 'ColorPicker',
  173. label: StringResources.get('propTabSelectedBarColor'),
  174. ariaLabel: StringResources.get('propTabSelectedBarColor'),
  175. paletteType: 'DashboardColorSet',
  176. open: false,
  177. showHexValue: true,
  178. addButton: true,
  179. onChange: function onChange(propertyName) {
  180. var propertyValueInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  181. _this.content.setPropertyValue(propertyName, propertyValueInfo.name);
  182. }
  183. }
  184. }
  185. }, {
  186. id: 'tabBackgroundColor',
  187. getPropertyValue: function getPropertyValue() {
  188. var layoutModel = _this.getLayoutModel();
  189. return layoutModel.get('tabBackgroundColor');
  190. },
  191. setPropertyValue: function setPropertyValue(value, transactionToken) {
  192. _this._changeTabColor('tabBackgroundColor', value, transactionToken);
  193. },
  194. editor: {
  195. sectionId: 'page.titleBackground',
  196. uiControl: {
  197. type: 'ColorPicker',
  198. label: StringResources.get('propTabBackgroundColor'),
  199. ariaLabel: StringResources.get('propTabBackgroundColor'),
  200. paletteType: 'DashboardColorSet',
  201. open: false,
  202. showHexValue: true,
  203. addButton: true,
  204. onChange: function onChange(propertyName) {
  205. var propertyValueInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  206. _this.content.setPropertyValue(propertyName, propertyValueInfo.name);
  207. }
  208. }
  209. }
  210. }, {
  211. id: 'tabRestoreDefaults',
  212. editor: {
  213. sectionId: 'page.titleBackground',
  214. uiControl: {
  215. type: 'SingleLineLinks',
  216. items: [{
  217. align: 'left',
  218. items: [{
  219. type: 'icon',
  220. class: 'iconTextLink',
  221. svgIcon: this._icons.getIcon('restore').id,
  222. iconTooltip: StringResources.get('propTabRestoreDefaults'),
  223. clickCallback: restoreMasterStyling
  224. }]
  225. }, {
  226. align: 'right',
  227. items: [{
  228. type: 'text',
  229. class: 'iconTextLink',
  230. value: StringResources.get('propTabRestoreDefaults'),
  231. ariaLabel: StringResources.get('propTabRestoreDefaults'),
  232. clickCallback: restoreMasterStyling
  233. }]
  234. }]
  235. }
  236. }
  237. }];
  238. };
  239. PageProperties.prototype.getPropertyLayoutList = function getPropertyLayoutList() {
  240. if (this._isTopLevelPage()) {
  241. return [];
  242. }
  243. return [{
  244. value: StringResources.get('individualTabProperties'),
  245. centerLabel: true,
  246. id: 'banner',
  247. type: 'Banner',
  248. backButton: true,
  249. ariaLabel: StringResources.get('individualTabProperties')
  250. }, {
  251. id: 'page',
  252. type: 'Group'
  253. }, {
  254. id: 'titleSection',
  255. type: 'Section',
  256. collapsible: false,
  257. label: StringResources.get('sectionName_tabTitle')
  258. }, {
  259. id: 'titleBackground',
  260. type: 'Section',
  261. collapsible: false,
  262. label: StringResources.get('sectionName_tabBackground')
  263. }, {
  264. id: 'tabIconArea',
  265. type: 'Section',
  266. collapsible: false,
  267. label: StringResources.get('propTabIconLabel')
  268. }];
  269. };
  270. PageProperties.prototype.getLayoutModel = function getLayoutModel() {
  271. var boardModel = this.dashboard.getFeature('internal').getBoardModel();
  272. return boardModel.layout.findModel(this.content.getId());
  273. };
  274. PageProperties.prototype._changeTabColor = function _changeTabColor(propertyName, propertyValue) {
  275. // get layout and update CSS
  276. var payload = {};
  277. // Treat transparent as reset to default
  278. if (propertyValue) {
  279. payload[propertyName] = propertyValue == 'transparent' ? null : this.dashboard.getFeature('Colors').getColorClassName(propertyValue);
  280. } else {
  281. payload[propertyName] = null;
  282. }
  283. this.dashboard.getFeature('Colors').prepareForColorModelChange(payload, propertyName);
  284. var model = this.getLayoutModel();
  285. model.set(payload, {
  286. sender: this.senderId,
  287. payloadData: { skipUndoRedo: true }
  288. });
  289. };
  290. return PageProperties;
  291. }();
  292. return PageProperties;
  293. });
  294. //# sourceMappingURL=PagePropertiesProvider.js.map