BasePropertyAction.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018, 2019
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['../../../../lib/@waca/core-client/js/core-client/ui/core/Events'], function (Events) {
  8. var BasePropertyAction = null;
  9. BasePropertyAction = Events.extend({
  10. init: function init(controller) {
  11. this.controller = controller;
  12. this.dashboardApi = controller.dashboardApi;
  13. BasePropertyAction.inherited('init', this, arguments);
  14. },
  15. refreshProperties: function refreshProperties() {
  16. var _this = this;
  17. //Delay our update, as in relative layouts the model is updated again after being set to convert px sizes to %.
  18. setTimeout(function () {
  19. return _this.controller.eventRouter.trigger('properties:refreshPane');
  20. }, 100);
  21. },
  22. updateModel: function updateModel(styleUpdateArray, transactionToken) {
  23. var _this2 = this;
  24. var transactionApi = this.dashboardApi.getFeature('Transaction');
  25. var localTransactionToken = transactionApi.startTransaction(transactionToken);
  26. styleUpdateArray.forEach(function (styleUpdate) {
  27. var content = _this2.dashboardApi.getCanvas().getContent(styleUpdate.id);
  28. //set each property without validation first
  29. //This must be done so any validation in relation to previously set values is accurate
  30. // (ie - testing a 'left' property in relation to a 'width' property before the 'width' is set)
  31. var options = Object.assign(localTransactionToken || {}, { validatePropertyValue: false });
  32. Object.keys(styleUpdate.style).forEach(function (propertyName) {
  33. content.setPropertyValue(propertyName, styleUpdate.style[propertyName], localTransactionToken);
  34. });
  35. options = Object.assign(localTransactionToken || {}, { validatePropertyValue: true });
  36. //then validate each one.
  37. Object.keys(styleUpdate.style).forEach(function (propertyName) {
  38. content.setPropertyValue(propertyName, styleUpdate.style[propertyName], options);
  39. });
  40. });
  41. transactionApi.endTransaction(localTransactionToken);
  42. }
  43. });
  44. return BasePropertyAction;
  45. });
  46. //# sourceMappingURL=BasePropertyAction.js.map