PropertiesModel.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Cognos Products: BI
  6. * (C) Copyright IBM Corp. 2019
  7. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['../../../../lib/@waca/dashboard-common/dist/core/Model'], function (Model) {
  10. var PropertiesModel = Model.extend({
  11. init: function init() {
  12. var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  13. PropertiesModel.inherited('init', this, arguments);
  14. // Add any property that's already in the model to the white list. This is so that
  15. // we don't lose properties that were added by features dynamically on subsequent saves
  16. for (var property in model) {
  17. this.whitelistAttrs.push(property);
  18. }
  19. },
  20. setPropertyValue: function setPropertyValue(propertyName, propertyValue, options) {
  21. // Ensures that the property name is part of the white list
  22. if (this.whitelistAttrs.indexOf(propertyName) === -1) {
  23. this.whitelistAttrs.push(propertyName);
  24. }
  25. var payload = {};
  26. // if the property value is an object, clone it before we store it.
  27. payload[propertyName] = propertyValue && (typeof propertyValue === 'undefined' ? 'undefined' : _typeof(propertyValue)) === 'object' ? JSON.parse(JSON.stringify(propertyValue)) : propertyValue;
  28. this.set(payload, options);
  29. },
  30. getPropertyValue: function getPropertyValue(propertyName) {
  31. var value = this.get(propertyName);
  32. if (value && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
  33. // If the value is an object return a clone. This will force the caller to call
  34. // setPropertyValue to make changes to the model instead of just modifying the object directly
  35. value = JSON.parse(JSON.stringify(value));
  36. }
  37. return value;
  38. }
  39. });
  40. return PropertiesModel;
  41. });
  42. //# sourceMappingURL=PropertiesModel.js.map