[IMP] Improve code.
bzr revid: ysa@tinyerp.com-20110816085621-ny2wb4ya9rr95ii9
This commit is contained in:
parent
b0e182e7a5
commit
27b8b20d16
|
@ -16,19 +16,17 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
|
|||
this.all_display_data = false;
|
||||
this.groups = [];
|
||||
},
|
||||
|
||||
start: function () {
|
||||
this.rpc("/base_kanban/kanbanview/load",
|
||||
{"model": this.model, "view_id": this.view_id}, this.on_loaded);
|
||||
},
|
||||
|
||||
on_loaded: function (data) {
|
||||
var self = this;
|
||||
this.template_xml = '';
|
||||
this.columns = data.all_fields;
|
||||
_.each(data.fields_view.arch.children, function(child) {
|
||||
if (child.tag == "template"){
|
||||
self.template_xml = openerp.base.json_node_to_xml(child, true)
|
||||
self.template_xml = openerp.base.json_node_to_xml(child, true);
|
||||
}
|
||||
});
|
||||
if (this.template_xml) {
|
||||
|
@ -40,7 +38,6 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
|
|||
});
|
||||
}
|
||||
},
|
||||
|
||||
on_show_data: function (datas) {
|
||||
var self = this;
|
||||
var new_qweb = new QWeb2.Engine();
|
||||
|
@ -70,7 +67,6 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
|
|||
this.$element.find(".oe_column").disableSelection();
|
||||
this.$element.find('button.oe_kanban_button_new').click(this.do_add_record);
|
||||
},
|
||||
|
||||
on_button_click: function (button_attrs, record_id) {
|
||||
var self = this;
|
||||
if (this.groups.length) {
|
||||
|
@ -90,24 +86,21 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
|
|||
} else {
|
||||
var index = parseInt(_.indexOf(self.dataset.ids, record_id));
|
||||
if (index >= 0) {
|
||||
_.extend(self.dataset, {domain: self.domain, context: self.context})
|
||||
self.on_confirm_click(self.dataset, button_attrs, index, record_id)
|
||||
_.extend(self.dataset, {domain: self.domain, context: self.context});
|
||||
self.on_confirm_click(self.dataset, button_attrs, index, record_id);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
on_confirm_click: function (dataset, button_attrs, index, record_id) {
|
||||
if (button_attrs.type == 'edit') {
|
||||
this.do_edit_record(dataset, index);
|
||||
} else {
|
||||
this.on_execute_button_click(dataset, button_attrs, record_id)
|
||||
this.on_execute_button_click(dataset, button_attrs, record_id);
|
||||
}
|
||||
},
|
||||
|
||||
do_add_record: function () {
|
||||
this.do_edit_record(this.dataset, null);
|
||||
},
|
||||
|
||||
do_edit_record: function (dataset, index) {
|
||||
var self = this;
|
||||
_.extend(this.dataset, {
|
||||
|
@ -118,28 +111,25 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
|
|||
self.do_switch_view('form');
|
||||
});
|
||||
},
|
||||
|
||||
do_delete: function (id) {
|
||||
var self = this;
|
||||
return $.when(this.dataset.unlink([id])).then(function () {
|
||||
self.drop_records(id);
|
||||
});
|
||||
},
|
||||
|
||||
drop_records: function (id) {
|
||||
var self = this;
|
||||
_.each(self.all_display_data, function(data, index) {
|
||||
_.each(data.records, function(record, index_row) {
|
||||
if (parseInt(record.id) == id) {
|
||||
self.all_display_data[index]['records'].splice(index_row, 1)
|
||||
self.all_display_data[index]['ids'].splice(index_row, 1)
|
||||
self.all_display_data[index]['records'].splice(index_row, 1);
|
||||
self.all_display_data[index]['ids'].splice(index_row, 1);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
self.$element.find("#main_" + id).remove()
|
||||
self.$element.find("#main_" + id).remove();
|
||||
},
|
||||
|
||||
on_execute_button_click: function (dataset, button_attrs, record_id) {
|
||||
var self = this;
|
||||
this.execute_action(
|
||||
|
@ -158,17 +148,15 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
|
|||
}
|
||||
);
|
||||
},
|
||||
|
||||
on_close_action: function (e) {
|
||||
var record_id = $(e.currentTarget).parents('.record:first').attr("id")
|
||||
var record_id = $(e.currentTarget).parents('.record:first').attr("id");
|
||||
if (record_id) {
|
||||
record_id = parseInt(record_id.split("_")[1])
|
||||
record_id = parseInt(record_id.split("_")[1]);
|
||||
if (record_id) {
|
||||
this.do_delete(record_id);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
on_recieve_record: function (event, ui) {
|
||||
var self = this;
|
||||
var from = ui.item.index();
|
||||
|
@ -182,10 +170,10 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
|
|||
var child_record = ui.item.parent().children();
|
||||
var data, sequence = 1, index = to;
|
||||
child_record.splice(0, to);
|
||||
var flag = false;
|
||||
if (to >= 0 && child_record) {
|
||||
var record_id = parseInt($(child_record).attr("id").split("_")[1]);
|
||||
if (record_id) {
|
||||
var flag = false;
|
||||
_.each(self.all_display_data, function(data, index) {
|
||||
_.each(data.records, function(record, index_row) {
|
||||
if(record_id == record.id && record.sequence) {
|
||||
|
@ -201,7 +189,7 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
|
|||
_.each(child_record, function (child) {
|
||||
var child_id = parseInt($(child).attr("id").split("_")[1]);
|
||||
if (child_id) {
|
||||
var flag = false;
|
||||
flag = false;
|
||||
_.each(self.all_display_data, function(data, index) {
|
||||
_.each(data.records, function(record, index_row) {
|
||||
if(parseInt(record.id) == child_id) {
|
||||
|
@ -219,7 +207,7 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
|
|||
});
|
||||
}
|
||||
if (self.group_by_field && self.source_index.column && self.source_index.column != ui.item.parent().attr('id')) {
|
||||
var value = ui.item.closest("td").attr("id")
|
||||
var value = ui.item.closest("td").attr("id");
|
||||
if (value) {
|
||||
var data_val = {};
|
||||
var wirte_id = parseInt(ui.item.attr("id").split("_")[1]);
|
||||
|
@ -253,19 +241,17 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
|
|||
}
|
||||
this.source_index = {};
|
||||
},
|
||||
|
||||
on_reload_kanban: function (){
|
||||
var self = this;
|
||||
var new_qweb = new QWeb2.Engine();
|
||||
new_qweb.add_template('<templates><t t-name="custom_template">' + this.template_xml + '</t></templates>')
|
||||
new_qweb.add_template('<templates><t t-name="custom_template">' + this.template_xml + '</t></templates>');
|
||||
_.each(self.all_display_data, function(data, index) {
|
||||
if (data.records.length > 0){
|
||||
_.each(data.records, function(record) {
|
||||
self.$element.find("#data_" + record.id).children().remove()
|
||||
self.$element.find("#data_" + record.id).children().remove();
|
||||
self.$element.find("#data_" + record.id).append(new_qweb.render('custom_template', record));
|
||||
});
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
self.$element.find("#column_" + data.value).remove();
|
||||
self.all_display_data.splice(index, 1);
|
||||
}
|
||||
|
@ -278,8 +264,7 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
|
|||
if (record_id) {
|
||||
if ($(this).data("type") == "delete") {
|
||||
self.do_delete(record_id);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
var button_attrs = $(this).data()
|
||||
self.on_button_click(button_attrs, record_id);
|
||||
}
|
||||
|
@ -321,7 +306,6 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
|
|||
|
||||
});
|
||||
},
|
||||
|
||||
do_render_group : function (datagroups) {
|
||||
this.all_display_data = [];
|
||||
var self = this;
|
||||
|
@ -333,10 +317,9 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
|
|||
if (!group.value) {
|
||||
group_name = "Undefined";
|
||||
group_value = 'false';
|
||||
}
|
||||
else if(group.value instanceof Array) {
|
||||
group_name = group.value[1]
|
||||
group_value = group.value[0]
|
||||
} else if (group.value instanceof Array) {
|
||||
group_name = group.value[1];
|
||||
group_value = group.value[0];
|
||||
}
|
||||
self.dataset.read_slice({}, function(records) {
|
||||
self.all_display_data.push({"value" : group_value, "records": records, 'header':group_name, 'ids': self.dataset.ids});
|
||||
|
|
Loading…
Reference in New Issue