Add MultiSelection entry to Dict field

issue8903
review284571003
This commit is contained in:
Nicolas Évrard
2019-12-30 14:26:14 +01:00
parent 15f0d69c86
commit 3268b3039d
2 changed files with 41 additions and 10 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add MultiSelection entry to Dict field
* Position new record based on order
* Reset display_size of TreeView when group is cleared or changed
* Allow relation field to be selected in CSV export
+40 -10
View File
@@ -4323,6 +4323,8 @@ function eval_pyson(value){
return Sao.View.Form.Dict.Boolean;
case 'selection':
return Sao.View.Form.Dict.Selection;
case 'multiselection':
return Sao.View.Form.Dict.MultiSelection;
case 'integer':
return Sao.View.Form.Dict.Integer;
case 'float':
@@ -4407,10 +4409,9 @@ function eval_pyson(value){
}
});
Sao.View.Form.Dict.Selection = Sao.class_(Sao.View.Form.Dict.Entry, {
class_: 'dict-selection',
Sao.View.Form.Dict.SelectionEntry = Sao.class_(Sao.View.Form.Dict.Entry, {
create_widget: function() {
Sao.View.Form.Dict.Selection._super.create_widget.call(this);
Sao.View.Form.Dict.SelectionEntry._super.create_widget.call(this);
var select = jQuery('<select/>', {
'class': 'form-control input-sm mousetrap'
});
@@ -4424,7 +4425,6 @@ function eval_pyson(value){
return a[1].localeCompare(b[1]);
});
}
selection.splice(0, 0, [null, '']);
selection.forEach(function(e) {
select.append(jQuery('<option/>', {
'value': JSON.stringify(e[0]),
@@ -4432,18 +4432,48 @@ function eval_pyson(value){
}));
});
},
get_value: function() {
return JSON.parse(this.input.val());
},
set_value: function(value) {
this.input.val(JSON.stringify(value));
},
set_readonly: function(readonly) {
this._readonly = readonly;
this.input.prop('disabled', readonly);
}
});
Sao.View.Form.Dict.Selection = Sao.class_(
Sao.View.Form.Dict.SelectionEntry, {
class_: 'dict-selection',
create_widget: function() {
Sao.View.Form.Dict.Selection._super.create_widget.call(this);
this.input.prepend(jQuery('<option/>', {
'value': JSON.stringify(null),
'text': '',
}));
},
get_value: function() {
return JSON.parse(this.input.val());
},
set_value: function(value) {
this.input.val(JSON.stringify(value));
},
});
Sao.View.Form.Dict.MultiSelection = Sao.class_(
Sao.View.Form.Dict.SelectionEntry, {
class_: 'dict-multiselection',
create_widget: function() {
Sao.View.Form.Dict.MultiSelection._super
.create_widget.call(this);
this.input.prop('multiple', true);
},
get_value: function() {
var value = this.input.val();
return value.map(function(e) { return JSON.parse(e); });
},
set_value: function(value) {
value = value.map(function(e) { return JSON.stringify(e); });
this.input.val(value);
}
});
Sao.View.Form.Dict.Float = Sao.class_(Sao.View.Form.Dict.Entry, {
class_: 'dict-float',
create_widget: function() {