changeset 8dcb3f10cbd2 in sao:default
details: https://hg.tryton.org/sao?cmd=changeset&node=8dcb3f10cbd2
description:
Add completion on xxx2Many and Dict
issue10265
review330691003
diffstat:
CHANGELOG | 1 +
src/common.js | 5 ++-
src/view/form.js | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 94 insertions(+), 9 deletions(-)
diffs (181 lines):
diff -r 6af100dbc938 -r 8dcb3f10cbd2 CHANGELOG
--- a/CHANGELOG Sun Apr 11 18:26:39 2021 +0200
+++ b/CHANGELOG Sun Apr 11 18:29:21 2021 +0200
@@ -1,3 +1,4 @@
+* Add completion on xxx2Many and Dict
* Add attachment preview
* Support document widget
* Support icon of type URL
diff -r 6af100dbc938 -r 8dcb3f10cbd2 src/common.js
--- a/src/common.js Sun Apr 11 18:26:39 2021 +0200
+++ b/src/common.js Sun Apr 11 18:29:21 2021 +0200
@@ -3388,6 +3388,7 @@
} else {
el.wrap('<div class="dropdown"/>');
this.dropdown = el.parent();
+ this.dropdown.css('display', 'table');
}
this.input = el.find('input').add(el.filter('input')).first();
this.input.attr('autocomplete', 'off');
@@ -3545,10 +3546,12 @@
};
var completion = new Sao.common.InputCompletion(
el, source, match_selected, format);
- completion.set_actions([
+ if (action_activated) {
+ completion.set_actions([
['search', Sao.i18n.gettext('Search...')],
['create', Sao.i18n.gettext('Create...')]],
action_activated);
+ }
};
Sao.common.update_completion = function(
diff -r 6af100dbc938 -r 8dcb3f10cbd2 src/view/form.js
--- a/src/view/form.js Sun Apr 11 18:26:39 2021 +0200
+++ b/src/view/form.js Sun Apr 11 18:29:21 2021 +0200
@@ -2998,9 +2998,15 @@
'class': 'form-control input-sm',
'name': attributes.name,
}).appendTo(group);
- // TODO add completion
- //
- //
+
+ if (!attributes.completion || attributes.completion == '1') {
+ Sao.common.get_completion(this.wid_text,
+ this._update_completion.bind(this),
+ this._completion_match_selected.bind(this),
+ this._completion_action_activated.bind(this));
+ this.wid_completion = true;
+ }
+
buttons = jQuery('<div/>', {
'class': 'input-group-btn',
}).appendTo(group);
@@ -3488,7 +3494,31 @@
},
set_value: function() {
this.screen.save_tree_state();
- }
+ },
+ _update_completion: function(text) {
+ if (!this.record) {
+ return;
+ }
+ var model = this.attributes.relation;
+ var domain = this.field.get_domain(this.record);
+ domain = [domain,
+ this.record.expr_eval(this.attributes.add_remove)];
+ var removed_ids = this.field.get_removed_ids(this.record);
+ domain = ['OR', domain, ['id', 'in', removed_ids]];
+ return Sao.common.update_completion(
+ this.wid_text, this.record, this.field, model, domain);
+ },
+ _completion_match_selected: function(value) {
+ this.screen.group.load([value.id], true);
+ this.wid_text.val('');
+ },
+ _completion_action_activated: function(action) {
+ if (action == 'search') {
+ this.add();
+ } else if (action == 'create') {
+ this.new_();
+ }
+ },
});
Sao.View.Form.Many2Many = Sao.class_(Sao.View.Form.Widget, {
@@ -3536,7 +3566,13 @@
// Use keydown to not receive focus-in TAB
this.entry.on('keydown', this.key_press.bind(this));
- // TODO completion
+ if (!attributes.completion || attributes.completion == '1') {
+ Sao.common.get_completion(group,
+ this._update_completion.bind(this),
+ this._completion_match_selected.bind(this),
+ this._completion_action_activated.bind(this));
+ this.wid_completion = true;
+ }
var buttons = jQuery('<div/>', {
'class': 'input-group-btn'
@@ -3758,14 +3794,40 @@
}
this.entry.val('');
}.bind(this);
+ var text = this.entry.val();
screen.switch_view().done(function() {
new Sao.Window.Form(screen, callback, {
'new_': true,
'save_current': true,
- rec_name: this.entry.val()
+ rec_name: text,
});
}.bind(this));
- }
+ },
+ _update_completion: function(text) {
+ if (!this.record) {
+ return;
+ }
+ var model = this.attributes.relation;
+ var domain = this.field.get_domain(this.record);
+ var add_remove = this.record.expr_eval(
+ this.attributes.add_remove);
+ if (!jQuery.isEmptyObject(add_remove)) {
+ domain = [domain, add_remove];
+ }
+ return Sao.common.update_completion(
+ this.entry, this.record, this.field, model, domain);
+ },
+ _completion_match_selected: function(value) {
+ this.screen.group.load([value.id], true);
+ this.entry.val('');
+ },
+ _completion_action_activated: function(action) {
+ if (action == 'search') {
+ this.add();
+ } else if (action == 'create') {
+ this.new_();
+ }
+ },
});
Sao.View.Form.BinaryMixin = Sao.class_(Sao.View.Form.Widget, {
@@ -4377,7 +4439,12 @@
'name': attributes.name,
}).appendTo(group);
- // TODO completion
+ if (!attributes.completion || attributes.completion == '1') {
+ Sao.common.get_completion(group,
+ this._update_completion.bind(this),
+ this._completion_match_selected.bind(this));
+ this.wid_completion = true;
+ }
this.but_add = jQuery('<button/>', {
'class': 'btn btn-default btn-sm',
@@ -4605,6 +4672,20 @@
}.bind(this));
this._set_button_sensitive();
},
+ _update_completion: function(text) {
+ if (this.wid_text.prop('disabled')) {
+ return;
+ }
+ if (!this.record) {
+ return;
+ }
+ return Sao.common.update_completion(
+ this.wid_text, this.record, this.field, this.schema_model);
+ },
+ _completion_match_selected: function(value) {
+ this.add_new_keys([value.id]);
+ this.wid_text.val('');
+ },
get_entries: function(type) {
switch (type) {
case 'char':