diff --git a/src/common.js b/src/common.js index 0a37c4c987..5c26eaf5d7 100644 --- a/src/common.js +++ b/src/common.js @@ -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 '

' + context.action + '

'; + } + } }); 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); }; diff --git a/src/sao.less b/src/sao.less index 2beaeb9019..5b339196b1 100644 --- a/src/sao.less +++ b/src/sao.less @@ -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; +} diff --git a/src/view.js b/src/view.js index acd8830076..7c816a575d 100644 --- a/src/view.js +++ b/src/view.js @@ -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();