##// END OF EJS Templates
Allow only vertical reorderingin sortable lists (#24062)....
Jean-Philippe Lang -
r15614:b0f89e68f44c
parent child
Show More
@@ -1,851 +1,852
1 1 /* Redmine - project management software
2 2 Copyright (C) 2006-2016 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 if (filterValue.length == 3) {
179 179 var optgroup = select.find('optgroup').filter(function(){return $(this).attr('label') == filterValue[2]});
180 180 if (!optgroup.length) {optgroup = $('<optgroup>').attr('label', filterValue[2]);}
181 181 option = optgroup.append(option);
182 182 }
183 183 } else {
184 184 option.val(filterValue).text(filterValue);
185 185 if ($.inArray(filterValue, values) > -1) {option.attr('selected', true);}
186 186 }
187 187 select.append(option);
188 188 }
189 189 break;
190 190 case "date":
191 191 case "date_past":
192 192 tr.find('td.values').append(
193 193 '<span style="display:none;"><input type="date" name="v['+field+'][]" id="values_'+fieldId+'_1" size="10" class="value date_value" /></span>' +
194 194 ' <span style="display:none;"><input type="date" name="v['+field+'][]" id="values_'+fieldId+'_2" size="10" class="value date_value" /></span>' +
195 195 ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="3" class="value" /> '+labelDayPlural+'</span>'
196 196 );
197 197 $('#values_'+fieldId+'_1').val(values[0]).datepickerFallback(datepickerOptions);
198 198 $('#values_'+fieldId+'_2').val(values[1]).datepickerFallback(datepickerOptions);
199 199 $('#values_'+fieldId).val(values[0]);
200 200 break;
201 201 case "string":
202 202 case "text":
203 203 tr.find('td.values').append(
204 204 '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="30" class="value" /></span>'
205 205 );
206 206 $('#values_'+fieldId).val(values[0]);
207 207 break;
208 208 case "relation":
209 209 tr.find('td.values').append(
210 210 '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="6" class="value" /></span>' +
211 211 '<span style="display:none;"><select class="value" name="v['+field+'][]" id="values_'+fieldId+'_1"></select></span>'
212 212 );
213 213 $('#values_'+fieldId).val(values[0]);
214 214 select = tr.find('td.values select');
215 215 for (i = 0; i < allProjects.length; i++) {
216 216 var filterValue = allProjects[i];
217 217 var option = $('<option>');
218 218 option.val(filterValue[1]).text(filterValue[0]);
219 219 if (values[0] == filterValue[1]) { option.attr('selected', true); }
220 220 select.append(option);
221 221 }
222 222 break;
223 223 case "integer":
224 224 case "float":
225 225 case "tree":
226 226 tr.find('td.values').append(
227 227 '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="14" class="value" /></span>' +
228 228 ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="14" class="value" /></span>'
229 229 );
230 230 $('#values_'+fieldId+'_1').val(values[0]);
231 231 $('#values_'+fieldId+'_2').val(values[1]);
232 232 break;
233 233 }
234 234 }
235 235
236 236 function toggleFilter(field) {
237 237 var fieldId = field.replace('.', '_');
238 238 if ($('#cb_' + fieldId).is(':checked')) {
239 239 $("#operators_" + fieldId).show().removeAttr('disabled');
240 240 toggleOperator(field);
241 241 } else {
242 242 $("#operators_" + fieldId).hide().attr('disabled', true);
243 243 enableValues(field, []);
244 244 }
245 245 }
246 246
247 247 function enableValues(field, indexes) {
248 248 var fieldId = field.replace('.', '_');
249 249 $('#tr_'+fieldId+' td.values .value').each(function(index) {
250 250 if ($.inArray(index, indexes) >= 0) {
251 251 $(this).removeAttr('disabled');
252 252 $(this).parents('span').first().show();
253 253 } else {
254 254 $(this).val('');
255 255 $(this).attr('disabled', true);
256 256 $(this).parents('span').first().hide();
257 257 }
258 258
259 259 if ($(this).hasClass('group')) {
260 260 $(this).addClass('open');
261 261 } else {
262 262 $(this).show();
263 263 }
264 264 });
265 265 }
266 266
267 267 function toggleOperator(field) {
268 268 var fieldId = field.replace('.', '_');
269 269 var operator = $("#operators_" + fieldId);
270 270 switch (operator.val()) {
271 271 case "!*":
272 272 case "*":
273 273 case "t":
274 274 case "ld":
275 275 case "w":
276 276 case "lw":
277 277 case "l2w":
278 278 case "m":
279 279 case "lm":
280 280 case "y":
281 281 case "o":
282 282 case "c":
283 283 case "*o":
284 284 case "!o":
285 285 enableValues(field, []);
286 286 break;
287 287 case "><":
288 288 enableValues(field, [0,1]);
289 289 break;
290 290 case "<t+":
291 291 case ">t+":
292 292 case "><t+":
293 293 case "t+":
294 294 case ">t-":
295 295 case "<t-":
296 296 case "><t-":
297 297 case "t-":
298 298 enableValues(field, [2]);
299 299 break;
300 300 case "=p":
301 301 case "=!p":
302 302 case "!p":
303 303 enableValues(field, [1]);
304 304 break;
305 305 default:
306 306 enableValues(field, [0]);
307 307 break;
308 308 }
309 309 }
310 310
311 311 function toggleMultiSelect(el) {
312 312 if (el.attr('multiple')) {
313 313 el.removeAttr('multiple');
314 314 el.attr('size', 1);
315 315 } else {
316 316 el.attr('multiple', true);
317 317 if (el.children().length > 10)
318 318 el.attr('size', 10);
319 319 else
320 320 el.attr('size', 4);
321 321 }
322 322 }
323 323
324 324 function showTab(name, url) {
325 325 $('#tab-content-' + name).parent().find('.tab-content').hide();
326 326 $('#tab-content-' + name).parent().find('div.tabs a').removeClass('selected');
327 327 $('#tab-content-' + name).show();
328 328 $('#tab-' + name).addClass('selected');
329 329 //replaces current URL with the "href" attribute of the current link
330 330 //(only triggered if supported by browser)
331 331 if ("replaceState" in window.history) {
332 332 window.history.replaceState(null, document.title, url);
333 333 }
334 334 return false;
335 335 }
336 336
337 337 function moveTabRight(el) {
338 338 var lis = $(el).parents('div.tabs').first().find('ul').children();
339 339 var bw = $(el).parents('div.tabs-buttons').outerWidth(true);
340 340 var tabsWidth = 0;
341 341 var i = 0;
342 342 lis.each(function() {
343 343 if ($(this).is(':visible')) {
344 344 tabsWidth += $(this).outerWidth(true);
345 345 }
346 346 });
347 347 if (tabsWidth < $(el).parents('div.tabs').first().width() - bw) { return; }
348 348 $(el).siblings('.tab-left').removeClass('disabled');
349 349 while (i<lis.length && !lis.eq(i).is(':visible')) { i++; }
350 350 var w = lis.eq(i).width();
351 351 lis.eq(i).hide();
352 352 if (tabsWidth - w < $(el).parents('div.tabs').first().width() - bw) {
353 353 $(el).addClass('disabled');
354 354 }
355 355 }
356 356
357 357 function moveTabLeft(el) {
358 358 var lis = $(el).parents('div.tabs').first().find('ul').children();
359 359 var i = 0;
360 360 while (i < lis.length && !lis.eq(i).is(':visible')) { i++; }
361 361 if (i > 0) {
362 362 lis.eq(i-1).show();
363 363 $(el).siblings('.tab-right').removeClass('disabled');
364 364 }
365 365 if (i <= 1) {
366 366 $(el).addClass('disabled');
367 367 }
368 368 }
369 369
370 370 function displayTabsButtons() {
371 371 var lis;
372 372 var tabsWidth;
373 373 var el;
374 374 var numHidden;
375 375 $('div.tabs').each(function() {
376 376 el = $(this);
377 377 lis = el.find('ul').children();
378 378 tabsWidth = 0;
379 379 numHidden = 0;
380 380 lis.each(function(){
381 381 if ($(this).is(':visible')) {
382 382 tabsWidth += $(this).outerWidth(true);
383 383 } else {
384 384 numHidden++;
385 385 }
386 386 });
387 387 var bw = $(el).parents('div.tabs-buttons').outerWidth(true);
388 388 if ((tabsWidth < el.width() - bw) && (lis.length === 0 || lis.first().is(':visible'))) {
389 389 el.find('div.tabs-buttons').hide();
390 390 } else {
391 391 el.find('div.tabs-buttons').show().children('button.tab-left').toggleClass('disabled', numHidden == 0);
392 392 }
393 393 });
394 394 }
395 395
396 396 function setPredecessorFieldsVisibility() {
397 397 var relationType = $('#relation_relation_type');
398 398 if (relationType.val() == "precedes" || relationType.val() == "follows") {
399 399 $('#predecessor_fields').show();
400 400 } else {
401 401 $('#predecessor_fields').hide();
402 402 }
403 403 }
404 404
405 405 function showModal(id, width, title) {
406 406 var el = $('#'+id).first();
407 407 if (el.length === 0 || el.is(':visible')) {return;}
408 408 if (!title) title = el.find('h3.title').text();
409 409 // moves existing modals behind the transparent background
410 410 $(".modal").zIndex(99);
411 411 el.dialog({
412 412 width: width,
413 413 modal: true,
414 414 resizable: false,
415 415 dialogClass: 'modal',
416 416 title: title
417 417 }).on('dialogclose', function(){
418 418 $(".modal").zIndex(101);
419 419 });
420 420 el.find("input[type=text], input[type=submit]").first().focus();
421 421 }
422 422
423 423 function hideModal(el) {
424 424 var modal;
425 425 if (el) {
426 426 modal = $(el).parents('.ui-dialog-content');
427 427 } else {
428 428 modal = $('#ajax-modal');
429 429 }
430 430 modal.dialog("close");
431 431 }
432 432
433 433 function submitPreview(url, form, target) {
434 434 $.ajax({
435 435 url: url,
436 436 type: 'post',
437 437 data: $('#'+form).serialize(),
438 438 success: function(data){
439 439 $('#'+target).html(data);
440 440 }
441 441 });
442 442 }
443 443
444 444 function collapseScmEntry(id) {
445 445 $('.'+id).each(function() {
446 446 if ($(this).hasClass('open')) {
447 447 collapseScmEntry($(this).attr('id'));
448 448 }
449 449 $(this).hide();
450 450 });
451 451 $('#'+id).removeClass('open');
452 452 }
453 453
454 454 function expandScmEntry(id) {
455 455 $('.'+id).each(function() {
456 456 $(this).show();
457 457 if ($(this).hasClass('loaded') && !$(this).hasClass('collapsed')) {
458 458 expandScmEntry($(this).attr('id'));
459 459 }
460 460 });
461 461 $('#'+id).addClass('open');
462 462 }
463 463
464 464 function scmEntryClick(id, url) {
465 465 var el = $('#'+id);
466 466 if (el.hasClass('open')) {
467 467 collapseScmEntry(id);
468 468 el.addClass('collapsed');
469 469 return false;
470 470 } else if (el.hasClass('loaded')) {
471 471 expandScmEntry(id);
472 472 el.removeClass('collapsed');
473 473 return false;
474 474 }
475 475 if (el.hasClass('loading')) {
476 476 return false;
477 477 }
478 478 el.addClass('loading');
479 479 $.ajax({
480 480 url: url,
481 481 success: function(data) {
482 482 el.after(data);
483 483 el.addClass('open').addClass('loaded').removeClass('loading');
484 484 }
485 485 });
486 486 return true;
487 487 }
488 488
489 489 function randomKey(size) {
490 490 var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
491 491 var key = '';
492 492 for (var i = 0; i < size; i++) {
493 493 key += chars.charAt(Math.floor(Math.random() * chars.length));
494 494 }
495 495 return key;
496 496 }
497 497
498 498 function updateIssueFrom(url, el) {
499 499 $('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){
500 500 $(this).data('valuebeforeupdate', $(this).val());
501 501 });
502 502 if (el) {
503 503 $("#form_update_triggered_by").val($(el).attr('id'));
504 504 }
505 505 return $.ajax({
506 506 url: url,
507 507 type: 'post',
508 508 data: $('#issue-form').serialize()
509 509 });
510 510 }
511 511
512 512 function replaceIssueFormWith(html){
513 513 var replacement = $(html);
514 514 $('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){
515 515 var object_id = $(this).attr('id');
516 516 if (object_id && $(this).data('valuebeforeupdate')!=$(this).val()) {
517 517 replacement.find('#'+object_id).val($(this).val());
518 518 }
519 519 });
520 520 $('#all_attributes').empty();
521 521 $('#all_attributes').prepend(replacement);
522 522 }
523 523
524 524 function updateBulkEditFrom(url) {
525 525 $.ajax({
526 526 url: url,
527 527 type: 'post',
528 528 data: $('#bulk_edit_form').serialize()
529 529 });
530 530 }
531 531
532 532 function observeAutocompleteField(fieldId, url, options) {
533 533 $(document).ready(function() {
534 534 $('#'+fieldId).autocomplete($.extend({
535 535 source: url,
536 536 minLength: 2,
537 537 position: {collision: "flipfit"},
538 538 search: function(){$('#'+fieldId).addClass('ajax-loading');},
539 539 response: function(){$('#'+fieldId).removeClass('ajax-loading');}
540 540 }, options));
541 541 $('#'+fieldId).addClass('autocomplete');
542 542 });
543 543 }
544 544
545 545 function observeSearchfield(fieldId, targetId, url) {
546 546 $('#'+fieldId).each(function() {
547 547 var $this = $(this);
548 548 $this.addClass('autocomplete');
549 549 $this.attr('data-value-was', $this.val());
550 550 var check = function() {
551 551 var val = $this.val();
552 552 if ($this.attr('data-value-was') != val){
553 553 $this.attr('data-value-was', val);
554 554 $.ajax({
555 555 url: url,
556 556 type: 'get',
557 557 data: {q: $this.val()},
558 558 success: function(data){ if(targetId) $('#'+targetId).html(data); },
559 559 beforeSend: function(){ $this.addClass('ajax-loading'); },
560 560 complete: function(){ $this.removeClass('ajax-loading'); }
561 561 });
562 562 }
563 563 };
564 564 var reset = function() {
565 565 if (timer) {
566 566 clearInterval(timer);
567 567 timer = setInterval(check, 300);
568 568 }
569 569 };
570 570 var timer = setInterval(check, 300);
571 571 $this.bind('keyup click mousemove', reset);
572 572 });
573 573 }
574 574
575 575 $(document).ready(function(){
576 576 $(".drdn .autocomplete").val('');
577 577
578 578 $(".drdn-trigger").click(function(e){
579 579 var drdn = $(this).closest(".drdn");
580 580 if (drdn.hasClass("expanded")) {
581 581 drdn.removeClass("expanded");
582 582 } else {
583 583 $(".drdn").removeClass("expanded");
584 584 drdn.addClass("expanded");
585 585 if (!isMobile()) {
586 586 drdn.find(".autocomplete").focus();
587 587 }
588 588 e.stopPropagation();
589 589 }
590 590 });
591 591 $(document).click(function(e){
592 592 if ($(e.target).closest(".drdn").length < 1) {
593 593 $(".drdn.expanded").removeClass("expanded");
594 594 }
595 595 });
596 596
597 597 observeSearchfield('projects-quick-search', null, $('#projects-quick-search').data('automcomplete-url'));
598 598
599 599 $(".drdn-content").keydown(function(event){
600 600 var items = $(this).find(".drdn-items");
601 601 var focused = items.find("a:focus");
602 602 switch (event.which) {
603 603 case 40: //down
604 604 if (focused.length > 0) {
605 605 focused.nextAll("a").first().focus();;
606 606 } else {
607 607 items.find("a").first().focus();;
608 608 }
609 609 event.preventDefault();
610 610 break;
611 611 case 38: //up
612 612 if (focused.length > 0) {
613 613 var prev = focused.prevAll("a");
614 614 if (prev.length > 0) {
615 615 prev.first().focus();
616 616 } else {
617 617 $(this).find(".autocomplete").focus();
618 618 }
619 619 event.preventDefault();
620 620 }
621 621 break;
622 622 case 35: //end
623 623 if (focused.length > 0) {
624 624 focused.nextAll("a").last().focus();
625 625 event.preventDefault();
626 626 }
627 627 break;
628 628 case 36: //home
629 629 if (focused.length > 0) {
630 630 focused.prevAll("a").last().focus();
631 631 event.preventDefault();
632 632 }
633 633 break;
634 634 }
635 635 });
636 636 });
637 637
638 638 function beforeShowDatePicker(input, inst) {
639 639 var default_date = null;
640 640 switch ($(input).attr("id")) {
641 641 case "issue_start_date" :
642 642 if ($("#issue_due_date").size() > 0) {
643 643 default_date = $("#issue_due_date").val();
644 644 }
645 645 break;
646 646 case "issue_due_date" :
647 647 if ($("#issue_start_date").size() > 0) {
648 648 var start_date = $("#issue_start_date").val();
649 649 if (start_date != "") {
650 650 start_date = new Date(Date.parse(start_date));
651 651 if (start_date > new Date()) {
652 652 default_date = $("#issue_start_date").val();
653 653 }
654 654 }
655 655 }
656 656 break;
657 657 }
658 658 $(input).datepickerFallback("option", "defaultDate", default_date);
659 659 }
660 660
661 661 (function($){
662 662 $.fn.positionedItems = function(sortableOptions, options){
663 663 var settings = $.extend({
664 664 firstPosition: 1
665 665 }, options );
666 666
667 667 return this.sortable($.extend({
668 axis: 'y',
668 669 handle: ".sort-handle",
669 670 helper: function(event, ui){
670 671 ui.children('td').each(function(){
671 672 $(this).width($(this).width());
672 673 });
673 674 return ui;
674 675 },
675 676 update: function(event, ui) {
676 677 var sortable = $(this);
677 678 var handle = ui.item.find(".sort-handle").addClass("ajax-loading");
678 679 var url = handle.data("reorder-url");
679 680 var param = handle.data("reorder-param");
680 681 var data = {};
681 682 data[param] = {position: ui.item.index() + settings['firstPosition']};
682 683 $.ajax({
683 684 url: url,
684 685 type: 'put',
685 686 dataType: 'script',
686 687 data: data,
687 688 success: function(data){
688 689 sortable.children(":even").removeClass("even").addClass("odd");
689 690 sortable.children(":odd").removeClass("odd").addClass("even");
690 691 },
691 692 error: function(jqXHR, textStatus, errorThrown){
692 693 alert(jqXHR.status);
693 694 sortable.sortable("cancel");
694 695 },
695 696 complete: function(jqXHR, textStatus, errorThrown){
696 697 handle.removeClass("ajax-loading");
697 698 }
698 699 });
699 700 },
700 701 }, sortableOptions));
701 702 }
702 703 }( jQuery ));
703 704
704 705 function initMyPageSortable(list, url) {
705 706 $('#list-'+list).sortable({
706 707 connectWith: '.block-receiver',
707 708 tolerance: 'pointer',
708 709 update: function(){
709 710 $.ajax({
710 711 url: url,
711 712 type: 'post',
712 713 data: {'blocks': $.map($('#list-'+list).children(), function(el){return $(el).attr('id');})}
713 714 });
714 715 }
715 716 });
716 717 $("#list-top, #list-left, #list-right").disableSelection();
717 718 }
718 719
719 720 var warnLeavingUnsavedMessage;
720 721 function warnLeavingUnsaved(message) {
721 722 warnLeavingUnsavedMessage = message;
722 723 $(document).on('submit', 'form', function(){
723 724 $('textarea').removeData('changed');
724 725 });
725 726 $(document).on('change', 'textarea', function(){
726 727 $(this).data('changed', 'changed');
727 728 });
728 729 window.onbeforeunload = function(){
729 730 var warn = false;
730 731 $('textarea').blur().each(function(){
731 732 if ($(this).data('changed')) {
732 733 warn = true;
733 734 }
734 735 });
735 736 if (warn) {return warnLeavingUnsavedMessage;}
736 737 };
737 738 }
738 739
739 740 function setupAjaxIndicator() {
740 741 $(document).bind('ajaxSend', function(event, xhr, settings) {
741 742 if ($('.ajax-loading').length === 0 && settings.contentType != 'application/octet-stream') {
742 743 $('#ajax-indicator').show();
743 744 }
744 745 });
745 746 $(document).bind('ajaxStop', function() {
746 747 $('#ajax-indicator').hide();
747 748 });
748 749 }
749 750
750 751 function setupTabs() {
751 752 if($('.tabs').length > 0) {
752 753 displayTabsButtons();
753 754 $(window).resize(displayTabsButtons);
754 755 }
755 756 }
756 757
757 758 function hideOnLoad() {
758 759 $('.hol').hide();
759 760 }
760 761
761 762 function addFormObserversForDoubleSubmit() {
762 763 $('form[method=post]').each(function() {
763 764 if (!$(this).hasClass('multiple-submit')) {
764 765 $(this).submit(function(form_submission) {
765 766 if ($(form_submission.target).attr('data-submitted')) {
766 767 form_submission.preventDefault();
767 768 } else {
768 769 $(form_submission.target).attr('data-submitted', true);
769 770 }
770 771 });
771 772 }
772 773 });
773 774 }
774 775
775 776 function defaultFocus(){
776 777 if (($('#content :focus').length == 0) && (window.location.hash == '')) {
777 778 $('#content input[type=text], #content textarea').first().focus();
778 779 }
779 780 }
780 781
781 782 function blockEventPropagation(event) {
782 783 event.stopPropagation();
783 784 event.preventDefault();
784 785 }
785 786
786 787 function toggleDisabledOnChange() {
787 788 var checked = $(this).is(':checked');
788 789 $($(this).data('disables')).attr('disabled', checked);
789 790 $($(this).data('enables')).attr('disabled', !checked);
790 791 $($(this).data('shows')).toggle(checked);
791 792 }
792 793 function toggleDisabledInit() {
793 794 $('input[data-disables], input[data-enables], input[data-shows]').each(toggleDisabledOnChange);
794 795 }
795 796
796 797 function toggleNewObjectDropdown() {
797 798 var dropdown = $('#new-object + ul.menu-children');
798 799 if(dropdown.hasClass('visible')){
799 800 dropdown.removeClass('visible');
800 801 }else{
801 802 dropdown.addClass('visible');
802 803 }
803 804 }
804 805
805 806 (function ( $ ) {
806 807
807 808 // detect if native date input is supported
808 809 var nativeDateInputSupported = true;
809 810
810 811 var input = document.createElement('input');
811 812 input.setAttribute('type','date');
812 813 if (input.type === 'text') {
813 814 nativeDateInputSupported = false;
814 815 }
815 816
816 817 var notADateValue = 'not-a-date';
817 818 input.setAttribute('value', notADateValue);
818 819 if (input.value === notADateValue) {
819 820 nativeDateInputSupported = false;
820 821 }
821 822
822 823 $.fn.datepickerFallback = function( options ) {
823 824 if (nativeDateInputSupported) {
824 825 return this;
825 826 } else {
826 827 return this.datepicker( options );
827 828 }
828 829 };
829 830 }( jQuery ));
830 831
831 832 $(document).ready(function(){
832 833 $('#content').on('change', 'input[data-disables], input[data-enables], input[data-shows]', toggleDisabledOnChange);
833 834 toggleDisabledInit();
834 835 });
835 836
836 837 function keepAnchorOnSignIn(form){
837 838 var hash = decodeURIComponent(self.document.location.hash);
838 839 if (hash) {
839 840 if (hash.indexOf("#") === -1) {
840 841 hash = "#" + hash;
841 842 }
842 843 form.action = form.action + hash;
843 844 }
844 845 return true;
845 846 }
846 847
847 848 $(document).ready(setupAjaxIndicator);
848 849 $(document).ready(hideOnLoad);
849 850 $(document).ready(addFormObserversForDoubleSubmit);
850 851 $(document).ready(defaultFocus);
851 852 $(document).ready(setupTabs);
General Comments 0
You need to be logged in to leave comments. Login now