2011-09-06 13:02:01 +00:00
|
|
|
openerp.web_kanban = function (openerp) {
|
2011-09-01 16:10:51 +00:00
|
|
|
|
2011-11-03 10:45:34 +00:00
|
|
|
var _t = openerp.web._t;
|
2011-09-07 09:37:43 +00:00
|
|
|
var QWeb = openerp.web.qweb;
|
2011-09-06 13:02:01 +00:00
|
|
|
QWeb.add_template('/web_kanban/static/src/xml/web_kanban.xml');
|
|
|
|
openerp.web.views.add('kanban', 'openerp.web_kanban.KanbanView');
|
|
|
|
openerp.web_kanban.KanbanView = openerp.web.View.extend({
|
2011-11-02 17:18:54 +00:00
|
|
|
template: "KanbanView",
|
2011-09-15 09:49:44 +00:00
|
|
|
init: function (parent, dataset, view_id, options) {
|
|
|
|
this._super(parent);
|
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-11-02 17:18:54 +00:00
|
|
|
this.model = this.dataset.model;
|
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-11-02 17:18:54 +00:00
|
|
|
this.fields_keys = [];
|
|
|
|
this.group_by = null;
|
2011-11-03 11:08:11 +00:00
|
|
|
this.records_states = {};
|
|
|
|
this.groups_states = {};
|
2011-08-09 11:25:56 +00:00
|
|
|
this.groups = [];
|
2011-11-02 17:18:54 +00:00
|
|
|
this.nr_columns = 3;
|
2011-10-20 14:32:54 +00:00
|
|
|
this.form_dialog = new openerp.web.FormDialog(this, {}, this.options.action_views_ids.form, dataset).start();
|
2011-11-03 10:45:34 +00:00
|
|
|
this.form_dialog.on_form_dialog_saved.add_last(this.do_reload);
|
2011-11-03 14:15:15 +00:00
|
|
|
this.aggregates = {};
|
2011-11-02 17:18:54 +00:00
|
|
|
this.qweb = new QWeb2.Engine();
|
|
|
|
this.qweb.debug = (window.location.search.indexOf('?debug') !== -1);
|
|
|
|
this.qweb.default_dict = {
|
2011-11-03 10:45:34 +00:00
|
|
|
'_' : _,
|
|
|
|
'_t' : _t
|
2011-11-02 17:18:54 +00:00
|
|
|
}
|
|
|
|
this.has_been_loaded = $.Deferred();
|
2011-11-03 10:45:34 +00:00
|
|
|
this.search_domain = this.search_context = this.search_group_by = null;
|
2011-07-28 09:51:52 +00:00
|
|
|
},
|
2011-09-01 16:10:51 +00:00
|
|
|
start: function() {
|
2011-09-15 09:42:46 +00:00
|
|
|
this._super();
|
2011-11-03 10:45:34 +00:00
|
|
|
this.$element.find('button.oe_kanban_button_new').click(this.do_add_record);
|
2011-11-02 17:18:54 +00:00
|
|
|
this.$groups = this.$element.find('.oe_kanban_groups tr');
|
|
|
|
var context = new openerp.web.CompoundContext(this.dataset.get_context());
|
|
|
|
return this.rpc('/web/view/load', {
|
|
|
|
'model': this.model,
|
|
|
|
'view_id': this.view_id,
|
|
|
|
'view_type': 'kanban',
|
|
|
|
context: context
|
|
|
|
}, this.on_loaded);
|
2011-07-28 09:51:52 +00:00
|
|
|
},
|
2011-09-01 16:10:51 +00:00
|
|
|
on_loaded: function(data) {
|
2011-09-06 23:08:59 +00:00
|
|
|
this.fields_view = data;
|
2011-11-02 17:18:54 +00:00
|
|
|
this.fields_keys = _.keys(this.fields_view.fields);
|
2011-09-05 14:18:12 +00:00
|
|
|
this.add_qweb_template();
|
2011-11-02 17:18:54 +00:00
|
|
|
this.has_been_loaded.resolve();
|
2011-07-28 09:51:52 +00:00
|
|
|
},
|
2011-09-05 14:18:12 +00:00
|
|
|
add_qweb_template: function() {
|
2011-11-02 17:18:54 +00:00
|
|
|
var group_operator = ['avg', 'max', 'min', 'sum', 'count']
|
2011-09-05 14:18:12 +00:00
|
|
|
for (var i=0, ii=this.fields_view.arch.children.length; i < ii; i++) {
|
|
|
|
var child = this.fields_view.arch.children[i];
|
2011-09-20 06:57:38 +00:00
|
|
|
if (child.tag === "field") {
|
|
|
|
for(j=0, jj=group_operator.length; j < jj; j++) {
|
|
|
|
if (child.attrs[group_operator[j]]) {
|
|
|
|
this.aggregates[child.attrs.name] = child.attrs[group_operator[j]];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-05 14:18:12 +00:00
|
|
|
if (child.tag === "templates") {
|
|
|
|
this.transform_qweb_template(child);
|
2011-09-06 13:45:20 +00:00
|
|
|
this.qweb.add_template(openerp.web.json_node_to_xml(child));
|
2011-09-05 14:18:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
transform_qweb_template: function(node) {
|
2011-09-12 14:14:44 +00:00
|
|
|
var qweb_prefix = QWeb.prefix;
|
2011-09-05 14:18:12 +00:00
|
|
|
switch (node.tag) {
|
|
|
|
case 'field':
|
|
|
|
node.tag = 't';
|
2011-09-08 15:50:07 +00:00
|
|
|
node.attrs['t-esc'] = 'record.' + node.attrs['name'] + '.value';
|
2011-09-05 14:18:12 +00:00
|
|
|
break
|
|
|
|
case 'button':
|
2011-09-06 12:50:11 +00:00
|
|
|
case 'a':
|
2011-09-05 14:18:12 +00:00
|
|
|
var type = node.attrs.type || '';
|
2011-09-12 12:59:38 +00:00
|
|
|
if (_.indexOf('action,object,edit,delete,color'.split(','), type) !== -1) {
|
2011-09-05 14:18:12 +00:00
|
|
|
_.each(node.attrs, function(v, k) {
|
2011-09-13 08:15:33 +00:00
|
|
|
if (_.indexOf('icon,type,name,string,context,states'.split(','), k) != -1) {
|
2011-09-12 14:14:44 +00:00
|
|
|
node.attrs['data-' + k] = v;
|
|
|
|
delete(node.attrs[k]);
|
|
|
|
}
|
2011-09-05 14:18:12 +00:00
|
|
|
});
|
|
|
|
if (node.attrs['data-states']) {
|
|
|
|
var states = _.map(node.attrs['data-states'].split(','), function(state) {
|
2011-10-26 13:35:14 +00:00
|
|
|
return "record.state.raw_value == '" + _.trim(state) + "'";
|
2011-09-05 14:18:12 +00:00
|
|
|
});
|
|
|
|
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: {
|
2011-09-06 13:02:01 +00:00
|
|
|
src: '/web/static/src/img/icons/' + node.attrs['data-icon'] + '.png',
|
2011-09-05 14:18:12 +00:00
|
|
|
width: '16',
|
|
|
|
height: '16'
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
2011-09-06 12:50:11 +00:00
|
|
|
if (node.tag == 'a') {
|
|
|
|
node.attrs.href = '#';
|
|
|
|
} else {
|
|
|
|
node.attrs.type = 'button';
|
|
|
|
}
|
|
|
|
node.attrs['class'] = (node.attrs['class'] || '') + ' oe_kanban_action oe_kanban_action_' + node.tag;
|
2011-09-05 14:18:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (node.children) {
|
|
|
|
for (var i = 0, ii = node.children.length; i < ii; i++) {
|
|
|
|
this.transform_qweb_template(node.children[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2011-11-03 10:45:34 +00:00
|
|
|
do_add_record: function() {
|
|
|
|
this.dataset.index = null;
|
|
|
|
this.do_switch_view('form');
|
|
|
|
},
|
2011-11-02 17:18:54 +00:00
|
|
|
do_search: function(domain, context, group_by) {
|
|
|
|
var self = this;
|
2011-11-03 10:45:34 +00:00
|
|
|
this.search_domain = domain;
|
|
|
|
this.search_context = context;
|
|
|
|
this.search_group_by = group_by;
|
2011-11-02 17:18:54 +00:00
|
|
|
$.when(this.has_been_loaded).then(function() {
|
|
|
|
self.group_by = group_by.length ? group_by[0] : self.fields_view.arch.attrs.default_group_by;
|
2011-11-03 14:15:15 +00:00
|
|
|
self.datagroup = new openerp.web.DataGroup(self, self.model, domain, context, self.group_by ? [self.group_by] : []);
|
2011-11-02 17:18:54 +00:00
|
|
|
self.datagroup.list(self.fields_keys, self.do_process_groups, self.do_process_dataset);
|
|
|
|
});
|
|
|
|
},
|
2011-11-03 10:45:34 +00:00
|
|
|
do_reload: function() {
|
|
|
|
this.do_search(this.search_domain, this.search_context, this.search_group_by);
|
|
|
|
},
|
2011-11-03 14:15:15 +00:00
|
|
|
do_clear_groups: function() {
|
|
|
|
_.each(this.groups, function(group) {
|
|
|
|
group.stop();
|
|
|
|
});
|
|
|
|
this.groups = [];
|
|
|
|
},
|
2011-11-02 17:18:54 +00:00
|
|
|
do_process_groups: function(groups) {
|
2011-11-03 14:15:15 +00:00
|
|
|
this.do_clear_groups();
|
|
|
|
this.dataset.ids = [];
|
|
|
|
var self = this,
|
|
|
|
remaining = groups.length - 1,
|
|
|
|
groups_array = [];
|
|
|
|
_.each(groups, function (group, index) {
|
|
|
|
var group_name, group_value, group_aggregates = {};
|
|
|
|
if (group.value instanceof Array) {
|
|
|
|
group_name = group.value[1];
|
|
|
|
group_value = group.value[0];
|
|
|
|
} else {
|
|
|
|
group_name = '' + group.value;
|
|
|
|
group_value = group.value;
|
|
|
|
}
|
|
|
|
_.each(self.aggregates, function(value, key) {
|
|
|
|
group_aggregates[value] = group.aggregates[key];
|
|
|
|
});
|
|
|
|
var dataset = new openerp.web.DataSetSearch(self, self.dataset.model, group.context, group.domain);
|
|
|
|
dataset.read_slice(self.fields_keys, {'domain': group.domain, 'context': group.context}, function(records) {
|
|
|
|
self.dataset.ids.push.apply(self.dataset.ids, dataset.ids);
|
|
|
|
groups_array[index] = new openerp.web_kanban.KanbanGroup(self, group_value, group_name, records, group_aggregates);
|
|
|
|
if (!remaining--) {
|
|
|
|
self.dataset.index = self.dataset.ids.length ? 0 : null;
|
|
|
|
self.do_add_groups(groups_array);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2011-11-02 17:18:54 +00:00
|
|
|
},
|
|
|
|
do_process_dataset: function(dataset) {
|
|
|
|
var self = this;
|
2011-11-03 14:15:15 +00:00
|
|
|
this.do_clear_groups();
|
2011-11-02 17:18:54 +00:00
|
|
|
this.dataset.read_slice(this.fields_keys, {}, function(records) {
|
|
|
|
var groups = [];
|
|
|
|
while (records.length) {
|
|
|
|
for (var i = 0; i < self.nr_columns; i++) {
|
|
|
|
if (!groups[i]) {
|
|
|
|
groups[i] = [];
|
|
|
|
}
|
|
|
|
groups[i].push(records.shift());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (var i = 0; i < groups.length; i++) {
|
|
|
|
groups[i] = new openerp.web_kanban.KanbanGroup(self, false, false, _.compact(groups[i]));
|
|
|
|
}
|
|
|
|
self.do_add_groups(groups);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
do_add_groups: function(groups) {
|
|
|
|
var self = this;
|
|
|
|
this.groups = groups;
|
|
|
|
_.each(this.groups, function(group) {
|
|
|
|
group.appendTo(self.$element.find('.oe_kanban_groups_headers'));
|
|
|
|
});
|
2011-11-03 15:17:46 +00:00
|
|
|
this.on_groups_started();
|
|
|
|
},
|
|
|
|
on_groups_started: function() {
|
2011-11-03 14:15:15 +00:00
|
|
|
this.compute_groups_width();
|
2011-11-02 17:18:54 +00:00
|
|
|
},
|
|
|
|
do_show: function () {
|
|
|
|
this.$element.show();
|
|
|
|
},
|
|
|
|
do_hide: function () {
|
|
|
|
this.$element.hide();
|
2011-11-03 14:15:15 +00:00
|
|
|
},
|
|
|
|
compute_groups_width: function() {
|
|
|
|
var unfolded = 0;
|
|
|
|
_.each(this.groups, function(group) {
|
|
|
|
unfolded += group.state.folded ? 0 : 1;
|
|
|
|
group.$element.css('width', '');
|
|
|
|
});
|
|
|
|
_.each(this.groups, function(group) {
|
|
|
|
if (!group.state.folded) {
|
|
|
|
group.$element.css('width', Math.round(100/unfolded) + '%');
|
|
|
|
}
|
|
|
|
});
|
2011-11-02 17:18:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
openerp.web_kanban.KanbanGroup = openerp.web.Widget.extend({
|
|
|
|
template: 'KanbanView.group_header',
|
2011-11-03 14:15:15 +00:00
|
|
|
init: function (parent, value, title, records, aggregates) {
|
2011-11-02 17:18:54 +00:00
|
|
|
var self = this;
|
|
|
|
this._super(parent);
|
|
|
|
this.view = parent;
|
|
|
|
this.value = value;
|
|
|
|
this.title = title;
|
2011-11-03 14:15:15 +00:00
|
|
|
this.aggregates = aggregates || {};
|
|
|
|
if (!title && !value) {
|
|
|
|
this.state = {};
|
|
|
|
this.foldable = this.draggable = false;
|
|
|
|
} else {
|
|
|
|
this.foldable = this.draggable = true;
|
|
|
|
var key = '' + this.view.group_by + '' + value;
|
|
|
|
if (!this.view.groups_states[key]) {
|
|
|
|
this.view.groups_states[key] = {
|
|
|
|
folded: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.state = this.view.groups_states[key];
|
|
|
|
}
|
2011-11-02 17:18:54 +00:00
|
|
|
this.$records = null;
|
|
|
|
this.records = _.map(records, function(record) {
|
|
|
|
return new openerp.web_kanban.KanbanRecord(self, record);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
start: function() {
|
2011-11-03 15:17:46 +00:00
|
|
|
var self = this,
|
|
|
|
def = this._super();
|
2011-11-02 17:18:54 +00:00
|
|
|
this.$records = $(QWeb.render('KanbanView.group_records_container', { widget : this}));
|
|
|
|
this.$records.appendTo(this.view.$element.find('.oe_kanban_groups_records'));
|
|
|
|
_.each(this.records, function(record) {
|
|
|
|
record.appendTo(self.$records);
|
|
|
|
});
|
2011-11-03 14:15:15 +00:00
|
|
|
this.$element.find(".oe_kanban_fold_icon").click(function() {
|
|
|
|
self.do_toggle_fold();
|
2011-11-03 15:17:46 +00:00
|
|
|
self.view.compute_groups_width();
|
2011-11-03 14:15:15 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
if (this.state.folded) {
|
|
|
|
this.do_toggle_fold();
|
|
|
|
}
|
2011-11-03 15:17:46 +00:00
|
|
|
return def;
|
2011-11-02 17:18:54 +00:00
|
|
|
},
|
|
|
|
stop: function() {
|
|
|
|
this._super();
|
|
|
|
this.$records.remove();
|
2011-11-03 10:45:34 +00:00
|
|
|
},
|
|
|
|
remove_record: function(id, remove_from_dataset) {
|
|
|
|
for (var i = 0, ii = this.records.length; i < ii; i++) {
|
|
|
|
if (this.records[i]['id'] === id) {
|
|
|
|
delete(this.records[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (remove_from_dataset) {
|
|
|
|
var idx = _.indexOf(this.view.dataset.ids, id);
|
|
|
|
if (idx > -1) {
|
|
|
|
delete(this.view.dataset.ids[idx]);
|
|
|
|
}
|
|
|
|
}
|
2011-11-03 14:15:15 +00:00
|
|
|
},
|
2011-11-03 15:17:46 +00:00
|
|
|
do_toggle_fold: function(compute_width) {
|
2011-11-03 14:15:15 +00:00
|
|
|
this.$element.toggleClass('oe_kanban_group_folded');
|
|
|
|
this.$records.find('.oe_kanban_record').toggle();
|
|
|
|
this.state.folded = this.$element.is('.oe_kanban_group_folded');
|
2011-11-02 17:18:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
openerp.web_kanban.KanbanRecord = openerp.web.Widget.extend({
|
|
|
|
template: 'KanbanView.record',
|
|
|
|
init: function (parent, record) {
|
|
|
|
this._super(parent);
|
|
|
|
this.group = parent;
|
|
|
|
this.view = parent.view;
|
2011-11-03 10:45:34 +00:00
|
|
|
this.id = null;
|
|
|
|
this.set_record(record);
|
2011-11-03 11:08:11 +00:00
|
|
|
if (!this.view.records_states[this.id]) {
|
|
|
|
this.view.records_states[this.id] = {
|
|
|
|
folded: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
this.state = this.view.records_states[this.id];
|
2011-11-03 10:45:34 +00:00
|
|
|
},
|
|
|
|
set_record: function(record) {
|
|
|
|
this.id = record.id;
|
2011-11-02 17:18:54 +00:00
|
|
|
this.record = this.transform_record(record);
|
|
|
|
},
|
2011-11-03 10:45:34 +00:00
|
|
|
start: function() {
|
|
|
|
this._super();
|
|
|
|
this.bind_events();
|
|
|
|
},
|
2011-11-02 17:18:54 +00:00
|
|
|
transform_record: function(record) {
|
|
|
|
var self = this,
|
|
|
|
new_record = {};
|
|
|
|
_.each(record, function(value, name) {
|
|
|
|
var r = _.clone(self.view.fields_view.fields[name]);
|
|
|
|
r.raw_value = value;
|
|
|
|
r.value = openerp.web.format_value(value, r);
|
|
|
|
new_record[name] = r;
|
|
|
|
});
|
|
|
|
return new_record;
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var ctx = {
|
|
|
|
record: this.record,
|
|
|
|
widget: this
|
|
|
|
}
|
|
|
|
for (var p in this) {
|
|
|
|
if (_.startsWith(p, 'kanban_')) {
|
|
|
|
ctx[p] = _.bind(this[p], this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this._super({
|
|
|
|
'content': this.view.qweb.render('kanban-box', ctx)
|
|
|
|
});
|
|
|
|
},
|
2011-11-03 10:45:34 +00:00
|
|
|
bind_events: function() {
|
2011-11-03 11:08:11 +00:00
|
|
|
var self = this,
|
|
|
|
$show_on_click = self.$element.find('.oe_kanban_box_show_onclick');
|
|
|
|
$show_on_click.toggle(self.state.folded);
|
2011-11-03 10:45:34 +00:00
|
|
|
this.$element.find('.oe_kanban_box_show_onclick_trigger').click(function() {
|
2011-11-03 11:08:11 +00:00
|
|
|
$show_on_click.toggle();
|
|
|
|
self.state.folded = !self.state.folded;
|
2011-11-03 10:45:34 +00:00
|
|
|
});
|
|
|
|
this.$element.find('.oe_kanban_action').click(function() {
|
|
|
|
var $action = $(this),
|
|
|
|
type = $action.data('type') || 'button',
|
|
|
|
method = 'do_action_' + type;
|
|
|
|
if (typeof self[method] === 'function') {
|
|
|
|
self[method]($action);
|
2011-11-03 11:19:15 +00:00
|
|
|
} else {
|
|
|
|
self.do_warn("Kanban: no action for type : " + type);
|
2011-11-03 10:45:34 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
do_action_delete: function($action) {
|
|
|
|
var self = this;
|
2011-11-03 10:55:18 +00:00
|
|
|
if (confirm(_t("Qre you sure you want to delete this record ?"))) {
|
|
|
|
return $.when(this.view.dataset.unlink([this.id])).then(function() {
|
|
|
|
self.group.remove_record(self.id)
|
|
|
|
self.stop();
|
|
|
|
});
|
|
|
|
}
|
2011-11-03 10:45:34 +00:00
|
|
|
},
|
|
|
|
do_action_edit: function($action) {
|
|
|
|
var self = this;
|
|
|
|
if ($action.attr('target') === 'dialog') {
|
|
|
|
this.view.form_dialog.select_id(this.id).then(function() {
|
|
|
|
self.view.form_dialog.open();
|
|
|
|
});
|
|
|
|
} else {
|
2011-11-03 11:08:11 +00:00
|
|
|
if (self.view.dataset.select_id(this.id)) {
|
2011-11-03 10:45:34 +00:00
|
|
|
this.view.do_switch_view('form');
|
|
|
|
} else {
|
2011-11-03 11:19:15 +00:00
|
|
|
this.do_warn("Kanban: could not find id#" + id);
|
2011-11-03 10:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
do_action_color: function($action) {
|
|
|
|
var self = this,
|
|
|
|
colors = '#FFFFFF,#CCCCCC,#FFC7C7,#FFF1C7,#E3FFC7,#C7FFD5,#C7FFFF,#C7D5FF,#E3C7FF,#FFC7F1'.split(','),
|
|
|
|
$cpicker = $(QWeb.render('KanbanColorPicker', { colors : colors, columns: 2 }));
|
|
|
|
$action.after($cpicker);
|
|
|
|
$cpicker.mouseenter(function() {
|
|
|
|
clearTimeout($cpicker.data('timeoutId'));
|
|
|
|
}).mouseleave(function(evt) {
|
|
|
|
var timeoutId = setTimeout(function() { $cpicker.remove() }, 500);
|
|
|
|
$cpicker.data('timeoutId', timeoutId);
|
|
|
|
});
|
|
|
|
$cpicker.find('a').click(function() {
|
|
|
|
var data = {};
|
|
|
|
data[$action.data('name')] = $(this).data('color');
|
|
|
|
self.view.dataset.write(self.id, data, {}, function() {
|
|
|
|
self.record[$action.data('name')] = $(this).data('color');
|
|
|
|
self.do_reload();
|
|
|
|
});
|
|
|
|
$cpicker.remove();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
},
|
2011-11-03 11:19:15 +00:00
|
|
|
do_action_object: function ($action) {
|
2011-11-03 10:45:34 +00:00
|
|
|
var button_attrs = $action.data();
|
2011-11-03 11:19:15 +00:00
|
|
|
this.view.do_execute_action(button_attrs, this.view.dataset, this.id, this.do_reload);
|
2011-11-03 10:45:34 +00:00
|
|
|
},
|
|
|
|
do_reload: function() {
|
|
|
|
var self = this;
|
|
|
|
this.view.dataset.read_ids([this.id], this.view.fields_keys, function(records) {
|
|
|
|
if (records.length) {
|
|
|
|
self.set_record(records[0]);
|
|
|
|
self.do_render();
|
|
|
|
} else {
|
|
|
|
self.stop();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
do_render: function() {
|
|
|
|
this.$element.html(this.render());
|
|
|
|
this.bind_events();
|
|
|
|
},
|
2011-11-02 17:18:54 +00:00
|
|
|
kanban_color: function(variable) {
|
|
|
|
var number_of_color_schemes = 10,
|
|
|
|
index = 0;
|
|
|
|
switch (typeof(variable)) {
|
|
|
|
case 'string':
|
|
|
|
for (var i=0, ii=variable.length; i<ii; i++) {
|
|
|
|
index += variable.charCodeAt(i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'number':
|
|
|
|
index = Math.round(variable);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
var color = (index % number_of_color_schemes);
|
|
|
|
return 'oe_kanban_color_' + color;
|
|
|
|
},
|
|
|
|
kanban_gravatar: function(email, size) {
|
|
|
|
size = size || 22;
|
|
|
|
var email_md5 = $.md5(email);
|
|
|
|
return 'http://www.gravatar.com/avatar/' + email_md5 + '.png?s=' + size;
|
|
|
|
},
|
|
|
|
kanban_image: function(model, field, id) {
|
|
|
|
id = id || '';
|
|
|
|
return '/web/binary/image?session_id=' + this.session.session_id + '&model=' + model + '&field=' + field + '&id=' + id;
|
|
|
|
},
|
|
|
|
kanban_text_ellipsis: function(s, size) {
|
|
|
|
size = size || 160;
|
|
|
|
if (!s) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return s.substr(0, size) + '...';
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
openerp.web_kanban.KanbanView_old = openerp.web.View.extend({
|
2011-09-15 07:30:58 +00:00
|
|
|
on_show_data: function() {
|
2011-07-29 09:04:30 +00:00
|
|
|
var self = this;
|
2011-09-15 07:30:58 +00:00
|
|
|
if (!this.group_by.length) {
|
|
|
|
this.do_record_group();
|
|
|
|
}
|
2011-08-18 13:16:20 +00:00
|
|
|
var drag_handel = false;
|
2011-09-06 12:50:11 +00:00
|
|
|
if (this.$element.find(".oe_kanban_draghandle").length > 0) {
|
|
|
|
drag_handel = ".oe_kanban_draghandle";
|
2011-08-18 13:16:20 +00:00
|
|
|
}
|
2011-09-15 07:36:03 +00:00
|
|
|
if (!this.group_by.length) {
|
|
|
|
drag_handel = true;
|
|
|
|
}
|
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-09-26 09:08:47 +00:00
|
|
|
scroll: false
|
2011-08-11 09:29:52 +00:00
|
|
|
});
|
2011-09-20 12:02:47 +00:00
|
|
|
},
|
|
|
|
do_fold_unfold_columns: function(event, element_id) {
|
|
|
|
var column_id = "column_" + element_id;
|
2011-09-21 09:52:45 +00:00
|
|
|
var column_element = this.$element.find("#" + column_id + " .oe_fold_column");
|
2011-09-20 12:02:47 +00:00
|
|
|
if (column_element.is(":hidden")) {
|
|
|
|
this.$element.find("#" + column_id).find("img.fold-columns-icon").attr('src', '/web_kanban/static/src/img/minus-icon.png');
|
|
|
|
column_element.show();
|
|
|
|
this.$element.find("#" + column_id + ".oe_table_column").css("width",Math.round(99 / this.all_display_data.length) + "%");
|
|
|
|
this.$element.find("#" + column_id + ".oe_vertical_text").hide();
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
this.$element.find("#" + column_id).find("img.fold-columns-icon").attr('src', '/web_kanban/static/src/img/plus-icon.png');
|
|
|
|
column_element.hide();
|
|
|
|
this.$element.find("#" + column_id + ".oe_table_column").css("width","0.5%");
|
|
|
|
this.$element.find("#" + column_id + ".oe_vertical_text").show();
|
|
|
|
}
|
|
|
|
|
2011-07-29 09:04:30 +00:00
|
|
|
},
|
2011-09-15 07:30:58 +00:00
|
|
|
do_record_group: function() {
|
2011-09-22 09:03:14 +00:00
|
|
|
if (this.NO_OF_COLUMNS && this.all_display_data.length > 0) {
|
2011-09-15 07:30:58 +00:00
|
|
|
var records = this.all_display_data[0].records;
|
|
|
|
var record_per_group = Math.round((records).length / this.NO_OF_COLUMNS);
|
|
|
|
this.all_display_data = [];
|
|
|
|
for (var i=0, ii=this.NO_OF_COLUMNS; i < ii; i++) {
|
2011-09-23 11:54:22 +00:00
|
|
|
this.all_display_data.push({'records': records.slice(0,record_per_group), 'value':i, 'header' : false, 'ids':[]});
|
2011-09-15 07:30:58 +00:00
|
|
|
records.splice(0,record_per_group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
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-19 10:16:32 +00:00
|
|
|
if (self.fields_view.fields.sequence != undefined && ((self.source_index.index >= 0 && self.source_index.index != from) ||
|
|
|
|
(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-09-19 12:44:22 +00:00
|
|
|
var value = ui.item.closest("td").attr("id");
|
2011-08-16 08:56:21 +00:00
|
|
|
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-07-28 09:51:52 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|