1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
odoo.define('web.kanban_column_quick_create', function (require) {
"use strict";
/**
* This file defines the ColumnQuickCreate widget for Kanban. It allows to
* create kanban columns directly from the Kanban view.
*/
var core = require('web.core');
var Dialog = require('web.Dialog');
var Widget = require('web.Widget');
var _t = core._t;
var QWeb = core.qweb;
var ColumnQuickCreate = Widget.extend({
template: 'KanbanView.ColumnQuickCreate',
events: {
'click .o_quick_create_folded': '_onUnfold',
'click .o_kanban_add': '_onAddClicked',
'click .o_kanban_examples': '_onShowExamples',
'keydown': '_onKeydown',
'keypress input': '_onKeypress',
'blur input': '_onInputBlur',
'focus input': '_onInputFocus',
},
/**
* @override
* @param {Object} [options]
* @param {Object} [options.examples]
*/
init: function (parent, options) {
this._super.apply(this, arguments);
this.applyExamplesText = options.applyExampleText || _t("Use This For My Kanban");
this.examples = options.examples;
this.folded = true;
this.isMobile = false;
},
/**
* @override
*/
start: function () {
this.$quickCreateFolded = this.$('.o_quick_create_folded');
this.$quickCreateUnfolded = this.$('.o_quick_create_unfolded');
this.$input = this.$('input');
// destroy the quick create when the user clicks outside
core.bus.on('click', this, this._onWindowClicked);
this._update();
return this._super.apply(this, arguments);
},
/**
* Called each time the quick create is attached into the DOM
*/
on_attach_callback: function () {
if (!this.folded) {
this.$input.focus();
}
},
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
/**
* Folds/unfolds the Column quick create widget
*/
toggleFold: function () {
this.folded = !this.folded;
this._update();
if (!this.folded) {
this.$input.focus();
this.trigger_up('scrollTo', {selector: '.o_column_quick_create'});
}
},
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* Clears the input value and notify the environment to create a column
*
* @private
*/
_add: function () {
var value = this.$input.val().trim();
if (!value.length) {
this._cancel();
return;
}
this.$input.val('');
this.trigger_up('quick_create_add_column', {value: value});
this.$input.focus();
},
/**
* Cancels the quick creation
*
* @private
*/
_cancel: function () {
if (!this.folded) {
this.$input.val('');
this.folded = true;
this._update();
}
},
/**
* Updates the rendering according to the current state (folded/unfolded)
*
* @private
*/
_update: function () {
this.$quickCreateFolded.toggle(this.folded);
this.$quickCreateUnfolded.toggle(!this.folded);
this.trigger_up('quick_create_column_updated');
},
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
/**
* @private
* @param {MouseEvent} event
*/
_onAddClicked: function (event) {
event.stopPropagation();
this._add();
},
/**
* When the input is not focused, no key event may occur in the column, so
* the discard feature will not work by pressing ESC. We simply hide the
* help message in that case, so we do not mislead our users.
*
* @private
* @param {KeyboardEvent} event
*/
_onInputBlur: function () {
this.$('.o_discard_msg').hide();
},
/**
* When the input is focused, we need to show the discard help message (it
* might have been hidden, @see _onInputBlur)
*
* @private
* @param {KeyboardEvent} event
*/
_onInputFocus: function () {
this.$('.o_discard_msg').show();
},
/**
* Cancels quick creation on escape keydown event
*
* @private
* @param {KeyEvent} event
*/
_onKeydown: function (event) {
if (event.keyCode === $.ui.keyCode.ESCAPE) {
this._cancel();
}
},
/**
* Validates quick creation on enter keypress event
*
* @private
* @param {KeyEvent} event
*/
_onKeypress: function (event) {
if (event.keyCode === $.ui.keyCode.ENTER) {
this._add();
}
},
/**
* Opens a dialog containing examples of Kanban processes
*
* @private
*/
_onShowExamples: function () {
var self = this;
var dialog = new Dialog(this, {
$content: $(QWeb.render('KanbanView.ExamplesDialog', {
examples: this.examples,
})),
buttons: [{
classes: 'btn-primary float-right',
text: this.applyExamplesText,
close: true,
click: function () {
const activeExample = self.examples[this.$('.nav-link.active').data("exampleIndex")];
activeExample.columns.forEach(column => {
self.trigger_up('quick_create_add_column', { value: column.toString(), foldQuickCreate: true });
});
}
}, {
classes: 'btn-secondary float-right',
close: true,
text: _t('Close'),
}],
size: "large",
title: "Kanban Examples",
}).open();
dialog.on('closed', this, function () {
self.$input.focus();
});
},
/**
* @private
*/
_onUnfold: function () {
if (this.folded) {
this.toggleFold();
}
},
/**
* When a click happens outside the quick create, we want to close it.
*
* @private
* @param {MouseEvent} event
*/
_onWindowClicked: function (event) {
// ignore clicks if the quick create is not in the dom
if (!document.contains(this.el)) {
return;
}
// ignore clicks in modals
if ($(event.target).closest('.modal').length) {
return;
}
// ignore clicks if target is inside the quick create
if (this.el.contains(event.target)) {
return;
}
this._cancel();
},
});
return ColumnQuickCreate;
});
|