|
|
|
@ -6,21 +6,22 @@ module.exports = Backbone.View.extend({ |
|
|
|
'change': 'handleChange', |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
template() { |
|
|
|
const holderClass = this.holderClass; |
|
|
|
return `<span class="${holderClass}"></span>`; |
|
|
|
return `<span class="${this.holderClass}"></span>`; |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
initialize(opts = {}) { |
|
|
|
const ppfx = opts.ppfx || ''; |
|
|
|
this.ppfx = ppfx; |
|
|
|
this.target = opts.target || {}; |
|
|
|
this.inputClass = ppfx + 'field'; |
|
|
|
this.inputHolderClass = ppfx + 'input-holder'; |
|
|
|
this.inputClass = `${ppfx}field`; |
|
|
|
this.holderClass = `${ppfx}input-holder`; |
|
|
|
this.ppfx = ppfx; |
|
|
|
this.listenTo(this.model, 'change:value', this.handleModelChange); |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Fired when the element of the property is updated |
|
|
|
*/ |
|
|
|
@ -28,6 +29,7 @@ module.exports = Backbone.View.extend({ |
|
|
|
this.model.trigger('el:change'); |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Handled when the view is changed |
|
|
|
*/ |
|
|
|
@ -37,6 +39,7 @@ module.exports = Backbone.View.extend({ |
|
|
|
this.elementUpdated(); |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Set value to the model |
|
|
|
* @param {string} value |
|
|
|
@ -49,6 +52,7 @@ module.exports = Backbone.View.extend({ |
|
|
|
input && (input.value = val); |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Updates the view when the model is changed |
|
|
|
* */ |
|
|
|
@ -56,26 +60,27 @@ module.exports = Backbone.View.extend({ |
|
|
|
this.setValue(value, opts); |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Get the input element |
|
|
|
* @return {HTMLElement} |
|
|
|
*/ |
|
|
|
getInputEl() { |
|
|
|
if(!this.inputEl) { |
|
|
|
if (!this.inputEl) { |
|
|
|
const plh = this.model.get('defaults'); |
|
|
|
const cls = this.inputCls; |
|
|
|
this.inputEl = $(`<input type="text" class="${cls}" placeholder="${plh}">`); |
|
|
|
} |
|
|
|
|
|
|
|
return this.inputEl.get(0); |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
const el = this.$el; |
|
|
|
const ppfx = this.ppfx; |
|
|
|
const holderClass = this.holderClass; |
|
|
|
el.addClass(this.inputClass); |
|
|
|
el.html(this.template()); |
|
|
|
el.find(`.${holderClass}`).append(this.getInputEl()); |
|
|
|
el.find(`.${this.holderClass}`).append(this.getInputEl()); |
|
|
|
return this; |
|
|
|
} |
|
|
|
|
|
|
|
|