[IMP] Read-only many2many implemented.
authorniv-openerp <nicolas.vanhoren@openerp.com>
Tue, 26 Apr 2011 11:24:13 +0000 (13:24 +0200)
committerniv-openerp <nicolas.vanhoren@openerp.com>
Tue, 26 Apr 2011 11:24:13 +0000 (13:24 +0200)
bzr revid: nicolas.vanhoren@openerp.com-20110426112413-nfoozpnol8zbli26

addons/base/static/src/js/data.js
addons/base/static/src/js/form.js

index a29f320..bd84f1d 100644 (file)
@@ -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:
index c6ec07b..08c4a4f 100644 (file)
@@ -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);