-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Property.js
82 lines (69 loc) · 1.69 KB
/
Property.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
module.exports = require('backbone').Model.extend({
defaults: {
name: '',
property: '',
type: '',
defaults: '',
info: '',
value: '',
icon: '',
functionName: '',
status: '',
visible: true,
fixedValues: ['initial', 'inherit'],
},
initialize(opt) {
var o = opt || {};
var name = this.get('name');
var prop = this.get('property');
if (!name) {
this.set('name', prop.charAt(0).toUpperCase() + prop.slice(1).replace(/-/g,' '));
}
const init = this.init && this.init.bind(this);
init && init();
},
/**
* Parse a raw value, generally fetched from the target, for this property
* @param {string} value
* @return {string}
*/
parseValue(value) {
if (!this.get('functionName')) {
return value;
}
const args = [];
let valueStr = value + '';
let start = valueStr.indexOf('(') + 1;
let end = valueStr.lastIndexOf(')');
args.push(start);
// Will try even if the last closing parentheses is not found
if (end >= 0) {
args.push(end);
}
return String.prototype.substring.apply(valueStr, args);
},
/**
* Get the default value
* @return {string}
* @private
*/
getDefaultValue() {
return this.get('defaults');
},
/**
* Get a complete value of the property.
* This probably will replace the getValue when all
* properties models will be splitted
* @param {string} val Custom value to replace the one on the model
* @return {string}
* @private
*/
getFullValue(val) {
const fn = this.get('functionName');
let value = val || this.get('value');
if (fn) {
value = `${fn}(${value})`;
}
return value;
},
});