cartodb-4.42/lib/assets/javascripts/builder/components/input-number/input-number-fixed-content-view.js

56 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-04-06 13:25:13 +08:00
var Backbone = require('backbone');
var CoreView = require('backbone/core-view');
module.exports = CoreView.extend({
render: function () {
this.clearSubViews();
this._removeForm();
this.$el.empty();
this._initForm();
return this;
},
_initForm: function () {
this._formModel = new Backbone.Model({
value: this.model.get('fixed')
});
this._formModel.schema = {
value: {
type: 'Number',
validators: ['required', {
type: 'interval',
min: this.options.min,
max: this.options.max,
step: this.options.step
}]
}
};
this._formModel.bind('change', function (input) {
this.model.set('fixed', input.get('value'));
}, this);
this._formView = new Backbone.Form({
className: 'CDB-ListDecoration-itemPadding',
model: this._formModel
});
this._formView.bind('change', function () {
this.commit();
});
this.$el.append(this._formView.render().$el);
},
_removeForm: function () {
// Backbone.Form removes the view with the following method
this._formView && this._formView.remove();
},
clean: function () {
this._removeForm();
CoreView.prototype.clean.call(this);
}
});