@@ -1,500 +1,499 | |||
|
1 | 1 | /* Redmine - project management software |
|
2 | 2 | Copyright (C) 2006-2012 Jean-Philippe Lang */ |
|
3 | 3 | |
|
4 | 4 | function checkAll(id, checked) { |
|
5 | 5 | if (checked) { |
|
6 | 6 | $('#'+id).find('input[type=checkbox]').attr('checked', true); |
|
7 | 7 | } else { |
|
8 | 8 | $('#'+id).find('input[type=checkbox]').removeAttr('checked'); |
|
9 | 9 | } |
|
10 | 10 | } |
|
11 | 11 | |
|
12 | 12 | function toggleCheckboxesBySelector(selector) { |
|
13 | 13 | var all_checked = true; |
|
14 | 14 | $(selector).each(function(index) { |
|
15 | 15 | if (!$(this).is(':checked')) { all_checked = false; } |
|
16 | 16 | }); |
|
17 | 17 | $(selector).attr('checked', !all_checked) |
|
18 | 18 | } |
|
19 | 19 | |
|
20 | 20 | function showAndScrollTo(id, focus) { |
|
21 | 21 | $('#'+id).show(); |
|
22 | 22 | if (focus!=null) { |
|
23 | 23 | $('#'+focus).focus(); |
|
24 | 24 | } |
|
25 | 25 | $('html, body').animate({scrollTop: $('#'+id).offset().top}, 100); |
|
26 | 26 | } |
|
27 | 27 | |
|
28 | 28 | function toggleRowGroup(el) { |
|
29 | 29 | var tr = $(el).parents('tr').first(); |
|
30 | 30 | var n = tr.next(); |
|
31 | 31 | tr.toggleClass('open'); |
|
32 | 32 | while (n.length && !n.hasClass('group')) { |
|
33 | 33 | n.toggle(); |
|
34 | 34 | n = n.next('tr'); |
|
35 | 35 | } |
|
36 | 36 | } |
|
37 | 37 | |
|
38 | 38 | function collapseAllRowGroups(el) { |
|
39 | 39 | var tbody = $(el).parents('tbody').first(); |
|
40 | 40 | tbody.children('tr').each(function(index) { |
|
41 | 41 | if ($(this).hasClass('group')) { |
|
42 | 42 | $(this).removeClass('open'); |
|
43 | 43 | } else { |
|
44 | 44 | $(this).hide(); |
|
45 | 45 | } |
|
46 | 46 | }); |
|
47 | 47 | } |
|
48 | 48 | |
|
49 | 49 | function expandAllRowGroups(el) { |
|
50 | 50 | var tbody = $(el).parents('tbody').first(); |
|
51 | 51 | tbody.children('tr').each(function(index) { |
|
52 | 52 | if ($(this).hasClass('group')) { |
|
53 | 53 | $(this).addClass('open'); |
|
54 | 54 | } else { |
|
55 | 55 | $(this).show(); |
|
56 | 56 | } |
|
57 | 57 | }); |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | function toggleAllRowGroups(el) { |
|
61 | 61 | var tr = $(el).parents('tr').first(); |
|
62 | 62 | if (tr.hasClass('open')) { |
|
63 | 63 | collapseAllRowGroups(el); |
|
64 | 64 | } else { |
|
65 | 65 | expandAllRowGroups(el); |
|
66 | 66 | } |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | function toggleFieldset(el) { |
|
70 | 70 | var fieldset = $(el).parents('fieldset').first(); |
|
71 | 71 | fieldset.toggleClass('collapsed'); |
|
72 | 72 | fieldset.children('div').toggle(); |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | function hideFieldset(el) { |
|
76 | 76 | var fieldset = $(el).parents('fieldset').first(); |
|
77 | 77 | fieldset.toggleClass('collapsed'); |
|
78 | 78 | fieldset.children('div').hide(); |
|
79 | 79 | } |
|
80 | 80 | |
|
81 | 81 | function add_filter() { |
|
82 | 82 | var select = $('#add_filter_select'); |
|
83 | 83 | var field = select.val(); |
|
84 | 84 | $('#tr_'+field).show(); |
|
85 | 85 | var check_box = $('#cb_' + field); |
|
86 | 86 | check_box.attr('checked', true); |
|
87 | 87 | toggle_filter(field); |
|
88 | 88 | select.val(''); |
|
89 | 89 | |
|
90 | 90 | select.children('option').each(function(index) { |
|
91 | 91 | if ($(this).attr('value') == field) { |
|
92 | 92 | $(this).attr('disabled', true); |
|
93 | 93 | } |
|
94 | 94 | }); |
|
95 | 95 | } |
|
96 | 96 | |
|
97 | 97 | function toggle_filter(field) { |
|
98 | 98 | check_box = $('#cb_' + field); |
|
99 | 99 | if (check_box.is(':checked')) { |
|
100 | 100 | $("#operators_" + field).show().removeAttr('disabled'); |
|
101 | 101 | toggle_operator(field); |
|
102 | 102 | } else { |
|
103 | 103 | $("#operators_" + field).hide().attr('disabled', true); |
|
104 | 104 | enableValues(field, []); |
|
105 | 105 | } |
|
106 | 106 | } |
|
107 | 107 | |
|
108 | 108 | function enableValues(field, indexes) { |
|
109 | 109 | $(".values_" + field).each(function(index) { |
|
110 | 110 | if (indexes.indexOf(index) >= 0) { |
|
111 | 111 | $(this).removeAttr('disabled'); |
|
112 | 112 | $(this).parents('span').first().show(); |
|
113 | 113 | } else { |
|
114 | 114 | $(this).val(''); |
|
115 | 115 | $(this).attr('disabled', true); |
|
116 | 116 | $(this).parents('span').first().hide(); |
|
117 | 117 | } |
|
118 | 118 | |
|
119 | 119 | if ($(this).hasClass('group')) { |
|
120 | 120 | $(this).addClass('open'); |
|
121 | 121 | } else { |
|
122 | 122 | $(this).show(); |
|
123 | 123 | } |
|
124 | 124 | }); |
|
125 | 125 | |
|
126 | 126 | if (indexes.length > 0) { |
|
127 | 127 | $("#div_values_" + field).show(); |
|
128 | 128 | } else { |
|
129 | 129 | $("#div_values_" + field).hide(); |
|
130 | 130 | } |
|
131 | 131 | } |
|
132 | 132 | |
|
133 | 133 | function toggle_operator(field) { |
|
134 | 134 | operator = $("#operators_" + field); |
|
135 | 135 | switch (operator.val()) { |
|
136 | 136 | case "!*": |
|
137 | 137 | case "*": |
|
138 | 138 | case "t": |
|
139 | 139 | case "w": |
|
140 | 140 | case "o": |
|
141 | 141 | case "c": |
|
142 | 142 | enableValues(field, []); |
|
143 | 143 | break; |
|
144 | 144 | case "><": |
|
145 | 145 | enableValues(field, [0,1]); |
|
146 | 146 | break; |
|
147 | 147 | case "<t+": |
|
148 | 148 | case ">t+": |
|
149 | 149 | case "t+": |
|
150 | 150 | case ">t-": |
|
151 | 151 | case "<t-": |
|
152 | 152 | case "t-": |
|
153 | 153 | enableValues(field, [2]); |
|
154 | 154 | break; |
|
155 | 155 | default: |
|
156 | 156 | enableValues(field, [0]); |
|
157 | 157 | break; |
|
158 | 158 | } |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | function toggle_multi_select(id) { |
|
162 | 162 | var select = $('#'+id); |
|
163 | 163 | if (select.attr('multiple')) { |
|
164 | 164 | select.removeAttr('multiple'); |
|
165 | 165 | } else { |
|
166 | 166 | select.attr('multiple', true); |
|
167 | 167 | } |
|
168 | 168 | } |
|
169 | 169 | |
|
170 | 170 | function submit_query_form(id) { |
|
171 | 171 | selectAllOptions("selected_columns"); |
|
172 | 172 | $('#'+id).submit(); |
|
173 | 173 | } |
|
174 | 174 | |
|
175 | 175 | function observeIssueFilters() { |
|
176 | 176 | $('#query_form input[type=text]').keypress(function(e){ |
|
177 | 177 | if (e.keyCode == 13) submit_query_form("query_form"); |
|
178 | 178 | }); |
|
179 | 179 | } |
|
180 | 180 | |
|
181 | 181 | var fileFieldCount = 1; |
|
182 | 182 | function addFileField() { |
|
183 | 183 | var fields = $('#attachments_fields'); |
|
184 | 184 | if (fields.children().length >= 10) return false; |
|
185 | 185 | fileFieldCount++; |
|
186 | 186 | var s = fields.children('span').first().clone(); |
|
187 | 187 | s.children('input.file').attr('name', "attachments[" + fileFieldCount + "][file]").val(''); |
|
188 | 188 | s.children('input.description').attr('name', "attachments[" + fileFieldCount + "][description]").val(''); |
|
189 | 189 | fields.append(s); |
|
190 | 190 | } |
|
191 | 191 | |
|
192 | 192 | function removeFileField(el) { |
|
193 | 193 | var fields = $('#attachments_fields'); |
|
194 | 194 | var s = $(el).parents('span').first(); |
|
195 | 195 | if (fields.children().length > 1) { |
|
196 | 196 | s.remove(); |
|
197 | 197 | } else { |
|
198 | 198 | s.children('input.file').val(''); |
|
199 | 199 | s.children('input.description').val(''); |
|
200 | 200 | } |
|
201 | 201 | } |
|
202 | 202 | |
|
203 | 203 | function checkFileSize(el, maxSize, message) { |
|
204 | 204 | var files = el.files; |
|
205 | 205 | if (files) { |
|
206 | 206 | for (var i=0; i<files.length; i++) { |
|
207 | 207 | if (files[i].size > maxSize) { |
|
208 | 208 | alert(message); |
|
209 | 209 | el.value = ""; |
|
210 | 210 | } |
|
211 | 211 | } |
|
212 | 212 | } |
|
213 | 213 | } |
|
214 | 214 | |
|
215 | 215 | function showTab(name) { |
|
216 | 216 | $('div#content .tab-content').hide(); |
|
217 | 217 | $('div.tabs a').removeClass('selected'); |
|
218 | 218 | $('#tab-content-' + name).show(); |
|
219 | 219 | $('#tab-' + name).addClass('selected'); |
|
220 | 220 | return false; |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | function moveTabRight(el) { |
|
224 | 224 | var lis = $(el).parents('div.tabs').first().find('ul').children(); |
|
225 | 225 | var tabsWidth = 0; |
|
226 | 226 | var i = 0; |
|
227 | 227 | lis.each(function(){ |
|
228 | 228 | if ($(this).is(':visible')) { |
|
229 | 229 | tabsWidth += $(this).width() + 6; |
|
230 | 230 | } |
|
231 | 231 | }); |
|
232 | 232 | if (tabsWidth < $(el).parents('div.tabs').first().width() - 60) { return; } |
|
233 | 233 | while (i<lis.length && !lis.eq(i).is(':visible')) { i++; } |
|
234 | 234 | lis.eq(i).hide(); |
|
235 | 235 | } |
|
236 | 236 | |
|
237 | 237 | function moveTabLeft(el) { |
|
238 | 238 | var lis = $(el).parents('div.tabs').first().find('ul').children(); |
|
239 | 239 | var i = 0; |
|
240 | 240 | while (i<lis.length && !lis.eq(i).is(':visible')) { i++; } |
|
241 | 241 | if (i>0) { |
|
242 | 242 | lis.eq(i-1).show(); |
|
243 | 243 | } |
|
244 | 244 | } |
|
245 | 245 | |
|
246 | 246 | function displayTabsButtons() { |
|
247 | 247 | var lis; |
|
248 | 248 | var tabsWidth = 0; |
|
249 | 249 | var el; |
|
250 | 250 | $('div.tabs').each(function() { |
|
251 | 251 | el = $(this); |
|
252 | 252 | lis = el.find('ul').children(); |
|
253 | 253 | lis.each(function(){ |
|
254 | 254 | if ($(this).is(':visible')) { |
|
255 | 255 | tabsWidth += $(this).width() + 6; |
|
256 | 256 | } |
|
257 | 257 | }); |
|
258 | 258 | if ((tabsWidth < el.width() - 60) && (lis.first().is(':visible'))) { |
|
259 | 259 | el.find('div.tabs-buttons').hide(); |
|
260 | 260 | } else { |
|
261 | 261 | el.find('div.tabs-buttons').show(); |
|
262 | 262 | } |
|
263 | 263 | }); |
|
264 | 264 | } |
|
265 | 265 | |
|
266 | 266 | function setPredecessorFieldsVisibility() { |
|
267 | 267 | var relationType = $('#relation_relation_type'); |
|
268 | 268 | if (relationType.val() == "precedes" || relationType.val() == "follows") { |
|
269 | 269 | $('#predecessor_fields').show(); |
|
270 | 270 | } else { |
|
271 | 271 | $('#predecessor_fields').hide(); |
|
272 | 272 | } |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | function showModal(id, width) { |
|
276 | 276 | var el = $('#'+id).first(); |
|
277 | 277 | if (el.length == 0 || el.is(':visible')) {return;} |
|
278 | 278 | var title = el.find('h3.title').text(); |
|
279 | 279 | el.dialog({ |
|
280 | 280 | width: width, |
|
281 | 281 | modal: true, |
|
282 | 282 | resizable: false, |
|
283 | 283 | dialogClass: 'modal', |
|
284 | 284 | title: title |
|
285 | 285 | }); |
|
286 | 286 | el.find("input[type=text], input[type=submit]").first().focus(); |
|
287 | 287 | } |
|
288 | 288 | |
|
289 | 289 | function hideModal(el) { |
|
290 | 290 | var modal; |
|
291 | 291 | if (el) { |
|
292 | 292 | modal = $(el).parents('.ui-dialog-content'); |
|
293 | 293 | } else { |
|
294 | 294 | modal = $('#ajax-modal'); |
|
295 | 295 | } |
|
296 | 296 | modal.dialog("close"); |
|
297 | 297 | } |
|
298 | 298 | |
|
299 | 299 | function submitPreview(url, form, target) { |
|
300 | 300 | $.ajax({ |
|
301 | 301 | url: url, |
|
302 | 302 | type: 'post', |
|
303 | 303 | data: $('#'+form).serialize(), |
|
304 | 304 | success: function(data){ |
|
305 | 305 | $('#'+target).html(data); |
|
306 | $('html, body').animate({scrollTop: $('#'+target).offset().top}, 100); | |
|
307 | 306 | } |
|
308 | 307 | }); |
|
309 | 308 | } |
|
310 | 309 | |
|
311 | 310 | function collapseScmEntry(id) { |
|
312 | 311 | $('.'+id).each(function() { |
|
313 | 312 | if ($(this).hasClass('open')) { |
|
314 | 313 | collapseScmEntry($(this).attr('id')); |
|
315 | 314 | } |
|
316 | 315 | $(this).hide(); |
|
317 | 316 | }); |
|
318 | 317 | $('#'+id).removeClass('open'); |
|
319 | 318 | } |
|
320 | 319 | |
|
321 | 320 | function expandScmEntry(id) { |
|
322 | 321 | $('.'+id).each(function() { |
|
323 | 322 | $(this).show(); |
|
324 | 323 | if ($(this).hasClass('loaded') && !$(this).hasClass('collapsed')) { |
|
325 | 324 | expandScmEntry($(this).attr('id')); |
|
326 | 325 | } |
|
327 | 326 | }); |
|
328 | 327 | $('#'+id).addClass('open'); |
|
329 | 328 | } |
|
330 | 329 | |
|
331 | 330 | function scmEntryClick(id, url) { |
|
332 | 331 | el = $('#'+id); |
|
333 | 332 | if (el.hasClass('open')) { |
|
334 | 333 | collapseScmEntry(id); |
|
335 | 334 | el.addClass('collapsed'); |
|
336 | 335 | return false; |
|
337 | 336 | } else if (el.hasClass('loaded')) { |
|
338 | 337 | expandScmEntry(id); |
|
339 | 338 | el.removeClass('collapsed'); |
|
340 | 339 | return false; |
|
341 | 340 | } |
|
342 | 341 | if (el.hasClass('loading')) { |
|
343 | 342 | return false; |
|
344 | 343 | } |
|
345 | 344 | el.addClass('loading'); |
|
346 | 345 | $.ajax({ |
|
347 | 346 | url: url, |
|
348 | 347 | success: function(data){ |
|
349 | 348 | el.after(data); |
|
350 | 349 | el.addClass('open').addClass('loaded').removeClass('loading'); |
|
351 | 350 | } |
|
352 | 351 | }); |
|
353 | 352 | return true; |
|
354 | 353 | } |
|
355 | 354 | |
|
356 | 355 | function randomKey(size) { |
|
357 | 356 | var chars = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); |
|
358 | 357 | var key = ''; |
|
359 | 358 | for (i = 0; i < size; i++) { |
|
360 | 359 | key += chars[Math.floor(Math.random() * chars.length)]; |
|
361 | 360 | } |
|
362 | 361 | return key; |
|
363 | 362 | } |
|
364 | 363 | |
|
365 | 364 | // Can't use Rails' remote select because we need the form data |
|
366 | 365 | function updateIssueFrom(url) { |
|
367 | 366 | $.ajax({ |
|
368 | 367 | url: url, |
|
369 | 368 | type: 'post', |
|
370 | 369 | data: $('#issue-form').serialize() |
|
371 | 370 | }); |
|
372 | 371 | } |
|
373 | 372 | |
|
374 | 373 | function updateBulkEditFrom(url) { |
|
375 | 374 | $.ajax({ |
|
376 | 375 | url: url, |
|
377 | 376 | type: 'post', |
|
378 | 377 | data: $('#bulk_edit_form').serialize() |
|
379 | 378 | }); |
|
380 | 379 | } |
|
381 | 380 | |
|
382 | 381 | function observeAutocompleteField(fieldId, url) { |
|
383 | 382 | $('#'+fieldId).autocomplete({ |
|
384 | 383 | source: url, |
|
385 | 384 | minLength: 2, |
|
386 | 385 | }); |
|
387 | 386 | } |
|
388 | 387 | |
|
389 | 388 | function observeSearchfield(fieldId, targetId, url) { |
|
390 | 389 | $('#'+fieldId).each(function() { |
|
391 | 390 | var $this = $(this); |
|
392 | 391 | $this.attr('data-value-was', $this.val()); |
|
393 | 392 | var check = function() { |
|
394 | 393 | var val = $this.val(); |
|
395 | 394 | if ($this.attr('data-value-was') != val){ |
|
396 | 395 | $this.attr('data-value-was', val); |
|
397 | 396 | if (val != '') { |
|
398 | 397 | $.ajax({ |
|
399 | 398 | url: url, |
|
400 | 399 | type: 'get', |
|
401 | 400 | data: {q: $this.val()}, |
|
402 | 401 | success: function(data){ $('#'+targetId).html(data); }, |
|
403 | 402 | beforeSend: function(){ $this.addClass('ajax-loading'); }, |
|
404 | 403 | complete: function(){ $this.removeClass('ajax-loading'); } |
|
405 | 404 | }); |
|
406 | 405 | } |
|
407 | 406 | } |
|
408 | 407 | }; |
|
409 | 408 | var reset = function() { |
|
410 | 409 | if (timer) { |
|
411 | 410 | clearInterval(timer); |
|
412 | 411 | timer = setInterval(check, 300); |
|
413 | 412 | } |
|
414 | 413 | }; |
|
415 | 414 | var timer = setInterval(check, 300); |
|
416 | 415 | $this.bind('keyup click mousemove', reset); |
|
417 | 416 | }); |
|
418 | 417 | } |
|
419 | 418 | |
|
420 | 419 | function observeProjectModules() { |
|
421 | 420 | var f = function() { |
|
422 | 421 | /* Hides trackers and issues custom fields on the new project form when issue_tracking module is disabled */ |
|
423 | 422 | if ($('#project_enabled_module_names_issue_tracking').attr('checked')) { |
|
424 | 423 | $('#project_trackers').show(); |
|
425 | 424 | }else{ |
|
426 | 425 | $('#project_trackers').hide(); |
|
427 | 426 | } |
|
428 | 427 | }; |
|
429 | 428 | |
|
430 | 429 | $(window).load(f); |
|
431 | 430 | $('#project_enabled_module_names_issue_tracking').change(f); |
|
432 | 431 | } |
|
433 | 432 | |
|
434 | 433 | function initMyPageSortable(list, url) { |
|
435 | 434 | $('#list-'+list).sortable({ |
|
436 | 435 | connectWith: '.block-receiver', |
|
437 | 436 | tolerance: 'pointer', |
|
438 | 437 | update: function(){ |
|
439 | 438 | $.ajax({ |
|
440 | 439 | url: url, |
|
441 | 440 | type: 'post', |
|
442 | 441 | data: {'blocks': $.map($('#list-'+list).children(), function(el){return $(el).attr('id');})} |
|
443 | 442 | }); |
|
444 | 443 | } |
|
445 | 444 | }); |
|
446 | 445 | $("#list-top, #list-left, #list-right").disableSelection(); |
|
447 | 446 | } |
|
448 | 447 | |
|
449 | 448 | var warnLeavingUnsavedMessage; |
|
450 | 449 | function warnLeavingUnsaved(message) { |
|
451 | 450 | warnLeavingUnsavedMessage = message; |
|
452 | 451 | |
|
453 | 452 | $('form').submit(function(){ |
|
454 | 453 | $('textarea').removeData('changed'); |
|
455 | 454 | }); |
|
456 | 455 | $('textarea').change(function(){ |
|
457 | 456 | $(this).data('changed', 'changed'); |
|
458 | 457 | }); |
|
459 | 458 | window.onbeforeunload = function(){ |
|
460 | 459 | var warn = false; |
|
461 | 460 | $('textarea').blur().each(function(){ |
|
462 | 461 | if ($(this).data('changed')) { |
|
463 | 462 | warn = true; |
|
464 | 463 | } |
|
465 | 464 | }); |
|
466 | 465 | if (warn) {return warnLeavingUnsavedMessage;} |
|
467 | 466 | }; |
|
468 | 467 | }; |
|
469 | 468 | |
|
470 | 469 | $(document).ready(function(){ |
|
471 | 470 | $('#ajax-indicator').bind('ajaxSend', function(){ |
|
472 | 471 | if ($('.ajax-loading').length == 0) { |
|
473 | 472 | $('#ajax-indicator').show(); |
|
474 | 473 | } |
|
475 | 474 | }); |
|
476 | 475 | $('#ajax-indicator').bind('ajaxStop', function(){ |
|
477 | 476 | $('#ajax-indicator').hide(); |
|
478 | 477 | }); |
|
479 | 478 | }); |
|
480 | 479 | |
|
481 | 480 | function hideOnLoad() { |
|
482 | 481 | $('.hol').hide(); |
|
483 | 482 | } |
|
484 | 483 | |
|
485 | 484 | function addFormObserversForDoubleSubmit() { |
|
486 | 485 | $('form[method=post]').each(function() { |
|
487 | 486 | if (!$(this).hasClass('multiple-submit')) { |
|
488 | 487 | $(this).submit(function(form_submission) { |
|
489 | 488 | if ($(form_submission.target).attr('data-submitted')) { |
|
490 | 489 | form_submission.preventDefault(); |
|
491 | 490 | } else { |
|
492 | 491 | $(form_submission.target).attr('data-submitted', true); |
|
493 | 492 | } |
|
494 | 493 | }); |
|
495 | 494 | } |
|
496 | 495 | }); |
|
497 | 496 | } |
|
498 | 497 | |
|
499 | 498 | $(document).ready(hideOnLoad); |
|
500 | 499 | $(document).ready(addFormObserversForDoubleSubmit); |
General Comments 0
You need to be logged in to leave comments.
Login now