From 0ae1e8f2b9b6d5d499b145302bc982fcaf7faa4a Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 22 Apr 2011 17:54:52 +0200 Subject: [PATCH 1/6] [IMP] Some code about many2many widgets. bzr revid: nicolas.vanhoren@openerp.com-20110422155452-9lth3lrm8pwf9c2r --- addons/base/static/src/js/form.js | 16 ++++++++++++++++ addons/base/static/src/js/list.js | 8 +++++--- addons/base/static/src/xml/base.xml | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js index 84d7fe0babd..ea2b377078b 100644 --- a/addons/base/static/src/js/form.js +++ b/addons/base/static/src/js/form.js @@ -896,6 +896,22 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({ init: function(view, node) { this._super(view, node); this.template = "FieldMany2Many"; + this.list_id = _.uniqueId("many2many"); + }, + start: function() { + debugger; + this._super.apply(this, arguments); + this.dataset = new openerp.base.DataSetSearch(this.session, this.field.relation); + this.list_view = new openerp.base.ListView(undefined, this.view.session, + this.list_id, this.dataset, false, undefined); + this.list_view.start(); + }, + set_value: function(value) { + if (value != false) { + this.dataset.ids = value; + this.dataset.count = value.length; + this.list_view.do_update(); + } } }); diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js index 8035616e59a..aa9882aed36 100644 --- a/addons/base/static/src/js/list.js +++ b/addons/base/static/src/js/list.js @@ -64,7 +64,7 @@ openerp.base.ListView = openerp.base.Controller.extend( return this.rpc("/base/listview/load", { model: this.model, view_id: this.view_id, - toolbar: !!this.view_manager.sidebar + toolbar: this.view_manager ? !!this.view_manager.sidebar : false }, this.on_loaded); }, /** @@ -168,7 +168,7 @@ openerp.base.ListView = openerp.base.Controller.extend( 'tr', 'click', this.on_select_row); // sidebar stuff - if (this.view_manager.sidebar) { + if (this.view_manager && this.view_manager.sidebar) { this.view_manager.sidebar.set_toolbar(data.fields_view.toolbar); } }, @@ -262,7 +262,9 @@ openerp.base.ListView = openerp.base.Controller.extend( view = view || 'form'; this.dataset.index = index; _.delay(_.bind(function () { - this.view_manager.on_mode_switch(view); + if(this.view_manager) { + this.view_manager.on_mode_switch(view); + } }, this)); }, /** diff --git a/addons/base/static/src/xml/base.xml b/addons/base/static/src/xml/base.xml index b49ef2c7d6a..4804f34d785 100644 --- a/addons/base/static/src/xml/base.xml +++ b/addons/base/static/src/xml/base.xml @@ -353,6 +353,7 @@
Many2Many widget +
From 5e2cda5a0c382c297e45bb28d32b9ad7c89b9271 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 26 Apr 2011 10:55:27 +0200 Subject: [PATCH 2/6] [FIX] Made the list appear in many2many. bzr revid: nicolas.vanhoren@openerp.com-20110426085527-5ntgrkug2clipp2s --- addons/base/static/src/js/form.js | 1 - addons/base/static/src/js/search.js | 1 - addons/base/static/src/xml/base.xml | 5 +---- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js index ea2b377078b..c6ec07b11e6 100644 --- a/addons/base/static/src/js/form.js +++ b/addons/base/static/src/js/form.js @@ -899,7 +899,6 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({ this.list_id = _.uniqueId("many2many"); }, start: function() { - debugger; this._super.apply(this, arguments); this.dataset = new openerp.base.DataSetSearch(this.session, this.field.relation); this.list_view = new openerp.base.ListView(undefined, this.view.session, diff --git a/addons/base/static/src/js/search.js b/addons/base/static/src/js/search.js index 0f4ab8585b8..ae5e8551b93 100644 --- a/addons/base/static/src/js/search.js +++ b/addons/base/static/src/js/search.js @@ -146,7 +146,6 @@ openerp.base.SearchView = openerp.base.Controller.extend({ do_search: function (e) { if (e && e.preventDefault) { e.preventDefault(); } - //debugger; var domains = [], contexts = []; var errors = []; diff --git a/addons/base/static/src/xml/base.xml b/addons/base/static/src/xml/base.xml index 4804f34d785..ef4cbba46b0 100644 --- a/addons/base/static/src/xml/base.xml +++ b/addons/base/static/src/xml/base.xml @@ -351,10 +351,7 @@ -
- Many2Many widget -
-
+
From 2cfc487ccddc9b1a21c23facdd44aee27b0d82c9 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 26 Apr 2011 13:24:13 +0200 Subject: [PATCH 3/6] [IMP] Read-only many2many implemented. bzr revid: nicolas.vanhoren@openerp.com-20110426112413-nfoozpnol8zbli26 --- addons/base/static/src/js/data.js | 9 +++++++++ addons/base/static/src/js/form.js | 28 ++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/addons/base/static/src/js/data.js b/addons/base/static/src/js/data.js index a29f320b79c..bd84f1d7229 100644 --- a/addons/base/static/src/js/data.js +++ b/addons/base/static/src/js/data.js @@ -183,6 +183,15 @@ openerp.base.DataSetSearch = openerp.base.DataSet.extend({ openerp.base.DataSetRelational = openerp.base.DataSet.extend( /** @lends openerp.base.DataSet# */{ }); +openerp.base.DataSetMany2Many = openerp.base.DataSetSearch.extend({ + /* should extend DataSetStatic instead, but list view still does not support it + */ + + unlink: function(ids) { + // just do nothing + }, +}); + }; // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js index c6ec07b11e6..08c4a4fbb74 100644 --- a/addons/base/static/src/js/form.js +++ b/addons/base/static/src/js/form.js @@ -900,20 +900,36 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({ }, start: function() { this._super.apply(this, arguments); - this.dataset = new openerp.base.DataSetSearch(this.session, this.field.relation); - this.list_view = new openerp.base.ListView(undefined, this.view.session, - this.list_id, this.dataset, false, undefined); + this.dataset = new openerp.base.DataSetMany2Many(this.session, this.field.relation); + this.list_view = new openerp.base.form.Many2ManyListView(undefined, this.view.session, + this.list_id, this.dataset, false, {'selected': false, 'addable': null, 'deletable': false}); this.list_view.start(); }, set_value: function(value) { if (value != false) { - this.dataset.ids = value; - this.dataset.count = value.length; - this.list_view.do_update(); + // this is not correct behavior, need to change once list view can work with + // static datasets + this.dataset.domain = [["id","in",value]]; + /*this.dataset.ids = value; + this.dataset.count = value.length;*/ + this.list_view.do_reload(); } } }); +openerp.base.form.Many2ManyListView = openerp.base.ListView.extend({ + do_delete: function (e) { + /* + e.stopImmediatePropagation(); + var ids = [this.rows[$(e.currentTarget).closest('tr').prevAll().length].data.id.value]; + this.dataset.ids = _.without.apply(null, [this.dataset.ids].concat(ids)); + this.dataset.count = this.dataset.ids.length; + // there may be a faster way + this.do_reload(); + */ + } +}); + openerp.base.form.FieldReference = openerp.base.form.Field.extend({ init: function(view, node) { this._super(view, node); From 96c1dacf4c2fd6b903d2d09697f2b3a21babf64b Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 26 Apr 2011 14:11:46 +0200 Subject: [PATCH 4/6] [IMP] m2m now support suppression of elements. bzr revid: nicolas.vanhoren@openerp.com-20110426121146-kq1cuu7i1r0nwfiq --- addons/base/static/src/js/data.js | 2 +- addons/base/static/src/js/form.js | 32 ++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/addons/base/static/src/js/data.js b/addons/base/static/src/js/data.js index bd84f1d7229..6d566f4de0a 100644 --- a/addons/base/static/src/js/data.js +++ b/addons/base/static/src/js/data.js @@ -183,7 +183,7 @@ openerp.base.DataSetSearch = openerp.base.DataSet.extend({ openerp.base.DataSetRelational = openerp.base.DataSet.extend( /** @lends openerp.base.DataSet# */{ }); -openerp.base.DataSetMany2Many = openerp.base.DataSetSearch.extend({ +openerp.base.DataSetMany2Many = openerp.base.DataSetStatic.extend({ /* should extend DataSetStatic instead, but list view still does not support it */ diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js index 08c4a4fbb74..5e0d739a279 100644 --- a/addons/base/static/src/js/form.js +++ b/addons/base/static/src/js/form.js @@ -902,32 +902,46 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({ this._super.apply(this, arguments); this.dataset = new openerp.base.DataSetMany2Many(this.session, this.field.relation); this.list_view = new openerp.base.form.Many2ManyListView(undefined, this.view.session, - this.list_id, this.dataset, false, {'selected': false, 'addable': null, 'deletable': false}); + this.list_id, this.dataset, false, {'selected': false, 'addable': 'Add'}); + var self = this; + this.list_view.do_delete.add_last(function() { + self.on_ui_change(); + }); this.list_view.start(); }, set_value: function(value) { if (value != false) { - // this is not correct behavior, need to change once list view can work with - // static datasets - this.dataset.domain = [["id","in",value]]; - /*this.dataset.ids = value; - this.dataset.count = value.length;*/ + this.dataset.ids = value; + this.dataset.count = value.length; this.list_view.do_reload(); } + }, + get_value: function() { + return [[6,false,this.dataset.ids]]; } }); openerp.base.form.Many2ManyListView = openerp.base.ListView.extend({ do_delete: function (e) { - /* e.stopImmediatePropagation(); var ids = [this.rows[$(e.currentTarget).closest('tr').prevAll().length].data.id.value]; this.dataset.ids = _.without.apply(null, [this.dataset.ids].concat(ids)); this.dataset.count = this.dataset.ids.length; // there may be a faster way this.do_reload(); - */ - } + }, + do_reload: function () { + /* Dear xmo, according to your comments, this method's implementation in list view seems + * to be a little bit bullshit. + * I assume the list view will be changed later, so I hope it will support static datasets. + */ + return this.rpc('/base/listview/fill', { + 'model': this.dataset.model, + 'id': this.view_id, + 'domain': [["id", "in", this.dataset.ids]], + 'context': this.dataset.context + }, this.do_fill_table); + }, }); openerp.base.form.FieldReference = openerp.base.form.Field.extend({ From 7bb1ffec7bb15d8a8dd246b5717377105e252c27 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 26 Apr 2011 16:13:34 +0200 Subject: [PATCH 5/6] [IMP] Improved m2m to open a popup when we click one of the items. bzr revid: nicolas.vanhoren@openerp.com-20110426141334-s3xl2y8rp9arphmn --- addons/base/static/src/js/form.js | 54 ++++++++++++++++++++++++++++-- addons/base/static/src/js/views.js | 9 ++++- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js index 5e0d739a279..4ed5c8f250a 100644 --- a/addons/base/static/src/js/form.js +++ b/addons/base/static/src/js/form.js @@ -904,9 +904,7 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({ this.list_view = new openerp.base.form.Many2ManyListView(undefined, this.view.session, this.list_id, this.dataset, false, {'selected': false, 'addable': 'Add'}); var self = this; - this.list_view.do_delete.add_last(function() { - self.on_ui_change(); - }); + this.list_view.m2m_field = this; this.list_view.start(); }, set_value: function(value) { @@ -929,6 +927,8 @@ openerp.base.form.Many2ManyListView = openerp.base.ListView.extend({ this.dataset.count = this.dataset.ids.length; // there may be a faster way this.do_reload(); + + this.m2m_field.on_ui_change(); }, do_reload: function () { /* Dear xmo, according to your comments, this method's implementation in list view seems @@ -942,6 +942,54 @@ openerp.base.form.Many2ManyListView = openerp.base.ListView.extend({ 'context': this.dataset.context }, this.do_fill_table); }, + do_add_record: function () { + // TODO: need to open a popup with search view + }, + on_select_row: function(event) { + var $target = $(event.currentTarget); + var row = this.rows[$target.prevAll().length]; + var id = row.data.id.value; + if(! id) { + return; + } + var action_manager = this.m2m_field.view.session.action_manager; + action_manager.do_action({ + "res_model": this.dataset.model, + "views":[[false,"form"]], + "res_id": id, + "type":"ir.actions.act_window", + "view_type":"form", + "view_mode":"form", + "target":"new" + }); + /*action_manager.do_action({ + "groups_id":[], + "domain":"[]", + "help":false, + "res_model":"partner.sms.send", + "search_view_id":false, + "id":75, + "src_model":"res.partner", + "views":[[false,"form"]], + "menus":false, + "display_menu_tip":true, + "usage":"", + "type":"ir.actions.act_window", + "string":"SMS Send", + "view_type":"form", + "view_id":false, + "auto_refresh":0, + "view_mode":"form", + "view_ids":[], + "target":"new", + "multi":false, + "name":"SMS Send", + "auto_search":true, + "filter":false, + "limit":0, + "context":"{}" + });*/ + } }); openerp.base.form.FieldReference = openerp.base.form.Field.extend({ diff --git a/addons/base/static/src/js/views.js b/addons/base/static/src/js/views.js index 8ef14a3edbf..8b29850d071 100644 --- a/addons/base/static/src/js/views.js +++ b/addons/base/static/src/js/views.js @@ -183,7 +183,14 @@ openerp.base.ViewManager = openerp.base.Controller.extend({ openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({ init: function(session, element_id, action, sidebar) { - var dataset = new openerp.base.DataSetSearch(session, action.res_model); + var dataset; + if(!action.res_id) { + dataset = new openerp.base.DataSetSearch(session, action.res_model); + } else { + dataset = new openerp.base.DataSetStatic(session, action.res_model); + dataset.ids = [action.res_id]; + dataset.count = 1; + } this._super(session, element_id, dataset, action.views); this.action = action; this.sidebar = sidebar; From 33a7bbb0c489b30f7a4889eb47f8163540e42ae7 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 26 Apr 2011 16:24:24 +0200 Subject: [PATCH 6/6] [FIX] Some problem when clicking 'Add' in many2many. bzr revid: nicolas.vanhoren@openerp.com-20110426142424-llpiez4i9tgvjkr6 --- addons/base/static/src/js/form.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js index 4ed5c8f250a..cda1b0047eb 100644 --- a/addons/base/static/src/js/form.js +++ b/addons/base/static/src/js/form.js @@ -942,7 +942,8 @@ openerp.base.form.Many2ManyListView = openerp.base.ListView.extend({ 'context': this.dataset.context }, this.do_fill_table); }, - do_add_record: function () { + do_add_record: function (e) { + e.stopImmediatePropagation(); // TODO: need to open a popup with search view }, on_select_row: function(event) {