Maxence Groine
7 years ago
4 changed files with 62 additions and 84 deletions
-
41web_widget_many2many_tags_multi_selection/README.rst
-
21web_widget_many2many_tags_multi_selection/__init__.py
-
24web_widget_many2many_tags_multi_selection/__manifest__.py
-
52web_widget_many2many_tags_multi_selection/static/src/js/view_form.js
@ -1,20 +1 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# Copyright (C) 2015-TODAY Akretion (<http://www.akretion.com>). |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
@ -1,39 +1,41 @@ |
|||
odoo.define('web_widget_many2many_tags_multi_selection.multiple_tags', function (require) { |
|||
"use strict"; |
|||
|
|||
var FormCommon = require('web.form_common'); |
|||
var rel_fields = require('web.relational_fields'); |
|||
var dialogs = require('web.view_dialogs'); |
|||
var core = require('web.core'); |
|||
var data = require('web.data'); |
|||
var _t = core._t; |
|||
|
|||
FormCommon.CompletionFieldMixin._search_create_popup = function(view, ids, context) { |
|||
rel_fields.FieldMany2One.include({ |
|||
_searchCreatePopup: function(view, ids, context) { |
|||
var self = this; |
|||
new FormCommon.SelectCreateDialog(this, { |
|||
res_model: self.field.relation, |
|||
domain: self.build_domain(), |
|||
context: new data.CompoundContext(self.build_context(), context || {}), |
|||
title: (view === 'search' ? _t("Search: ") : _t("Create: ")) + this.string, |
|||
initial_ids: ids ? _.map(ids, function(x) {return x[0];}) : undefined, |
|||
initial_view: view, |
|||
disable_multiple_selection: this.field.type != 'many2many', |
|||
on_selected: function(element_ids) { |
|||
for(var i=0, len=element_ids.length; i<len;i++) { |
|||
self.add_id(element_ids[i]); |
|||
if (self.field.type != 'many2many') { |
|||
break; |
|||
} |
|||
} |
|||
self.focus(); |
|||
} |
|||
}).open(); |
|||
var domain = self.build_domain(); |
|||
|
|||
if (self.field.type == 'many2many') { |
|||
var selected_ids = self.get_search_blacklist(); |
|||
// Don't include already selected instances in the search domain
|
|||
var domain = self.record.getDomain({fieldName: self.name}); |
|||
if (self.field.type === 'many2many') { |
|||
var selected_ids = self._getSearchBlacklist(); |
|||
if (selected_ids.length > 0) { |
|||
domain = new data.CompoundDomain(domain, ["!", ["id", "in", selected_ids]]); |
|||
domain.push(['id', 'not in', selected_ids]); |
|||
} |
|||
} |
|||
|
|||
new dialogs.SelectCreateDialog(self, _.extend({}, self.nodeOptions, { |
|||
res_model: self.field.relation, |
|||
domain: domain, |
|||
context: _.extend({}, self.record.getContext(self.recordParams), context || {}), |
|||
title: (view === 'search' ? _t("Search: ") : _t("Create: ")) + self.string, |
|||
initial_ids: ids ? _.map(ids, function(x) {return x[0];}) : undefined, |
|||
initial_view: view, |
|||
disable_multiple_selection: self.field.type !== 'many2many', |
|||
on_selected: function(records) { |
|||
if (self.field.type !== 'many2many') { |
|||
self.reinitialize(records[0]); |
|||
} else { |
|||
self.reinitialize(records); |
|||
} |
|||
self.activate(); |
|||
} |
|||
})).open(); |
|||
}, |
|||
}); |
|||
}); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue