2012-04-17 12:48:30 +00:00
|
|
|
openerp.web_kanban = function (instance) {
|
2011-09-01 16:10:51 +00:00
|
|
|
|
2012-04-17 12:48:30 +00:00
|
|
|
var _t = instance.web._t,
|
|
|
|
_lt = instance.web._lt;
|
|
|
|
var QWeb = instance.web.qweb;
|
|
|
|
instance.web.views.add('kanban', 'instance.web_kanban.KanbanView');
|
2011-11-04 18:05:12 +00:00
|
|
|
|
2012-04-17 12:48:30 +00:00
|
|
|
instance.web_kanban.KanbanView = instance.web.View.extend({
|
2011-11-02 17:18:54 +00:00
|
|
|
template: "KanbanView",
|
2011-12-16 13:00:00 +00:00
|
|
|
display_name: _lt('Kanban'),
|
2012-06-27 14:12:49 +00:00
|
|
|
default_nr_columns: 1,
|
2012-04-05 16:14:04 +00:00
|
|
|
view_type: "kanban",
|
2012-05-25 12:09:47 +00:00
|
|
|
quick_create_class: "instance.web_kanban.QuickCreate",
|
2012-05-23 13:01:16 +00:00
|
|
|
number_of_color_schemes: 10,
|
2011-09-15 09:49:44 +00:00
|
|
|
init: function (parent, dataset, view_id, options) {
|
2012-05-14 15:21:32 +00:00
|
|
|
this._super(parent, dataset, view_id, options);
|
2012-10-18 11:49:50 +00:00
|
|
|
var self = this;
|
2012-06-04 09:31:03 +00:00
|
|
|
_.defaults(this.options, {
|
|
|
|
"quick_creatable": true,
|
|
|
|
"creatable": true,
|
|
|
|
"create_text": undefined,
|
|
|
|
"read_only_mode": false,
|
|
|
|
"confirm_on_delete": true,
|
|
|
|
});
|
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;
|
2012-08-14 21:37:08 +00:00
|
|
|
this.group_by_field = {};
|
2012-08-14 19:53:16 +00:00
|
|
|
this.grouped_by_m2o = false;
|
2011-11-04 21:20:36 +00:00
|
|
|
this.state = {
|
|
|
|
groups : {},
|
|
|
|
records : {}
|
|
|
|
};
|
2011-08-09 11:25:56 +00:00
|
|
|
this.groups = [];
|
2011-11-03 14:15:15 +00:00
|
|
|
this.aggregates = {};
|
2011-11-15 13:53:49 +00:00
|
|
|
this.group_operators = ['avg', 'max', 'min', 'sum', 'count'];
|
2011-11-02 17:18:54 +00:00
|
|
|
this.qweb = new QWeb2.Engine();
|
2012-08-14 15:29:00 +00:00
|
|
|
this.qweb.debug = instance.session.debug;
|
2011-11-24 21:06:00 +00:00
|
|
|
this.qweb.default_dict = _.clone(QWeb.default_dict);
|
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-11-07 09:48:59 +00:00
|
|
|
this.currently_dragging = {};
|
2012-10-16 12:29:51 +00:00
|
|
|
this.limit = options.limit || 40;
|
2012-04-09 16:42:29 +00:00
|
|
|
this.add_group_mutex = new $.Mutex();
|
2012-10-18 11:49:50 +00:00
|
|
|
this.on('view_loaded', self, self.load_kanban);
|
2011-07-28 09:51:52 +00:00
|
|
|
},
|
2012-09-04 10:19:16 +00:00
|
|
|
start: function() {
|
|
|
|
var self = this;
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
this.$el.on('click', '.oe_kanban_dummy_cell', function() {
|
|
|
|
if (self.$buttons) {
|
|
|
|
self.$buttons.find('.oe_kanban_add_column').effect('bounce', {distance: 18, times: 5}, 150);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-05-22 13:40:49 +00:00
|
|
|
destroy: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2012-05-24 15:58:37 +00:00
|
|
|
$('html').off('click.kanban');
|
2012-05-22 13:40:49 +00:00
|
|
|
},
|
2012-10-18 11:49:50 +00:00
|
|
|
load_kanban: function(data) {
|
2012-05-21 09:59:41 +00:00
|
|
|
this.fields_view = data;
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.addClass(this.fields_view.arch.attrs['class']);
|
2012-04-10 14:20:51 +00:00
|
|
|
this.$buttons = $(QWeb.render("KanbanView.buttons", {'widget': this}));
|
|
|
|
if (this.options.$buttons) {
|
|
|
|
this.$buttons.appendTo(this.options.$buttons);
|
|
|
|
} else {
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.find('.oe_kanban_buttons').replaceWith(this.$buttons);
|
2012-04-10 14:20:51 +00:00
|
|
|
}
|
|
|
|
this.$buttons
|
2012-08-14 19:53:16 +00:00
|
|
|
.on('click', 'button.oe_kanban_button_new', this.do_add_record)
|
|
|
|
.on('click', '.oe_kanban_add_column', this.do_add_group);
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$groups = this.$el.find('.oe_kanban_groups tr');
|
2012-01-17 20:26:07 +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();
|
2012-10-18 11:49:50 +00:00
|
|
|
this.trigger('kanban_view_loaded', data);
|
2012-04-05 16:14:04 +00:00
|
|
|
return $.when();
|
2011-07-28 09:51:52 +00:00
|
|
|
},
|
2012-05-21 09:59:41 +00:00
|
|
|
_is_quick_create_enabled: function() {
|
2012-09-05 09:16:20 +00:00
|
|
|
if (!this.options.quick_creatable || !this.is_action_enabled('create'))
|
2012-05-21 09:59:41 +00:00
|
|
|
return false;
|
|
|
|
if (this.fields_view.arch.attrs.quick_create !== undefined)
|
|
|
|
return JSON.parse(this.fields_view.arch.attrs.quick_create);
|
|
|
|
return !! this.group_by;
|
|
|
|
},
|
2012-09-04 14:11:55 +00:00
|
|
|
is_action_enabled: function(action) {
|
2012-09-03 07:24:39 +00:00
|
|
|
if (action === 'create' && !this.options.creatable)
|
2012-05-21 09:59:41 +00:00
|
|
|
return false;
|
2012-09-03 07:24:39 +00:00
|
|
|
return this._super(action);
|
2012-05-21 09:59:41 +00:00
|
|
|
},
|
2012-09-18 15:30:35 +00:00
|
|
|
/* add_qweb_template
|
|
|
|
* select the nodes into the xml and send to extract_aggregates the nodes with TagName="field"
|
|
|
|
*/
|
2011-09-05 14:18:12 +00:00
|
|
|
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);
|
2012-04-17 12:48:30 +00:00
|
|
|
this.qweb.add_template(instance.web.json_node_to_xml(child));
|
2011-09-05 14:18:12 +00:00
|
|
|
break;
|
2011-11-15 13:53:49 +00:00
|
|
|
} else if (child.tag === 'field') {
|
|
|
|
this.extract_aggregates(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-09-18 15:30:35 +00:00
|
|
|
/* extract_aggregates
|
|
|
|
* extract the agggregates from the nodes (TagName="field")
|
|
|
|
*/
|
2011-11-15 13:53:49 +00:00
|
|
|
extract_aggregates: function(node) {
|
|
|
|
for (var j = 0, jj = this.group_operators.length; j < jj; j++) {
|
|
|
|
if (node.attrs[this.group_operators[j]]) {
|
|
|
|
this.aggregates[node.attrs.name] = node.attrs[this.group_operators[j]];
|
|
|
|
break;
|
2011-09-05 14:18:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
transform_qweb_template: function(node) {
|
2012-06-07 13:02:31 +00:00
|
|
|
var qweb_add_if = function(node, condition) {
|
|
|
|
if (node.attrs[QWeb.prefix + '-if']) {
|
|
|
|
condition = _.str.sprintf("(%s) and (%s)", node.attrs[QWeb.prefix + '-if'], condition);
|
|
|
|
}
|
|
|
|
node.attrs[QWeb.prefix + '-if'] = condition;
|
|
|
|
};
|
|
|
|
// Process modifiers
|
|
|
|
if (node.tag && node.attrs.modifiers) {
|
|
|
|
var modifiers = JSON.parse(node.attrs.modifiers || '{}');
|
|
|
|
if (modifiers.invisible) {
|
|
|
|
qweb_add_if(node, _.str.sprintf("!kanban_compute_domain(%s)", JSON.stringify(modifiers.invisible)));
|
|
|
|
}
|
|
|
|
}
|
2011-09-05 14:18:12 +00:00
|
|
|
switch (node.tag) {
|
|
|
|
case 'field':
|
2012-09-18 15:30:35 +00:00
|
|
|
if(this.fields_view.fields[ node.attrs['name'] ].type == 'many2many'){
|
|
|
|
node.tag = 'div';
|
2012-09-19 08:32:01 +00:00
|
|
|
node.attrs['class'] = 'oe_form_field oe_tags';
|
2012-09-18 15:30:35 +00:00
|
|
|
node.attrs['model'] = this.fields_view.fields[node.attrs['name']].relation;
|
|
|
|
node.attrs['t-att-data'] = 'record.' + node.attrs['name'] + '.raw_value';
|
|
|
|
}else {
|
|
|
|
node.tag = QWeb.prefix;
|
|
|
|
node.attrs[QWeb.prefix + '-esc'] = 'record.' + node.attrs['name'] + '.value';
|
|
|
|
}
|
2012-01-25 08:53:10 +00:00
|
|
|
break;
|
2011-09-05 14:18:12 +00:00
|
|
|
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 || '';
|
2012-08-29 11:47:13 +00:00
|
|
|
if (_.indexOf('action,object,edit,open,delete'.split(','), type) !== -1) {
|
2011-09-05 14:18:12 +00:00
|
|
|
_.each(node.attrs, function(v, k) {
|
2011-12-06 17:33:17 +00:00
|
|
|
if (_.indexOf('icon,type,name,args,string,context,states,kanban_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-string']) {
|
|
|
|
node.attrs.title = node.attrs['data-string'];
|
|
|
|
}
|
|
|
|
if (node.attrs['data-icon']) {
|
|
|
|
node.children = [{
|
|
|
|
tag: 'img',
|
|
|
|
attrs: {
|
2012-08-14 15:29:00 +00:00
|
|
|
src: instance.session.prefix + '/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-09-07 19:20:52 +00:00
|
|
|
do_add_record: function() {
|
|
|
|
this.dataset.index = null;
|
|
|
|
this.do_switch_view('form');
|
2011-08-16 07:20:39 +00:00
|
|
|
},
|
2012-08-14 19:53:16 +00:00
|
|
|
do_add_group: function() {
|
|
|
|
var self = this;
|
|
|
|
self.do_action({
|
|
|
|
name: _t("Add column"),
|
2012-08-14 21:37:08 +00:00
|
|
|
res_model: self.group_by_field.relation,
|
2012-08-14 19:53:16 +00:00
|
|
|
views: [[false, 'form']],
|
|
|
|
type: 'ir.actions.act_window',
|
|
|
|
target: "new",
|
|
|
|
flags: {
|
|
|
|
action_buttons: true,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var am = instance.webclient.action_manager;
|
|
|
|
var form = am.dialog_widget.views.form.controller;
|
2012-10-15 13:52:36 +00:00
|
|
|
form.on("on_button_cancel", am.dialog, am.dialog.close);
|
2012-10-10 12:09:17 +00:00
|
|
|
form.on('record_created', self, function(r) {
|
|
|
|
(new instance.web.DataSet(self, self.group_by_field.relation)).name_get([r]).then(function(new_record) {
|
2012-10-15 13:52:36 +00:00
|
|
|
am.dialog.close();
|
2012-08-16 15:21:43 +00:00
|
|
|
var domain = self.dataset.domain.slice(0);
|
|
|
|
domain.push([self.group_by, '=', new_record[0][0]]);
|
|
|
|
var dataset = new instance.web.DataSetSearch(self, self.dataset.model, self.dataset.get_context(), domain);
|
|
|
|
var datagroup = {
|
2012-10-16 13:20:03 +00:00
|
|
|
get: function(key) {
|
|
|
|
return this[key];
|
|
|
|
},
|
2012-08-16 15:21:43 +00:00
|
|
|
value: new_record[0],
|
|
|
|
length: 0,
|
|
|
|
aggregates: {},
|
|
|
|
};
|
|
|
|
var new_group = new instance.web_kanban.KanbanGroup(self, [], datagroup, dataset);
|
|
|
|
self.do_add_groups([new_group]).then(function() {
|
2012-08-24 18:27:07 +00:00
|
|
|
$(window).scrollTo(self.groups.slice(-1)[0].$el, { axis: 'x' });
|
2012-08-16 15:21:43 +00:00
|
|
|
});
|
|
|
|
});
|
2012-08-14 19:53:16 +00:00
|
|
|
});
|
|
|
|
},
|
2011-11-02 17:18:54 +00:00
|
|
|
do_search: function(domain, context, group_by) {
|
2011-10-20 16:30:08 +00:00
|
|
|
var self = this;
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.find('.oe_view_nocontent').remove();
|
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;
|
2012-08-14 21:37:08 +00:00
|
|
|
self.group_by_field = self.fields_view.fields[self.group_by] || {};
|
|
|
|
self.grouped_by_m2o = (self.group_by_field.type === 'many2one');
|
2012-08-14 19:53:16 +00:00
|
|
|
self.$buttons.find('.oe_alternative').toggle(self.grouped_by_m2o);
|
2012-08-24 18:27:07 +00:00
|
|
|
self.$el.toggleClass('oe_kanban_grouped_by_m2o', self.grouped_by_m2o);
|
2012-10-16 13:20:03 +00:00
|
|
|
var grouping = new instance.web.Model(self.dataset.model, context, domain).query().group_by(self.group_by);
|
|
|
|
$.when(grouping).then(function(groups) {
|
|
|
|
if (groups) {
|
|
|
|
self.do_process_groups(groups);
|
|
|
|
} else {
|
|
|
|
self.do_process_dataset();
|
|
|
|
}
|
2012-10-16 13:22:23 +00:00
|
|
|
});
|
2011-10-20 16:30:08 +00:00
|
|
|
});
|
2011-08-08 10:46:32 +00:00
|
|
|
},
|
2011-11-02 17:18:54 +00:00
|
|
|
do_process_groups: function(groups) {
|
2012-04-09 16:42:29 +00:00
|
|
|
var self = this;
|
2012-10-16 12:29:51 +00:00
|
|
|
this.$el.removeClass('oe_kanban_ungrouped').addClass('oe_kanban_grouped');
|
2012-04-09 16:42:29 +00:00
|
|
|
this.add_group_mutex.exec(function() {
|
|
|
|
self.dataset.ids = [];
|
|
|
|
var remaining = groups.length - 1,
|
|
|
|
groups_array = [];
|
2012-05-07 15:25:31 +00:00
|
|
|
return $.when.apply(null, _.map(groups, function (group, index) {
|
2012-08-08 15:17:09 +00:00
|
|
|
var dataset = new instance.web.DataSetSearch(self, self.dataset.model,
|
2012-10-16 13:20:03 +00:00
|
|
|
new instance.web.CompoundContext(self.dataset.get_context(), group.model.context()), group.model.domain());
|
2012-05-07 15:25:31 +00:00
|
|
|
return dataset.read_slice(self.fields_keys.concat(['__last_update']), { 'limit': self.limit })
|
|
|
|
.pipe(function(records) {
|
|
|
|
self.dataset.ids.push.apply(self.dataset.ids, dataset.ids);
|
|
|
|
groups_array[index] = new instance.web_kanban.KanbanGroup(self, records, group, dataset);
|
|
|
|
if (!remaining--) {
|
|
|
|
self.dataset.index = self.dataset.size() ? 0 : null;
|
|
|
|
return self.do_add_groups(groups_array);
|
|
|
|
}
|
2012-04-09 16:42:29 +00:00
|
|
|
});
|
2012-05-07 15:25:31 +00:00
|
|
|
}));
|
2011-09-12 12:59:38 +00:00
|
|
|
});
|
2012-10-16 12:29:51 +00:00
|
|
|
self.do_clear_groups();
|
2011-09-08 15:50:07 +00:00
|
|
|
},
|
2012-10-16 13:20:03 +00:00
|
|
|
do_process_dataset: function() {
|
2011-09-23 08:48:38 +00:00
|
|
|
var self = this;
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.remove('oe_kanban_grouped').addClass('oe_kanban_ungrouped');
|
2012-04-09 16:42:29 +00:00
|
|
|
this.add_group_mutex.exec(function() {
|
|
|
|
var def = $.Deferred();
|
|
|
|
self.dataset.read_slice(self.fields_keys.concat(['__last_update']), { 'limit': self.limit }).then(function(records) {
|
2012-07-11 09:14:31 +00:00
|
|
|
var kgroup = new instance.web_kanban.KanbanGroup(self, records, null, self.dataset);
|
|
|
|
self.do_add_groups([kgroup]).then(function() {
|
|
|
|
if (_.isEmpty(records)) {
|
|
|
|
self.no_result();
|
|
|
|
}
|
|
|
|
def.resolve();
|
|
|
|
});
|
2012-04-09 16:42:29 +00:00
|
|
|
}).then(null, function() {
|
|
|
|
def.reject();
|
|
|
|
});
|
|
|
|
return def;
|
2011-09-23 08:48:38 +00:00
|
|
|
});
|
2012-10-16 12:29:51 +00:00
|
|
|
self.do_clear_groups();
|
2011-09-23 08:48:38 +00:00
|
|
|
},
|
2011-11-04 18:05:12 +00:00
|
|
|
do_reload: function() {
|
|
|
|
this.do_search(this.search_domain, this.search_context, this.search_group_by);
|
2011-08-08 10:46:32 +00:00
|
|
|
},
|
2011-11-04 18:05:12 +00:00
|
|
|
do_clear_groups: function() {
|
2012-10-16 12:29:51 +00:00
|
|
|
var groups = this.groups.slice(0);
|
|
|
|
this.groups = [];
|
|
|
|
_.each(groups, function(group) {
|
2012-02-21 16:29:12 +00:00
|
|
|
group.destroy();
|
2011-08-08 10:46:32 +00:00
|
|
|
});
|
|
|
|
},
|
2011-11-02 17:18:54 +00:00
|
|
|
do_add_groups: function(groups) {
|
2012-05-07 15:25:31 +00:00
|
|
|
var self = this;
|
2012-10-16 12:29:51 +00:00
|
|
|
var $parent = this.$el.parent();
|
|
|
|
this.$el.detach();
|
2011-11-07 10:34:28 +00:00
|
|
|
_.each(groups, function(group) {
|
|
|
|
self.groups[group.undefined_title ? 'unshift' : 'push'](group);
|
|
|
|
});
|
2012-10-16 12:29:51 +00:00
|
|
|
var $last_td = self.$el.find('.oe_kanban_groups_headers td:last');
|
2012-05-07 15:25:31 +00:00
|
|
|
var groups_started = _.map(this.groups, function(group) {
|
2012-08-16 15:21:43 +00:00
|
|
|
if (!group.is_started) {
|
2012-10-16 12:29:51 +00:00
|
|
|
return group.insertBefore($last_td);
|
2012-08-16 15:21:43 +00:00
|
|
|
}
|
2012-05-07 15:25:31 +00:00
|
|
|
});
|
|
|
|
return $.when.apply(null, groups_started).then(function () {
|
|
|
|
self.on_groups_started();
|
2012-10-16 12:29:51 +00:00
|
|
|
self.$el.appendTo($parent);
|
2012-10-16 15:38:40 +00:00
|
|
|
_.each(self.groups, function(group) {
|
|
|
|
group.compute_cards_auto_height();
|
|
|
|
});
|
2011-11-02 17:18:54 +00:00
|
|
|
});
|
2011-08-10 09:46:46 +00:00
|
|
|
},
|
2011-11-03 15:17:46 +00:00
|
|
|
on_groups_started: function() {
|
2011-08-04 13:27:51 +00:00
|
|
|
var self = this;
|
2011-11-03 14:15:15 +00:00
|
|
|
this.compute_groups_width();
|
2011-11-04 18:05:12 +00:00
|
|
|
if (this.group_by) {
|
2012-08-14 19:53:16 +00:00
|
|
|
// Kanban cards drag'n'drop
|
2012-10-16 12:29:51 +00:00
|
|
|
var $columns = this.$el.find('.oe_kanban_column');
|
|
|
|
$columns.sortable({
|
2011-11-04 18:05:12 +00:00
|
|
|
handle : '.oe_kanban_draghandle',
|
|
|
|
start: function(event, ui) {
|
2011-11-07 09:48:59 +00:00
|
|
|
self.currently_dragging.index = ui.item.index();
|
|
|
|
self.currently_dragging.group = ui.item.parents('.oe_kanban_column:first').data('widget');
|
2012-08-28 12:39:06 +00:00
|
|
|
ui.item.find('*').on('click.prevent', function(ev) {
|
|
|
|
return false;
|
|
|
|
});
|
2012-10-01 15:49:16 +00:00
|
|
|
ui.placeholder.height(ui.item.height());
|
|
|
|
},
|
|
|
|
revert: 150,
|
2011-11-04 18:05:12 +00:00
|
|
|
stop: function(event, ui) {
|
2012-08-14 19:53:16 +00:00
|
|
|
var record = ui.item.data('widget');
|
|
|
|
var old_index = self.currently_dragging.index;
|
|
|
|
var new_index = ui.item.index();
|
|
|
|
var old_group = self.currently_dragging.group;
|
|
|
|
var new_group = ui.item.parents('.oe_kanban_column:first').data('widget');
|
2011-11-04 18:05:12 +00:00
|
|
|
if (!(old_group.title === new_group.title && old_group.value === new_group.value && old_index == new_index)) {
|
|
|
|
self.on_record_moved(record, old_group, old_index, new_group, new_index);
|
|
|
|
}
|
2012-08-28 12:39:06 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
// A bit hacky but could not find a better solution for Firefox (problem not present in chrome)
|
|
|
|
// http://stackoverflow.com/questions/274843/preventing-javascript-click-event-with-scriptaculous-drag-and-drop
|
|
|
|
ui.item.find('*').off('click.prevent');
|
|
|
|
}, 0);
|
2011-11-04 18:05:12 +00:00
|
|
|
},
|
|
|
|
scroll: false
|
|
|
|
});
|
2012-10-16 12:29:51 +00:00
|
|
|
// Keep connectWith out of the sortable initialization for performance sake:
|
|
|
|
// http://www.planbox.com/blog/development/coding/jquery-ui-sortable-slow-to-bind.html
|
|
|
|
$columns.sortable({ connectWith: $columns });
|
|
|
|
|
2012-08-14 19:53:16 +00:00
|
|
|
// Kanban groups drag'n'drop
|
|
|
|
var start_index;
|
|
|
|
if (this.grouped_by_m2o) {
|
|
|
|
this.$('.oe_kanban_groups_headers').sortable({
|
2012-08-16 13:43:07 +00:00
|
|
|
items: '.oe_kanban_group_header',
|
2012-08-14 19:53:16 +00:00
|
|
|
helper: 'clone',
|
|
|
|
axis: 'x',
|
|
|
|
opacity: 0.5,
|
|
|
|
scroll: false,
|
|
|
|
start: function(event, ui) {
|
|
|
|
start_index = ui.item.index();
|
2012-08-14 22:23:29 +00:00
|
|
|
self.$('.oe_kanban_record').css({ visibility: 'hidden' });
|
2012-08-14 19:53:16 +00:00
|
|
|
},
|
|
|
|
stop: function(event, ui) {
|
|
|
|
var stop_index = ui.item.index();
|
|
|
|
if (start_index !== stop_index) {
|
|
|
|
var $start_column = $('.oe_kanban_groups_records .oe_kanban_column').eq(start_index);
|
|
|
|
var $stop_column = $('.oe_kanban_groups_records .oe_kanban_column').eq(stop_index);
|
|
|
|
var method = (start_index > stop_index) ? 'insertBefore' : 'insertAfter';
|
|
|
|
$start_column[method]($stop_column);
|
|
|
|
var tmp_group = self.groups.splice(start_index, 1)[0];
|
|
|
|
self.groups.splice(stop_index, 0, tmp_group);
|
|
|
|
var new_sequence = _.pluck(self.groups, 'value');
|
2012-08-14 21:37:08 +00:00
|
|
|
(new instance.web.DataSet(self, self.group_by_field.relation)).resequence(new_sequence).then(function(r) {
|
2012-08-14 22:13:34 +00:00
|
|
|
if (r === false) {
|
|
|
|
console.error("Kanban: could not resequence model '%s'. Probably no 'sequence' field.", self.group_by_field.relation);
|
|
|
|
}
|
2012-08-14 19:53:16 +00:00
|
|
|
});
|
|
|
|
}
|
2012-08-14 22:23:29 +00:00
|
|
|
self.$('.oe_kanban_record').css({ visibility: 'visible' });
|
2012-08-14 19:53:16 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-11-04 18:05:12 +00:00
|
|
|
} else {
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.find('.oe_kanban_draghandle').removeClass('oe_kanban_draghandle');
|
2011-08-08 08:37:48 +00:00
|
|
|
}
|
2012-09-19 09:03:11 +00:00
|
|
|
instance.web_kanban.KanbanView.postprocessing_widget_many2many_tags(self);
|
2011-11-04 18:05:12 +00:00
|
|
|
},
|
|
|
|
on_record_moved : function(record, old_group, old_index, new_group, new_index) {
|
2011-11-28 10:49:43 +00:00
|
|
|
var self = this;
|
2012-02-09 17:59:02 +00:00
|
|
|
$.fn.tipsy.clear();
|
2012-08-24 18:27:07 +00:00
|
|
|
$(old_group.$el).add(new_group.$el).find('.oe_kanban_aggregates, .oe_kanban_group_length').hide();
|
2011-11-04 18:05:12 +00:00
|
|
|
if (old_group === new_group) {
|
|
|
|
new_group.records.splice(old_index, 1);
|
|
|
|
new_group.records.splice(new_index, 0, record);
|
|
|
|
new_group.do_save_sequences();
|
|
|
|
} else {
|
|
|
|
old_group.records.splice(old_index, 1);
|
|
|
|
new_group.records.splice(new_index, 0, record);
|
|
|
|
record.group = new_group;
|
|
|
|
var data = {};
|
|
|
|
data[this.group_by] = new_group.value;
|
2012-10-01 08:56:09 +00:00
|
|
|
this.dataset.write(record.id, data, {}).then(function() {
|
2012-09-16 17:26:12 +00:00
|
|
|
record.do_reload();
|
2011-11-07 10:34:28 +00:00
|
|
|
new_group.do_save_sequences();
|
2011-11-28 10:49:43 +00:00
|
|
|
}).fail(function(error, evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
alert("An error has occured while moving the record to this group.");
|
|
|
|
self.do_reload(); // TODO: use draggable + sortable in order to cancel the dragging when the rcp fails
|
2011-08-11 09:29:52 +00:00
|
|
|
});
|
2011-08-04 13:27:51 +00:00
|
|
|
}
|
2011-11-02 17:18:54 +00:00
|
|
|
},
|
2011-11-03 14:15:15 +00:00
|
|
|
compute_groups_width: function() {
|
|
|
|
var unfolded = 0;
|
2012-07-12 15:26:35 +00:00
|
|
|
var self = this;
|
2011-11-03 14:15:15 +00:00
|
|
|
_.each(this.groups, function(group) {
|
|
|
|
unfolded += group.state.folded ? 0 : 1;
|
2012-08-24 18:27:07 +00:00
|
|
|
group.$el.children(':first').css('width', '');
|
2011-11-03 14:15:15 +00:00
|
|
|
});
|
|
|
|
_.each(this.groups, function(group) {
|
|
|
|
if (!group.state.folded) {
|
2012-08-24 18:27:07 +00:00
|
|
|
if (182*unfolded>=self.$el.width()) {
|
|
|
|
group.$el.children(':first').css('width', "170px");
|
|
|
|
} else if (262*unfolded<self.$el.width()) {
|
|
|
|
group.$el.children(':first').css('width', "250px");
|
2012-07-30 15:00:52 +00:00
|
|
|
} else {
|
2012-08-04 16:45:42 +00:00
|
|
|
// -12 because of padding 6 between cards
|
|
|
|
// -1 because of the border of the latest dummy column
|
2012-08-24 18:27:07 +00:00
|
|
|
group.$el.children(':first').css('width', Math.floor((self.$el.width()-1)/unfolded)-12 + 'px');
|
2012-07-12 15:26:35 +00:00
|
|
|
}
|
2011-08-03 10:26:53 +00:00
|
|
|
}
|
2011-11-03 14:15:15 +00:00
|
|
|
});
|
2012-01-03 16:06:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
do_show: function() {
|
2012-04-10 14:20:51 +00:00
|
|
|
if (this.$buttons) {
|
|
|
|
this.$buttons.show();
|
|
|
|
}
|
2012-01-03 16:06:50 +00:00
|
|
|
this.do_push_state({});
|
|
|
|
return this._super();
|
2012-04-06 12:30:28 +00:00
|
|
|
},
|
2012-04-10 14:20:51 +00:00
|
|
|
do_hide: function () {
|
|
|
|
if (this.$buttons) {
|
|
|
|
this.$buttons.hide();
|
|
|
|
}
|
|
|
|
return this._super();
|
|
|
|
},
|
2012-06-25 15:01:50 +00:00
|
|
|
open_record: function(id, editable) {
|
2012-04-06 12:30:28 +00:00
|
|
|
if (this.dataset.select_id(id)) {
|
2012-08-16 09:38:18 +00:00
|
|
|
this.do_switch_view('form', null, { mode: editable ? "edit" : undefined });
|
2012-04-06 12:30:28 +00:00
|
|
|
} else {
|
|
|
|
this.do_warn("Kanban: could not find id#" + id);
|
|
|
|
}
|
|
|
|
},
|
2012-05-10 09:04:04 +00:00
|
|
|
no_result: function() {
|
|
|
|
if (this.groups.group_by
|
|
|
|
|| !this.options.action
|
|
|
|
|| !this.options.action.help) {
|
|
|
|
return;
|
|
|
|
}
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.find('.oe_view_nocontent').remove();
|
|
|
|
this.$el.prepend(
|
2012-08-04 15:10:59 +00:00
|
|
|
$('<div class="oe_view_nocontent">').html(this.options.action.help)
|
2012-05-10 09:04:04 +00:00
|
|
|
);
|
2012-09-12 10:05:52 +00:00
|
|
|
var create_nocontent = this.$buttons;
|
|
|
|
this.$el.find('.oe_view_nocontent').click(function() {
|
2012-09-14 11:47:47 +00:00
|
|
|
create_nocontent.effect('bounce', {distance: 18, times: 5}, 150);
|
2012-09-12 10:05:52 +00:00
|
|
|
});
|
2012-05-10 09:04:04 +00:00
|
|
|
}
|
2011-11-02 17:18:54 +00:00
|
|
|
});
|
|
|
|
|
2012-09-19 09:03:11 +00:00
|
|
|
/*
|
|
|
|
* widget for list of tags/categories
|
|
|
|
* make the rpc request for all ids/model and insert value inside .oe_tags fields
|
|
|
|
*/
|
|
|
|
instance.web_kanban.KanbanView.postprocessing_widget_many2many_tags = function(self){
|
|
|
|
var model_list_id={};
|
|
|
|
|
|
|
|
// select all widget for the kanban view or the widget inside the record
|
|
|
|
self.$el.find(".oe_form_field.oe_tags").each(function(){
|
|
|
|
var model = $(this).attr("model");
|
|
|
|
if(model.length){
|
|
|
|
var data = $(this).attr("data");
|
|
|
|
var list = data.split(",");
|
|
|
|
|
|
|
|
//select all id (per model)
|
|
|
|
if(!model_list_id[model]) model_list_id[model]=[];
|
|
|
|
for(var t=0;t<list.length;t++) if(list[t]!="") model_list_id[model].push( list[t] );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// rpc and insert
|
|
|
|
for(var model in model_list_id){
|
|
|
|
if(model_list_id[model].length>0){
|
|
|
|
var block = self.$el.find(".oe_form_field.oe_tags[model='" + model + "']");
|
|
|
|
var dataset = new instance.web.DataSetSearch(self, model, self.session.context);
|
|
|
|
dataset.name_get(_.uniq( model_list_id[model] )).then(
|
|
|
|
function(result) {
|
|
|
|
for(var t=0;t<result.length;t++){
|
|
|
|
block.filter(function(){ return this.getAttribute("data").match(new RegExp('(^|,)'+result[t][0]+'(,|$)')); })
|
|
|
|
.append('<span class="oe_tag" data-list_id="' + result[t][0] +'"">'+result[t][1]+'</span>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-25 12:09:47 +00:00
|
|
|
function get_class(name) {
|
|
|
|
return new instance.web.Registry({'tmp' : name}).get_object("tmp");
|
|
|
|
}
|
|
|
|
|
2012-08-14 13:42:46 +00:00
|
|
|
instance.web_kanban.KanbanGroup = instance.web.Widget.extend({
|
2011-11-02 17:18:54 +00:00
|
|
|
template: 'KanbanView.group_header',
|
2012-02-09 17:59:02 +00:00
|
|
|
init: function (parent, records, group, dataset) {
|
2011-11-02 17:18:54 +00:00
|
|
|
var self = this;
|
|
|
|
this._super(parent);
|
2012-02-09 17:59:02 +00:00
|
|
|
this.$has_been_started = $.Deferred();
|
2011-11-02 17:18:54 +00:00
|
|
|
this.view = parent;
|
2012-02-09 17:59:02 +00:00
|
|
|
this.group = group;
|
|
|
|
this.dataset = dataset;
|
|
|
|
this.dataset_offset = 0;
|
|
|
|
this.aggregates = {};
|
|
|
|
this.value = this.title = null;
|
|
|
|
if (this.group) {
|
2012-10-16 13:20:03 +00:00
|
|
|
this.value = group.get('value');
|
|
|
|
this.title = group.get('value');
|
2012-02-22 11:52:28 +00:00
|
|
|
if (this.value instanceof Array) {
|
|
|
|
this.title = this.value[1];
|
|
|
|
this.value = this.value[0];
|
|
|
|
}
|
2012-08-14 21:37:08 +00:00
|
|
|
var field = this.view.group_by_field;
|
2012-08-16 12:02:15 +00:00
|
|
|
if (!_.isEmpty(field)) {
|
2012-02-13 17:20:38 +00:00
|
|
|
try {
|
2012-10-16 13:20:03 +00:00
|
|
|
this.title = instance.web.format_value(group.get('value'), field, false);
|
2012-02-13 17:20:38 +00:00
|
|
|
} catch(e) {}
|
2012-02-09 17:59:02 +00:00
|
|
|
}
|
|
|
|
_.each(this.view.aggregates, function(value, key) {
|
2012-10-16 13:20:03 +00:00
|
|
|
self.aggregates[value] = group.get('aggregates')[key];
|
2012-02-09 17:59:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.title === false) {
|
2011-11-04 18:26:19 +00:00
|
|
|
this.title = _t('Undefined');
|
|
|
|
this.undefined_title = true;
|
2011-08-03 10:26:53 +00:00
|
|
|
}
|
2012-02-09 17:59:02 +00:00
|
|
|
var key = this.view.group_by + '-' + this.value;
|
2011-11-04 21:20:36 +00:00
|
|
|
if (!this.view.state.groups[key]) {
|
|
|
|
this.view.state.groups[key] = {
|
2012-10-16 13:20:03 +00:00
|
|
|
folded: group ? group.get('folded') : false
|
2012-05-22 13:40:49 +00:00
|
|
|
};
|
2011-08-05 08:32:30 +00:00
|
|
|
}
|
2011-11-04 21:20:36 +00:00
|
|
|
this.state = this.view.state.groups[key];
|
2011-11-02 17:18:54 +00:00
|
|
|
this.$records = null;
|
2012-02-09 17:59:02 +00:00
|
|
|
|
|
|
|
this.records = [];
|
|
|
|
this.$has_been_started.then(function() {
|
|
|
|
self.do_add_records(records);
|
2011-11-02 17:18:54 +00:00
|
|
|
});
|
2011-08-05 08:32:30 +00:00
|
|
|
},
|
2011-11-02 17:18:54 +00:00
|
|
|
start: function() {
|
2011-11-03 15:17:46 +00:00
|
|
|
var self = this,
|
|
|
|
def = this._super();
|
2012-05-14 14:42:46 +00:00
|
|
|
if (! self.view.group_by) {
|
2012-08-24 18:27:07 +00:00
|
|
|
self.$el.addClass("oe_kanban_no_group");
|
2012-08-08 15:17:09 +00:00
|
|
|
self.quick = new (get_class(self.view.quick_create_class))(this, self.dataset, {}, false)
|
2012-05-14 14:42:46 +00:00
|
|
|
.on('added', self, self.proxy('quick_created'));
|
|
|
|
self.quick.replace($(".oe_kanban_no_group_qc_placeholder"));
|
|
|
|
}
|
2011-11-02 17:18:54 +00:00
|
|
|
this.$records = $(QWeb.render('KanbanView.group_records_container', { widget : this}));
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$records.insertBefore(this.view.$el.find('.oe_kanban_groups_records td:last'));
|
2012-08-16 10:50:17 +00:00
|
|
|
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.on('click', '.oe_kanban_group_dropdown li a', function(ev) {
|
2012-08-16 10:50:17 +00:00
|
|
|
var fn = 'do_action_' + $(ev.target).data().action;
|
|
|
|
if (typeof(self[fn]) === 'function') {
|
|
|
|
self[fn]($(ev.target));
|
|
|
|
}
|
2011-09-06 12:50:11 +00:00
|
|
|
});
|
2012-08-16 10:50:17 +00:00
|
|
|
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.find('.oe_kanban_add').click(function () {
|
2012-09-19 12:48:59 +00:00
|
|
|
if (self.quick) {
|
|
|
|
return self.quick.trigger('close');
|
|
|
|
}
|
2012-05-11 14:28:31 +00:00
|
|
|
var ctx = {};
|
|
|
|
ctx['default_' + self.view.group_by] = self.value;
|
2012-05-25 12:09:47 +00:00
|
|
|
self.quick = new (get_class(self.view.quick_create_class))(this, self.dataset, ctx, true)
|
2012-05-14 14:42:46 +00:00
|
|
|
.on('added', self, self.proxy('quick_created'))
|
|
|
|
.on('close', self, function() {
|
|
|
|
this.quick.destroy();
|
|
|
|
delete this.quick;
|
|
|
|
});
|
2012-05-31 10:01:09 +00:00
|
|
|
self.quick.appendTo($(".oe_kanban_group_list_header", self.$records));
|
2012-05-11 14:28:31 +00:00
|
|
|
self.quick.focus();
|
2012-04-16 12:33:59 +00:00
|
|
|
});
|
2012-07-26 00:23:18 +00:00
|
|
|
// Add bounce effect on image '+' of kanban header when click on empty space of kanban grouped column.
|
2012-10-16 12:29:51 +00:00
|
|
|
this.$records.on('click', '.oe_kanban_show_more', this.do_show_more);
|
2011-11-03 14:15:15 +00:00
|
|
|
if (this.state.folded) {
|
|
|
|
this.do_toggle_fold();
|
|
|
|
}
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.data('widget', this);
|
2011-11-04 18:05:12 +00:00
|
|
|
this.$records.data('widget', this);
|
2012-02-09 17:59:02 +00:00
|
|
|
this.$has_been_started.resolve();
|
2012-09-04 13:50:45 +00:00
|
|
|
var add_btn = this.$el.find('.oe_kanban_add');
|
|
|
|
add_btn.tipsy({delayIn: 500, delayOut: 1000});
|
2012-08-08 07:38:21 +00:00
|
|
|
this.$records.click(function (ev) {
|
|
|
|
if (ev.target == ev.currentTarget) {
|
|
|
|
if (!self.state.folded) {
|
2012-09-04 13:50:45 +00:00
|
|
|
add_btn.effect('bounce', {distance: 18, times: 5}, 150);
|
2012-08-16 10:50:17 +00:00
|
|
|
}
|
2012-08-08 07:38:21 +00:00
|
|
|
}
|
|
|
|
});
|
2012-08-16 15:21:43 +00:00
|
|
|
this.is_started = true;
|
2011-11-03 15:17:46 +00:00
|
|
|
return def;
|
2011-08-03 10:26:53 +00:00
|
|
|
},
|
2012-05-23 08:53:58 +00:00
|
|
|
compute_cards_auto_height: function() {
|
2012-08-16 17:13:06 +00:00
|
|
|
// oe_kanban_no_auto_height is an empty class used to disable this feature
|
|
|
|
if (!this.view.group_by) {
|
|
|
|
var min_height = 0;
|
|
|
|
var els = [];
|
|
|
|
_.each(this.records, function(r) {
|
2012-08-24 18:27:07 +00:00
|
|
|
var $e = r.$el.children(':first:not(.oe_kanban_no_auto_height)').css('min-height', 0);
|
2012-08-16 17:13:06 +00:00
|
|
|
if ($e.length) {
|
|
|
|
els.push($e[0]);
|
|
|
|
min_height = Math.max(min_height, $e.outerHeight());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$(els).css('min-height', min_height);
|
|
|
|
}
|
2012-05-09 16:21:16 +00:00
|
|
|
},
|
2012-02-21 16:29:12 +00:00
|
|
|
destroy: function() {
|
2011-11-02 17:18:54 +00:00
|
|
|
this._super();
|
2011-11-04 21:20:36 +00:00
|
|
|
if (this.$records) {
|
|
|
|
this.$records.remove();
|
2011-09-07 19:20:52 +00:00
|
|
|
}
|
|
|
|
},
|
2012-02-09 17:59:02 +00:00
|
|
|
do_show_more: function(evt) {
|
|
|
|
var self = this;
|
|
|
|
this.dataset.read_slice(this.view.fields_keys.concat(['__last_update']), {
|
|
|
|
'limit': self.view.limit,
|
|
|
|
'offset': self.dataset_offset += self.view.limit
|
|
|
|
}).then(this.do_add_records);
|
|
|
|
},
|
2012-04-16 12:33:59 +00:00
|
|
|
do_add_records: function(records, prepend) {
|
2012-02-09 17:59:02 +00:00
|
|
|
var self = this;
|
2012-10-16 12:29:51 +00:00
|
|
|
var $list_header = this.$records.find('.oe_kanban_group_list_header');
|
|
|
|
var $show_more = this.$records.find('.oe_kanban_show_more');
|
|
|
|
|
2012-02-09 17:59:02 +00:00
|
|
|
_.each(records, function(record) {
|
2012-04-17 12:48:30 +00:00
|
|
|
var rec = new instance.web_kanban.KanbanRecord(self, record);
|
2012-04-16 12:33:59 +00:00
|
|
|
if (!prepend) {
|
2012-10-16 12:29:51 +00:00
|
|
|
rec.insertBefore($show_more);
|
2012-04-16 12:33:59 +00:00
|
|
|
self.records.push(rec);
|
|
|
|
} else {
|
2012-10-16 12:29:51 +00:00
|
|
|
rec.insertAfter($list_header);
|
2012-04-16 12:33:59 +00:00
|
|
|
self.records.unshift(rec);
|
|
|
|
}
|
2012-02-09 17:59:02 +00:00
|
|
|
});
|
2012-10-16 12:29:51 +00:00
|
|
|
if ($show_more.length) {
|
|
|
|
var size = this.dataset.size();
|
|
|
|
$show_more.toggle(this.records.length < size).find('.oe_kanban_remaining').text(size - this.records.length);
|
|
|
|
}
|
2012-02-09 17:59:02 +00:00
|
|
|
},
|
2011-11-03 10:45:34 +00:00
|
|
|
remove_record: function(id, remove_from_dataset) {
|
2012-06-04 09:14:31 +00:00
|
|
|
for (var i = 0; i < this.records.length; i++) {
|
2011-11-03 10:45:34 +00:00
|
|
|
if (this.records[i]['id'] === id) {
|
2011-11-04 18:05:12 +00:00
|
|
|
this.records.splice(i, 1);
|
2012-06-04 09:14:31 +00:00
|
|
|
i--;
|
2011-11-03 10:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-03 14:15:15 +00:00
|
|
|
},
|
2011-11-03 15:17:46 +00:00
|
|
|
do_toggle_fold: function(compute_width) {
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.add(this.$records).toggleClass('oe_kanban_group_folded');
|
|
|
|
this.state.folded = this.$el.is('.oe_kanban_group_folded');
|
2012-08-16 10:50:17 +00:00
|
|
|
this.$("ul.oe_kanban_group_dropdown li a[data-action=toggle_fold]").text((this.state.folded) ? _t("Unfold") : _t("Fold"));
|
|
|
|
},
|
|
|
|
do_action_toggle_fold: function() {
|
|
|
|
this.do_toggle_fold();
|
|
|
|
this.view.compute_groups_width();
|
2011-11-04 18:05:12 +00:00
|
|
|
},
|
2012-08-16 11:58:35 +00:00
|
|
|
do_action_edit: function() {
|
|
|
|
var self = this;
|
|
|
|
self.do_action({
|
2012-10-16 13:20:03 +00:00
|
|
|
res_id: this.value,
|
2012-08-16 11:58:35 +00:00
|
|
|
name: _t("Edit column"),
|
|
|
|
res_model: self.view.group_by_field.relation,
|
|
|
|
views: [[false, 'form']],
|
|
|
|
type: 'ir.actions.act_window',
|
|
|
|
target: "new",
|
|
|
|
flags: {
|
|
|
|
action_buttons: true,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var am = instance.webclient.action_manager;
|
|
|
|
var form = am.dialog_widget.views.form.controller;
|
2012-10-15 13:52:36 +00:00
|
|
|
form.on("on_button_cancel", am.dialog, am.dialog.close);
|
2012-10-10 13:20:49 +00:00
|
|
|
form.on('record_saved', self, function() {
|
2012-10-15 13:52:36 +00:00
|
|
|
am.dialog.close();
|
2012-08-16 11:58:35 +00:00
|
|
|
self.view.do_reload();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
do_action_delete: function() {
|
|
|
|
var self = this;
|
|
|
|
if (confirm(_t("Are you sure to remove this column ?"))) {
|
2012-10-16 13:20:03 +00:00
|
|
|
(new instance.web.DataSet(self, self.view.group_by_field.relation)).unlink([self.value]).then(function(r) {
|
2012-08-16 11:58:35 +00:00
|
|
|
self.view.do_reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2011-11-04 18:05:12 +00:00
|
|
|
do_save_sequences: function() {
|
|
|
|
var self = this;
|
|
|
|
if (_.indexOf(this.view.fields_keys, 'sequence') > -1) {
|
2012-08-14 22:13:34 +00:00
|
|
|
var new_sequence = _.pluck(this.records, 'id');
|
|
|
|
self.view.dataset.resequence(new_sequence);
|
2011-11-04 18:05:12 +00:00
|
|
|
}
|
2012-04-16 12:33:59 +00:00
|
|
|
},
|
|
|
|
/**
|
2012-08-10 09:45:22 +00:00
|
|
|
* Handles a newly created record
|
2012-04-16 12:33:59 +00:00
|
|
|
*
|
2012-08-10 09:45:22 +00:00
|
|
|
* @param {id} id of the newly created record
|
2012-04-16 12:33:59 +00:00
|
|
|
*/
|
|
|
|
quick_created: function (record) {
|
2012-05-25 13:09:14 +00:00
|
|
|
var id = record, self = this;
|
2012-05-14 15:21:32 +00:00
|
|
|
this.dataset.read_ids([id], this.view.fields_keys)
|
2012-04-16 12:33:59 +00:00
|
|
|
.then(function (records) {
|
2012-04-16 13:08:34 +00:00
|
|
|
self.view.dataset.ids.push(id);
|
2012-05-31 10:01:09 +00:00
|
|
|
self.do_add_records(records, true);
|
2012-04-16 12:33:59 +00:00
|
|
|
});
|
2011-11-02 17:18:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-14 13:42:46 +00:00
|
|
|
instance.web_kanban.KanbanRecord = instance.web.Widget.extend({
|
2011-11-02 17:18:54 +00:00
|
|
|
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-04 21:20:36 +00:00
|
|
|
if (!this.view.state.records[this.id]) {
|
|
|
|
this.view.state.records[this.id] = {
|
2011-11-03 11:08:11 +00:00
|
|
|
folded: false
|
|
|
|
};
|
|
|
|
}
|
2011-11-04 21:20:36 +00:00
|
|
|
this.state = this.view.state.records[this.id];
|
2011-11-03 10:45:34 +00:00
|
|
|
},
|
|
|
|
set_record: function(record) {
|
2012-06-07 13:02:31 +00:00
|
|
|
var self = this;
|
2011-11-03 10:45:34 +00:00
|
|
|
this.id = record.id;
|
2012-06-07 13:02:31 +00:00
|
|
|
this.values = {};
|
|
|
|
_.each(record, function(v, k) {
|
|
|
|
self.values[k] = {
|
|
|
|
value: v
|
|
|
|
};
|
|
|
|
});
|
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();
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.data('widget', this);
|
2011-11-03 10:45:34 +00:00
|
|
|
this.bind_events();
|
|
|
|
},
|
2011-11-02 17:18:54 +00:00
|
|
|
transform_record: function(record) {
|
2011-09-01 20:24:39 +00:00
|
|
|
var self = this,
|
|
|
|
new_record = {};
|
|
|
|
_.each(record, function(value, name) {
|
2011-11-15 12:30:59 +00:00
|
|
|
var r = _.clone(self.view.fields_view.fields[name] || {});
|
2011-11-30 08:27:49 +00:00
|
|
|
if ((r.type === 'date' || r.type === 'datetime') && value) {
|
2012-04-17 12:48:30 +00:00
|
|
|
r.raw_value = instance.web.auto_str_to_date(value);
|
2011-11-30 08:27:49 +00:00
|
|
|
} else {
|
|
|
|
r.raw_value = value;
|
|
|
|
}
|
2012-04-17 12:48:30 +00:00
|
|
|
r.value = instance.web.format_value(value, r);
|
2011-09-01 20:24:39 +00:00
|
|
|
new_record[name] = r;
|
|
|
|
});
|
|
|
|
return new_record;
|
|
|
|
},
|
2012-08-14 13:53:24 +00:00
|
|
|
renderElement: function() {
|
2011-11-28 15:00:03 +00:00
|
|
|
this.qweb_context = {
|
2011-11-02 17:18:54 +00:00
|
|
|
record: this.record,
|
2012-06-04 09:31:03 +00:00
|
|
|
widget: this,
|
|
|
|
read_only_mode: this.view.options.read_only_mode,
|
2012-01-25 08:53:10 +00:00
|
|
|
};
|
2011-11-02 17:18:54 +00:00
|
|
|
for (var p in this) {
|
2011-11-15 12:30:59 +00:00
|
|
|
if (_.str.startsWith(p, 'kanban_')) {
|
2011-11-28 15:00:03 +00:00
|
|
|
this.qweb_context[p] = _.bind(this[p], this);
|
2011-08-19 09:54:48 +00:00
|
|
|
}
|
2011-11-02 17:18:54 +00:00
|
|
|
}
|
2012-08-14 13:53:24 +00:00
|
|
|
var $el = instance.web.qweb.render(this.template, {
|
|
|
|
'widget': this,
|
2011-11-28 15:00:03 +00:00
|
|
|
'content': this.view.qweb.render('kanban-box', this.qweb_context)
|
2011-11-02 17:18:54 +00:00
|
|
|
});
|
2012-08-14 13:53:24 +00:00
|
|
|
this.replaceElement($el);
|
2011-08-19 09:54:48 +00:00
|
|
|
},
|
2011-11-03 10:45:34 +00:00
|
|
|
bind_events: function() {
|
2012-05-22 13:40:49 +00:00
|
|
|
var self = this;
|
2012-05-23 13:01:16 +00:00
|
|
|
this.setup_color_picker();
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.find('[tooltip]').tipsy({
|
2012-01-26 13:24:41 +00:00
|
|
|
delayIn: 500,
|
|
|
|
delayOut: 0,
|
|
|
|
fade: true,
|
|
|
|
title: function() {
|
2011-11-28 15:00:03 +00:00
|
|
|
var template = $(this).attr('tooltip');
|
|
|
|
if (!self.view.qweb.has_template(template)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return self.view.qweb.render(template, self.qweb_context);
|
2012-01-26 13:24:41 +00:00
|
|
|
},
|
|
|
|
gravity: 's',
|
|
|
|
html: true,
|
|
|
|
opacity: 0.8,
|
|
|
|
trigger: 'hover'
|
2011-11-28 15:00:03 +00:00
|
|
|
});
|
|
|
|
|
2012-09-05 09:05:44 +00:00
|
|
|
// If no draghandle is found, make the whole card as draghandle (provided one can edit)
|
2012-08-24 18:27:07 +00:00
|
|
|
if (!this.$el.find('.oe_kanban_draghandle').length) {
|
2012-09-05 09:05:44 +00:00
|
|
|
this.$el.children(':first')
|
|
|
|
.toggleClass('oe_kanban_draghandle', this.view.is_action_enabled('edit'));
|
2012-05-22 14:32:35 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 11:10:57 +00:00
|
|
|
this.$el.find('.oe_kanban_action').click(function(ev) {
|
|
|
|
ev.preventDefault();
|
2011-11-03 10:45:34 +00:00
|
|
|
var $action = $(this),
|
|
|
|
type = $action.data('type') || 'button',
|
2011-11-28 11:51:36 +00:00
|
|
|
method = 'do_action_' + (type === 'action' ? 'object' : type);
|
2012-09-04 14:11:55 +00:00
|
|
|
if ((type === 'edit' || type === 'delete') && ! self.view.is_action_enabled(type)) {
|
2012-08-20 12:20:20 +00:00
|
|
|
self.view.open_record(self.id);
|
|
|
|
} else if (_.str.startsWith(type, 'switch_')) {
|
2011-12-08 12:25:35 +00:00
|
|
|
self.view.do_switch_view(type.substr(7));
|
|
|
|
} else if (typeof self[method] === 'function') {
|
2011-11-03 10:45:34 +00:00
|
|
|
self[method]($action);
|
2011-11-03 11:19:15 +00:00
|
|
|
} else {
|
|
|
|
self.do_warn("Kanban: no action for type : " + type);
|
2011-08-01 10:15:28 +00:00
|
|
|
}
|
2011-11-03 10:45:34 +00:00
|
|
|
});
|
2012-05-24 15:58:37 +00:00
|
|
|
|
2012-09-18 17:19:47 +00:00
|
|
|
if (this.$el.find('.oe_kanban_global_click,.oe_kanban_global_click_edit').length) {
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.on('click', function(ev) {
|
2012-06-20 14:59:02 +00:00
|
|
|
if (!ev.isTrigger && !$(ev.target).data('events')) {
|
2012-06-25 15:01:50 +00:00
|
|
|
var trigger = true;
|
|
|
|
var elem = ev.target;
|
|
|
|
var ischild = true;
|
|
|
|
var children = [];
|
|
|
|
while (elem) {
|
|
|
|
var events = $(elem).data('events');
|
|
|
|
if (elem == ev.currentTarget) {
|
|
|
|
ischild = false;
|
|
|
|
}
|
|
|
|
if (ischild) {
|
|
|
|
children.push(elem);
|
|
|
|
if (events && events.click) {
|
|
|
|
// do not trigger global click if one child has a click event registered
|
|
|
|
trigger = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (trigger && events && events.click) {
|
|
|
|
_.each(events.click, function(click_event) {
|
|
|
|
if (click_event.selector) {
|
|
|
|
// For each parent of original target, check if a
|
|
|
|
// delegated click is bound to any previously found children
|
|
|
|
_.each(children, function(child) {
|
|
|
|
if ($(child).is(click_event.selector)) {
|
|
|
|
trigger = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
elem = elem.parentElement;
|
|
|
|
}
|
|
|
|
if (trigger) {
|
|
|
|
self.on_card_clicked(ev);
|
|
|
|
}
|
2012-06-20 14:59:02 +00:00
|
|
|
}
|
|
|
|
});
|
2012-06-07 08:54:51 +00:00
|
|
|
}
|
2012-05-24 15:58:37 +00:00
|
|
|
},
|
2012-09-18 17:19:47 +00:00
|
|
|
/* actions when user click on the block with a specific class
|
|
|
|
* open on normal view : oe_kanban_global_click
|
|
|
|
* open on form/edit view : oe_kanban_global_click_edit
|
|
|
|
*/
|
2012-06-20 14:59:02 +00:00
|
|
|
on_card_clicked: function(ev) {
|
2012-09-18 17:19:47 +00:00
|
|
|
if(this.$el.find('.oe_kanban_global_click_edit').size()>0)
|
|
|
|
this.do_action_edit();
|
|
|
|
else
|
2012-09-19 06:44:31 +00:00
|
|
|
this.do_action_open();
|
2011-11-03 10:45:34 +00:00
|
|
|
},
|
2012-05-23 13:01:16 +00:00
|
|
|
setup_color_picker: function() {
|
|
|
|
var self = this;
|
2012-08-24 18:27:07 +00:00
|
|
|
var $el = this.$el.find('ul.oe_kanban_colorpicker');
|
2012-05-23 13:01:16 +00:00
|
|
|
if ($el.length) {
|
|
|
|
$el.html(QWeb.render('KanbanColorPicker', {
|
|
|
|
widget: this
|
|
|
|
}));
|
2012-06-20 14:59:02 +00:00
|
|
|
$el.on('click', 'a', function(ev) {
|
|
|
|
ev.preventDefault();
|
2012-05-23 13:01:16 +00:00
|
|
|
var color_field = $(this).parents('.oe_kanban_colorpicker').first().data('field') || 'color';
|
|
|
|
var data = {};
|
|
|
|
data[color_field] = $(this).data('color');
|
2012-10-01 08:56:09 +00:00
|
|
|
self.view.dataset.write(self.id, data, {}).then(function() {
|
2012-05-23 13:01:16 +00:00
|
|
|
self.record[color_field] = $(this).data('color');
|
|
|
|
self.do_reload();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2011-11-03 10:45:34 +00:00
|
|
|
do_action_delete: function($action) {
|
|
|
|
var self = this;
|
2012-06-04 09:31:03 +00:00
|
|
|
function do_it() {
|
|
|
|
return $.when(self.view.dataset.unlink([self.id])).then(function() {
|
2012-01-25 08:53:10 +00:00
|
|
|
self.group.remove_record(self.id);
|
2012-02-21 16:29:12 +00:00
|
|
|
self.destroy();
|
2011-09-20 06:57:38 +00:00
|
|
|
});
|
2012-06-06 08:19:15 +00:00
|
|
|
}
|
2012-06-04 09:31:03 +00:00
|
|
|
if (this.view.options.confirm_on_delete) {
|
|
|
|
if (confirm(_t("Are you sure you want to delete this record ?"))) {
|
|
|
|
return do_it();
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
return do_it();
|
2011-11-03 10:45:34 +00:00
|
|
|
},
|
|
|
|
do_action_edit: function($action) {
|
2012-08-02 10:15:40 +00:00
|
|
|
this.view.open_record(this.id, true);
|
2011-11-03 10:45:34 +00:00
|
|
|
},
|
2012-08-29 11:47:13 +00:00
|
|
|
do_action_open: function($action) {
|
|
|
|
this.view.open_record(this.id);
|
|
|
|
},
|
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-07-29 09:04:30 +00:00
|
|
|
},
|
2011-11-03 10:45:34 +00:00
|
|
|
do_reload: function() {
|
|
|
|
var self = this;
|
2012-01-17 20:26:07 +00:00
|
|
|
this.view.dataset.read_ids([this.id], this.view.fields_keys.concat(['__last_update'])).then(function(records) {
|
2011-11-03 10:45:34 +00:00
|
|
|
if (records.length) {
|
|
|
|
self.set_record(records[0]);
|
2012-08-16 15:21:43 +00:00
|
|
|
self.renderElement();
|
2012-08-24 18:27:07 +00:00
|
|
|
self.$el.data('widget', self);
|
2012-05-23 13:01:16 +00:00
|
|
|
self.bind_events();
|
|
|
|
self.group.compute_cards_auto_height();
|
2012-09-19 09:03:11 +00:00
|
|
|
instance.web_kanban.KanbanView.postprocessing_widget_many2many_tags(self);
|
2011-11-03 10:45:34 +00:00
|
|
|
} else {
|
2012-02-21 16:29:12 +00:00
|
|
|
self.destroy();
|
2011-11-03 10:45:34 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-05-23 13:01:16 +00:00
|
|
|
kanban_getcolor: function(variable) {
|
|
|
|
var index = 0;
|
2011-11-02 17:18:54 +00:00
|
|
|
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 '';
|
|
|
|
}
|
2012-05-23 13:01:16 +00:00
|
|
|
var color = (index % this.view.number_of_color_schemes);
|
|
|
|
return color;
|
|
|
|
},
|
|
|
|
kanban_color: function(variable) {
|
2012-05-23 13:31:52 +00:00
|
|
|
var color = this.kanban_getcolor(variable);
|
|
|
|
return color === '' ? '' : 'oe_kanban_color_' + color;
|
2011-11-02 17:18:54 +00:00
|
|
|
},
|
|
|
|
kanban_gravatar: function(email, size) {
|
|
|
|
size = size || 22;
|
2011-11-15 14:01:06 +00:00
|
|
|
email = _.str.trim(email || '').toLowerCase();
|
|
|
|
var default_ = _.str.isBlank(email) ? 'mm' : 'identicon';
|
2011-11-02 17:18:54 +00:00
|
|
|
var email_md5 = $.md5(email);
|
2011-11-15 14:01:06 +00:00
|
|
|
return 'http://www.gravatar.com/avatar/' + email_md5 + '.png?s=' + size + '&d=' + default_;
|
2011-11-02 17:18:54 +00:00
|
|
|
},
|
2012-08-21 16:15:17 +00:00
|
|
|
kanban_image: function(model, field, id, cache, options) {
|
|
|
|
options = options || {};
|
2012-08-08 09:15:32 +00:00
|
|
|
var url;
|
2012-07-11 12:47:31 +00:00
|
|
|
if (this.record[field] && this.record[field].value && ! /^\d+(\.\d*)? \w+$/.test(this.record[field].value)) {
|
2012-06-22 06:14:47 +00:00
|
|
|
url = 'data:image/png;base64,' + this.record[field].value;
|
2012-08-08 09:15:32 +00:00
|
|
|
} else if (this.record[field] && ! this.record[field].value) {
|
|
|
|
url = "/web/static/src/img/placeholder.png";
|
|
|
|
} else {
|
2012-08-09 12:54:19 +00:00
|
|
|
id = escape(JSON.stringify(id));
|
2012-08-21 16:15:17 +00:00
|
|
|
if (options.preview_image)
|
|
|
|
field = options.preview_image;
|
2012-08-14 15:29:00 +00:00
|
|
|
url = instance.session.prefix + '/web/binary/image?session_id=' + this.session.session_id + '&model=' + model + '&field=' + field + '&id=' + id;
|
2012-08-08 09:15:32 +00:00
|
|
|
if (cache !== undefined) {
|
|
|
|
// Set the cache duration in seconds.
|
|
|
|
url += '&cache=' + parseInt(cache, 10);
|
|
|
|
}
|
2012-06-22 06:14:47 +00:00
|
|
|
}
|
2012-01-17 13:45:41 +00:00
|
|
|
return url;
|
2011-11-02 17:18:54 +00:00
|
|
|
},
|
|
|
|
kanban_text_ellipsis: function(s, size) {
|
|
|
|
size = size || 160;
|
|
|
|
if (!s) {
|
|
|
|
return '';
|
2011-12-07 10:29:00 +00:00
|
|
|
} else if (s.length <= size) {
|
|
|
|
return s;
|
|
|
|
} else {
|
|
|
|
return s.substr(0, size) + '...';
|
2011-11-02 17:18:54 +00:00
|
|
|
}
|
2012-06-07 13:02:31 +00:00
|
|
|
},
|
|
|
|
kanban_compute_domain: function(domain) {
|
|
|
|
return instance.web.form.compute_domain(domain, this.values);
|
2011-09-05 14:47:58 +00:00
|
|
|
}
|
2011-07-28 09:51:52 +00:00
|
|
|
});
|
2012-04-16 12:33:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Quick creation view.
|
|
|
|
*
|
|
|
|
* Triggers a single event "added" with a single parameter "name", which is the
|
|
|
|
* name entered by the user
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @type {*}
|
|
|
|
*/
|
2012-05-11 10:25:02 +00:00
|
|
|
instance.web_kanban.QuickCreate = instance.web.Widget.extend({
|
2012-04-16 12:33:59 +00:00
|
|
|
template: 'KanbanView.quick_create',
|
2012-05-11 14:28:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* close_btn: If true, the widget will display a "Close" button able to trigger
|
|
|
|
* a "close" event.
|
|
|
|
*/
|
2012-05-14 14:42:46 +00:00
|
|
|
init: function(parent, dataset, context, buttons) {
|
2012-05-11 14:28:31 +00:00
|
|
|
this._super(parent);
|
|
|
|
this._dataset = dataset;
|
2012-05-14 14:42:46 +00:00
|
|
|
this._buttons = buttons || false;
|
2012-05-11 14:28:31 +00:00
|
|
|
this._context = context || {};
|
|
|
|
},
|
2012-04-16 12:33:59 +00:00
|
|
|
start: function () {
|
|
|
|
var self = this;
|
2012-08-24 18:27:07 +00:00
|
|
|
self.$input = this.$el.find('input');
|
2012-05-14 14:42:46 +00:00
|
|
|
self.$input.keyup(function(event){
|
|
|
|
if(event.keyCode == 13){
|
|
|
|
self.quick_add();
|
|
|
|
}
|
|
|
|
});
|
2012-08-24 18:27:07 +00:00
|
|
|
$(".oe_kanban_quick_create_add", this.$el).click(function () {
|
2012-05-14 14:42:46 +00:00
|
|
|
self.quick_add();
|
2012-04-16 12:33:59 +00:00
|
|
|
});
|
2012-09-19 13:02:39 +00:00
|
|
|
$(".oe_kanban_quick_create_close", this.$el).click(function (ev) {
|
|
|
|
ev.preventDefault();
|
2012-05-11 14:28:31 +00:00
|
|
|
self.trigger('close');
|
|
|
|
});
|
2012-05-31 10:05:03 +00:00
|
|
|
self.$input.keyup(function(e) {
|
|
|
|
if (e.keyCode == 27 && self._buttons) {
|
|
|
|
self.trigger('close');
|
|
|
|
}
|
|
|
|
});
|
2012-05-11 14:28:31 +00:00
|
|
|
},
|
|
|
|
focus: function() {
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.find('input').focus();
|
2012-05-11 14:28:31 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Handles user event from nested quick creation view
|
|
|
|
*/
|
2012-05-14 14:42:46 +00:00
|
|
|
quick_add: function () {
|
2012-05-11 14:28:31 +00:00
|
|
|
var self = this;
|
|
|
|
this._dataset.call(
|
2012-09-19 13:02:39 +00:00
|
|
|
'name_create', [self.$input.val() || false, new instance.web.CompoundContext(
|
2012-05-11 14:28:31 +00:00
|
|
|
this._dataset.get_context(), this._context)])
|
2012-05-14 15:51:44 +00:00
|
|
|
.pipe(function(record) {
|
2012-05-14 16:08:26 +00:00
|
|
|
self.$input.val("");
|
2012-05-25 13:09:14 +00:00
|
|
|
self.trigger('added', record[0]);
|
2012-05-14 16:33:23 +00:00
|
|
|
}, function(error, event) {
|
|
|
|
event.preventDefault();
|
2012-05-14 15:51:44 +00:00
|
|
|
return self.slow_create();
|
2012-05-11 14:28:31 +00:00
|
|
|
});
|
|
|
|
},
|
2012-05-14 15:51:44 +00:00
|
|
|
slow_create: function() {
|
|
|
|
var self = this;
|
|
|
|
var pop = new instance.web.form.SelectCreatePopup(this);
|
|
|
|
pop.select_element(
|
2012-05-14 16:33:23 +00:00
|
|
|
self._dataset.model,
|
2012-05-14 15:51:44 +00:00
|
|
|
{
|
|
|
|
title: _t("Create: ") + (this.string || this.name),
|
|
|
|
initial_view: "form",
|
|
|
|
disable_multiple_selection: true
|
|
|
|
},
|
2012-05-14 16:33:23 +00:00
|
|
|
[],
|
|
|
|
{"default_name": self.$input.val()}
|
2012-05-14 15:51:44 +00:00
|
|
|
);
|
2012-10-12 13:10:44 +00:00
|
|
|
pop.on("elements_selected", self, function(element_ids) {
|
2012-05-14 16:08:26 +00:00
|
|
|
self.$input.val("");
|
2012-05-25 13:09:14 +00:00
|
|
|
self.trigger('added', element_ids[0]);
|
2012-05-14 15:51:44 +00:00
|
|
|
});
|
|
|
|
}
|
2012-04-16 12:33:59 +00:00
|
|
|
});
|
2011-07-28 09:51:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|