|
|
|
@ -16,33 +16,44 @@ define(['backbone','./TraitView'], |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
getInputEl: function() { |
|
|
|
if(!this.$input){ |
|
|
|
if(!this.$input){ |
|
|
|
var md = this.model; |
|
|
|
var opts = md.get('options') || []; |
|
|
|
this.input = '<select>'; |
|
|
|
var opts = md.get('options') || []; |
|
|
|
this.input = '<select>'; |
|
|
|
if(opts.length){ |
|
|
|
_.each(opts, function(el){ |
|
|
|
var name, value, style; |
|
|
|
var attrs = ''; |
|
|
|
if(typeof el === 'string'){ |
|
|
|
name = el; |
|
|
|
value = el; |
|
|
|
}else{ |
|
|
|
name = el.name ? el.name : el.value; |
|
|
|
value = el.value.replace(/"/g,'"'); |
|
|
|
style = el.style ? el.style.replace(/"/g,'"') : ''; |
|
|
|
attrs += style ? 'style="' + style + '"' : ''; |
|
|
|
} |
|
|
|
var name, value, style; |
|
|
|
var attrs = ''; |
|
|
|
if(typeof el === 'string'){ |
|
|
|
name = el; |
|
|
|
value = el; |
|
|
|
}else{ |
|
|
|
name = el.name ? el.name : el.value; |
|
|
|
value = el.value.replace(/"/g,'"'); |
|
|
|
style = el.style ? el.style.replace(/"/g,'"') : ''; |
|
|
|
attrs += style ? 'style="' + style + '"' : ''; |
|
|
|
} |
|
|
|
this.input += '<option value="' + value + '" ' + attrs + '>' + name + '</option>'; |
|
|
|
}, this); |
|
|
|
} |
|
|
|
this.input += '</select>'; |
|
|
|
this.$input = $(this.input); |
|
|
|
// TODO check also model attributes in case of changeProp
|
|
|
|
|
|
|
|
var target = this.target; |
|
|
|
var name = md.get('name'); |
|
|
|
var val = md.get('value'); |
|
|
|
|
|
|
|
if (md.get('changeProp')) { |
|
|
|
val = val || target.get(name); |
|
|
|
} else { |
|
|
|
var attrs = target.get('attributes'); |
|
|
|
val = attrs[name]; |
|
|
|
} |
|
|
|
|
|
|
|
if(val) |
|
|
|
this.$input.val(val); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return this.$input.get(0); |
|
|
|
}, |
|
|
|
|
|
|
|
|