From 36c91aa98e249fed0151295c4aedc7a2b96de26e Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 7 May 2012 14:54:34 +0200 Subject: [PATCH] wip bzr revid: nicolas.vanhoren@openerp.com-20120507125434-c5v8u7zj8vzhqtvo --- addons/web/static/src/js/view_form.js | 56 +++++---------------------- addons/web/static/src/xml/base.xml | 4 +- 2 files changed, 12 insertions(+), 48 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 7463df1c50f..6f4503b76bf 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3051,8 +3051,8 @@ instance.web.form.One2ManyKanbanView = instance.web_kanban.KanbanView.extend({ }); } -instance.web.form.FieldMany2ManyTags = instance.web.form.AbstractField.extend({ - template: "FieldMany2Many", +instance.web.form.FieldMany2ManyTags = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.CompletionFieldMixin, { + template: "FieldMany2ManyTags", init: function() { this._super.apply(this, arguments); this.limit = 7; @@ -3060,7 +3060,7 @@ instance.web.form.FieldMany2ManyTags = instance.web.form.AbstractField.extend({ }, start: function() { var self = this; - var textarea = $("textarea", this.$element).textext({ + var $textarea = $("textarea", this.$element).textext({ plugins : 'arrow prompt autocomplete', prompt : "Add one...", autocomplete: { @@ -3078,53 +3078,17 @@ instance.web.form.FieldMany2ManyTags = instance.web.form.AbstractField.extend({ }, }, }).bind('getSuggestions', function(e, data) { + var _this = this; var str = !!data ? data.query || '' : ''; - self.get_search_result(str); - }); - }, - get_search_result: function(str) { - var self = this; - var dataset = new instance.web.DataSet(this, this.field.relation, self.build_context()); - this.orderer.add(dataset.name_search( - str, self.build_domain(), 'ilike', this.limit + 1)).then(function(data) { - - // possible selections for the m2m - self.values = _.map(data, function(x) { - return { - type: 'data', - label: _.str.escapeHTML(x[1]), - data: x, - }; + self.get_search_result(str).then(function(result) { + self.search_result = result; + $(_this).trigger('setSuggestions', {result : _.map(result, function(el, i) { + return _.extend(el, {index:i}); + })}); }); - - // search more... if more results than max - if (values.length > self.limit) { - values = values.slice(0, self.limit); - values.push({type: 'action', label: _t("   Search More..."), action: function() { - dataset.name_search(search_val, self.build_domain(), 'ilike' - , false, function(data) { - self._search_create_popup("search", data); - }); - }}); - } - // quick create - var raw_result = _(data.result).map(function(x) {return x[1];}); - if (search_val.length > 0 && - !_.include(raw_result, search_val)) { - values.push({label: _.str.sprintf(_t('   Create "%s"'), - $('').text(search_val).html()), action: function() { - self._quick_create(search_val); - }}); - } - // create... - values.push({label: _t("   Create and Edit..."), action: function() { - self._search_create_popup("form", undefined, {"default_name": search_val}); - }}); - - $(this).trigger('setSuggestions', {result : _.map(list, function(el, i) {return {index:i, label:el};})}); }); }, -}); +})); /* * TODO niv: clean those deferred stuff, it could be better diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index fa8048b07cc..b48789f6e0f 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1039,9 +1039,9 @@ - +
- +