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