Add Search / Create actions to many2one autocompletion popup

review15341002
This commit is contained in:
Nicolas Évrard committed 2015-04-30 17:38:56 +02:00
1 parent efa43c9cae
commit 0f813b0cf7
3 files changed
+49 -7

No files matched your search

+29 -4
View File
@@ -2836,15 +2836,41 @@
});
Sao.common.processing = new Sao.common.Processing();
Sao.common.get_completion = function(entry, source, match_selected,
search, create) {
Sao.common.get_completion = function(entry, source, match_selected) {
entry.attr('autocomplete', 'off');
entry.typeahead({
'minLength': 1,
'highlight': true
}, {
'name': 'suggestions',
'source': source,
'displayKey': 'rec_name'
'displayKey': 'rec_name',
}, {
'name': 'actions',
'source': function(query, process) {
var results = [];
if (entry.data('search')) {
results.push({
'id': 'search',
'action': 'Search …',
'query': query
});
}
if (entry.data('create')) {
results.push({
'id': 'create',
'action': 'Create …',
'query': query
});
}
process(results);
},
'displayKey': 'query',
'templates': {
'suggestion': function(context) {
return '<p>' + context.action + '</p>';
}
}
});
entry.on('typeahead:selected', match_selected);
};
@@ -2871,7 +2897,6 @@
if (entry.typeahead('val') != search_text) {
return prm.reject();
}
// TODO search & create
prm.resolve(results);
}, prm.reject);
};
+6
View File
@@ -198,3 +198,9 @@
.tt-hint {
background-color: transparent !important;
}
.tt-dataset-actions {
font-style: italic;
font-variant: small-caps;
border-top: 1px #ddd solid;
}
+14 -3
View File
@@ -2399,9 +2399,20 @@
prm.done(process);
},
_completion_match_selected: function(event_, selected_item, name) {
this.record().field_set_client(this.field_name,
this.value_from_id(selected_item.id,
selected_item.rec_name), true);
if (selected_item.id == 'search') {
// it's necessary to set the value so that edit() can get it
// and make the search on the user provided content
this.value(selected_item.query);
this.edit();
this.value('');
} else if (selected_item.id == 'create') {
this.new_();
this.value('');
} else {
this.record().field_set_client(this.field_name,
this.value_from_id(selected_item.id,
selected_item.rec_name), true);
}
},
display: function(record, field) {
var screen_record = this.record();