[ADD] web_kanban: on_create attribute

Possibility to specify the action to execute when the user clicks on 'Create'
in the kanban view.

If set to magic 'quick_create', it opens the quick create in the first column.
This commit is contained in:
Adrien Dieudonne
2016-06-16 14:59:39 +02:00
committed by Aaron Bohy
parent 939ebba682
commit ef83d19b6c
+18 -2
View File
@@ -70,6 +70,7 @@ var KanbanView = View.extend({
this.grouped = undefined;
this.group_by_field = undefined;
this.default_group_by = this.fields_view.arch.attrs.default_group_by;
this.on_create = this.fields_view.arch.attrs.on_create;
this.grouped_by_m2o = undefined;
this.relation = undefined;
this.is_empty = undefined;
@@ -157,7 +158,8 @@ var KanbanView = View.extend({
},
do_reload: function() {
this.do_search(this.search_domain, this.search_context, [this.group_by_field]);
var group_by = this.group_by_field ? [this.group_by_field] : [];
this.do_search(this.search_domain, this.search_context, group_by);
},
load_records: function (offset, dataset) {
@@ -319,9 +321,23 @@ var KanbanView = View.extend({
* $node may be undefined, in which case the ListView inserts them into this.options.$buttons
*/
render_buttons: function($node) {
var self = this;
if (this.options.action_buttons !== false && this.is_action_enabled('create')) {
this.$buttons = $(QWeb.render("KanbanView.buttons", {'widget': this}));
this.$buttons.on('click', 'button.o-kanban-button-new', this.add_record.bind(this));
this.$buttons.on('click', 'button.o-kanban-button-new', function () {
if (self.grouped && self.widgets.length && self.on_create === 'quick_create') {
// Activate the quick create in the first column
self.widgets[0].add_quick_create();
} else if (self.on_create) {
// Execute the given action
self.do_action(self.on_create, {
on_close: self.do_reload.bind(self),
});
} else {
// Open the form view
self.add_record();
}
});
// Set 'Create' button as btn-default if there is no column
if (this.grouped && this.widgets.length === 0) {