Browse Source

Refactor abstract ui input

pull/487/head
Artur Arseniev 8 years ago
parent
commit
6e48ca0e4f
  1. 23
      src/domain_abstract/ui/Input.js
  2. 6
      src/style_manager/model/PropertySlider.js
  3. 2
      src/style_manager/view/PropertySliderView.js

23
src/domain_abstract/ui/Input.js

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

6
src/style_manager/model/PropertySlider.js

@ -2,8 +2,8 @@ const Property = require('./PropertyInteger');
module.exports = Property.extend({ module.exports = Property.extend({
defaults: Object.assign({}, Property.prototype.defaults, { defaults: { ...Property.prototype.defaults,
showInput: 1, showInput: 1,
}), },
}); });

2
src/style_manager/view/PropertySliderView.js

@ -1,4 +1,3 @@
const InputNumber = require('domain_abstract/ui/InputNumber');
const Property = require('./PropertyIntegerView'); const Property = require('./PropertyIntegerView');
module.exports = Property.extend({ module.exports = Property.extend({
@ -31,6 +30,7 @@ module.exports = Property.extend({
inputValueChanged() { inputValueChanged() {
const model = this.model; const model = this.model;
const step = model.get('step'); const step = model.get('step');
console.log('slider ', this.getSliderEl().value, ' input', this.getInputEl().value);
this.getInputEl().value = this.getSliderEl().value; this.getInputEl().value = this.getSliderEl().value;
const value = this.getInputValue() - step; const value = this.getInputValue() - step;
model.set('value', value, {avoidStore: 1}).set('value', value + step); model.set('value', value, {avoidStore: 1}).set('value', value + step);

Loading…
Cancel
Save