From b64e5247be509a8dc03e6d54191c132a33de9974 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Thu, 1 Aug 2019 08:33:38 +0200 Subject: [PATCH] Add new methods to TraitView --- src/trait_manager/view/TraitView.js | 40 +++++++++++++++++++---------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/trait_manager/view/TraitView.js b/src/trait_manager/view/TraitView.js index eea0fc02d..e729493c8 100644 --- a/src/trait_manager/view/TraitView.js +++ b/src/trait_manager/view/TraitView.js @@ -13,28 +13,23 @@ export default Backbone.View.extend({ }, initialize(o) { - const model = this.model; - const name = model.get('name'); - const target = model.target; this.config = o.config || {}; this.em = this.config.em; this.pfx = this.config.stylePrefix || ''; this.ppfx = this.config.pStylePrefix || ''; + const { model, pfx, ppfx } = this; + const { target } = model; this.target = target; - this.className = this.pfx + 'trait'; - this.labelClass = this.ppfx + 'label'; - this.fieldClass = - this.ppfx + 'field ' + this.ppfx + 'field-' + model.get('type'); - this.inputhClass = this.ppfx + 'input-holder'; + this.className = `${pfx}trait`; + this.labelClass = `${ppfx}label`; + this.fieldClass = `${ppfx}field ${ppfx}field-${model.get('type')}`; + this.inputhClass = `${ppfx}input-holder`; model.off('change:value', this.onValueChange); this.listenTo(model, 'change:value', this.onValueChange); model.view = this; - this.tmpl = - '
'; + this.tmpl = `
+
+
`; }, /** @@ -92,12 +87,29 @@ export default Backbone.View.extend({ return label.charAt(0).toUpperCase() + label.slice(1).replace(/-/g, ' '); }, + /** + * Returns current target component + */ + getComponent() { + return this.target; + }, + + getEl() { + return this.getInputEl(); + }, + /** * Returns input element * @return {HTMLElement} * @private */ getInputEl() { + if (this.createEl) { + if (!this.inputEl) { + this.inputEl = this.createEl(); + } + return this.inputEl; + } if (!this.$input) { const md = this.model; const plh = md.get('placeholder') || md.get('default') || '';