Browse Source

Add `setOptions`, `addOption` and `getOptions` to PropertyRadio. Closes #1215

pull/1229/head
Artur Arseniev 8 years ago
parent
commit
d2a24fd783
  1. 29
      src/style_manager/model/PropertyRadio.js
  2. 16
      src/style_manager/view/PropertySelectView.js

29
src/style_manager/model/PropertyRadio.js

@ -1,9 +1,36 @@
const Property = require('./Property');
module.exports = Property.extend({
defaults: {
defaults: () => ({
...Property.prototype.defaults,
// Array of options, eg. [{name: 'Label ', value: '100'}]
options: []
}),
initialize(...args) {
Property.prototype.initialize.apply(this, args);
this.listenTo(this, 'change:options', this.onOptionChange);
},
onOptionChange() {
this.set('list', this.get('options'));
},
getOptions() {
const { options, list } = this.attributes;
return options && options.length ? options : list;
},
setOptions(opts = []) {
this.set('options', opts);
return this;
},
addOption(opt) {
if (opt) {
const opts = this.getOptions();
this.setOptions([...opts, opt]);
}
return this;
}
});

16
src/style_manager/view/PropertySelectView.js

@ -1,7 +1,8 @@
import Backbone from 'backbone';
import PropertyView from './PropertyView';
const $ = Backbone.$;
module.exports = require('./PropertyView').extend({
module.exports = PropertyView.extend({
templateInput() {
const pfx = this.pfx;
const ppfx = this.ppfx;
@ -15,10 +16,19 @@ module.exports = require('./PropertyView').extend({
`;
},
initialize(...args) {
PropertyView.prototype.initialize.apply(this, args);
this.listenTo(this.model, 'change:options', this.updateOptions);
},
updateOptions() {
this.input = null;
this.onRender();
},
onRender() {
var pfx = this.pfx;
const model = this.model;
const options = model.get('list') || model.get('options') || [];
const options = this.model.getOptions();
if (!this.input) {
let optionsStr = '';

Loading…
Cancel
Save