[ADD] Kanban qweb template pre-processing

bzr revid: fme@openerp.com-20110905141812-d0ybzi57u9qlkkhv
This commit is contained in:
Fabien Meghazi 2011-09-05 16:18:12 +02:00
parent 98e336c3ee
commit d9d7732099
3 changed files with 69 additions and 30 deletions

View File

@ -1,20 +1,20 @@
.openerp .oe_column {
.openerp .oe_kanban_view .oe_column {
float: left;
width: 100%;
}
.record {
margin: 0 0 0.5em 0;
.openerp .oe_kanban_view .ui-sortable-placeholder {
border: 1px dotted black;
visibility: visible !important;
height: 60px !important;
}
.ui-sortable-placeholder {
border: 1px dotted black;
visibility: visible !important;
height: 60px !important;
}
.openerp .oe_column_heading {
.openerp .oe_kanban_view .oe_column_heading {
color: #000000;
font-size: 1.5em;
font-weight: bold;
}
.openerp .oe_kanban_button {
height: 22px;
margin: 0;
}

View File

@ -17,11 +17,6 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
this.all_display_data = false;
this.groups = [];
this.qweb = new QWeb2.Engine();
this.qweb.actions_precedence.push('field');
this.qweb.compile_action_field = function(value) {
var val = this.node.attributes['name'].value + '.value';
return this.compile_action_esc(val);
}
},
start: function() {
return this.rpc("/base_kanban/kanbanview/load",
@ -30,15 +25,7 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
on_loaded: function(data) {
var self = this;
this.fields_view = data.fields_view;
for (var i=0, ii=data.fields_view.arch.children.length; i < ii; i++) {
var child = data.fields_view.arch.children[i];
if (child.tag == "templates") {
var template_xml = openerp.base.json_node_to_xml(child, true);
template_xml = template_xml.replace(/<field /g, '<t t-field="" ').replace(/<\/field>/g, '</t>');
self.qweb.add_template(template_xml);
break;
}
}
this.add_qweb_template();
if (this.qweb.has_template('kanban-box')) {
self.dataset.read_slice(_.keys(self.fields_view.fields), {
context: self.dataset.get_context(),
@ -50,6 +37,59 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
);
}
},
add_qweb_template: function() {
for (var i=0, ii=this.fields_view.arch.children.length; i < ii; i++) {
var child = this.fields_view.arch.children[i];
if (child.tag === "templates") {
this.transform_qweb_template(child);
this.qweb.add_template(openerp.base.json_node_to_xml(child, true));
break;
}
}
},
transform_qweb_template: function(node) {
switch (node.tag) {
case 'field':
node.tag = 't';
node.attrs['t-esc'] = node.attrs['name'] + '.value';
break
case 'button':
var type = node.attrs.type || '';
if (_.indexOf('action,object,edit,delete,'.split(','), type) !== -1) {
_.each(node.attrs, function(v, k) {
node.attrs['data-' + k] = v;
delete(node.attrs[k]);
});
if (node.attrs['data-states']) {
var states = _.map(node.attrs['data-states'].split(','), function(state) {
return "state.value == '" + _.trim(state) + "'";
});
node.attrs['t-if'] = states.join(' or ');
}
if (node.attrs['data-string']) {
node.attrs.title = node.attrs['data-string'];
}
if (node.attrs['data-icon']) {
node.children = [{
tag: 'img',
attrs: {
src: '/base/static/src/img/icons/' + node.attrs['data-icon'] + '.png',
width: '16',
height: '16'
}
}];
}
node.attrs.type = 'button';
node.attrs['class'] = 'oe_kanban_button';
}
break;
}
if (node.children) {
for (var i = 0, ii = node.children.length; i < ii; i++) {
this.transform_qweb_template(node.children[i]);
}
}
},
on_show_data: function(data) {
var self = this;
this.$element.html(QWeb.render("KanbanView", {"data": data}));
@ -67,7 +107,6 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
},
stop: self.on_receive_record,
});
this.$element.find(".record").addClass( "ui-widget ui-widget-content ui-corner-all" )
this.$element.find(".oe_column").disableSelection()
this.$element.find('button.oe_kanban_button_new').click(this.do_add_record);
},
@ -252,7 +291,7 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
});
this.$element.find( ".oe_table_column " ).css("width", 99 / self.all_display_data.length +"%");
this.$element.find('button').click(function() {
var record_id = $(this).closest(".record").attr("id");
var record_id = $(this).closest(".oe_kanban_record").attr("id");
if (record_id) {
record_id = parseInt(record_id.split("_")[1])
if (record_id) {
@ -306,7 +345,7 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
self.groups = [];
self.dataset.read_slice([], {}, function(records) {
self.all_display_data = [{'records': records, 'value':false, 'header' : false, 'ids': self.dataset.ids}];
self.$element.find("#kanbanview").remove();
self.$element.find(".oe_kanban_view").remove();
self.on_show_data(self.all_display_data);
});
}
@ -330,7 +369,7 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
self.dataset.read_slice([], {}, function(records) {
self.all_display_data.push({"value" : group_value, "records": records, 'header':group_name, 'ids': self.dataset.ids});
if (datagroups.length == self.all_display_data.length) {
self.$element.find("#kanbanview").remove();
self.$element.find(".oe_kanban_view").remove();
self.on_show_data(self.all_display_data);
}
});

View File

@ -1,6 +1,6 @@
<template>
<t t-name="KanbanView">
<table style="width:100%;" id="kanbanview">
<table style="width:100%;" class="oe_kanban_view">
<tr>
<td>
<div class="oe_form_header">
@ -16,7 +16,7 @@
<tr>
<td t-foreach="data" t-as="columns" class="oe_table_column" t-att-id="'column_' + columns.value">
<div class="oe_column" t-att-id="'column_' + columns.value">
<div t-foreach="columns.records" t-as="record" class="record" t-att-id="'main_' + record.id"/>
<div t-foreach="columns.records" t-as="record" class="oe_kanban_record" t-att-id="'main_' + record.id"/>
</div>
</td>
</tr>