2011-07-28 09:51:52 +00:00
|
|
|
openerp.base_kanban = function (openerp) {
|
2011-07-29 09:04:30 +00:00
|
|
|
QWeb.add_template('/base_kanban/static/src/xml/base_kanban.xml');
|
2011-07-28 09:51:52 +00:00
|
|
|
openerp.base.views.add('kanban', 'openerp.base_kanban.KanbanView');
|
|
|
|
openerp.base_kanban.KanbanView = openerp.base.View.extend({
|
|
|
|
|
|
|
|
init: function(parent, element_id, dataset, view_id) {
|
|
|
|
this._super(parent, element_id);
|
|
|
|
this.view_manager = parent;
|
|
|
|
this.dataset = dataset;
|
|
|
|
this.model = this.dataset.model;
|
|
|
|
this.view_id = view_id;
|
2011-07-29 09:04:30 +00:00
|
|
|
this.element_id = element_id;
|
2011-07-28 09:51:52 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
start: function() {
|
|
|
|
this.rpc("/base_kanban/kanbanview/load",
|
|
|
|
{"model": this.model, "view_id": this.view_id}, this.on_loaded);
|
|
|
|
},
|
|
|
|
on_loaded: function(data) {
|
2011-07-29 09:04:30 +00:00
|
|
|
var self = this;
|
2011-08-01 10:15:28 +00:00
|
|
|
this.template_xml = '';
|
2011-07-29 09:04:30 +00:00
|
|
|
|
2011-07-28 09:51:52 +00:00
|
|
|
_.each(data.fields_view.arch.children, function(child) {
|
|
|
|
if (child.tag == "template"){
|
2011-08-01 10:15:28 +00:00
|
|
|
self.template_xml = openerp.base.json_node_to_xml(child, true)
|
2011-07-28 09:51:52 +00:00
|
|
|
}
|
|
|
|
});
|
2011-08-01 10:15:28 +00:00
|
|
|
if(this.template_xml){
|
2011-07-29 09:04:30 +00:00
|
|
|
self.dataset.read_slice([], 0, false, function (records) {
|
2011-08-01 10:15:28 +00:00
|
|
|
self.on_show_data([{'records': records, 'value':false}]);
|
2011-07-29 09:04:30 +00:00
|
|
|
});
|
|
|
|
}
|
2011-07-28 09:51:52 +00:00
|
|
|
},
|
2011-07-29 09:04:30 +00:00
|
|
|
|
2011-08-01 10:15:28 +00:00
|
|
|
on_show_data: function(datas) {
|
2011-07-29 09:04:30 +00:00
|
|
|
var self = this;
|
|
|
|
var new_qweb = new QWeb2.Engine();
|
2011-08-01 10:15:28 +00:00
|
|
|
new_qweb.add_template('<templates><t t-name="custom_template">' + this.template_xml + '</t></templates>')
|
|
|
|
self.$element.html(QWeb.render("KanbanBiew", {"datas" :datas}));
|
|
|
|
_.each(datas, function(data) {
|
|
|
|
_.each(data.records, function(record) {
|
|
|
|
self.$element.find("#data_" + record.id).append(new_qweb.render('custom_template', record));
|
|
|
|
});
|
2011-07-29 09:04:30 +00:00
|
|
|
});
|
|
|
|
|
2011-08-01 10:15:28 +00:00
|
|
|
this.$element.find(".oe_column").sortable({
|
|
|
|
connectWith: ".oe_column"
|
2011-07-29 09:04:30 +00:00
|
|
|
});
|
2011-08-01 11:45:23 +00:00
|
|
|
this.$element.find(".record").addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all")
|
|
|
|
.find(".record-header")
|
2011-07-29 09:04:30 +00:00
|
|
|
.addClass("ui-widget-header ui-corner-all")
|
|
|
|
.prepend( "<span class='ui-icon ui-icon-closethick'></span><span class='ui-icon ui-icon-minusthick'></span>")
|
|
|
|
.end()
|
2011-08-01 11:45:23 +00:00
|
|
|
.find( ".record-content" );
|
2011-07-29 09:04:30 +00:00
|
|
|
|
2011-08-01 11:45:23 +00:00
|
|
|
this.$element.find(".record-header .ui-icon").click(function() {
|
2011-07-29 09:04:30 +00:00
|
|
|
$(this).toggleClass("ui-icon-minusthick").toggleClass("ui-icon-plusthick");
|
2011-08-01 11:45:23 +00:00
|
|
|
$(this).parents(".record:first").find(".record-content").toggle();
|
2011-07-29 09:04:30 +00:00
|
|
|
});
|
2011-08-01 11:45:23 +00:00
|
|
|
this.$element.find('.record .ui-icon-closethick').click(this.on_close_action);
|
2011-08-01 10:15:28 +00:00
|
|
|
this.$element.find(".oe_column").disableSelection();
|
|
|
|
self.$element.find( ".oe_column" ).css("width", 99 / datas.length +"%");
|
2011-07-29 09:04:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
on_close_action: function(e) {
|
2011-08-01 11:45:23 +00:00
|
|
|
$(e.currentTarget).parents('.record:first').remove();
|
2011-07-29 09:04:30 +00:00
|
|
|
},
|
|
|
|
|
2011-08-01 10:15:28 +00:00
|
|
|
do_search: function (domains, contexts, group_by) {
|
|
|
|
var self = this;
|
|
|
|
this.rpc('/base/session/eval_domain_and_context', {
|
|
|
|
domains: domains,
|
|
|
|
contexts: contexts,
|
|
|
|
group_by_seq: group_by
|
|
|
|
}, function (results) {
|
|
|
|
self.dataset.context = results.context;
|
|
|
|
self.dataset.domain = results.domain;
|
|
|
|
self.groups = new openerp.base.DataGroup(
|
|
|
|
self, self.model, results.domain, results.context, results.group_by);
|
|
|
|
self.groups.list([],
|
|
|
|
function (groups) {
|
|
|
|
self.do_render_group(groups);
|
|
|
|
},
|
|
|
|
function (dataset) {
|
|
|
|
self.dataset.read_slice(false, false, false, function(records) {
|
|
|
|
self.on_show_data([{'records': records, 'value':false}]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
do_render_group : function(datagroups){
|
|
|
|
this.columns = [];
|
|
|
|
var self = this;
|
|
|
|
_.each(datagroups, function (group) {
|
|
|
|
self.dataset.context = group.context;
|
|
|
|
self.dataset.domain = group.domain;
|
2011-08-01 11:45:23 +00:00
|
|
|
var group_name = group.value;
|
|
|
|
if(!group_name) {
|
|
|
|
group_name = "Undefined"
|
|
|
|
}
|
|
|
|
else if(group_name instanceof Array) {
|
|
|
|
group_name = group_name[1]
|
2011-08-01 10:15:28 +00:00
|
|
|
}
|
|
|
|
self.dataset.read_slice(false, false, false, function(records) {
|
2011-08-01 11:45:23 +00:00
|
|
|
self.columns.push({"value" : group_name, "records": records});
|
2011-08-01 10:15:28 +00:00
|
|
|
if (datagroups.length == self.columns.length) {
|
|
|
|
self.on_show_data(self.columns);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-07-29 09:04:30 +00:00
|
|
|
do_show: function () {
|
|
|
|
this.$element.show();
|
|
|
|
},
|
|
|
|
|
|
|
|
do_hide: function () {
|
|
|
|
this.$element.hide();
|
|
|
|
},
|
|
|
|
|
2011-07-28 09:51:52 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|