VisProperty.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2013, 2019
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. *
  7. */
  8. define(['../../lib/@waca/dashboard-common/dist/core/Model'], function (Model) {
  9. 'use strict';
  10. /**
  11. * VisProperty represents the value of a particular property of a visualization (as defined in its definition)
  12. * A property includes a type, group, default value, etc (from the definition) and optionally, a 'model value' for user-set values.
  13. * For details on property definitions, see smartVis component, definitions.json.
  14. * @param {Object}
  15. * attrs Properties to mix-in
  16. * @class
  17. */
  18. var VisProperty = null;
  19. VisProperty = Model.extend({
  20. whitelistAttrs: ['id', 'value'],
  21. init: function init(attrs) {
  22. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  23. this.collection = options.collection;
  24. // If this visProperty is multilingual, tag the 'value' property in the localizedProps array
  25. if (attrs && this.collection && this.collection.localizedPropIds && this.collection.localizedPropIds.indexOf(attrs.id) !== -1) {
  26. this.localizedProps = ['value'];
  27. }
  28. if (attrs.type === 'colorClass') {
  29. this.colorClass = true;
  30. }
  31. VisProperty.inherited('init', this, arguments);
  32. },
  33. /**
  34. * Persist a value to the model for this property (Note: for now, this is the widget model)
  35. * @param value A value (currently supports strings for type String, Color, Font and boolean for Boolean).
  36. */
  37. setValue: function setValue(value) {
  38. if (this.isOfType('Boolean')) {
  39. // TODO: Should not be converting boolean values to string values
  40. this.set({ value: value.toString() });
  41. } else {
  42. this.set({ value: value });
  43. }
  44. },
  45. /**
  46. * @returns true if this property has not been overridden from the default value as stored in the
  47. * property definition (see smartVis definitions.json)
  48. */
  49. isDefault: function isDefault() {
  50. return this.value === undefined;
  51. },
  52. /**
  53. * @param specifiedType - such as 'Boolean' or 'ColorPalette'
  54. * @returns true iff this property is of the type specified
  55. */
  56. isOfType: function isOfType(specifiedType) {
  57. return this.propertyType === specifiedType;
  58. },
  59. getType: function getType() {
  60. return this.propertyType;
  61. },
  62. /**
  63. * @returns true if this property is deemed to be a 'public' property
  64. * (meaning editable via a property sheet or some other UI)...returned by visModel.getPublicProperties()
  65. */
  66. isPublic: function isPublic() {
  67. return this['public'] === true; // don't use this.public, as public is a reserved word.
  68. },
  69. /**
  70. * The value for this property can be one of the three following things (ranked in priority):
  71. * 1) The overridden value which is stored in the owner widgets model. Also check if the property is mapped to other.
  72. * 2) The value provided by the theme, which is stored in the owner widgets theme definition.
  73. * 3) The value provided as a default in the vis definition, which is stored in the vis model, since now vida definition will always have a default value
  74. * The following three routines provide access to these values.
  75. */
  76. _getWidgetModelValue: function _getWidgetModelValue() {
  77. var modelValue = null;
  78. // get value from model with VIPR id
  79. modelValue = this.get('value');
  80. if (modelValue !== undefined && modelValue !== null) {
  81. return modelValue;
  82. }
  83. return modelValue;
  84. },
  85. /**
  86. * @returns the value of this property as either a string or boolean value.
  87. * Overridden values are returned first, then default values as defined in definitions.json
  88. */
  89. getValue: function getValue() {
  90. var value = this._getWidgetModelValue();
  91. if (value !== undefined && this.isOfType('Boolean')) {
  92. // TODO: This is a hack, booleans should be stored as booleans
  93. value = value === 'true' || value === true;
  94. }
  95. return value;
  96. },
  97. isResolveColor: function isResolveColor() {
  98. return !this.colorClass;
  99. },
  100. // TODO - what is the difference between predefined value && default..
  101. // Seems like something needs some cleaning up
  102. getPredefinedValue: function getPredefinedValue() {
  103. return this.predefinedValue;
  104. },
  105. /**
  106. * @return the default value of this property as defined in the definition.
  107. */
  108. getDefaultValue: function getDefaultValue() {
  109. if (this.isOfType('Boolean')) {
  110. // TODO: This is a hack, booleans should be stored as booleans
  111. return this.defaultValue === 'true' || this.defaultValue === true;
  112. }
  113. return this.defaultValue;
  114. }
  115. });
  116. return VisProperty;
  117. });
  118. //# sourceMappingURL=VisProperty.js.map