diff --git a/addons/base_kanban/static/src/js/kanban.js b/addons/base_kanban/static/src/js/kanban.js
index 0e928f492e5..c66351b98ae 100644
--- a/addons/base_kanban/static/src/js/kanban.js
+++ b/addons/base_kanban/static/src/js/kanban.js
@@ -9,12 +9,9 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
this.dataset = dataset;
this.model = this.dataset.model;
this.view_id = view_id;
- this.element_id = element_id;
this.group_by_field = false;
- this.domains = this.dataset.domain;
- this.contexts = this.dataset.context;
- this.group_by = false;
- this.destination_index = false;
+ this.source_index = {};
+ this.all_display_data = false;
},
start: function() {
@@ -32,7 +29,9 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
});
if(this.template_xml){
self.dataset.read_slice([], 0, false, function (records) {
- self.on_reload_kanban([{'records': records, 'value':false, 'header': false}]);
+ self.all_display_data = [];
+ self.all_display_data.push({'records': records, 'value':false, 'header': false});
+ self.on_show_data(self.all_display_data);
});
}
},
@@ -41,19 +40,14 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
var self = this;
this.all_records = [];
var new_qweb = new QWeb2.Engine();
- new_qweb.add_template('' + this.template_xml + '')
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));
- self.all_records.push(record);
- });
- });
- this.$element.find( ".oe_table_column " ).css("width", 99 / datas.length +"%");
+ this.on_reload_kanban();
this.$element.find(".oe_column").sortable({
connectWith: ".oe_column",
start: function(event, ui) {
- self.destination_index = ui.item.index();
+ self.source_index['index'] = ui.item.index();
+ self.source_index['column'] = ui.item.parent().attr('id');
+ console.log("self.source_index::",self.source_index);
},
stop: self.on_recieve_record,
});
@@ -78,18 +72,23 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
on_recieve_record: function(event, ui) {
var self = this;
- var from = ui.item.index(), to = ui.item.prev().index() || 0;
+ var from = ui.item.index();
this.flag = false;
- if(this.columns.sequence && self.destination_index != from){
+ var to = ui.item.prev().index() || 0;
+ if(!ui.item.attr("id")){
+ return false;
+ }
+ if(self.columns.sequence && self.source_index.index && self.source_index.index != from) {
var child_record = ui.item.parent().children();
- var data, sequence=1, index = to;
+ var data, sequence = 1, index = to;
child_record.splice(0, to);
if(to >= 0 && child_record) {
var record_id = child_record.attr('id').split("_");
if(record_id.length >= 2) {
- _.each(this.all_records, function(record){
+ _.each(self.all_records, function(record){
if(parseInt(record_id[1]) == record.id && record.sequence) {
sequence = record.sequence;
+ return false;
}
});
}
@@ -97,34 +96,74 @@ 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) {
+ _.each(self.all_display_data, function(data, index) {
+ _.each(data.records, function(record, index_row) {
+ if(parseInt(record.id) == child_id) {
+ self.all_display_data[index]['records'][index_row]['sequence'] = sequence;
+ return false;
+ }
+ });
+ });
self.dataset.write(child_id, {sequence: sequence});
sequence++;
self.flag = true;
}
});
}
- if(ui.item.attr("id") && this.group_by_field) {
+ 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")
if(value) {
var data_val = {};
+ var wirte_id = parseInt(ui.item.attr("id").split("_")[1]);
value = value.split("_")[1];
if(value == 'false') {
value = false;
}
- data_val[this.group_by_field] = value;
- this.dataset.write(parseInt(ui.item.attr("id").split("_")[1]), data_val);
- this.flag = true;
+ var update_record = false;
+ _.each(self.all_display_data, function(data, index) {
+ _.each(data.records, function(record, index_row) {
+ if(parseInt(record.id) == wirte_id) {
+ self.all_display_data[index]['records'][index_row][self.group_by_field] = value;
+ update_record = self.all_display_data[index]['records'].splice(index_row,1)
+ return false;
+ }
+ });
+ });
+ _.each(self.all_display_data, function(data, index) {
+ if (data.value == value || (data.value == 'false' && value == false)) {
+ self.all_display_data[index]['records'].push(update_record[0]);
+ }
+ });
+ data_val[self.group_by_field] = value;
+ self.dataset.write(wirte_id, data_val);
+ self.flag = true;
}
}
- if(this.flag) {
- this.do_actual_search(this.domains, this.contexts, this.group_by);
+ if(self.flag) {
+ self.on_reload_kanban(this.all_display_data);
}
- this.destination_index = false;
+ this.source_index = {};
},
- on_reload_kanban: function(datas){
- this.$element.find("#kanbanview").remove();
- this.on_show_data(datas);
+ on_reload_kanban: function(){
+ var self = this;
+ var new_qweb = new QWeb2.Engine();
+ this.all_records = []
+ new_qweb.add_template('' + this.template_xml + '')
+ _.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).append(new_qweb.render('custom_template', record));
+ self.all_records.push(record);
+ });
+ }
+ else{
+ self.$element.find("#column_" + data.value).remove();
+ self.all_display_data.splice(index, 1);
+ }
+ });
+ this.$element.find( ".oe_table_column " ).css("width", 99 / self.all_display_data.length +"%");
},
do_search: function (domains, contexts, group_by) {
@@ -134,38 +173,32 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
contexts: contexts,
group_by_seq: group_by
}, function (results) {
- self.contexts = results.context;
- self.domains = results.domain;
- self.group_by = results.group_by;
- self.do_actual_search(results.domain, results.context, results.group_by);
+ self.group_by_field = false;
+ 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) {
+ if (group_by.length >= 1) {
+ self.group_by_field = group_by[0].group_by;
+ self.do_render_group(groups);
+ }
+ },
+ function (dataset) {
+ self.dataset.read_slice(false, false, false, function(records) {
+ self.all_display_data = [];
+ self.all_display_data.push({'records': records, 'value':false, 'header' : false});
+ self.$element.find("#kanbanview").remove();
+ self.on_show_data(self.all_display_data);
+ });
+ }
+ );
+
});
},
- do_actual_search: function (domain, context, group_by) {
- var self = this;
-
- this.group_by_field = false;
-
- self.dataset.context = context;
- self.dataset.domain = domain;
- this.groups = new openerp.base.DataGroup(this, this.model, domain, context, group_by || []);
- this.groups.list([],
- function (groups) {
- if (group_by.length >= 1) {
- self.group_by_field = group_by[0];
- self.do_render_group(groups);
- }
- },
- function (dataset) {
- self.dataset.read_slice(false, false, false, function(records) {
- self.on_reload_kanban([{'records': records, 'value':false, 'header' : false}]);
- });
- }
- );
-
- },
do_render_group : function(datagroups){
- this.columns = [];
+ this.all_display_data = [];
var self = this;
_.each(datagroups, function (group) {
self.dataset.context = group.context;
@@ -181,9 +214,10 @@ openerp.base_kanban.KanbanView = openerp.base.View.extend({
group_value = group.value[0]
}
self.dataset.read_slice(false, false, false, function(records) {
- self.columns.push({"value" : group_value, "records": records, 'header':group_name});
- if (datagroups.length == self.columns.length) {
- self.on_reload_kanban(self.columns);
+ self.all_display_data.push({"value" : group_value, "records": records, 'header':group_name});
+ if (datagroups.length == self.all_display_data.length) {
+ self.$element.find("#kanbanview").remove();
+ self.on_show_data(self.all_display_data);
}
});
});
diff --git a/addons/base_kanban/static/src/xml/base_kanban.xml b/addons/base_kanban/static/src/xml/base_kanban.xml
index 4b1ca3f44b4..2e1109dfee5 100644
--- a/addons/base_kanban/static/src/xml/base_kanban.xml
+++ b/addons/base_kanban/static/src/xml/base_kanban.xml
@@ -3,9 +3,9 @@