2011-08-18 13:24:18 +00:00
|
|
|
/*---------------------------------------------------------
|
|
|
|
* OpenERP Web Mobile List View
|
|
|
|
*---------------------------------------------------------*/
|
|
|
|
|
2012-04-17 12:48:30 +00:00
|
|
|
openerp.web_mobile.list_mobile = function (instance) {
|
2011-08-18 13:24:18 +00:00
|
|
|
|
2012-08-14 13:53:24 +00:00
|
|
|
instance.web_mobile.ListView = instance.web_mobile.MobileWidget.extend({
|
2011-09-22 15:54:11 +00:00
|
|
|
|
|
|
|
template: 'ListView',
|
|
|
|
|
2011-07-08 12:26:49 +00:00
|
|
|
init: function(session, element_id, list_id) {
|
|
|
|
this._super(session, element_id);
|
|
|
|
this.list_id = list_id;
|
|
|
|
},
|
|
|
|
start: function() {
|
2011-09-28 06:25:19 +00:00
|
|
|
this.rpc('/web/menu/action', {'menu_id': this.list_id}, this.on_menu_action_loaded);
|
2011-07-08 12:26:49 +00:00
|
|
|
},
|
|
|
|
on_menu_action_loaded: function(data) {
|
|
|
|
var self = this;
|
|
|
|
if (data.action.length) {
|
|
|
|
this.action = data.action[0][2];
|
2011-10-19 11:50:55 +00:00
|
|
|
return this.rpc('/web/listview/load', {
|
|
|
|
model: this.action.res_model,
|
|
|
|
view_id: this.action.views[0][0],
|
|
|
|
view_type: "tree",
|
|
|
|
context: this.action.context,
|
|
|
|
toolbar: false
|
|
|
|
}, this.on_search_data);
|
2011-07-08 12:26:49 +00:00
|
|
|
}
|
|
|
|
},
|
2011-08-31 06:18:16 +00:00
|
|
|
on_search_data: function(ev){
|
2011-07-08 12:26:49 +00:00
|
|
|
var self = this;
|
2011-12-07 09:54:29 +00:00
|
|
|
var list_ids = [];
|
2012-04-17 12:48:30 +00:00
|
|
|
var datasearch = new instance.web.DataSetSearch(self, self.action.res_model,self.action.context);
|
2011-12-01 11:26:58 +00:00
|
|
|
datasearch.domain = self.action.domain;
|
2012-01-10 16:54:51 +00:00
|
|
|
datasearch.read_slice(['name'], {context:datasearch.context, domain: datasearch.domain, limit:80}).then(function(listresult){
|
2011-12-07 09:54:29 +00:00
|
|
|
_.each(listresult, function(i) {
|
|
|
|
list_ids.push(i.id);
|
|
|
|
});
|
2011-10-19 11:50:55 +00:00
|
|
|
_.extend(self.action.context,{"html_name_get" : true});
|
2012-04-17 12:48:30 +00:00
|
|
|
var dataset = new instance.web.DataSet(self, datasearch.model,datasearch.context);
|
2011-12-07 09:54:29 +00:00
|
|
|
dataset.name_get(list_ids,function(res){
|
2011-10-19 11:50:55 +00:00
|
|
|
var additional = "";
|
|
|
|
if(res['html_name_get']){
|
|
|
|
additional = res['display'];
|
2011-09-13 06:23:31 +00:00
|
|
|
}
|
2011-10-19 11:50:55 +00:00
|
|
|
self.$element.html(self.render({'records': res, 'data': additional }));
|
|
|
|
self.$element.find("[data-role=header]").find('h1').html(self.action.name);
|
|
|
|
self.$element.find("[data-role=header]").find('#home').click(function(){
|
|
|
|
$.mobile.changePage("#oe_menu", "slide", false, true);
|
|
|
|
});
|
|
|
|
self.$element.find("a#list-id").click(self.on_list_click);
|
|
|
|
$.mobile.changePage("#"+self.element_id, "slide", false, true);
|
2011-12-22 12:07:13 +00:00
|
|
|
self.$element.find("a#list-id").find('span').addClass('desc');
|
2011-09-13 06:23:31 +00:00
|
|
|
});
|
2011-07-08 12:26:49 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
on_list_click: function(ev) {
|
2011-09-06 09:31:39 +00:00
|
|
|
var $record = $(ev.currentTarget);
|
2011-07-08 12:26:49 +00:00
|
|
|
var self = this;
|
2011-09-21 09:33:12 +00:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
2011-07-08 12:26:49 +00:00
|
|
|
id = $record.data('id');
|
2011-09-16 10:49:38 +00:00
|
|
|
head_title = $.trim($record.text());
|
2011-09-22 07:33:03 +00:00
|
|
|
if(!$('[id^="oe_form_'+id+this.action.res_model+'"]').html()){
|
|
|
|
$('<div id="oe_form_'+id+this.action.res_model+'" data-role="page" data-url="oe_form_'+id+this.action.res_model+'"> </div>').appendTo('#moe');
|
2012-04-17 12:48:30 +00:00
|
|
|
this.formview = new instance.web_mobile.FormView(this, "oe_form_"+id+this.action.res_model, id, this.action, head_title, '' ,'');
|
2011-09-14 07:07:30 +00:00
|
|
|
this.formview.start();
|
|
|
|
}else{
|
2011-09-22 12:34:40 +00:00
|
|
|
$.mobile.changePage('#oe_form_'+id+this.action.res_model, "slide", false, true);
|
2011-09-14 07:07:30 +00:00
|
|
|
}
|
2011-07-08 12:26:49 +00:00
|
|
|
}
|
|
|
|
});
|
2011-09-06 08:58:53 +00:00
|
|
|
};
|