TopLevelPropertiesProvider.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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', '../../../dashboard/layout/LayoutHelper', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../lib/@waca/baglass/js/baglass/utils/Utils', '../../../lib/@waca/core-client/js/core-client/ui/dialogs/ConfirmationDialog', '../../../lib/@waca/dashboard-common/dist/api/PropertiesProviderAPI', 'underscore', '../../../dashboard/widgets/PropertyListUtil'], function (StringResources, LayoutHelper, APIFactory, Utils, ConfirmationDialog, PropertiesProviderAPI, _, PropertyListUtil) {
  10. var MINIMUM_PAGESIZE = { width: 320, height: 200 };
  11. var PAGESIZES = {
  12. '16:9': {
  13. 'width': 1280,
  14. 'height': 720
  15. },
  16. '4:3': {
  17. 'width': 1280,
  18. 'height': 960
  19. },
  20. 'letter': {
  21. 'width': 612,
  22. 'height': 792
  23. },
  24. 'legal': {
  25. 'width': 612,
  26. 'height': 1008
  27. },
  28. 'a4': {
  29. 'width': 595,
  30. 'height': 842
  31. },
  32. 'tabloid': {
  33. 'width': 792,
  34. 'height': 1224
  35. },
  36. 'infographic': {
  37. 'width': 512,
  38. 'height': 1024
  39. }
  40. };
  41. var PRESET_PAGE_SIZES = [{
  42. label: StringResources.get('propPageSizePresetCustom'),
  43. value: 'custom'
  44. }, {
  45. label: StringResources.get('propPageSizePreset16x9'),
  46. value: '16:9'
  47. }, {
  48. label: StringResources.get('propPageSizePreset4x3'),
  49. value: '4:3'
  50. }, {
  51. label: StringResources.get('letter'),
  52. value: 'letter'
  53. }, {
  54. label: StringResources.get('legal'),
  55. value: 'legal'
  56. }, {
  57. label: StringResources.get('a4'),
  58. value: 'a4'
  59. }, {
  60. label: StringResources.get('tabloid'),
  61. value: 'tabloid'
  62. }, {
  63. label: StringResources.get('propPageSizePresetInfographic'),
  64. value: 'infographic'
  65. }];
  66. var TopLevelProperties = function () {
  67. function TopLevelProperties(options) {
  68. _classCallCheck(this, TopLevelProperties);
  69. this.dashboard = options.dashboardApi || options.dashboardAPI;
  70. this.content = options.content;
  71. this.content.getFeature('Properties').registerProvider(this.getAPI());
  72. }
  73. TopLevelProperties.prototype.getCanvas = function getCanvas() {
  74. if (!this.canvas) {
  75. this.canvas = this.dashboard.getCanvas();
  76. }
  77. return this.canvas;
  78. };
  79. TopLevelProperties.prototype.getLayoutModel = function getLayoutModel() {
  80. var boardModel = this.dashboard.getFeature('internal').getBoardModel();
  81. return boardModel.layout.findModel(this.content.getId());
  82. };
  83. TopLevelProperties.prototype.getAPI = function getAPI() {
  84. return APIFactory.createAPI(this, [PropertiesProviderAPI]);
  85. };
  86. TopLevelProperties.prototype._getCommonType = function _getCommonType(contentType) {
  87. return contentType && contentType.split('.')[0];
  88. };
  89. TopLevelProperties.prototype._getSubType = function _getSubType(contentType) {
  90. if (contentType && contentType.indexOf('.') !== -1) {
  91. return contentType.split('.')[1];
  92. } else {
  93. return null;
  94. }
  95. };
  96. TopLevelProperties.prototype.getPropertyList = function getPropertyList() {
  97. var _this2 = this;
  98. var propertyList = [];
  99. if (this._isTopLevelPage()) {
  100. propertyList.push.apply(propertyList, this._getTopLevelLayoutPropertiesList());
  101. // All layouts have the background color property
  102. propertyList.push(this._getBackgroundColorProperty());
  103. }
  104. // Default the setPropertyValue and getPropertyValue for any property that doesn't define those methods
  105. propertyList.forEach(function (property) {
  106. if (!property.setPropertyValue) {
  107. property.setPropertyValue = function (value) {
  108. return _this2._setPropertyValueInModel(property.id, value);
  109. };
  110. }
  111. if (!property.getPropertyValue) {
  112. property.getPropertyValue = function () {
  113. return _this2._getPropertyValueFromModel(property.id);
  114. };
  115. }
  116. });
  117. return propertyList;
  118. };
  119. TopLevelProperties.prototype.getPropertyLayoutList = function getPropertyLayoutList() {
  120. var propertiesLayoutSpec = [];
  121. if (this._isTopLevelPage()) {
  122. propertiesLayoutSpec = this._getTopLevelPropertiesLayoutSpec();
  123. }
  124. return propertiesLayoutSpec;
  125. };
  126. TopLevelProperties.prototype._getTopLevelPropertiesLayoutSpec = function _getTopLevelPropertiesLayoutSpec() {
  127. var topLevelPropertiesLayoutSpec = [{
  128. id: 'general',
  129. type: 'Group',
  130. label: StringResources.get('tabName_general')
  131. }, {
  132. id: 'canvas',
  133. type: 'Section',
  134. label: StringResources.get('sectionName_canvas'),
  135. position: 1
  136. }, {
  137. id: 'pageSize',
  138. type: 'Section',
  139. collapsible: false,
  140. label: StringResources.get('propPageSizeLabel'),
  141. position: 2
  142. }, {
  143. id: 'colorsAndTheme',
  144. type: 'Section',
  145. label: StringResources.get('sectionName_colorsAndThemes'),
  146. position: 3
  147. }, {
  148. id: 'grid',
  149. type: 'Section',
  150. collapsible: false,
  151. label: StringResources.get('gridLabel'),
  152. position: 2
  153. }, {
  154. id: 'pageSizeSplit',
  155. type: 'Split',
  156. items: [{
  157. id: 'left',
  158. align: 'left',
  159. items: []
  160. }, {
  161. id: 'right',
  162. align: 'right',
  163. items: []
  164. }]
  165. }];
  166. return topLevelPropertiesLayoutSpec;
  167. };
  168. TopLevelProperties.prototype._getTopLevelLayoutPropertiesList = function _getTopLevelLayoutPropertiesList() {
  169. var _this3 = this;
  170. var _this = this;
  171. var model = this.getLayoutModel();
  172. return [{
  173. id: 'layoutPositioning',
  174. getPropertyValue: function getPropertyValue() {
  175. return model.getValueFromSelfOrParent('layoutPositioning');
  176. },
  177. setPropertyValue: this._setLayoutPositioning.bind(this),
  178. validatePropertyValue: function validatePropertyValue(value) {
  179. return {
  180. isValid: ['relative', 'absolute'].indexOf(value) !== -1,
  181. message: 'layoutPositioning must be either relative or absolute.'
  182. };
  183. },
  184. editor: {
  185. sectionId: 'general.canvas',
  186. position: 1,
  187. uiControl: {
  188. type: 'DropDown',
  189. label: StringResources.get('propLayoutPositioning'),
  190. getOptions: this._getLayoutPositioningSpecOptions.bind(this),
  191. coachMark: {
  192. render: function render(options) {
  193. Utils.addCoachmark({
  194. id: 'com.ibm.bi.dashboard.dashboardCoreProperties.layoutPositioning',
  195. title: StringResources.get('propLayoutPositioningCoachmarkTitle'),
  196. contents: StringResources.get('propLayoutPositioningCoachmarkContent'),
  197. placement: 'bottom',
  198. glassContext: options.glassContext,
  199. $el: options.$el
  200. });
  201. }
  202. },
  203. onChange: function onChange(propertyName, propertyValue) {
  204. _this._onChangeLayoutPosition(this, propertyValue);
  205. }
  206. }
  207. }
  208. }, {
  209. id: 'pageSizePreset',
  210. getPropertyValue: this._getPageSizePreset.bind(this),
  211. setPropertyValue: this._setPageSizePreset.bind(this),
  212. editor: {
  213. sectionId: 'general.canvas.pageSize',
  214. position: 1,
  215. uiControl: {
  216. type: 'DropDown',
  217. label: StringResources.get('propPageSizePreset'),
  218. ariaLabel: StringResources.get('propPageSizePresetAriaLabel'),
  219. options: PRESET_PAGE_SIZES,
  220. onChange: this._onChangePresetPageSize.bind(this)
  221. }
  222. }
  223. }, {
  224. id: 'fitPage',
  225. getPropertyValue: function getPropertyValue() {
  226. var fitPage = false;
  227. if (model.getValueFromSelfOrParent('layoutPositioning') !== 'absolute') {
  228. fitPage = model.getValueFromSelfOrParent('fitPage') || false;
  229. }
  230. return fitPage;
  231. },
  232. setPropertyValue: function setPropertyValue(value) {
  233. model.set({ 'fitPage': value });
  234. },
  235. editor: {
  236. sectionId: 'general.canvas.pageSize',
  237. position: 2,
  238. uiControl: {
  239. type: 'ToggleButton',
  240. label: StringResources.get('fitPageText')
  241. }
  242. }
  243. }, {
  244. id: 'pageSizeWidth',
  245. getPropertyValue: function getPropertyValue() {
  246. var pageSize = _this3._getPropertyValueFromModel('pageSize');
  247. return pageSize && pageSize.width;
  248. },
  249. setPropertyValue: function setPropertyValue(value) {
  250. _this3._setPageSizeDirection(value, 'pageSizeWidth', true);
  251. },
  252. editor: {
  253. sectionId: 'general.canvas.pageSize.pageSizeSplit.left',
  254. uiControl: {
  255. 'type': 'InputLabel',
  256. 'label': StringResources.get('propPageSizeWidth'),
  257. 'ariaLabel': StringResources.get('propPageSizeWidthAriaLabel'),
  258. 'multiline': true,
  259. 'handleReturnKey': true,
  260. 'onChange': function onChange(propertyName, propertyValue) {
  261. _this._onChangePageSize(propertyName, propertyValue, this);
  262. }
  263. }
  264. }
  265. }, {
  266. id: 'pageSizeHeight',
  267. getPropertyValue: function getPropertyValue() {
  268. var pageSize = _this3._getPropertyValueFromModel('pageSize');
  269. return pageSize && pageSize.height;
  270. },
  271. setPropertyValue: function setPropertyValue(value) {
  272. _this3._setPageSizeDirection(value, 'pageSizeHeight', true);
  273. },
  274. editor: {
  275. sectionId: 'general.canvas.pageSize.pageSizeSplit.right',
  276. uiControl: {
  277. 'type': 'InputLabel',
  278. 'label': StringResources.get('propPageSizeHeight'),
  279. 'ariaLabel': StringResources.get('propPageSizeHeightAriaLabel'),
  280. 'multiline': true,
  281. 'handleReturnKey': true,
  282. 'onChange': function onChange(propertyName, propertyValue) {
  283. _this._onChangePageSize(propertyName, propertyValue, this);
  284. }
  285. }
  286. }
  287. }, {
  288. id: 'showGrid',
  289. editor: {
  290. sectionId: 'general.canvas.grid',
  291. position: 1,
  292. uiControl: {
  293. type: 'ToggleButton',
  294. label: StringResources.get('gridText')
  295. }
  296. }
  297. }, {
  298. id: 'snapGrid',
  299. editor: {
  300. sectionId: 'general.canvas.grid',
  301. position: 2,
  302. uiControl: {
  303. type: 'ToggleButton',
  304. label: StringResources.get('snapText')
  305. }
  306. }
  307. }, {
  308. id: 'snapObjects',
  309. editor: {
  310. sectionId: 'general.canvas.grid',
  311. position: 3,
  312. uiControl: {
  313. type: 'ToggleButton',
  314. label: StringResources.get('snapObjectsText')
  315. }
  316. }
  317. }];
  318. };
  319. TopLevelProperties.prototype._getBackgroundColorProperty = function _getBackgroundColorProperty() {
  320. var _this4 = this;
  321. return {
  322. id: 'fillColor',
  323. getPropertyValue: function getPropertyValue() {
  324. return _this4._getPropertyValueFromModel('fillColor') || 'transparent';
  325. },
  326. setPropertyValue: this._setFillColor.bind(this),
  327. editor: {
  328. sectionId: 'general.colorsAndTheme',
  329. position: 2,
  330. uiControl: {
  331. type: 'ColorPicker',
  332. label: StringResources.get('propDashboardBackgroundColor'),
  333. ariaLabel: StringResources.get('propDashboardBackgroundColor'),
  334. paletteType: 'DashboardColorSet',
  335. open: false,
  336. showHexValue: true,
  337. addButton: true
  338. }
  339. }
  340. };
  341. };
  342. TopLevelProperties.prototype._setFillColor = function _setFillColor(propertyValue) {
  343. var colorsFeature = this.dashboard.getFeature('Colors');
  344. var data = {
  345. undoRedoTransactionId: _.uniqueId('layout_fillColorChange_')
  346. };
  347. var payload = {
  348. fillColor: this.dashboard.getFeature('Colors').getColorClassName(propertyValue)
  349. };
  350. var model = this.getLayoutModel();
  351. colorsFeature.prepareForColorModelChange(payload, 'fillColor');
  352. model.set(payload, {
  353. sender: model.id,
  354. payloadData: data
  355. });
  356. };
  357. TopLevelProperties.prototype._getPageSizePreset = function _getPageSizePreset() {
  358. var model = this.getLayoutModel();
  359. var _model$get = model.get('pageSize'),
  360. width = _model$get.width,
  361. height = _model$get.height;
  362. var preset = 'custom';
  363. var checkWidth = parseInt(width, 10),
  364. checkHeight = parseInt(height, 10);
  365. for (var value in PAGESIZES) {
  366. if (PAGESIZES.hasOwnProperty(value)) {
  367. var currentPreset = PAGESIZES[value];
  368. if (currentPreset.width === checkWidth && currentPreset.height === checkHeight) {
  369. preset = value;
  370. break;
  371. }
  372. }
  373. }
  374. return preset;
  375. };
  376. TopLevelProperties.prototype._setPageSizePreset = function _setPageSizePreset(propertyValue) {
  377. var presetValues = PAGESIZES[propertyValue];
  378. if (presetValues) {
  379. if (this.getCanvas().getPropertyValue('layoutPositioning') !== 'absolute') {
  380. this.getCanvas().setPropertyValue('fitPage', propertyValue === '16:9' || propertyValue === '4:3' ? true : false);
  381. }
  382. var currentPageSizeWidth = this.getCanvas().getPropertyValue('pageSizeWidth');
  383. var currentPageSizeHeight = this.getCanvas().getPropertyValue('pageSizeHeight');
  384. if (!currentPageSizeWidth || currentPageSizeWidth !== presetValues.width || !currentPageSizeHeight || currentPageSizeHeight !== presetValues.height) {
  385. this._setPageSize({
  386. width: presetValues.width,
  387. height: presetValues.height
  388. }, true);
  389. }
  390. }
  391. };
  392. TopLevelProperties.prototype._onChangePresetPageSize = function _onChangePresetPageSize(propertyName, propertyValue) {
  393. var presetValues = PAGESIZES[propertyValue];
  394. if (presetValues) {
  395. var model = this.getLayoutModel();
  396. if (model.get('layoutPositioning') !== 'absolute') {
  397. // @todo: can we explicity set the property without triggering an event?
  398. this.dashboard.triggerDashboardEvent('properties:setValue', {
  399. propertyName: 'fitPage',
  400. value: propertyValue === '16:9' || propertyValue === '4:3' ? true : false
  401. });
  402. }
  403. this.getCanvas().setPropertyValue(propertyName, propertyValue);
  404. }
  405. };
  406. TopLevelProperties.prototype._getPropertyValueFromModel = function _getPropertyValueFromModel(propName) {
  407. var model = this.getLayoutModel();
  408. // In case of livewidget previews, we have a content but it is not attached to the layout, which causes the model to be null.
  409. return model && model.get(propName);
  410. };
  411. TopLevelProperties.prototype._setPropertyValueInModel = function _setPropertyValueInModel(propName, propValue, options) {
  412. var payload = {};
  413. var model = this.getLayoutModel();
  414. payload[propName] = propValue;
  415. model.set(payload, options);
  416. };
  417. TopLevelProperties.prototype._isTopLevelPage = function _isTopLevelPage() {
  418. return !this.content.getContainer();
  419. };
  420. TopLevelProperties.prototype._onChangeLayoutPosition = function _onChangeLayoutPosition(propertyControl, propertyValue) {
  421. var _this5 = this;
  422. var transaction = this.dashboard.getFeature('Transaction');
  423. var transactionToken = transaction.startTransaction();
  424. if (!transactionToken.undoRedoTransactionId) {
  425. transactionToken.undoRedoTransactionId = transactionToken.transactionId;
  426. }
  427. var oldLayoutPositioning = this.getCanvas().getPropertyValue('layoutPositioning');
  428. if (oldLayoutPositioning) {
  429. if (propertyValue === 'absolute') {
  430. this.dashboard.triggerDashboardEvent('properties:updateEnabled', { propertyName: 'fitPage', enabled: false });
  431. this.dashboard.triggerDashboardEvent('properties:setValue', { propertyName: 'fitPage', value: false });
  432. } else {
  433. this.dashboard.triggerDashboardEvent('properties:updateEnabled', { propertyName: 'fitPage', enabled: true });
  434. var preset = this._getPageSizePreset();
  435. if (preset === '16:9' || preset === '4:3') {
  436. this.dashboard.triggerDashboardEvent('properties:setValue', { propertyName: 'fitPage', value: true });
  437. } else {
  438. this.dashboard.triggerDashboardEvent('properties:setValue', { propertyName: 'fitPage', value: false });
  439. }
  440. }
  441. this.getCanvas().setPropertyValue('layoutPositioning', propertyValue, transactionToken);
  442. transaction.endTransaction(transactionToken);
  443. } else {
  444. // Confirm layout upgrade with user
  445. var onOK = function onOK() {
  446. _this5.getCanvas().setPropertyValue('layoutPositioning', propertyValue, transactionToken);
  447. transaction.endTransaction(transactionToken);
  448. // Update property control - which should remove "undefined" as an option
  449. // Ideally we should only be updating the one control of interest.
  450. // But, this doesn't currently work right for items in a section block.
  451. // let event = {
  452. // 'propertySpec': this._getLayoutPositioningSpec(),
  453. // 'removeProperty': false
  454. // };
  455. // this.dashboard.triggerDashboardEvent('properties:refreshProperty', event);
  456. _this5.dashboard.triggerDashboardEvent('properties:refreshPane');
  457. };
  458. var onCancel = function onCancel() {
  459. // Reset back to undefined state
  460. propertyControl._lastChangedValue = 'undefined'; // Bug in glass, setValue doesn't reset _lastChangedValue.
  461. propertyControl.setValue('undefined');
  462. };
  463. var oConfirmationDialog = new ConfirmationDialog('warning', StringResources.get('confirmLayoutStyleUpgradeTitle'), StringResources.get('confirmLayoutStyleUpgrade'));
  464. oConfirmationDialog.confirm(onOK, onCancel);
  465. }
  466. };
  467. TopLevelProperties.prototype._setLayoutPositioning = function _setLayoutPositioning(propertyValue, transactionToken) {
  468. var transaction = this.dashboard.getFeature('Transaction');
  469. var data = transaction.startTransaction(transactionToken);
  470. if (!data.undoRedoTransactionId) {
  471. data.undoRedoTransactionId = data.transactionId;
  472. }
  473. var model = this.getLayoutModel();
  474. model.set({ layoutPositioning: propertyValue }, {
  475. payloadData: data,
  476. sender: this.senderId
  477. });
  478. if (propertyValue === 'absolute') {
  479. model.set({ 'fitPage': false }, {
  480. payloadData: data,
  481. sender: this.senderId
  482. });
  483. } else {
  484. var preset = this._getPageSizePreset();
  485. if (preset === '16:9' || preset === '4:3') {
  486. model.set({ 'fitPage': true }, {
  487. payloadData: data,
  488. sender: this.senderId
  489. });
  490. } else {
  491. model.set({ 'fitPage': false }, {
  492. payloadData: data,
  493. sender: this.senderId
  494. });
  495. }
  496. }
  497. transaction.endTransaction(data);
  498. this.dashboard.triggerDashboardEvent('layout:resize');
  499. };
  500. TopLevelProperties.prototype._getLayoutPositioningSpecOptions = function _getLayoutPositioningSpecOptions() {
  501. var currentValue = this.getCanvas().getPropertyValue('layoutPositioning');
  502. var layoutPositioningOptions = [];
  503. if (!currentValue) {
  504. layoutPositioningOptions.push({
  505. label: '',
  506. value: 'undefined'
  507. });
  508. }
  509. layoutPositioningOptions.push({
  510. label: StringResources.get('propLayoutRelative'),
  511. value: 'relative'
  512. }, {
  513. label: StringResources.get('propLayoutAbsolute'),
  514. value: 'absolute'
  515. });
  516. return layoutPositioningOptions;
  517. };
  518. TopLevelProperties.prototype._onChangePageSize = function _onChangePageSize(propertyName, propertyValue, propertyControl) {
  519. if (propertyControl.propertiesManagerChange) {
  520. propertyControl.onChangeValueHold = propertyValue;
  521. } else {
  522. this.getCanvas().setPropertyValue(propertyName, propertyValue);
  523. // It's possible the value got tweaked because of the bounding rect size.
  524. var currentValue = parseInt(this.getCanvas().getPropertyValue(propertyName), 10);
  525. var propertyNameList = ['pageSizeSplit', propertyName];
  526. if (isNaN(currentValue)) {
  527. this.dashboard.triggerDashboardEvent('properties:setValue', { propertyName: propertyNameList, value: propertyControl.onChangeValueHold });
  528. } else if (propertyValue !== propertyControl.onChangeValueHold) {
  529. propertyControl.onChangeValueHold = PropertyListUtil.getPropertyDisplayString(currentValue, StringResources.get('pixelUnit'), true);
  530. this.dashboard.triggerDashboardEvent('properties:setValue', { propertyName: propertyNameList, value: propertyControl.onChangeValueHold });
  531. }
  532. }
  533. };
  534. TopLevelProperties.prototype._showPageSizeChangeToast = function _showPageSizeChangeToast() {
  535. this.dashboard.showToast(StringResources.get('propPageSizeAdjustedMessage'), {
  536. type: 'info'
  537. });
  538. };
  539. TopLevelProperties.prototype._setPageSizeDirection = function _setPageSizeDirection(propValue, propName) {
  540. var showToast = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  541. var numericValue = parseInt(propValue, 10);
  542. if (!isNaN(numericValue)) {
  543. var model = this.getLayoutModel();
  544. var direction = propName === 'pageSizeWidth' ? 'width' : 'height';
  545. var otherDirection = propName === 'pageSizeWidth' ? 'height' : 'width';
  546. var currentPageSize = model.get('pageSize') || {};
  547. if (currentPageSize[direction] === numericValue) {
  548. return;
  549. }
  550. var newPageSize = {};
  551. newPageSize[direction] = numericValue;
  552. newPageSize[otherDirection] = currentPageSize[otherDirection];
  553. this._setPageSize(newPageSize, showToast);
  554. // Not modelled as a seperate property, but our API exposes it. Throw an event in case anybody is listening to it
  555. var eventName = direction === 'width' ? 'change:pageSizeWidth' : 'change:pageSizeHeight';
  556. model.trigger(eventName, {
  557. value: newPageSize[direction],
  558. model: model,
  559. eventName: eventName
  560. });
  561. }
  562. };
  563. TopLevelProperties.prototype._setPageSize = function _setPageSize(newSize) {
  564. var showToast = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  565. var model = this.getLayoutModel();
  566. var sizeChanged = false;
  567. var minimumSize = LayoutHelper.getBoundingPageSize(model, MINIMUM_PAGESIZE);
  568. if (minimumSize) {
  569. if (isNaN(newSize.width) || minimumSize.width > newSize.width) {
  570. newSize.width = minimumSize.width;
  571. sizeChanged = true;
  572. }
  573. if (isNaN(newSize.height) || minimumSize.height > newSize.height) {
  574. newSize.height = minimumSize.height;
  575. sizeChanged = true;
  576. }
  577. if (sizeChanged && showToast) {
  578. this._showPageSizeChangeToast();
  579. }
  580. }
  581. model.set({
  582. 'pageSize': newSize
  583. });
  584. this.dashboard.triggerDashboardEvent('layout:resize');
  585. return newSize;
  586. };
  587. return TopLevelProperties;
  588. }();
  589. return TopLevelProperties;
  590. });
  591. //# sourceMappingURL=TopLevelPropertiesProvider.js.map