TabPropertiesProvider.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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 Cognos Products: Dashboard
  6. * (C) Copyright IBM Corp. 2020
  7. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['../../../app/nls/StringResources', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../lib/@waca/dashboard-common/dist/api/PropertiesProviderAPI'], function (StringResources, APIFactory, PropertiesProviderAPI) {
  10. var TAB_POSITION = [{
  11. 'value': 'top',
  12. 'label': StringResources.get('propTop')
  13. }, {
  14. 'value': 'left',
  15. 'label': StringResources.get('propLeft')
  16. }, {
  17. 'value': 'bottom',
  18. 'label': StringResources.get('propBottom')
  19. }, {
  20. 'value': 'right',
  21. 'label': StringResources.get('propRight')
  22. }];
  23. var TAB_ICON_POSITION = [{
  24. 'value': 'right',
  25. 'label': StringResources.get('propRightTitle')
  26. }, {
  27. 'value': 'left',
  28. 'label': StringResources.get('propLeftTitle')
  29. }, {
  30. 'value': 'top',
  31. 'label': StringResources.get('propTopTitle')
  32. }, {
  33. 'value': 'bottom',
  34. 'label': StringResources.get('propBottomTitle')
  35. }];
  36. var TabProperties = function () {
  37. function TabProperties(_ref) {
  38. var dashboardApi = _ref.dashboardApi,
  39. dashboardAPI = _ref.dashboardAPI,
  40. features = _ref.features,
  41. content = _ref.content,
  42. options = _ref.options;
  43. _classCallCheck(this, TabProperties);
  44. this._dashboard = dashboardApi || dashboardAPI;
  45. this._content = content;
  46. this._icons = features['Dashboard.Icons'];
  47. this._allowHidingMultipleTabs = !options || options.allowHidingMultipleTabs !== false;
  48. }
  49. TabProperties.prototype.initialize = function initialize() {
  50. this._content.getFeature('Properties').registerProvider(this.getAPI());
  51. };
  52. TabProperties.prototype._getCanvas = function _getCanvas() {
  53. if (!this._canvas) {
  54. this._canvas = this._dashboard.getCanvas();
  55. }
  56. return this._canvas;
  57. };
  58. TabProperties.prototype.getLayoutModel = function getLayoutModel() {
  59. var boardModel = this._dashboard.getFeature('internal').getBoardModel();
  60. return boardModel.layout.findModel(this._content.getId());
  61. };
  62. TabProperties.prototype.getAPI = function getAPI() {
  63. return APIFactory.createAPI(this, [PropertiesProviderAPI]);
  64. };
  65. TabProperties.prototype.getPropertyList = function getPropertyList() {
  66. var _this = this;
  67. var propertyList = this._getTabPropertiesList();
  68. // Default the setPropertyValue and getPropertyValue for any property that doesn't define those methods
  69. propertyList.forEach(function (property) {
  70. if (!property.setPropertyValue) {
  71. property.setPropertyValue = function (value) {
  72. return _this._setPropertyValueInModel(property.id, value);
  73. };
  74. }
  75. if (!property.getPropertyValue) {
  76. property.getPropertyValue = function () {
  77. return _this._getPropertyValueFromModel(property.id);
  78. };
  79. }
  80. });
  81. return propertyList;
  82. };
  83. TabProperties.prototype.getPropertyLayoutList = function getPropertyLayoutList() {
  84. var propertiesLayoutSpec = [{
  85. id: 'general',
  86. type: 'Group',
  87. label: StringResources.get('tabName_general')
  88. }, {
  89. id: 'tabs',
  90. type: 'Section',
  91. label: StringResources.get('sectionName_tabs'),
  92. position: 3
  93. }, {
  94. id: 'masterTabStyles',
  95. type: 'Section',
  96. collapsible: false,
  97. label: StringResources.get('propMasterTabStylesLabel')
  98. }, {
  99. id: 'individualTabStyles',
  100. type: 'Section',
  101. collapsible: false,
  102. label: StringResources.get('propIndividualTabStylesLabel')
  103. }];
  104. return propertiesLayoutSpec;
  105. };
  106. TabProperties.prototype._individualTabSlideOut = function _individualTabSlideOut(page) {
  107. var propertiesManager = this._dashboard.getFeature('propertiesManager');
  108. return propertiesManager.getPropertyLayoutList([page]).then(function (properties) {
  109. return propertiesManager.addChild({
  110. overlay: true,
  111. label: StringResources.get('individualTabProperties'),
  112. content: {
  113. module: 'dashboard/contentpane/PropertyUIControlView',
  114. items: properties,
  115. content: page,
  116. refreshChild: true
  117. },
  118. pageChildId: page.getId()
  119. });
  120. });
  121. };
  122. TabProperties.prototype._getIndividualTabStylesLinks = function _getIndividualTabStylesLinks() {
  123. var _this2 = this;
  124. var pages = this._getCanvas().findContent({ type: 'page' });
  125. return pages.map(function (page, index) {
  126. var clickCallback = function clickCallback() {
  127. _this2._individualTabSlideOut(page);
  128. };
  129. var tabIcon = page.getPropertyValue('tabIcon');
  130. return {
  131. id: 'tabIndividualStylingLink' + index,
  132. editor: {
  133. sectionId: 'general.tabs.individualTabStyles',
  134. uiControl: {
  135. type: 'SingleLineLinks',
  136. clickCallback: clickCallback,
  137. items: [{
  138. align: 'left',
  139. items: [{
  140. type: 'icon',
  141. svgIcon: tabIcon !== 'transparent' ? tabIcon : null,
  142. iconTooltip: StringResources.get('propIndividualTabStylesAriaLabel')
  143. }]
  144. }, {
  145. align: 'right',
  146. items: [{
  147. type: 'text',
  148. value: page.getPropertyValue('title'),
  149. showRightArrow: true
  150. }]
  151. }]
  152. }
  153. }
  154. };
  155. });
  156. };
  157. TabProperties.prototype._getTabPropertiesList = function _getTabPropertiesList() {
  158. var _this3 = this;
  159. var restoreMasterStyling = function restoreMasterStyling() {
  160. var transaction = _this3._dashboard.getFeature('Transaction');
  161. var transactionToken = transaction.startTransaction();
  162. _this3._getCanvas().setPropertyValue('tabTextColor', 'transparent', transactionToken);
  163. _this3._getCanvas().setPropertyValue('tabSelectedLineColor', 'transparent', transactionToken);
  164. _this3._getCanvas().setPropertyValue('tabBackgroundColor', 'transparent', transactionToken);
  165. transaction.endTransaction(transactionToken);
  166. _this3._dashboard.triggerDashboardEvent('properties:refreshPane', {
  167. focusSelector: '.clickCallback_left_0_tabRestoreDefaults'
  168. });
  169. };
  170. var model = this.getLayoutModel();
  171. var disableShowTabs = !this._allowHidingMultipleTabs && model.items.length > 1;
  172. return [{
  173. id: 'showTabsInPreview',
  174. supportsUndoRedo: true,
  175. getPropertyValue: function getPropertyValue() {
  176. return !model.get('hideTab');
  177. },
  178. setPropertyValue: function setPropertyValue(value) {
  179. var oldValue = !model.get('hideTab');
  180. if (!oldValue || oldValue !== value) {
  181. model.set({
  182. 'hideTab': !value
  183. }, {
  184. payloadData: { skipUndoRedo: true }
  185. });
  186. }
  187. },
  188. editor: {
  189. sectionId: 'general.tabs',
  190. uiControl: {
  191. type: 'ToggleButton',
  192. label: StringResources.get('propShowTabsInPreview'),
  193. readOnly: disableShowTabs,
  194. disabled: disableShowTabs
  195. }
  196. }
  197. }, {
  198. id: 'tabPosition',
  199. supportsUndoRedo: true,
  200. getPropertyValue: function getPropertyValue() {
  201. return model.get('tabPosition');
  202. },
  203. setPropertyValue: function setPropertyValue(value) {
  204. var oldValue = model.get('tabPosition');
  205. if (!oldValue || oldValue !== value) {
  206. model.set({
  207. 'tabPosition': value
  208. }, {
  209. payloadData: { skipUndoRedo: true }
  210. });
  211. }
  212. },
  213. editor: {
  214. sectionId: 'general.tabs',
  215. uiControl: {
  216. type: 'DropDown',
  217. label: StringResources.get('propTabPosition'),
  218. options: TAB_POSITION
  219. }
  220. }
  221. }, {
  222. id: 'tabIconPosition',
  223. supportsUndoRedo: true,
  224. getPropertyValue: function getPropertyValue() {
  225. return model.get('tabIconPosition');
  226. },
  227. setPropertyValue: function setPropertyValue(value) {
  228. var oldValue = model.get('tabIconPosition');
  229. if (!oldValue || oldValue !== value) {
  230. model.set({
  231. 'tabIconPosition': value
  232. }, {
  233. payloadData: { skipUndoRedo: true }
  234. });
  235. }
  236. },
  237. editor: {
  238. sectionId: 'general.tabs',
  239. uiControl: {
  240. type: 'DropDown',
  241. label: StringResources.get('propTabIconPosition'),
  242. options: TAB_ICON_POSITION
  243. }
  244. }
  245. }, {
  246. id: 'tabTextColor',
  247. supportsUndoRedo: true,
  248. setPropertyValue: function setPropertyValue(value, transactionToken) {
  249. _this3._changeTabColor('tabTextColor', value, transactionToken);
  250. },
  251. editor: {
  252. sectionId: 'general.tabs.masterTabStyles',
  253. uiControl: {
  254. type: 'ColorPicker',
  255. label: StringResources.get('propTabTextColor'),
  256. ariaLabel: StringResources.get('propTabTextColor'),
  257. paletteType: 'DashboardColorSet',
  258. open: false,
  259. showHexValue: true,
  260. addButton: true,
  261. onChange: function onChange(propertyName) {
  262. var propertyValueInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  263. _this3._getCanvas().setPropertyValue(propertyName, propertyValueInfo.name);
  264. }
  265. }
  266. }
  267. }, {
  268. id: 'tabSelectedLineColor',
  269. supportsUndoRedo: true,
  270. setPropertyValue: function setPropertyValue(value, transactionToken) {
  271. _this3._changeTabColor('tabSelectedLineColor', value, transactionToken);
  272. },
  273. editor: {
  274. sectionId: 'general.tabs.masterTabStyles',
  275. uiControl: {
  276. type: 'ColorPicker',
  277. label: StringResources.get('propTabSelectedBarColor'),
  278. ariaLabel: StringResources.get('propTabSelectedBarColor'),
  279. paletteType: 'DashboardColorSet',
  280. open: false,
  281. showHexValue: true,
  282. addButton: true,
  283. onChange: function onChange(propertyName) {
  284. var propertyValueInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  285. _this3._getCanvas().setPropertyValue(propertyName, propertyValueInfo.name);
  286. }
  287. }
  288. }
  289. }, {
  290. id: 'tabBackgroundColor',
  291. supportsUndoRedo: true,
  292. setPropertyValue: function setPropertyValue(value, transactionToken) {
  293. _this3._changeTabColor('tabBackgroundColor', value, transactionToken);
  294. },
  295. editor: {
  296. sectionId: 'general.tabs.masterTabStyles',
  297. uiControl: {
  298. type: 'ColorPicker',
  299. label: StringResources.get('propTabBackgroundColor'),
  300. ariaLabel: StringResources.get('propTabBackgroundColor'),
  301. paletteType: 'DashboardColorSet',
  302. open: false,
  303. showHexValue: true,
  304. addButton: true,
  305. onChange: function onChange(propertyName) {
  306. var propertyValueInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  307. _this3._getCanvas().setPropertyValue(propertyName, propertyValueInfo.name);
  308. }
  309. }
  310. }
  311. }, {
  312. id: 'tabRestoreDefaults',
  313. editor: {
  314. sectionId: 'general.tabs.masterTabStyles',
  315. uiControl: {
  316. type: 'SingleLineLinks',
  317. items: [{
  318. align: 'left',
  319. items: [{
  320. type: 'icon',
  321. class: 'iconTextLink',
  322. svgIcon: this._icons.getIcon('restore').id,
  323. iconTooltip: StringResources.get('propTabRestoreDefaults'),
  324. clickCallback: restoreMasterStyling
  325. }]
  326. }, {
  327. align: 'right',
  328. items: [{
  329. type: 'text',
  330. class: 'iconTextLink',
  331. value: StringResources.get('propTabRestoreDefaults'),
  332. ariaLabel: StringResources.get('propTabRestoreDefaults'),
  333. clickCallback: restoreMasterStyling
  334. }]
  335. }]
  336. }
  337. }
  338. }, {
  339. id: 'allowHidingMultipleTabs',
  340. getPropertyValue: function getPropertyValue() {
  341. return _this3._allowHidingMultipleTabs;
  342. },
  343. setPropertyValue: function setPropertyValue() {
  344. throw new Error('not supported');
  345. }
  346. }].concat(this._getIndividualTabStylesLinks());
  347. };
  348. TabProperties.prototype._changeTabColor = function _changeTabColor(propertyName, propertyValue) {
  349. // get layout and update CSS
  350. var payload = {};
  351. // Treat transparent as reset to default
  352. if (propertyValue) {
  353. payload[propertyName] = propertyValue == 'transparent' ? null : this._dashboard.getFeature('Colors').getColorClassName(propertyValue);
  354. } else {
  355. payload[propertyName] = null;
  356. }
  357. this._dashboard.getFeature('Colors').prepareForColorModelChange(payload, propertyName);
  358. var model = this.getLayoutModel();
  359. model.set(payload, {
  360. sender: this.senderId,
  361. payloadData: { skipUndoRedo: true }
  362. });
  363. };
  364. TabProperties.prototype._getPropertyValueFromModel = function _getPropertyValueFromModel(propName) {
  365. var model = this.getLayoutModel();
  366. // In case of livewidget previews, we have a content but it is not attached to the layout, which causes the model to be null.
  367. return model && model.get(propName);
  368. };
  369. TabProperties.prototype._setPropertyValueInModel = function _setPropertyValueInModel(propName, propValue) {
  370. var payload = {};
  371. var model = this.getLayoutModel();
  372. payload[propName] = propValue;
  373. model.set(payload, {
  374. payloadData: { skipUndoRedo: true }
  375. });
  376. };
  377. return TabProperties;
  378. }();
  379. return TabProperties;
  380. });
  381. //# sourceMappingURL=TabPropertiesProvider.js.map