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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
// Common functions
var Kanboard = (function() {
return {
// Display a popup
Popover: function(e, callback) {
e.preventDefault();
e.stopPropagation();
$.get(e.target.getAttribute("href"), function(content) {
$("body").append('<div id="popover-container"><div id="popover-content">' + content + '</div></div>');
$("#popover-container").click(function() {
$(this).remove();
});
$("#popover-content").click(function(e) {
e.stopPropagation();
});
if (callback) {
callback();
}
});
},
// Return true if the page is visible
IsVisible: function() {
var property = "";
if (typeof document.hidden !== "undefined") {
property = "visibilityState";
} else if (typeof document.mozHidden !== "undefined") {
property = "mozVisibilityState";
} else if (typeof document.msHidden !== "undefined") {
property = "msVisibilityState";
} else if (typeof document.webkitHidden !== "undefined") {
property = "webkitVisibilityState";
}
if (property != "") {
return document[property] == "visible";
}
return true;
},
// Common init
Before: function() {
// Datepicker
$(".form-date").datepicker({
showOtherMonths: true,
selectOtherMonths: true,
dateFormat: 'yy-mm-dd'
});
}
};
})();
// Board related functions
Kanboard.Board = (function() {
var checkInterval = null;
// Setup the board
function board_load_events()
{
// Drag and drop
$(".column").sortable({
connectWith: ".column",
placeholder: "draggable-placeholder",
stop: function(event, ui) {
board_save(ui.item.attr('data-task-id'));
}
});
// Assignee change
$(".assignee-popover").click(Kanboard.Popover);
// Task edit popover
$(".task-edit-popover").click(function(e) {
Kanboard.Popover(e, Kanboard.Task.Init);
});
// Redirect to the task details page
$("[data-task-id]").each(function() {
$(this).click(function() {
window.location = "?controller=task&action=show&task_id=" + $(this).attr("data-task-id");
});
});
// Automatic refresh
var interval = parseInt($("#board").attr("data-check-interval"));
if (interval > 0) {
checkInterval = window.setInterval(board_check, interval * 1000);
}
}
// Stop events
function board_unload_events()
{
$("[data-task-id]").off();
clearInterval(checkInterval);
}
// Save and refresh the board
function board_save(selected_task_id)
{
var data = [];
var boardSelector = $("#board");
var projectId = boardSelector.attr("data-project-id");
board_unload_events();
$(".column").each(function() {
var columnId = $(this).attr("data-column-id");
$("#column-" + columnId + " .task-board").each(function(index) {
data.push({
"task_id": parseInt($(this).attr("data-task-id")),
"position": index + 1,
"column_id": parseInt(columnId)
});
});
});
$.ajax({
cache: false,
url: "?controller=board&action=save&project_id=" + projectId,
data: {"positions": data, "csrf_token": boardSelector.attr("data-csrf-token"), "selected_task_id": selected_task_id},
type: "POST",
success: function(data) {
$("#board").remove();
$("#main").append(data);
board_load_events();
filter_apply();
}
});
}
// Check if a board have been changed by someone else
function board_check()
{
var boardSelector = $("#board");
var projectId = boardSelector.attr("data-project-id");
var timestamp = boardSelector.attr("data-time");
if (Kanboard.IsVisible() && projectId != undefined && timestamp != undefined) {
$.ajax({
cache: false,
url: "?controller=board&action=check&project_id=" + projectId + "×tamp=" + timestamp,
statusCode: {
200: function(data) {
boardSelector.remove();
$("#main").append(data);
board_unload_events();
board_load_events();
filter_apply();
}
}
});
}
}
// Apply user or date filter (change tasks opacity)
function filter_apply()
{
var selectedUserId = $("#form-user_id").val();
var selectedCategoryId = $("#form-category_id").val();
var filterDueDate = $("#filter-due-date").hasClass("filter-on");
$("[data-task-id]").each(function(index, item) {
var ownerId = item.getAttribute("data-owner-id");
var dueDate = item.getAttribute("data-due-date");
var categoryId = item.getAttribute("data-category-id");
if (ownerId != selectedUserId && selectedUserId != -1) {
item.style.opacity = "0.2";
}
else {
item.style.opacity = "1.0";
}
if (filterDueDate && (dueDate == "" || dueDate == "0")) {
item.style.opacity = "0.2";
}
if (categoryId != selectedCategoryId && selectedCategoryId != -1) {
item.style.opacity = "0.2";
}
});
}
// Load filter events
function filter_load_events()
{
$("#form-user_id").change(filter_apply);
$("#form-category_id").change(filter_apply);
$("#filter-due-date").click(function(e) {
$(this).toggleClass("filter-on");
filter_apply();
e.preventDefault();
});
}
return {
Init: function() {
board_load_events();
filter_load_events();
// Project select box
$("#board-selector").chosen({
width: 180
});
$("#board-selector").change(function() {
window.location = "?controller=board&action=show&project_id=" + $(this).val();
});
}
};
})();
// Task related functions
Kanboard.Task = (function() {
return {
Init: function() {
Kanboard.Before();
// Image preview for attachments
$(".file-popover").click(Kanboard.Popover);
}
};
})();
// Project related functions
Kanboard.Project = (function() {
return {
Init: function() {
Kanboard.Before();
}
};
})();
// Initialization
$(function() {
if ($("#board").length) {
Kanboard.Board.Init();
}
else if ($("#task-section").length) {
Kanboard.Task.Init();
}
else if ($("#project-section").length) {
Kanboard.Project.Init();
}
});
|