123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2013, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *
- */
- define(['../../lib/@waca/dashboard-common/dist/core/Model'], function (Model) {
- 'use strict';
- /**
- * VisProperty represents the value of a particular property of a visualization (as defined in its definition)
- * A property includes a type, group, default value, etc (from the definition) and optionally, a 'model value' for user-set values.
- * For details on property definitions, see smartVis component, definitions.json.
- * @param {Object}
- * attrs Properties to mix-in
- * @class
- */
- var VisProperty = null;
- VisProperty = Model.extend({
- whitelistAttrs: ['id', 'value'],
- init: function init(attrs) {
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- this.collection = options.collection;
- // If this visProperty is multilingual, tag the 'value' property in the localizedProps array
- if (attrs && this.collection && this.collection.localizedPropIds && this.collection.localizedPropIds.indexOf(attrs.id) !== -1) {
- this.localizedProps = ['value'];
- }
- if (attrs.type === 'colorClass') {
- this.colorClass = true;
- }
- VisProperty.inherited('init', this, arguments);
- },
- /**
- * Persist a value to the model for this property (Note: for now, this is the widget model)
- * @param value A value (currently supports strings for type String, Color, Font and boolean for Boolean).
- */
- setValue: function setValue(value) {
- if (this.isOfType('Boolean')) {
- // TODO: Should not be converting boolean values to string values
- this.set({ value: value.toString() });
- } else {
- this.set({ value: value });
- }
- },
- /**
- * @returns true if this property has not been overridden from the default value as stored in the
- * property definition (see smartVis definitions.json)
- */
- isDefault: function isDefault() {
- return this.value === undefined;
- },
- /**
- * @param specifiedType - such as 'Boolean' or 'ColorPalette'
- * @returns true iff this property is of the type specified
- */
- isOfType: function isOfType(specifiedType) {
- return this.propertyType === specifiedType;
- },
- getType: function getType() {
- return this.propertyType;
- },
- /**
- * @returns true if this property is deemed to be a 'public' property
- * (meaning editable via a property sheet or some other UI)...returned by visModel.getPublicProperties()
- */
- isPublic: function isPublic() {
- return this['public'] === true; // don't use this.public, as public is a reserved word.
- },
- /**
- * The value for this property can be one of the three following things (ranked in priority):
- * 1) The overridden value which is stored in the owner widgets model. Also check if the property is mapped to other.
- * 2) The value provided by the theme, which is stored in the owner widgets theme definition.
- * 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
- * The following three routines provide access to these values.
- */
- _getWidgetModelValue: function _getWidgetModelValue() {
- var modelValue = null;
- // get value from model with VIPR id
- modelValue = this.get('value');
- if (modelValue !== undefined && modelValue !== null) {
- return modelValue;
- }
- return modelValue;
- },
- /**
- * @returns the value of this property as either a string or boolean value.
- * Overridden values are returned first, then default values as defined in definitions.json
- */
- getValue: function getValue() {
- var value = this._getWidgetModelValue();
- if (value !== undefined && this.isOfType('Boolean')) {
- // TODO: This is a hack, booleans should be stored as booleans
- value = value === 'true' || value === true;
- }
- return value;
- },
- isResolveColor: function isResolveColor() {
- return !this.colorClass;
- },
- // TODO - what is the difference between predefined value && default..
- // Seems like something needs some cleaning up
- getPredefinedValue: function getPredefinedValue() {
- return this.predefinedValue;
- },
- /**
- * @return the default value of this property as defined in the definition.
- */
- getDefaultValue: function getDefaultValue() {
- if (this.isOfType('Boolean')) {
- // TODO: This is a hack, booleans should be stored as booleans
- return this.defaultValue === 'true' || this.defaultValue === true;
- }
- return this.defaultValue;
- }
- });
- return VisProperty;
- });
- //# sourceMappingURL=VisProperty.js.map
|