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