keeweb/app/scripts/views/fields/field-view-select.js

53 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-01-31 07:50:28 +01:00
const FieldView = require('./field-view');
2016-06-05 16:49:00 +02:00
2017-01-31 07:50:28 +01:00
const FieldViewSelect = FieldView.extend({
2016-06-05 16:49:00 +02:00
readonly: true,
2016-07-17 13:30:38 +02:00
2016-06-05 16:49:00 +02:00
renderValue: function(value) {
2019-08-16 23:05:39 +02:00
return (
'<select>' +
value
.map(opt => {
return (
'<option ' +
'value="' +
_.escape(opt.id) +
'" ' +
(opt.selected ? 'selected ' : '') +
'>' +
_.escape(opt.value) +
'</option>'
);
})
.join('') +
'</select>'
);
2016-06-05 16:49:00 +02:00
},
render: function() {
FieldView.prototype.render.call(this);
this.valueEl.addClass('details__field-value--select');
2016-07-17 13:30:38 +02:00
this.valueEl.find('select:first').change(e => {
this.triggerChange({ val: e.target.value, field: this.model.name });
2016-06-05 16:49:00 +02:00
});
},
fieldLabelClick: function() {},
fieldValueClick: function() {},
edit: function() {},
startEdit: function() {},
endEdit: function(newVal, extra) {
if (!this.editing) {
return;
}
delete this.input;
FieldView.prototype.endEdit.call(this, newVal, extra);
}
});
module.exports = FieldViewSelect;