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',
},
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;
}

6
src/style_manager/model/PropertySlider.js

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

2
src/style_manager/view/PropertySliderView.js

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

Loading…
Cancel
Save