-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Trait.js
43 lines (36 loc) · 824 Bytes
/
Trait.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
var Backbone = require('backbone');
module.exports = Backbone.Model.extend({
defaults: {
type: 'text', // text, number, range, select
label: '',
name: '',
min: '',
max: '',
value: '',
target: '',
default: '',
placeholder: '',
changeProp: 0,
options: [],
},
initialize() {
if (this.get('target')) {
this.target = this.get('target');
this.unset('target');
}
},
/**
* Get the initial value of the trait
* @return {string}
*/
getInitValue() {
const target = this.target;
const name = this.get('name');
let value;
if (target) {
const attrs = target.get('attributes');
value = this.get('changeProp') ? target.get(name) : attrs[name];
}
return value || this.get('value') || this.get('default');
}
});