2011-03-30 14:00:48 +00:00
|
|
|
|
2011-03-30 14:35:56 +00:00
|
|
|
openerp.base.list = function (openerp) {
|
2011-03-30 14:00:48 +00:00
|
|
|
|
2011-03-31 15:25:31 +00:00
|
|
|
openerp.base.views.add('list', 'openerp.base.ListView');
|
2011-03-30 14:00:48 +00:00
|
|
|
openerp.base.ListView = openerp.base.Controller.extend({
|
|
|
|
init: function(session, element_id, dataset, view_id) {
|
|
|
|
this._super(session, element_id);
|
|
|
|
this.dataset = dataset;
|
|
|
|
this.model = dataset.model;
|
|
|
|
this.view_id = view_id;
|
|
|
|
this.name = "";
|
2011-03-31 14:44:22 +00:00
|
|
|
// TODO: default to action.limit
|
|
|
|
// TODO: decide if limit is a property of DataSet and thus global to all views (calendar ?)
|
|
|
|
this.limit = 80;
|
2011-03-30 14:00:48 +00:00
|
|
|
|
|
|
|
this.cols = [];
|
|
|
|
|
|
|
|
this.$table = null;
|
|
|
|
this.colnames = [];
|
|
|
|
this.colmodel = [];
|
|
|
|
|
|
|
|
this.event_loading = false; // TODO in the future prevent abusive click by masking
|
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
//this.log('Starting ListView '+this.model+this.view_id)
|
2011-04-01 11:50:05 +00:00
|
|
|
return this.rpc("/base/listview/load", {"model": this.model, "view_id":this.view_id}, this.on_loaded);
|
2011-03-30 14:00:48 +00:00
|
|
|
},
|
|
|
|
on_loaded: function(data) {
|
|
|
|
this.fields_view = data.fields_view;
|
|
|
|
//this.log(this.fields_view);
|
|
|
|
this.name = "" + this.fields_view.arch.attrs.string;
|
|
|
|
this.$element.html(QWeb.render("ListView", {"fields_view": this.fields_view}));
|
|
|
|
this.$table = this.$element.find("table");
|
|
|
|
this.cols = [];
|
|
|
|
this.colnames = [];
|
|
|
|
this.colmodel = [];
|
|
|
|
// TODO uss a object for each col, fill it with view and fallback to dataset.model_field
|
|
|
|
var tree = this.fields_view.arch.children;
|
|
|
|
for(var i = 0; i < tree.length; i++) {
|
|
|
|
var col = tree[i];
|
|
|
|
if(col.tag == "field") {
|
|
|
|
this.cols.push(col.attrs.name);
|
|
|
|
this.colnames.push(col.attrs.name);
|
|
|
|
this.colmodel.push({ name: col.attrs.name, index: col.attrs.name });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.dataset.fields = this.cols;
|
2011-04-04 15:06:19 +00:00
|
|
|
|
2011-03-30 14:00:48 +00:00
|
|
|
var width = this.$element.width();
|
|
|
|
this.$table.jqGrid({
|
|
|
|
datatype: "local",
|
|
|
|
height: "100%",
|
|
|
|
rowNum: 100,
|
|
|
|
//rowList: [10,20,30],
|
|
|
|
colNames: this.colnames,
|
|
|
|
colModel: this.colmodel,
|
|
|
|
//pager: "#plist47",
|
|
|
|
viewrecords: true,
|
|
|
|
caption: this.name
|
|
|
|
}).setGridWidth(width);
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
$(window).bind('resize', function() {
|
|
|
|
self.$element.children().hide();
|
|
|
|
self.$table.setGridWidth(self.$element.width());
|
|
|
|
self.$element.children().show();
|
|
|
|
}).trigger('resize');
|
|
|
|
},
|
|
|
|
do_fill_table: function(records) {
|
|
|
|
this.log("do_fill_table");
|
|
|
|
|
|
|
|
this.$table
|
|
|
|
.clearGridData()
|
|
|
|
.addRowData('id', _.map(records, function (record) {
|
|
|
|
return record.values;
|
|
|
|
}));
|
|
|
|
|
2011-03-31 14:44:22 +00:00
|
|
|
},
|
2011-04-04 15:34:26 +00:00
|
|
|
do_show: function () {
|
|
|
|
// TODO: re-trigger search
|
|
|
|
this.$element.show();
|
|
|
|
},
|
|
|
|
do_hide: function () {
|
|
|
|
this.$element.hide();
|
|
|
|
},
|
2011-03-31 14:44:22 +00:00
|
|
|
do_search: function (domains, contexts, groupbys) {
|
|
|
|
var self = this;
|
|
|
|
this.rpc('/base/session/eval_domain_and_context', {
|
|
|
|
domains: domains,
|
|
|
|
contexts: contexts,
|
|
|
|
group_by_seq: groupbys
|
|
|
|
}, function (results) {
|
|
|
|
// TODO: handle non-empty results.group_by with read_group
|
2011-04-04 15:06:19 +00:00
|
|
|
self.dataset.context = results.context;
|
|
|
|
self.dataset.domain = results.domain;
|
|
|
|
self.dataset.fetch(self.dataset.fields, 0, self.limit, self.do_fill_table);
|
2011-03-31 14:44:22 +00:00
|
|
|
});
|
2011-03-30 14:00:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
openerp.base.TreeView = openerp.base.Controller.extend({
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|