|
@@
-1,609
+1,634
|
|
1
|
1
|
/* Redmine - project management software
|
|
2
|
2
|
Copyright (C) 2006-2014 Jean-Philippe Lang */
|
|
3
|
3
|
|
|
4
|
4
|
function checkAll(id, checked) {
|
|
5
|
5
|
$('#'+id).find('input[type=checkbox]:enabled').prop('checked', checked);
|
|
6
|
6
|
}
|
|
7
|
7
|
|
|
8
|
8
|
function toggleCheckboxesBySelector(selector) {
|
|
9
|
9
|
var all_checked = true;
|
|
10
|
10
|
$(selector).each(function(index) {
|
|
11
|
11
|
if (!$(this).is(':checked')) { all_checked = false; }
|
|
12
|
12
|
});
|
|
13
|
13
|
$(selector).prop('checked', !all_checked);
|
|
14
|
14
|
}
|
|
15
|
15
|
|
|
16
|
16
|
function showAndScrollTo(id, focus) {
|
|
17
|
17
|
$('#'+id).show();
|
|
18
|
18
|
if (focus !== null) {
|
|
19
|
19
|
$('#'+focus).focus();
|
|
20
|
20
|
}
|
|
21
|
21
|
$('html, body').animate({scrollTop: $('#'+id).offset().top}, 100);
|
|
22
|
22
|
}
|
|
23
|
23
|
|
|
24
|
24
|
function toggleRowGroup(el) {
|
|
25
|
25
|
var tr = $(el).parents('tr').first();
|
|
26
|
26
|
var n = tr.next();
|
|
27
|
27
|
tr.toggleClass('open');
|
|
28
|
28
|
while (n.length && !n.hasClass('group')) {
|
|
29
|
29
|
n.toggle();
|
|
30
|
30
|
n = n.next('tr');
|
|
31
|
31
|
}
|
|
32
|
32
|
}
|
|
33
|
33
|
|
|
34
|
34
|
function collapseAllRowGroups(el) {
|
|
35
|
35
|
var tbody = $(el).parents('tbody').first();
|
|
36
|
36
|
tbody.children('tr').each(function(index) {
|
|
37
|
37
|
if ($(this).hasClass('group')) {
|
|
38
|
38
|
$(this).removeClass('open');
|
|
39
|
39
|
} else {
|
|
40
|
40
|
$(this).hide();
|
|
41
|
41
|
}
|
|
42
|
42
|
});
|
|
43
|
43
|
}
|
|
44
|
44
|
|
|
45
|
45
|
function expandAllRowGroups(el) {
|
|
46
|
46
|
var tbody = $(el).parents('tbody').first();
|
|
47
|
47
|
tbody.children('tr').each(function(index) {
|
|
48
|
48
|
if ($(this).hasClass('group')) {
|
|
49
|
49
|
$(this).addClass('open');
|
|
50
|
50
|
} else {
|
|
51
|
51
|
$(this).show();
|
|
52
|
52
|
}
|
|
53
|
53
|
});
|
|
54
|
54
|
}
|
|
55
|
55
|
|
|
56
|
56
|
function toggleAllRowGroups(el) {
|
|
57
|
57
|
var tr = $(el).parents('tr').first();
|
|
58
|
58
|
if (tr.hasClass('open')) {
|
|
59
|
59
|
collapseAllRowGroups(el);
|
|
60
|
60
|
} else {
|
|
61
|
61
|
expandAllRowGroups(el);
|
|
62
|
62
|
}
|
|
63
|
63
|
}
|
|
64
|
64
|
|
|
65
|
65
|
function toggleFieldset(el) {
|
|
66
|
66
|
var fieldset = $(el).parents('fieldset').first();
|
|
67
|
67
|
fieldset.toggleClass('collapsed');
|
|
68
|
68
|
fieldset.children('div').toggle();
|
|
69
|
69
|
}
|
|
70
|
70
|
|
|
71
|
71
|
function hideFieldset(el) {
|
|
72
|
72
|
var fieldset = $(el).parents('fieldset').first();
|
|
73
|
73
|
fieldset.toggleClass('collapsed');
|
|
74
|
74
|
fieldset.children('div').hide();
|
|
75
|
75
|
}
|
|
76
|
76
|
|
|
|
77
|
// columns selection
|
|
|
78
|
function moveOptions(theSelFrom, theSelTo) {
|
|
|
79
|
$(theSelFrom).find('option:selected').detach().prop("selected", false).appendTo($(theSelTo));
|
|
|
80
|
}
|
|
|
81
|
|
|
|
82
|
function moveOptionUp(theSel) {
|
|
|
83
|
$(theSel).find('option:selected').each(function(){
|
|
|
84
|
$(this).prev(':not(:selected)').detach().insertAfter($(this));
|
|
|
85
|
});
|
|
|
86
|
}
|
|
|
87
|
|
|
|
88
|
function moveOptionTop(theSel) {
|
|
|
89
|
$(theSel).find('option:selected').detach().prependTo($(theSel));
|
|
|
90
|
}
|
|
|
91
|
|
|
|
92
|
function moveOptionDown(theSel) {
|
|
|
93
|
$($(theSel).find('option:selected').get().reverse()).each(function(){
|
|
|
94
|
$(this).next(':not(:selected)').detach().insertBefore($(this));
|
|
|
95
|
});
|
|
|
96
|
}
|
|
|
97
|
|
|
|
98
|
function moveOptionBottom(theSel) {
|
|
|
99
|
$(theSel).find('option:selected').detach().appendTo($(theSel));
|
|
|
100
|
}
|
|
|
101
|
|
|
77
|
102
|
function initFilters() {
|
|
78
|
103
|
$('#add_filter_select').change(function() {
|
|
79
|
104
|
addFilter($(this).val(), '', []);
|
|
80
|
105
|
});
|
|
81
|
106
|
$('#filters-table td.field input[type=checkbox]').each(function() {
|
|
82
|
107
|
toggleFilter($(this).val());
|
|
83
|
108
|
});
|
|
84
|
109
|
$('#filters-table').on('click', 'td.field input[type=checkbox]', function() {
|
|
85
|
110
|
toggleFilter($(this).val());
|
|
86
|
111
|
});
|
|
87
|
112
|
$('#filters-table').on('click', '.toggle-multiselect', function() {
|
|
88
|
113
|
toggleMultiSelect($(this).siblings('select'));
|
|
89
|
114
|
});
|
|
90
|
115
|
$('#filters-table').on('keypress', 'input[type=text]', function(e) {
|
|
91
|
116
|
if (e.keyCode == 13) $(this).closest('form').submit();
|
|
92
|
117
|
});
|
|
93
|
118
|
}
|
|
94
|
119
|
|
|
95
|
120
|
function addFilter(field, operator, values) {
|
|
96
|
121
|
var fieldId = field.replace('.', '_');
|
|
97
|
122
|
var tr = $('#tr_'+fieldId);
|
|
98
|
123
|
if (tr.length > 0) {
|
|
99
|
124
|
tr.show();
|
|
100
|
125
|
} else {
|
|
101
|
126
|
buildFilterRow(field, operator, values);
|
|
102
|
127
|
}
|
|
103
|
128
|
$('#cb_'+fieldId).prop('checked', true);
|
|
104
|
129
|
toggleFilter(field);
|
|
105
|
130
|
$('#add_filter_select').val('').children('option').each(function() {
|
|
106
|
131
|
if ($(this).attr('value') == field) {
|
|
107
|
132
|
$(this).attr('disabled', true);
|
|
108
|
133
|
}
|
|
109
|
134
|
});
|
|
110
|
135
|
}
|
|
111
|
136
|
|
|
112
|
137
|
function buildFilterRow(field, operator, values) {
|
|
113
|
138
|
var fieldId = field.replace('.', '_');
|
|
114
|
139
|
var filterTable = $("#filters-table");
|
|
115
|
140
|
var filterOptions = availableFilters[field];
|
|
116
|
141
|
if (!filterOptions) return;
|
|
117
|
142
|
var operators = operatorByType[filterOptions['type']];
|
|
118
|
143
|
var filterValues = filterOptions['values'];
|
|
119
|
144
|
var i, select;
|
|
120
|
145
|
|
|
121
|
146
|
var tr = $('<tr class="filter">').attr('id', 'tr_'+fieldId).html(
|
|
122
|
147
|
'<td class="field"><input checked="checked" id="cb_'+fieldId+'" name="f[]" value="'+field+'" type="checkbox"><label for="cb_'+fieldId+'"> '+filterOptions['name']+'</label></td>' +
|
|
123
|
148
|
'<td class="operator"><select id="operators_'+fieldId+'" name="op['+field+']"></td>' +
|
|
124
|
149
|
'<td class="values"></td>'
|
|
125
|
150
|
);
|
|
126
|
151
|
filterTable.append(tr);
|
|
127
|
152
|
|
|
128
|
153
|
select = tr.find('td.operator select');
|
|
129
|
154
|
for (i = 0; i < operators.length; i++) {
|
|
130
|
155
|
var option = $('<option>').val(operators[i]).text(operatorLabels[operators[i]]);
|
|
131
|
156
|
if (operators[i] == operator) { option.attr('selected', true); }
|
|
132
|
157
|
select.append(option);
|
|
133
|
158
|
}
|
|
134
|
159
|
select.change(function(){ toggleOperator(field); });
|
|
135
|
160
|
|
|
136
|
161
|
switch (filterOptions['type']) {
|
|
137
|
162
|
case "list":
|
|
138
|
163
|
case "list_optional":
|
|
139
|
164
|
case "list_status":
|
|
140
|
165
|
case "list_subprojects":
|
|
141
|
166
|
tr.find('td.values').append(
|
|
142
|
167
|
'<span style="display:none;"><select class="value" id="values_'+fieldId+'_1" name="v['+field+'][]"></select>' +
|
|
143
|
168
|
' <span class="toggle-multiselect"> </span></span>'
|
|
144
|
169
|
);
|
|
145
|
170
|
select = tr.find('td.values select');
|
|
146
|
171
|
if (values.length > 1) { select.attr('multiple', true); }
|
|
147
|
172
|
for (i = 0; i < filterValues.length; i++) {
|
|
148
|
173
|
var filterValue = filterValues[i];
|
|
149
|
174
|
var option = $('<option>');
|
|
150
|
175
|
if ($.isArray(filterValue)) {
|
|
151
|
176
|
option.val(filterValue[1]).text(filterValue[0]);
|
|
152
|
177
|
if ($.inArray(filterValue[1], values) > -1) {option.attr('selected', true);}
|
|
153
|
178
|
} else {
|
|
154
|
179
|
option.val(filterValue).text(filterValue);
|
|
155
|
180
|
if ($.inArray(filterValue, values) > -1) {option.attr('selected', true);}
|
|
156
|
181
|
}
|
|
157
|
182
|
select.append(option);
|
|
158
|
183
|
}
|
|
159
|
184
|
break;
|
|
160
|
185
|
case "date":
|
|
161
|
186
|
case "date_past":
|
|
162
|
187
|
tr.find('td.values').append(
|
|
163
|
188
|
'<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="10" class="value date_value" /></span>' +
|
|
164
|
189
|
' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="10" class="value date_value" /></span>' +
|
|
165
|
190
|
' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="3" class="value" /> '+labelDayPlural+'</span>'
|
|
166
|
191
|
);
|
|
167
|
192
|
$('#values_'+fieldId+'_1').val(values[0]).datepicker(datepickerOptions);
|
|
168
|
193
|
$('#values_'+fieldId+'_2').val(values[1]).datepicker(datepickerOptions);
|
|
169
|
194
|
$('#values_'+fieldId).val(values[0]);
|
|
170
|
195
|
break;
|
|
171
|
196
|
case "string":
|
|
172
|
197
|
case "text":
|
|
173
|
198
|
tr.find('td.values').append(
|
|
174
|
199
|
'<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="30" class="value" /></span>'
|
|
175
|
200
|
);
|
|
176
|
201
|
$('#values_'+fieldId).val(values[0]);
|
|
177
|
202
|
break;
|
|
178
|
203
|
case "relation":
|
|
179
|
204
|
tr.find('td.values').append(
|
|
180
|
205
|
'<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="6" class="value" /></span>' +
|
|
181
|
206
|
'<span style="display:none;"><select class="value" name="v['+field+'][]" id="values_'+fieldId+'_1"></select></span>'
|
|
182
|
207
|
);
|
|
183
|
208
|
$('#values_'+fieldId).val(values[0]);
|
|
184
|
209
|
select = tr.find('td.values select');
|
|
185
|
210
|
for (i = 0; i < allProjects.length; i++) {
|
|
186
|
211
|
var filterValue = allProjects[i];
|
|
187
|
212
|
var option = $('<option>');
|
|
188
|
213
|
option.val(filterValue[1]).text(filterValue[0]);
|
|
189
|
214
|
if (values[0] == filterValue[1]) { option.attr('selected', true); }
|
|
190
|
215
|
select.append(option);
|
|
191
|
216
|
}
|
|
192
|
217
|
case "integer":
|
|
193
|
218
|
case "float":
|
|
194
|
219
|
tr.find('td.values').append(
|
|
195
|
220
|
'<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="6" class="value" /></span>' +
|
|
196
|
221
|
' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="6" class="value" /></span>'
|
|
197
|
222
|
);
|
|
198
|
223
|
$('#values_'+fieldId+'_1').val(values[0]);
|
|
199
|
224
|
$('#values_'+fieldId+'_2').val(values[1]);
|
|
200
|
225
|
break;
|
|
201
|
226
|
}
|
|
202
|
227
|
}
|
|
203
|
228
|
|
|
204
|
229
|
function toggleFilter(field) {
|
|
205
|
230
|
var fieldId = field.replace('.', '_');
|
|
206
|
231
|
if ($('#cb_' + fieldId).is(':checked')) {
|
|
207
|
232
|
$("#operators_" + fieldId).show().removeAttr('disabled');
|
|
208
|
233
|
toggleOperator(field);
|
|
209
|
234
|
} else {
|
|
210
|
235
|
$("#operators_" + fieldId).hide().attr('disabled', true);
|
|
211
|
236
|
enableValues(field, []);
|
|
212
|
237
|
}
|
|
213
|
238
|
}
|
|
214
|
239
|
|
|
215
|
240
|
function enableValues(field, indexes) {
|
|
216
|
241
|
var fieldId = field.replace('.', '_');
|
|
217
|
242
|
$('#tr_'+fieldId+' td.values .value').each(function(index) {
|
|
218
|
243
|
if ($.inArray(index, indexes) >= 0) {
|
|
219
|
244
|
$(this).removeAttr('disabled');
|
|
220
|
245
|
$(this).parents('span').first().show();
|
|
221
|
246
|
} else {
|
|
222
|
247
|
$(this).val('');
|
|
223
|
248
|
$(this).attr('disabled', true);
|
|
224
|
249
|
$(this).parents('span').first().hide();
|
|
225
|
250
|
}
|
|
226
|
251
|
|
|
227
|
252
|
if ($(this).hasClass('group')) {
|
|
228
|
253
|
$(this).addClass('open');
|
|
229
|
254
|
} else {
|
|
230
|
255
|
$(this).show();
|
|
231
|
256
|
}
|
|
232
|
257
|
});
|
|
233
|
258
|
}
|
|
234
|
259
|
|
|
235
|
260
|
function toggleOperator(field) {
|
|
236
|
261
|
var fieldId = field.replace('.', '_');
|
|
237
|
262
|
var operator = $("#operators_" + fieldId);
|
|
238
|
263
|
switch (operator.val()) {
|
|
239
|
264
|
case "!*":
|
|
240
|
265
|
case "*":
|
|
241
|
266
|
case "t":
|
|
242
|
267
|
case "ld":
|
|
243
|
268
|
case "w":
|
|
244
|
269
|
case "lw":
|
|
245
|
270
|
case "l2w":
|
|
246
|
271
|
case "m":
|
|
247
|
272
|
case "lm":
|
|
248
|
273
|
case "y":
|
|
249
|
274
|
case "o":
|
|
250
|
275
|
case "c":
|
|
251
|
276
|
enableValues(field, []);
|
|
252
|
277
|
break;
|
|
253
|
278
|
case "><":
|
|
254
|
279
|
enableValues(field, [0,1]);
|
|
255
|
280
|
break;
|
|
256
|
281
|
case "<t+":
|
|
257
|
282
|
case ">t+":
|
|
258
|
283
|
case "><t+":
|
|
259
|
284
|
case "t+":
|
|
260
|
285
|
case ">t-":
|
|
261
|
286
|
case "<t-":
|
|
262
|
287
|
case "><t-":
|
|
263
|
288
|
case "t-":
|
|
264
|
289
|
enableValues(field, [2]);
|
|
265
|
290
|
break;
|
|
266
|
291
|
case "=p":
|
|
267
|
292
|
case "=!p":
|
|
268
|
293
|
case "!p":
|
|
269
|
294
|
enableValues(field, [1]);
|
|
270
|
295
|
break;
|
|
271
|
296
|
default:
|
|
272
|
297
|
enableValues(field, [0]);
|
|
273
|
298
|
break;
|
|
274
|
299
|
}
|
|
275
|
300
|
}
|
|
276
|
301
|
|
|
277
|
302
|
function toggleMultiSelect(el) {
|
|
278
|
303
|
if (el.attr('multiple')) {
|
|
279
|
304
|
el.removeAttr('multiple');
|
|
280
|
305
|
el.attr('size', 1);
|
|
281
|
306
|
} else {
|
|
282
|
307
|
el.attr('multiple', true);
|
|
283
|
308
|
if (el.children().length > 10)
|
|
284
|
309
|
el.attr('size', 10);
|
|
285
|
310
|
else
|
|
286
|
311
|
el.attr('size', 4);
|
|
287
|
312
|
}
|
|
288
|
313
|
}
|
|
289
|
314
|
|
|
290
|
315
|
function showTab(name, url) {
|
|
291
|
316
|
$('div#content .tab-content').hide();
|
|
292
|
317
|
$('div.tabs a').removeClass('selected');
|
|
293
|
318
|
$('#tab-content-' + name).show();
|
|
294
|
319
|
$('#tab-' + name).addClass('selected');
|
|
295
|
320
|
//replaces current URL with the "href" attribute of the current link
|
|
296
|
321
|
//(only triggered if supported by browser)
|
|
297
|
322
|
if ("replaceState" in window.history) {
|
|
298
|
323
|
window.history.replaceState(null, document.title, url);
|
|
299
|
324
|
}
|
|
300
|
325
|
return false;
|
|
301
|
326
|
}
|
|
302
|
327
|
|
|
303
|
328
|
function moveTabRight(el) {
|
|
304
|
329
|
var lis = $(el).parents('div.tabs').first().find('ul').children();
|
|
305
|
330
|
var tabsWidth = 0;
|
|
306
|
331
|
var i = 0;
|
|
307
|
332
|
lis.each(function() {
|
|
308
|
333
|
if ($(this).is(':visible')) {
|
|
309
|
334
|
tabsWidth += $(this).width() + 6;
|
|
310
|
335
|
}
|
|
311
|
336
|
});
|
|
312
|
337
|
if (tabsWidth < $(el).parents('div.tabs').first().width() - 60) { return; }
|
|
313
|
338
|
while (i<lis.length && !lis.eq(i).is(':visible')) { i++; }
|
|
314
|
339
|
lis.eq(i).hide();
|
|
315
|
340
|
}
|
|
316
|
341
|
|
|
317
|
342
|
function moveTabLeft(el) {
|
|
318
|
343
|
var lis = $(el).parents('div.tabs').first().find('ul').children();
|
|
319
|
344
|
var i = 0;
|
|
320
|
345
|
while (i < lis.length && !lis.eq(i).is(':visible')) { i++; }
|
|
321
|
346
|
if (i > 0) {
|
|
322
|
347
|
lis.eq(i-1).show();
|
|
323
|
348
|
}
|
|
324
|
349
|
}
|
|
325
|
350
|
|
|
326
|
351
|
function displayTabsButtons() {
|
|
327
|
352
|
var lis;
|
|
328
|
353
|
var tabsWidth = 0;
|
|
329
|
354
|
var el;
|
|
330
|
355
|
$('div.tabs').each(function() {
|
|
331
|
356
|
el = $(this);
|
|
332
|
357
|
lis = el.find('ul').children();
|
|
333
|
358
|
lis.each(function(){
|
|
334
|
359
|
if ($(this).is(':visible')) {
|
|
335
|
360
|
tabsWidth += $(this).width() + 6;
|
|
336
|
361
|
}
|
|
337
|
362
|
});
|
|
338
|
363
|
if ((tabsWidth < el.width() - 60) && (lis.first().is(':visible'))) {
|
|
339
|
364
|
el.find('div.tabs-buttons').hide();
|
|
340
|
365
|
} else {
|
|
341
|
366
|
el.find('div.tabs-buttons').show();
|
|
342
|
367
|
}
|
|
343
|
368
|
});
|
|
344
|
369
|
}
|
|
345
|
370
|
|
|
346
|
371
|
function setPredecessorFieldsVisibility() {
|
|
347
|
372
|
var relationType = $('#relation_relation_type');
|
|
348
|
373
|
if (relationType.val() == "precedes" || relationType.val() == "follows") {
|
|
349
|
374
|
$('#predecessor_fields').show();
|
|
350
|
375
|
} else {
|
|
351
|
376
|
$('#predecessor_fields').hide();
|
|
352
|
377
|
}
|
|
353
|
378
|
}
|
|
354
|
379
|
|
|
355
|
380
|
function showModal(id, width) {
|
|
356
|
381
|
var el = $('#'+id).first();
|
|
357
|
382
|
if (el.length === 0 || el.is(':visible')) {return;}
|
|
358
|
383
|
var title = el.find('h3.title').text();
|
|
359
|
384
|
el.dialog({
|
|
360
|
385
|
width: width,
|
|
361
|
386
|
modal: true,
|
|
362
|
387
|
resizable: false,
|
|
363
|
388
|
dialogClass: 'modal',
|
|
364
|
389
|
title: title
|
|
365
|
390
|
});
|
|
366
|
391
|
el.find("input[type=text], input[type=submit]").first().focus();
|
|
367
|
392
|
}
|
|
368
|
393
|
|
|
369
|
394
|
function hideModal(el) {
|
|
370
|
395
|
var modal;
|
|
371
|
396
|
if (el) {
|
|
372
|
397
|
modal = $(el).parents('.ui-dialog-content');
|
|
373
|
398
|
} else {
|
|
374
|
399
|
modal = $('#ajax-modal');
|
|
375
|
400
|
}
|
|
376
|
401
|
modal.dialog("close");
|
|
377
|
402
|
}
|
|
378
|
403
|
|
|
379
|
404
|
function submitPreview(url, form, target) {
|
|
380
|
405
|
$.ajax({
|
|
381
|
406
|
url: url,
|
|
382
|
407
|
type: 'post',
|
|
383
|
408
|
data: $('#'+form).serialize(),
|
|
384
|
409
|
success: function(data){
|
|
385
|
410
|
$('#'+target).html(data);
|
|
386
|
411
|
}
|
|
387
|
412
|
});
|
|
388
|
413
|
}
|
|
389
|
414
|
|
|
390
|
415
|
function collapseScmEntry(id) {
|
|
391
|
416
|
$('.'+id).each(function() {
|
|
392
|
417
|
if ($(this).hasClass('open')) {
|
|
393
|
418
|
collapseScmEntry($(this).attr('id'));
|
|
394
|
419
|
}
|
|
395
|
420
|
$(this).hide();
|
|
396
|
421
|
});
|
|
397
|
422
|
$('#'+id).removeClass('open');
|
|
398
|
423
|
}
|
|
399
|
424
|
|
|
400
|
425
|
function expandScmEntry(id) {
|
|
401
|
426
|
$('.'+id).each(function() {
|
|
402
|
427
|
$(this).show();
|
|
403
|
428
|
if ($(this).hasClass('loaded') && !$(this).hasClass('collapsed')) {
|
|
404
|
429
|
expandScmEntry($(this).attr('id'));
|
|
405
|
430
|
}
|
|
406
|
431
|
});
|
|
407
|
432
|
$('#'+id).addClass('open');
|
|
408
|
433
|
}
|
|
409
|
434
|
|
|
410
|
435
|
function scmEntryClick(id, url) {
|
|
411
|
436
|
var el = $('#'+id);
|
|
412
|
437
|
if (el.hasClass('open')) {
|
|
413
|
438
|
collapseScmEntry(id);
|
|
414
|
439
|
el.addClass('collapsed');
|
|
415
|
440
|
return false;
|
|
416
|
441
|
} else if (el.hasClass('loaded')) {
|
|
417
|
442
|
expandScmEntry(id);
|
|
418
|
443
|
el.removeClass('collapsed');
|
|
419
|
444
|
return false;
|
|
420
|
445
|
}
|
|
421
|
446
|
if (el.hasClass('loading')) {
|
|
422
|
447
|
return false;
|
|
423
|
448
|
}
|
|
424
|
449
|
el.addClass('loading');
|
|
425
|
450
|
$.ajax({
|
|
426
|
451
|
url: url,
|
|
427
|
452
|
success: function(data) {
|
|
428
|
453
|
el.after(data);
|
|
429
|
454
|
el.addClass('open').addClass('loaded').removeClass('loading');
|
|
430
|
455
|
}
|
|
431
|
456
|
});
|
|
432
|
457
|
return true;
|
|
433
|
458
|
}
|
|
434
|
459
|
|
|
435
|
460
|
function randomKey(size) {
|
|
436
|
461
|
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
437
|
462
|
var key = '';
|
|
438
|
463
|
for (var i = 0; i < size; i++) {
|
|
439
|
464
|
key += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
440
|
465
|
}
|
|
441
|
466
|
return key;
|
|
442
|
467
|
}
|
|
443
|
468
|
|
|
444
|
469
|
function updateIssueFrom(url) {
|
|
445
|
470
|
$('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){
|
|
446
|
471
|
$(this).data('valuebeforeupdate', $(this).val());
|
|
447
|
472
|
});
|
|
448
|
473
|
$.ajax({
|
|
449
|
474
|
url: url,
|
|
450
|
475
|
type: 'post',
|
|
451
|
476
|
data: $('#issue-form').serialize()
|
|
452
|
477
|
});
|
|
453
|
478
|
}
|
|
454
|
479
|
|
|
455
|
480
|
function replaceIssueFormWith(html){
|
|
456
|
481
|
var replacement = $(html);
|
|
457
|
482
|
$('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){
|
|
458
|
483
|
var object_id = $(this).attr('id');
|
|
459
|
484
|
if (object_id && $(this).data('valuebeforeupdate')!=$(this).val()) {
|
|
460
|
485
|
replacement.find('#'+object_id).val($(this).val());
|
|
461
|
486
|
}
|
|
462
|
487
|
});
|
|
463
|
488
|
$('#all_attributes').empty();
|
|
464
|
489
|
$('#all_attributes').prepend(replacement);
|
|
465
|
490
|
}
|
|
466
|
491
|
|
|
467
|
492
|
function updateBulkEditFrom(url) {
|
|
468
|
493
|
$.ajax({
|
|
469
|
494
|
url: url,
|
|
470
|
495
|
type: 'post',
|
|
471
|
496
|
data: $('#bulk_edit_form').serialize()
|
|
472
|
497
|
});
|
|
473
|
498
|
}
|
|
474
|
499
|
|
|
475
|
500
|
function observeAutocompleteField(fieldId, url, options) {
|
|
476
|
501
|
$(document).ready(function() {
|
|
477
|
502
|
$('#'+fieldId).autocomplete($.extend({
|
|
478
|
503
|
source: url,
|
|
479
|
504
|
minLength: 2,
|
|
480
|
505
|
search: function(){$('#'+fieldId).addClass('ajax-loading');},
|
|
481
|
506
|
response: function(){$('#'+fieldId).removeClass('ajax-loading');}
|
|
482
|
507
|
}, options));
|
|
483
|
508
|
$('#'+fieldId).addClass('autocomplete');
|
|
484
|
509
|
});
|
|
485
|
510
|
}
|
|
486
|
511
|
|
|
487
|
512
|
function observeSearchfield(fieldId, targetId, url) {
|
|
488
|
513
|
$('#'+fieldId).each(function() {
|
|
489
|
514
|
var $this = $(this);
|
|
490
|
515
|
$this.addClass('autocomplete');
|
|
491
|
516
|
$this.attr('data-value-was', $this.val());
|
|
492
|
517
|
var check = function() {
|
|
493
|
518
|
var val = $this.val();
|
|
494
|
519
|
if ($this.attr('data-value-was') != val){
|
|
495
|
520
|
$this.attr('data-value-was', val);
|
|
496
|
521
|
$.ajax({
|
|
497
|
522
|
url: url,
|
|
498
|
523
|
type: 'get',
|
|
499
|
524
|
data: {q: $this.val()},
|
|
500
|
525
|
success: function(data){ if(targetId) $('#'+targetId).html(data); },
|
|
501
|
526
|
beforeSend: function(){ $this.addClass('ajax-loading'); },
|
|
502
|
527
|
complete: function(){ $this.removeClass('ajax-loading'); }
|
|
503
|
528
|
});
|
|
504
|
529
|
}
|
|
505
|
530
|
};
|
|
506
|
531
|
var reset = function() {
|
|
507
|
532
|
if (timer) {
|
|
508
|
533
|
clearInterval(timer);
|
|
509
|
534
|
timer = setInterval(check, 300);
|
|
510
|
535
|
}
|
|
511
|
536
|
};
|
|
512
|
537
|
var timer = setInterval(check, 300);
|
|
513
|
538
|
$this.bind('keyup click mousemove', reset);
|
|
514
|
539
|
});
|
|
515
|
540
|
}
|
|
516
|
541
|
|
|
517
|
542
|
function initMyPageSortable(list, url) {
|
|
518
|
543
|
$('#list-'+list).sortable({
|
|
519
|
544
|
connectWith: '.block-receiver',
|
|
520
|
545
|
tolerance: 'pointer',
|
|
521
|
546
|
update: function(){
|
|
522
|
547
|
$.ajax({
|
|
523
|
548
|
url: url,
|
|
524
|
549
|
type: 'post',
|
|
525
|
550
|
data: {'blocks': $.map($('#list-'+list).children(), function(el){return $(el).attr('id');})}
|
|
526
|
551
|
});
|
|
527
|
552
|
}
|
|
528
|
553
|
});
|
|
529
|
554
|
$("#list-top, #list-left, #list-right").disableSelection();
|
|
530
|
555
|
}
|
|
531
|
556
|
|
|
532
|
557
|
var warnLeavingUnsavedMessage;
|
|
533
|
558
|
function warnLeavingUnsaved(message) {
|
|
534
|
559
|
warnLeavingUnsavedMessage = message;
|
|
535
|
560
|
$(document).on('submit', 'form', function(){
|
|
536
|
561
|
$('textarea').removeData('changed');
|
|
537
|
562
|
});
|
|
538
|
563
|
$(document).on('change', 'textarea', function(){
|
|
539
|
564
|
$(this).data('changed', 'changed');
|
|
540
|
565
|
});
|
|
541
|
566
|
window.onbeforeunload = function(){
|
|
542
|
567
|
var warn = false;
|
|
543
|
568
|
$('textarea').blur().each(function(){
|
|
544
|
569
|
if ($(this).data('changed')) {
|
|
545
|
570
|
warn = true;
|
|
546
|
571
|
}
|
|
547
|
572
|
});
|
|
548
|
573
|
if (warn) {return warnLeavingUnsavedMessage;}
|
|
549
|
574
|
};
|
|
550
|
575
|
}
|
|
551
|
576
|
|
|
552
|
577
|
function setupAjaxIndicator() {
|
|
553
|
578
|
$(document).bind('ajaxSend', function(event, xhr, settings) {
|
|
554
|
579
|
if ($('.ajax-loading').length === 0 && settings.contentType != 'application/octet-stream') {
|
|
555
|
580
|
$('#ajax-indicator').show();
|
|
556
|
581
|
}
|
|
557
|
582
|
});
|
|
558
|
583
|
$(document).bind('ajaxStop', function() {
|
|
559
|
584
|
$('#ajax-indicator').hide();
|
|
560
|
585
|
});
|
|
561
|
586
|
}
|
|
562
|
587
|
|
|
563
|
588
|
function hideOnLoad() {
|
|
564
|
589
|
$('.hol').hide();
|
|
565
|
590
|
}
|
|
566
|
591
|
|
|
567
|
592
|
function addFormObserversForDoubleSubmit() {
|
|
568
|
593
|
$('form[method=post]').each(function() {
|
|
569
|
594
|
if (!$(this).hasClass('multiple-submit')) {
|
|
570
|
595
|
$(this).submit(function(form_submission) {
|
|
571
|
596
|
if ($(form_submission.target).attr('data-submitted')) {
|
|
572
|
597
|
form_submission.preventDefault();
|
|
573
|
598
|
} else {
|
|
574
|
599
|
$(form_submission.target).attr('data-submitted', true);
|
|
575
|
600
|
}
|
|
576
|
601
|
});
|
|
577
|
602
|
}
|
|
578
|
603
|
});
|
|
579
|
604
|
}
|
|
580
|
605
|
|
|
581
|
606
|
function defaultFocus(){
|
|
582
|
607
|
if ($('#content :focus').length == 0) {
|
|
583
|
608
|
$('#content input[type=text], #content textarea').first().focus();
|
|
584
|
609
|
}
|
|
585
|
610
|
}
|
|
586
|
611
|
|
|
587
|
612
|
function blockEventPropagation(event) {
|
|
588
|
613
|
event.stopPropagation();
|
|
589
|
614
|
event.preventDefault();
|
|
590
|
615
|
}
|
|
591
|
616
|
|
|
592
|
617
|
function toggleDisabledOnChange() {
|
|
593
|
618
|
var checked = $(this).is(':checked');
|
|
594
|
619
|
$($(this).data('disables')).attr('disabled', checked);
|
|
595
|
620
|
$($(this).data('enables')).attr('disabled', !checked);
|
|
596
|
621
|
}
|
|
597
|
622
|
function toggleDisabledInit() {
|
|
598
|
623
|
$('input[data-disables], input[data-enables]').each(toggleDisabledOnChange);
|
|
599
|
624
|
}
|
|
600
|
625
|
$(document).ready(function(){
|
|
601
|
626
|
$('#content').on('change', 'input[data-disables], input[data-enables]', toggleDisabledOnChange);
|
|
602
|
627
|
toggleDisabledInit();
|
|
603
|
628
|
});
|
|
604
|
629
|
|
|
605
|
630
|
$(document).ready(setupAjaxIndicator);
|
|
606
|
631
|
$(document).ready(hideOnLoad);
|
|
607
|
632
|
$(document).ready(addFormObserversForDoubleSubmit);
|
|
608
|
633
|
$(document).ready(defaultFocus);
|
|
609
|
634
|
|