ContentModel.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI
  5. * (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(['../../../lib/@waca/dashboard-common/dist/core/Model', './properties/PropertiesModel'], function (Model, PropertiesModel) {
  9. var ContentModel = Model.extend({
  10. nestedModels: {
  11. properties: PropertiesModel
  12. },
  13. whitelistAttrs: ['properties', 'features'],
  14. init: function init() {
  15. var contentSpec = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  16. ContentModel.inherited('init', this, arguments);
  17. if (contentSpec.conditionalFormatting) {
  18. this.whitelistAttrs.push('conditionalFormatting');
  19. }
  20. this.features = contentSpec.features || {};
  21. },
  22. /**
  23. * Sets a property in the nested PropertiesModel. If the PropertiesModel doesn't exist yet, a default empty one is created
  24. * @param {String} propertyName - The name of the property to set
  25. * @param {Object} propertyValue - The value to set
  26. * @param {TransactionToken} options
  27. */
  28. setPropertyValue: function setPropertyValue(propertyName, propertyValue, options) {
  29. if (!this.properties) {
  30. this.properties = new PropertiesModel();
  31. }
  32. this.properties.setPropertyValue(propertyName, propertyValue, options);
  33. },
  34. /**
  35. * Gets a property value from the nested PropertyModel. If the property model doesn't exist, undefined is returned.
  36. * @param {String} propertyName - The name of the property to set
  37. */
  38. getPropertyValue: function getPropertyValue(propertyName) {
  39. if (!this.properties) {
  40. return undefined;
  41. }
  42. return this.properties.getPropertyValue(propertyName);
  43. },
  44. /**
  45. * This is temporary until the code to allow a feature to contibute to our model is complete
  46. */
  47. getConditionalFormatting: function getConditionalFormatting() {
  48. return this.get('conditionalFormatting');
  49. },
  50. /**
  51. * This is temporary until the code to allow a feature to contibute to our model is complete
  52. */
  53. setConditionalFormatting: function setConditionalFormatting(value, options) {
  54. if (this.whitelistAttrs.indexOf('conditionalFormatting') === -1) {
  55. this.whitelistAttrs.push('conditionalFormatting');
  56. }
  57. var paylaod = {
  58. conditionalFormatting: value
  59. };
  60. this.set(paylaod, options);
  61. }
  62. });
  63. return ContentModel;
  64. });
  65. //# sourceMappingURL=ContentModel.js.map