[MERGE] Improvements about the many2many.
bzr revid: nicolas.vanhoren@openerp.com-20110427143538-n70q2vuu567ymzj7
This commit is contained in:
@@ -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.DataSetStatic.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:
|
||||
|
||||
@@ -896,6 +896,73 @@ 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() {
|
||||
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': 'Add'});
|
||||
var self = this;
|
||||
this.list_view.m2m_field = this;
|
||||
this.list_view.start();
|
||||
},
|
||||
set_value: function(value) {
|
||||
if (value != false) {
|
||||
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();
|
||||
|
||||
this.m2m_field.on_ui_change();
|
||||
},
|
||||
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);
|
||||
},
|
||||
do_add_record: function (e) {
|
||||
e.stopImmediatePropagation();
|
||||
// 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"
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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));
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -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 = [];
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -351,9 +351,7 @@
|
||||
</div>
|
||||
</t>
|
||||
<t t-name="FieldMany2Many">
|
||||
<div style="background: #ccc; padding: 20px">
|
||||
Many2Many widget
|
||||
</div>
|
||||
<div t-att-id="widget.list_id"></div>
|
||||
</t>
|
||||
<t t-name="FieldReference">
|
||||
<input type="text" t-att-name="widget.name" t-att-id="widget.element_id" t-att-class="'field_' + widget.type" style="width: 100%" placeholder="Widget Reference"/>
|
||||
|
||||
Reference in New Issue
Block a user