2011-07-28 09:51:52 +00:00
|
|
|
openerp.base_kanban = function (openerp) {
|
2011-09-01 16:10:51 +00:00
|
|
|
|
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({
|
2011-09-01 16:10:51 +00:00
|
|
|
init: function (parent, element_id, dataset, view_id, options) {
|
2011-07-28 09:51:52 +00:00
|
|
|
this._super(parent, element_id);
|
2011-09-01 16:10:51 +00:00
|
|
|
this.set_default_options(options);
|
2011-07-28 09:51:52 +00:00
|
|
|
this.dataset = dataset;
|
2011-09-01 16:10:51 +00:00
|
|
|
this.model = dataset.model;
|
2011-08-11 09:29:52 +00:00
|
|
|
this.domain = dataset.domain;
|
|
|
|
this.context = dataset.context;
|
2011-07-28 09:51:52 +00:00
|
|
|
this.view_id = view_id;
|
2011-09-01 16:10:51 +00:00
|
|
|
this.fields_view = {};
|
2011-08-19 09:54:48 +00:00
|
|
|
this.group_by = [];
|
2011-08-08 08:37:48 +00:00
|
|
|
this.source_index = {};
|
|
|
|
this.all_display_data = false;
|
2011-08-09 11:25:56 +00:00
|
|
|
this.groups = [];
|
2011-09-01 16:10:51 +00:00
|
|
|
this.qweb = new QWeb2.Engine();
|
2011-07-28 09:51:52 +00:00
|
|
|
},
|
2011-09-01 16:10:51 +00:00
|
|
|
start: function() {
|
|
|
|
return this.rpc("/base_kanban/kanbanview/load",
|
|
|
|
{"model": this.model, "view_id": this.view_id}, this.on_loaded);
|
2011-07-28 09:51:52 +00:00
|
|
|
},
|
2011-09-01 16:10:51 +00:00
|
|
|
on_loaded: function(data) {
|
2011-07-29 09:04:30 +00:00
|
|
|
var self = this;
|
2011-09-01 16:10:51 +00:00
|
|
|
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;
|
2011-07-28 09:51:52 +00:00
|
|
|
}
|
2011-09-01 16:10:51 +00:00
|
|
|
}
|
|
|
|
if (this.qweb.has_template('kanban-box')) {
|
|
|
|
self.dataset.read_slice(_.keys(self.fields_view.fields), {
|
|
|
|
context: self.dataset.get_context(),
|
|
|
|
domain: self.dataset.get_domain()
|
|
|
|
}, function (records) {
|
|
|
|
self.all_display_data = [{'records': records, 'value': false, 'header': false, 'ids': self.dataset.ids}];
|
|
|
|
self.on_show_data(self.all_display_data);
|
|
|
|
}
|
|
|
|
);
|
2011-08-11 09:29:52 +00:00
|
|
|
}
|
2011-07-28 09:51:52 +00:00
|
|
|
},
|
2011-09-01 16:10:51 +00:00
|
|
|
on_show_data: function(data) {
|
2011-07-29 09:04:30 +00:00
|
|
|
var self = this;
|
2011-09-01 16:10:51 +00:00
|
|
|
this.$element.html(QWeb.render("KanbanBiew", {"data": data}));
|
2011-08-08 08:37:48 +00:00
|
|
|
this.on_reload_kanban();
|
2011-08-18 13:16:20 +00:00
|
|
|
var drag_handel = false;
|
|
|
|
if (this.$element.find(".oe-kanban-draghandle").length > 0) {
|
|
|
|
drag_handel = ".oe-kanban-draghandle";
|
|
|
|
}
|
2011-08-11 09:29:52 +00:00
|
|
|
this.$element.find(".oe_column").sortable({
|
|
|
|
connectWith: ".oe_column",
|
2011-08-18 13:16:20 +00:00
|
|
|
handle : drag_handel,
|
2011-08-11 09:29:52 +00:00
|
|
|
start: function(event, ui) {
|
2011-08-08 08:37:48 +00:00
|
|
|
self.source_index['index'] = ui.item.index();
|
|
|
|
self.source_index['column'] = ui.item.parent().attr('id');
|
2011-08-05 09:48:55 +00:00
|
|
|
},
|
2011-09-01 16:10:51 +00:00
|
|
|
stop: self.on_receive_record,
|
2011-08-11 09:29:52 +00:00
|
|
|
});
|
2011-08-18 10:39:14 +00:00
|
|
|
this.$element.find(".record").addClass( "ui-widget ui-widget-content ui-corner-all" )
|
2011-08-18 13:16:20 +00:00
|
|
|
this.$element.find(".oe_column").disableSelection()
|
2011-08-16 07:20:39 +00:00
|
|
|
this.$element.find('button.oe_kanban_button_new').click(this.do_add_record);
|
2011-07-29 09:04:30 +00:00
|
|
|
},
|
2011-08-16 08:56:21 +00:00
|
|
|
on_button_click: function (button_attrs, record_id) {
|
2011-08-09 11:25:56 +00:00
|
|
|
var self = this;
|
2011-08-16 08:56:21 +00:00
|
|
|
if (this.groups.length) {
|
2011-08-10 09:46:46 +00:00
|
|
|
_.each(this.groups, function (group) {
|
2011-08-11 09:29:52 +00:00
|
|
|
group.list([],
|
|
|
|
function (groups) {},
|
|
|
|
function (dataset) {
|
2011-08-19 07:07:40 +00:00
|
|
|
dataset.read_slice([], {}, function(records) {
|
2011-08-11 09:29:52 +00:00
|
|
|
var index = parseInt(_.indexOf(dataset.ids, record_id));
|
|
|
|
if(index >= 0) {
|
|
|
|
self.on_confirm_click(dataset, button_attrs, index, record_id);
|
|
|
|
}
|
|
|
|
});
|
2011-08-10 09:46:46 +00:00
|
|
|
}
|
2011-08-11 09:29:52 +00:00
|
|
|
);
|
2011-08-10 05:23:08 +00:00
|
|
|
});
|
2011-08-16 08:56:21 +00:00
|
|
|
} else {
|
2011-08-10 09:46:46 +00:00
|
|
|
var index = parseInt(_.indexOf(self.dataset.ids, record_id));
|
2011-08-16 08:56:21 +00:00
|
|
|
if (index >= 0) {
|
|
|
|
_.extend(self.dataset, {domain: self.domain, context: self.context});
|
|
|
|
self.on_confirm_click(self.dataset, button_attrs, index, record_id);
|
2011-08-10 05:23:08 +00:00
|
|
|
}
|
2011-08-09 11:25:56 +00:00
|
|
|
}
|
|
|
|
},
|
2011-08-16 08:56:21 +00:00
|
|
|
on_confirm_click: function (dataset, button_attrs, index, record_id) {
|
|
|
|
if (button_attrs.type == 'edit') {
|
2011-08-11 09:29:52 +00:00
|
|
|
this.do_edit_record(dataset, index);
|
2011-08-16 08:56:21 +00:00
|
|
|
} else {
|
|
|
|
this.on_execute_button_click(dataset, button_attrs, record_id);
|
2011-08-10 09:46:46 +00:00
|
|
|
}
|
|
|
|
},
|
2011-08-16 07:20:39 +00:00
|
|
|
do_add_record: function () {
|
|
|
|
this.do_edit_record(this.dataset, null);
|
|
|
|
},
|
2011-08-11 09:29:52 +00:00
|
|
|
do_edit_record: function (dataset, index) {
|
|
|
|
var self = this;
|
|
|
|
_.extend(this.dataset, {
|
|
|
|
domain: dataset.domain,
|
|
|
|
context: dataset.get_context()
|
2011-08-19 07:07:40 +00:00
|
|
|
}).read_slice([], {}, function () {
|
2011-08-11 09:29:52 +00:00
|
|
|
self.dataset.index = index;
|
|
|
|
self.do_switch_view('form');
|
|
|
|
});
|
2011-08-08 10:46:32 +00:00
|
|
|
},
|
|
|
|
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) {
|
2011-08-16 08:56:21 +00:00
|
|
|
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);
|
2011-08-08 10:46:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2011-08-16 08:56:21 +00:00
|
|
|
self.$element.find("#main_" + id).remove();
|
2011-08-08 10:46:32 +00:00
|
|
|
},
|
2011-08-16 08:56:21 +00:00
|
|
|
on_execute_button_click: function (dataset, button_attrs, record_id) {
|
2011-08-10 05:23:08 +00:00
|
|
|
var self = this;
|
|
|
|
this.execute_action(
|
2011-08-11 09:29:52 +00:00
|
|
|
button_attrs, dataset,
|
2011-08-10 05:23:08 +00:00
|
|
|
record_id, function () {
|
2011-08-10 11:58:56 +00:00
|
|
|
var count = 1;
|
2011-08-10 11:09:43 +00:00
|
|
|
_.each(self.all_display_data, function(data, index) {
|
|
|
|
self.dataset.read_ids( data.ids, [], function(records){
|
|
|
|
self.all_display_data[index].records = records;
|
2011-08-10 11:58:56 +00:00
|
|
|
if(self.all_display_data.length == count) {
|
2011-08-19 09:54:48 +00:00
|
|
|
self.do_actual_search();
|
2011-08-10 11:58:56 +00:00
|
|
|
}
|
|
|
|
count++;
|
2011-08-10 11:09:43 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2011-08-10 09:46:46 +00:00
|
|
|
},
|
2011-09-01 16:10:51 +00:00
|
|
|
on_receive_record: function (event, ui) {
|
2011-08-04 13:27:51 +00:00
|
|
|
var self = this;
|
2011-08-08 08:37:48 +00:00
|
|
|
var from = ui.item.index();
|
2011-08-12 12:18:25 +00:00
|
|
|
var search_action = false;
|
2011-08-08 08:37:48 +00:00
|
|
|
var to = ui.item.prev().index() || 0;
|
2011-08-16 08:56:21 +00:00
|
|
|
if (!ui.item.attr("id")) {
|
2011-08-08 08:37:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-09-01 16:10:51 +00:00
|
|
|
// TODO fme: check what was this sequence
|
|
|
|
if (self.fields_view.fields.sequence && (self.source_index.index >= 0 && self.source_index.index != from) ||
|
2011-08-12 12:18:25 +00:00
|
|
|
(self.source_index.column && self.source_index.column != ui.item.parent().attr('id'))) {
|
2011-08-11 09:29:52 +00:00
|
|
|
var child_record = ui.item.parent().children();
|
|
|
|
var data, sequence = 1, index = to;
|
|
|
|
child_record.splice(0, to);
|
2011-08-16 08:56:21 +00:00
|
|
|
var flag = false;
|
|
|
|
if (to >= 0 && child_record) {
|
2011-08-12 12:18:25 +00:00
|
|
|
var record_id = parseInt($(child_record).attr("id").split("_")[1]);
|
2011-08-16 08:56:21 +00:00
|
|
|
if (record_id) {
|
2011-08-12 12:18:25 +00:00
|
|
|
_.each(self.all_display_data, function(data, index) {
|
|
|
|
_.each(data.records, function(record, index_row) {
|
2011-08-19 09:54:48 +00:00
|
|
|
if(record_id == record.id && record.sequence) {
|
|
|
|
sequence = record.sequence;
|
|
|
|
flag = true;
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-12 12:18:25 +00:00
|
|
|
});
|
|
|
|
if(flag) {return false;}
|
2011-08-11 09:29:52 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_.each(child_record, function (child) {
|
|
|
|
var child_id = parseInt($(child).attr("id").split("_")[1]);
|
2011-08-16 08:56:21 +00:00
|
|
|
if (child_id) {
|
|
|
|
flag = false;
|
2011-08-11 09:29:52 +00:00
|
|
|
_.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;
|
2011-08-12 12:18:25 +00:00
|
|
|
flag = true;
|
2011-08-11 09:29:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2011-08-16 08:56:21 +00:00
|
|
|
if (flag) {return false;}
|
2011-08-11 09:29:52 +00:00
|
|
|
});
|
|
|
|
self.dataset.write(child_id, {sequence: sequence});
|
|
|
|
sequence++;
|
2011-08-12 12:18:25 +00:00
|
|
|
search_action = true;
|
2011-08-11 09:29:52 +00:00
|
|
|
}
|
|
|
|
});
|
2011-08-04 13:27:51 +00:00
|
|
|
}
|
2011-08-19 10:45:54 +00:00
|
|
|
if (self.group_by.length > 0 && self.source_index.column && self.source_index.column != ui.item.parent().attr('id')) {
|
2011-08-16 08:56:21 +00:00
|
|
|
var value = ui.item.closest("td").attr("id");
|
|
|
|
if (value) {
|
2011-08-03 10:26:53 +00:00
|
|
|
var data_val = {};
|
2011-08-08 08:37:48 +00:00
|
|
|
var wirte_id = parseInt(ui.item.attr("id").split("_")[1]);
|
2011-08-03 10:26:53 +00:00
|
|
|
value = value.split("_")[1];
|
2011-08-16 08:56:21 +00:00
|
|
|
if (value == 'false') {
|
2011-08-03 10:26:53 +00:00
|
|
|
value = false;
|
|
|
|
}
|
2011-08-08 08:37:48 +00:00
|
|
|
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) {
|
2011-08-19 10:45:54 +00:00
|
|
|
self.all_display_data[index]['records'][index_row][self.group_by[0]] = value;
|
2011-08-08 08:37:48 +00:00
|
|
|
update_record = self.all_display_data[index]['records'].splice(index_row,1)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2011-08-16 08:56:21 +00:00
|
|
|
if (update_record) {return false;}
|
2011-08-08 08:37:48 +00:00
|
|
|
});
|
|
|
|
_.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]);
|
|
|
|
}
|
|
|
|
});
|
2011-08-19 10:45:54 +00:00
|
|
|
data_val[self.group_by[0]] = value;
|
2011-08-08 08:37:48 +00:00
|
|
|
self.dataset.write(wirte_id, data_val);
|
2011-08-12 12:18:25 +00:00
|
|
|
search_action = true;
|
2011-08-03 10:26:53 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-16 08:56:21 +00:00
|
|
|
if (search_action) {
|
2011-08-10 11:09:43 +00:00
|
|
|
self.on_reload_kanban();
|
2011-08-05 08:32:30 +00:00
|
|
|
}
|
2011-08-08 08:37:48 +00:00
|
|
|
this.source_index = {};
|
2011-08-05 08:32:30 +00:00
|
|
|
},
|
2011-08-16 08:56:21 +00:00
|
|
|
on_reload_kanban: function (){
|
2011-08-08 08:37:48 +00:00
|
|
|
var self = this;
|
2011-09-01 16:10:51 +00:00
|
|
|
QWeb2.Element.prototype.compile_action_field = function(value) {
|
|
|
|
debugger;
|
|
|
|
this.top("r.push(context.engine.tools.html_escape(" + (this.format_expression(value)) + "));");
|
|
|
|
};
|
2011-08-08 08:37:48 +00:00
|
|
|
_.each(self.all_display_data, function(data, index) {
|
2011-08-16 08:56:21 +00:00
|
|
|
if (data.records.length > 0){
|
2011-08-08 08:37:48 +00:00
|
|
|
_.each(data.records, function(record) {
|
2011-08-18 10:39:14 +00:00
|
|
|
self.$element.find("#main_" + record.id).children().remove();
|
2011-09-01 16:10:51 +00:00
|
|
|
self.$element.find("#main_" + record.id).append(self.qweb.render('kanban-box', record));
|
2011-08-11 09:29:52 +00:00
|
|
|
});
|
2011-08-16 08:56:21 +00:00
|
|
|
} else {
|
2011-08-08 08:37:48 +00:00
|
|
|
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 +"%");
|
2011-08-16 08:56:21 +00:00
|
|
|
this.$element.find('button').click(function() {
|
2011-08-10 11:09:43 +00:00
|
|
|
var record_id = $(this).closest(".record").attr("id");
|
2011-08-16 08:56:21 +00:00
|
|
|
if (record_id) {
|
2011-08-10 11:09:43 +00:00
|
|
|
record_id = parseInt(record_id.split("_")[1])
|
2011-08-16 08:56:21 +00:00
|
|
|
if (record_id) {
|
|
|
|
if ($(this).data("type") == "delete") {
|
2011-08-10 11:09:43 +00:00
|
|
|
self.do_delete(record_id);
|
2011-08-16 08:56:21 +00:00
|
|
|
} else {
|
2011-08-10 11:09:43 +00:00
|
|
|
var button_attrs = $(this).data()
|
|
|
|
self.on_button_click(button_attrs, record_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-08-03 10:26:53 +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) {
|
2011-08-19 09:54:48 +00:00
|
|
|
self.domain = results.domain;
|
|
|
|
self.context = results.context;
|
|
|
|
self.group_by = results.group_by;
|
|
|
|
self.do_actual_search();
|
2011-08-01 10:15:28 +00:00
|
|
|
});
|
|
|
|
},
|
2011-08-19 09:54:48 +00:00
|
|
|
do_actual_search : function () {
|
|
|
|
var self = this;
|
|
|
|
self.datagroup = new openerp.base.DataGroup(self, self.model, self.domain, self.context, self.group_by || []);
|
|
|
|
self.dataset.context = self.context;
|
|
|
|
self.dataset.domain = self.domain;
|
|
|
|
self.datagroup.list([],
|
|
|
|
function (groups) {
|
|
|
|
self.groups = groups;
|
2011-08-19 10:45:54 +00:00
|
|
|
self.do_render_group(groups);
|
2011-08-19 09:54:48 +00:00
|
|
|
},
|
|
|
|
function (dataset) {
|
|
|
|
self.domain = dataset.domain;
|
|
|
|
self.context = dataset.context;
|
|
|
|
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.on_show_data(self.all_display_data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
2011-08-16 08:56:21 +00:00
|
|
|
do_render_group : function (datagroups) {
|
2011-08-08 08:37:48 +00:00
|
|
|
this.all_display_data = [];
|
2011-08-01 10:15:28 +00:00
|
|
|
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;
|
2011-08-03 10:26:53 +00:00
|
|
|
var group_value = group.value;
|
2011-08-16 08:56:21 +00:00
|
|
|
if (!group.value) {
|
2011-08-03 10:26:53 +00:00
|
|
|
group_name = "Undefined";
|
|
|
|
group_value = 'false';
|
2011-08-16 08:56:21 +00:00
|
|
|
} else if (group.value instanceof Array) {
|
|
|
|
group_name = group.value[1];
|
|
|
|
group_value = group.value[0];
|
2011-08-01 10:15:28 +00:00
|
|
|
}
|
2011-08-19 07:07:40 +00:00
|
|
|
self.dataset.read_slice([], {}, function(records) {
|
2011-08-10 05:23:08 +00:00
|
|
|
self.all_display_data.push({"value" : group_value, "records": records, 'header':group_name, 'ids': self.dataset.ids});
|
2011-08-08 08:37:48 +00:00
|
|
|
if (datagroups.length == self.all_display_data.length) {
|
|
|
|
self.$element.find("#kanbanview").remove();
|
|
|
|
self.on_show_data(self.all_display_data);
|
2011-08-11 09:29:52 +00:00
|
|
|
}
|
|
|
|
});
|
2011-08-01 10:15:28 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
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:
|