PluginProbe
MaxButtons – Create buttons / 7.0
MaxButtons – Create buttons v7.0
6.23 6.24 6.25 6.26 6.26.1 6.27 6.28 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.1.1 7.1.2 7.1.3 7.10 7.11 7.13 7.13.1 7.13.2 7.13.3 All 100 releases
maxbuttons / js / maxbuttons-admin.js

maxbuttons-admin.js in MaxButtons – Create buttons 7.0, at js/maxbuttons-admin.js

855 lines 20.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 function maxAdmin()
2 {
3
4 //return this;
5 }
6 maxAdmin.prototype = {
7 //initialized: false,
8 colorUpdateTime: true,
9 fields: null,
10 button_id: null,
11 form_updated: false,
12 tabs: null,
13 }; // MaxAdmin
14
15 maxAdmin.prototype.init = function () {
16
17 this.button_id = $('input[name="button_id"]').val();
18 // Prevents the output button from being clickable (also in admin list view )
19 $(document).on('click', ".maxbutton-preview", function(e) { e.preventDefault(); });
20 $(document).on('click', '.output .preview-toggle', $.proxy(this.toggle_preview, this));
21
22 // overview input paging
23 $('#maxbuttons .input-paging').on('change', $.proxy(this.do_paging, this));
24
25 $('.manual-toggle').on('click', $.proxy(this.toggleManual, this));
26 $('.manual-entry').draggable({
27 cancel: 'p, li',
28 });
29
30 $(document).on('submit', 'form.mb_ajax_save', $.proxy(this.formAjaxSave, this));
31
32 // copy / delete / trash action buttons via ajax
33 $(document).on('click', '[data-buttonaction]', $.proxy(this.button_action, this ));
34
35 // conditionals
36 $(document).on('reInitConditionals', $.proxy(this.initConditionials, this));
37 this.initConditionials(); // conditional options
38 // range inputs
39
40 $(document).on('change, input', 'input[type="range"]', $.proxy(this.updateRange, this ));
41 this.updateRange(null);
42
43 /*
44 ****
45 ### After this only init for button main edit screen
46 ****
47
48 */
49 if ($('#new-button-form').length == 0)
50 return;
51
52
53 if (this.button_id > 0) {
54 $("#maxbuttons .mb-message").show();
55 }
56
57 this.initResponsive(); // responsive edit interface
58
59 $("#maxbuttons .output").draggable({
60 cancel: '.nodrag',
61 });
62
63 $('#maxbuttons .color-field').wpColorPicker(
64 {
65 width: 300,
66
67 change: $.proxy( _.throttle(function(event, ui) {
68 event.preventDefault();
69 var color = ui.color.toString();
70 this.update_color(event,ui, color);
71 }, 200), this),
72
73 }
74 );
75
76 /* Copy Color Interface */
77 $('.input.mbcolor .arrows').on('click', $.proxy(this.copyColor, this) );
78
79 $('#radius_toggle').on('click', $.proxy(this.toggleRadiusLock,this));
80
81 if ( typeof buttonFieldMap != 'undefined')
82 this.fields = $.parseJSON(buttonFieldMap);
83
84 // bind to all inputs, except for color-field or items with different handler.
85 $('#maxbuttons input').not('.color-field').on('keyup change', $.proxy(this.update_preview,this));
86 $('#maxbuttons input.color-field').on('focus', $.proxy(this.select_field, this));
87
88 $('#maxbuttons select').on('change', $.proxy(this.update_preview, this));
89
90 $(window).on('beforeunload', $.proxy(function () { if (this.form_updated) return maxajax.leave_page; }, this));
91 $(document).on('keyup', 'input', function (e) {
92
93 if (e.keyCode && e.keyCode == 13)
94 {
95 $(":input")[$(":input").index(document.activeElement) + 1].focus();
96 return false;
97 }
98 });
99
100 $(".button-save").click( $.proxy(function() {
101 this.saveIndicator(false); // prevent alert when saving.
102 $("#new-button-form").submit();
103 return false;
104 }, this) );
105
106 // Expand shortcode tabs for more examples.
107 $('.shortcode-expand').on('click', this.toggleShortcode);
108
109 }; // INIT
110
111
112 maxAdmin.prototype.repaint_preview = function ()
113 {
114 $('.mb_tab input[type="text"]').trigger('change');
115 $('.mb_tab input[type="number"]').trigger('change');
116 $('.mb_tab select').trigger('change');
117 $('.mb_tab input[type="hidden"]').trigger('change');
118 $('.mb_tab input[type="radio"]:checked').trigger('change');
119 $('.mb_tab input[type="checkbox"]:checked').trigger('change');
120
121 //$(document).trigger('colorUpdate', ['#text_color', $('#text_color').val() ]);
122 //$(document).trigger('colorUpdate', ['#text_color_hover', $('#text_color_hover').val() ]);
123
124 }
125
126 maxAdmin.prototype.update_preview = function(e)
127 {
128 e.preventDefault();
129
130 this.saveIndicator(true);
131 var target = $(e.target);
132
133 // migration to data field
134 var field = $(target).data('field');
135 if (typeof field == 'undefined')
136 var id = $(target).attr('id'); // this should change to be ready for the option to have two the same fields on multi locations.
137 else
138 var id = field;
139
140 var data = this.fields[id];
141
142 if (typeof data == 'undefined')
143 return; // field doesn't have updates
144
145 if (typeof data.css != 'undefined')
146 {
147 value = target.val();
148
149 if (typeof data.css_unit != 'undefined' && value.indexOf(data.css_unit) == -1)
150 value += data.css_unit;
151
152 // a target that is checkbox but not checked should unset (empty) value.
153 if (target.is(':checkbox') && ! target.is(':checked') )
154 value = '';
155
156 this.putCSS(data, value);
157 }
158 if (typeof data.attr !== 'undefined')
159 {
160 $('.output .result').find('a').attr(data.attr, target.val());
161 }
162 if (typeof data.func !== 'undefined')
163 {
164 var funcName = data.func;
165 var self = this;
166 if (funcName.indexOf('.') < 0)
167 {
168 funcName = 'self.' + funcName + '(target)';
169 }
170 else {
171 funcName = funcName + '(target)';
172 }
173
174 try
175 {
176 var callFunc = new Function ('target', 'self', funcName);
177 callFunc(target, this);
178 }
179 catch(err)
180 {
181 console.log(err);
182 }
183
184 }
185 };
186
187 maxAdmin.prototype.select_field = function(e)
188 {
189 $(e.target).select();
190 }
191
192 maxAdmin.prototype.button_action = function(e)
193 {
194 e.preventDefault();
195 var action = $(e.target).data('buttonaction');
196
197 this.form_updated = false;
198
199 var button_id = $(e.target).data('buttonid');
200 var nonce = $('input[name="' + action + '_nonce"]').val();
201
202 var url = maxajax.ajax_url;
203 var data =
204 {
205 action: 'mb_button_action',
206 button_action: action,
207 button_id: button_id,
208 nonce: nonce,
209
210 };
211
212 $.post({
213 url: url,
214 data: data,
215 success: function (data) {
216 response = JSON.parse(data);
217
218 if (typeof response.redirection != 'undefined')
219 {
220 window.location = response.redirection;
221 }
222 },
223 error: function () {
224 console.log('error in button action' + action);
225 },
226 });
227 }
228
229 /* Check the copy modal and display a warning if the button has been changes */
230 maxAdmin.prototype.checkCopyModal = function(modal)
231 {
232 if (this.form_updated)
233 {
234 modal.currentModal.find('.mb-message').show();
235
236 }
237 else
238 $(modal.currentModal).find('.mb-message').hide();
239 }
240
241 maxAdmin.prototype.toggle_preview = function (e)
242 {
243 if ( $('.output .inner').is(':hidden') )
244 {
245 $('.output .inner').show();
246 $('.output').css('height', 'auto');
247 $('.preview .preview-toggle').removeClass('dashicons-arrow-down').addClass('dashicons-arrow-up');
248 }
249 else
250 {
251 $('.output .inner').hide();
252 $('.output').css('height', 'auto');
253 $('.preview .preview-toggle').removeClass('dashicons-arrow-up').addClass('dashicons-arrow-down');
254 }
255 };
256
257
258 maxAdmin.prototype.putCSS = function(data,value,state)
259 {
260 state = state || 'both';
261
262 var element = '.maxbutton';
263 if (state == 'hover')
264 element = 'a.hover ';
265 else if(state == 'normal')
266 element = 'a.normal ';
267
268 if (typeof data.csspart != 'undefined')
269 {
270 var parts = data.csspart.split(",");
271 for(i=0; i < parts.length; i++)
272 {
273 var cpart = parts[i];
274 var fullpart = element + " ." + cpart;
275 $('.output .result').find(fullpart).css(data.css, value);
276 }
277 }
278 else
279 $('.output .result').find(element).css(data.css, value);
280 }
281
282 maxAdmin.prototype.update_color = function(event, ui, color)
283 {
284 event.preventDefault();
285 this.saveIndicator(true);
286
287 var target = $(event.target);
288 //var color = target.val();
289
290 if (color.indexOf('#') === -1)
291 color = '#' + color;
292
293 var id = target.attr('id');
294 $('#' + id).val(color); // otherwise field value is running 1 click behind.
295
296
297 if(id.indexOf('box_shadow') !== -1)
298 {
299 this.updateBoxShadow(target);
300 }
301 else if(id.indexOf('text_shadow') !== -1)
302 {
303 this.updateTextShadow(target);
304 }
305 else if (id.indexOf('gradient') !== -1)
306 {
307 if (id.indexOf('hover') == -1)
308 this.updateGradient();
309 else
310 this.updateGradient(true);
311 }
312 else if (id == 'button_preview')
313 {
314 $(".output .result").css('backgroundColor', color);
315 }
316 else // simple update
317 {
318
319 if (id.indexOf('hover') == -1)
320 {
321 state = 'normal';
322 }
323 else
324 {
325 state = 'hover';
326 }
327
328 var data = this.fields[id];
329
330 this.putCSS(data, color, state);
331 return;
332 }
333
334
335 };
336
337 maxAdmin.prototype.copyColor = function (e)
338 {
339 e.preventDefault();
340 e.stopPropagation(); // stop the color picker from closing itself.
341
342 var target = $(e.target);
343 var bindto = $(e.target).parents('[data-bind]');
344 var fieldId = '#' + bindto.data('id'); // Field which is used
345 var bindId = '#' + bindto.data('bind'); // Field is bound to.
346
347 // check which arrow was pressed
348 if (target.hasClass('arrow-right'))
349 var arrow_click = 'right';
350 else
351 var arrow_click = 'left';
352
353 // check on which side the interface is. If arrows are on right side, it's the left side (...)
354 if (bindto.hasClass('right') )
355 var if_side = 'left';
356 else
357 var if_side = 'right';
358
359 /* Decide which color to replace. If interface is left - then right click is copy to other element, but if interface is right, right is overwrite current element.
360 Left : right click - copy, left replace.
361 Right : right click - replace, left copy.
362 */
363 if (if_side == 'left')
364 {
365 if (arrow_click == 'right')
366 copy = true;
367 else
368 copy = false;
369 }
370 else if (if_side == 'right')
371 {
372 if (arrow_click == 'right')
373 copy = false;
374 else
375 copy = true;
376 }
377
378 if ( copy )
379 {
380 $(bindId).val( $(fieldId).val() );
381 $(bindId).trigger('change');
382 $(bindId).wpColorPicker('color', $(fieldId).val());
383 }
384 else
385 {
386 $(fieldId).val( $(bindId).val() );
387 $(fieldId).trigger('change');
388 $(fieldId).wpColorPicker('color', $(bindId).val());
389 }
390
391 }
392
393 maxAdmin.prototype.updateGradient = function(hover)
394 {
395 hover = hover || false;
396
397 var hovtarget = '';
398 if (hover)
399 hovtarget = "_hover";
400
401 var stop = parseInt($('#gradient_stop').val());
402
403 if (isNaN(stop) )
404 stop = 45;
405
406 var gradients_on = $('#use_gradient').prop('checked');
407
408 var start = this.hexToRgb($('#gradient_start_color' + hovtarget).val());
409 var end = this.hexToRgb($('#gradient_end_color' + hovtarget).val());
410 var startop = parseInt($('#gradient_start_opacity' + hovtarget).val());
411 var endop = parseInt($('#gradient_end_opacity' + hovtarget).val());
412
413 if (! gradients_on)
414 {
415 end = start;
416 endop = startop;
417 }
418
419 if(isNaN(startop)) startop = 100;
420 if(isNaN(endop)) endop = 100;
421
422 if (!hover)
423 var button = $('.output .result').find('a.normal');
424 else
425 var button = $('.output .result').find('a.hover');
426
427
428
429
430 button.css("background", "linear-gradient( rgba(" + start + "," + (startop/100) + ") " + stop + "%," + " rgba(" + end + "," + (endop/100) + ") )");
431 button.css("background", "-moz-linear-gradient( rgba(" + start + "," + (startop/100) + ") " + stop + "%," + " rgba(" + end + "," + (endop/100) + ") )");
432 button.css("background", "-o-linear-gradient( rgba(" + start + "," + (startop/100) + ") " + stop + "%," + " rgba(" + end + "," + (endop/100) + ") )");
433 button.css("background", "-webkit-gradient(linear, left top, left bottom, color-stop(" +stop+ "%, rgba(" + start + "," + (startop/100) + ")), color-stop(1, rgba(" + end + "," + (endop/100) + ") ));");
434
435
436 }
437
438 maxAdmin.prototype.hexToRgb = function(hex) {
439
440 hex = hex.replace('#','');
441 var bigint = parseInt(hex, 16);
442 var r = (bigint >> 16) & 255;
443 var g = (bigint >> 8) & 255;
444 var b = bigint & 255;
445
446 return r + "," + g + "," + b;
447 }
448
449 maxAdmin.prototype.updateBoxShadow = function (target)
450 {
451 target = target || null;
452
453 var left = $("#box_shadow_offset_left").val();
454 var top = $("#box_shadow_offset_top").val();
455 var width = $("#box_shadow_width").val();
456 var spread = $('#box_shadow_spread').val();
457
458 var color = $("#box_shadow_color").val();
459 var hovcolor = $("#box_shadow_color_hover").val();
460
461 $('.output .result').find('a.normal').css("boxShadow",left + 'px ' + top + 'px ' + width + 'px ' + spread + 'px ' + color);
462 $('.output .result').find('a.hover').css("boxShadow",left + 'px ' + top + 'px ' + width + 'px ' + spread + 'px ' + hovcolor);
463 }
464
465 maxAdmin.prototype.updateTextShadow = function(target,hover)
466 {
467 hover = hover || false;
468
469 var left = $("#text_shadow_offset_left").val();
470 var top = $("#text_shadow_offset_top").val();
471 var width = $("#text_shadow_width").val();
472
473 var color = $("#text_shadow_color").val();
474 var hovcolor = $("#text_shadow_color_hover").val();
475
476 var id = $(target).attr('id');
477 var data = this.fields[id];
478
479 data.css = 'textShadow';
480
481 var value = left + 'px ' + top + 'px ' + width + 'px ' + color;
482 this.putCSS(data, value, 'normal');
483
484 value = left + 'px ' + top + 'px ' + width + 'px ' + hovcolor;
485 this.putCSS(data, value, 'hover');
486
487 }
488
489 maxAdmin.prototype.updateAnchorText = function (target)
490 {
491 var preview_text = $('.output .result').find('a .mb-text');
492
493 // This can happen when the text is removed, button is saved, so the preview doesn't load the text element.
494 if (preview_text.length === 0)
495 {
496 $('.output .result').find('a').append('<span class="mb-text"></span>');
497 $('.output .result').find('a .mb-text').css({'display':'block','line-height':'1em','box-sizing':'border-box'});
498
499 this.repaint_preview();
500 }
501 $('.output .result').find('a .mb-text').text(target.val());
502 }
503
504 maxAdmin.prototype.updateGradientOpacity = function(target)
505 {
506 this.updateGradient(true);
507 this.updateGradient(false);
508 }
509
510 maxAdmin.prototype.updateDimension = function (target)
511 {
512 var dimension = $(target).val();
513 var id = $(target).attr('id');
514 var data = this.fields[id];
515 if (dimension > 0)
516 this.putCSS(data, dimension);
517 else
518 this.putCSS(data, 'auto');
519 }
520
521 maxAdmin.prototype.updateRadius = function(target)
522 {
523 var value = target.val();
524 var fields = ['radius_bottom_left', 'radius_bottom_right', 'radius_top_left', 'radius_top_right'];
525
526 if ( $('#radius_toggle').data('lock') == 'lock')
527 {
528 for(i=0; i < fields.length; i++)
529 {
530 var id = fields[i];
531 $('#' + id).val(value);
532 var data = this.fields[id];
533 this.putCSS(data,value + 'px');
534
535 }
536
537 }
538 }
539
540 maxAdmin.prototype.toggleRadiusLock = function (event)
541 {
542 var target = $(event.target);
543 var lock = $(target).data('lock');
544 if (lock == 'lock')
545 {
546 $(target).removeClass('dashicons-lock').addClass('dashicons-unlock');
547 $(target).data('lock', 'unlock');
548 }
549 else if (lock == 'unlock')
550 {
551 $(target).removeClass('dashicons-unlock').addClass('dashicons-lock');
552 $(target).data('lock', 'lock');
553 }
554
555 }
556
557
558 maxAdmin.prototype.initResponsive = function()
559 {
560
561 window.maxFoundry.maxadmin.responsive = new mbResponsive();
562 window.maxFoundry.maxadmin.responsive.init(this);
563
564 }
565
566
567 maxAdmin.prototype.do_paging = function(e)
568 {
569 var page = parseInt($(e.target).val());
570
571 if (page <= parseInt($(e.target).attr('max')) )
572 {
573 var url = $(e.target).data("url");
574 window.location = url + "&paged=" + page;
575
576 }
577 }
578
579
580 maxAdmin.prototype.toggleShortcode = function (e)
581 {
582 if ($('.shortcode-expand').hasClass('closed'))
583 {
584 $(' .mb-message.shortcode .expanded').css('display','inline-block');
585 $('.shortcode-expand span').removeClass('dashicons-arrow-down').addClass('dashicons-arrow-up');
586 $('.shortcode-expand').removeClass('closed').addClass('open');
587 }
588 else
589 {
590 $(' .mb-message.shortcode .expanded').css('display','none');
591 $('.shortcode-expand span').addClass('dashicons-arrow-down').removeClass('dashicons-arrow-up');
592 $('.shortcode-expand').addClass('closed').removeClass('open');
593 }
594
595 }
596
597 maxAdmin.prototype.toggleManual = function (e)
598 {
599 e.preventDefault();
600 var $target = $(e.target);
601
602 var subject = $target.data("target");
603 var $newWindow = $('.manual-entry[data-manual="' + subject + '"]');
604
605 if ($newWindow.is(':visible'))
606 {
607 $newWindow.hide();
608 return true;
609 }
610
611 var offset = $('[data-options="' + subject + '"]').position() ;
612 // top + height to position under manual link.
613 var top = offset.top + $target.height();
614
615 $newWindow.css('top', top);
616 $newWindow.css('right',15);
617 $newWindow.css('left', 'auto');
618
619 $newWindow.show();
620 }
621
622 maxAdmin.prototype.initConditionials = function ()
623 {
624 var mAP = this;
625 $('[data-show]').each(function () {
626 var condition = $(this).data('show');
627 var target = condition.target;
628 var values = condition.values;
629 var self = this;
630
631 $(document).on('change','[name="' + target + '"]', {child: this, values: values}, $.proxy(mAP.updateConditional, mAP) );
632
633 if ( $('[name="' + target + '"]').length > 1) // trigger change to test condition
634 {
635 $('[name="' + target + '"]:checked').trigger('change', ['conditional']); // radio / checkbox button
636 }
637 else {
638 $('[name="' + target + '"]').trigger('change', ['conditional']);
639 }
640 });
641
642 // problem here is fields having same target, will add the same event over and over //
643 // the target, input array, have a lot of input fields, which all receive the events. this is the issue.
644
645 var updatelist = [];
646
647 $('[data-has]').each(function () {
648 var condition = $(this).data('has');
649 var target = condition.target;
650 var values = condition.values;
651
652 $('[name="' + target + '"]').on('change', {target: target, child: this, values: values}, $.proxy(mAP.updateHasConditional, mAP) );
653
654 var targetdecl = '[name="' + target + '"]';
655 if (! $.inArray(targetdecl, updatelist));
656 updatelist.push(targetdecl);
657 });
658
659 if (updatelist.length > 0)
660 {
661 // the issue will a lot of event checking still exist..
662 $(updatelist.toString()).first().trigger('change', ['conditional']);
663 }
664
665 }
666
667 maxAdmin.prototype.updateConditional = function (event)
668 {
669 var data = event.data;
670 var cond_values = data.values;
671 var cond_child = data.child;
672
673 var target = $(event.currentTarget);
674 var value = $(target).val();
675
676 // if type = checkbox: cond_value checked means it has to be 'checked' to show. Otherwise 'unchecked' go hide.
677 if (target.attr('type') === 'checkbox')
678 {
679
680 var checked = $(target).prop('checked');
681
682 if (cond_values == 'checked' && checked)
683 value = 'checked';
684 else if (cond_values == 'unchecked' && !checked)
685 value = 'unchecked';
686 else
687 value = 0;
688 }
689
690 if (cond_values.indexOf(value) >= 0)
691 {
692
693 $(cond_child).fadeIn('fast');
694 $(cond_child).find('input, select').trigger('change');
695 }
696 else
697 {
698 $(cond_child).fadeOut('fast');
699 $(cond_child).find('input, select').trigger('change');
700 }
701 }
702
703 maxAdmin.prototype.updateHasConditional = function(event)
704 {
705 var mAP = this;
706 var data = event.data;
707
708 var cond_values = data.values;
709 var cond_child = data.child;
710
711 var target = data.target;
712
713 var hascond = false;
714
715 /** The issue here is to change this calls, to searches directly for value form cond_values ( mostly 1-3 options ) and not run the entire DOM each time.
716 */
717 var filter = [];
718 $(cond_values).each(function (el)
719 {
720
721 filter.push( '[value=' + this + ']');
722 } );
723
724 if ($('[name="' + target + '"]').filter( filter.toString() ).length > 0)
725 {
726 hascond = true;
727 }
728 else {
729 hascond = false
730 }
731
732 if (hascond)
733 {
734 $(cond_child).fadeIn('fast');
735 }
736 else
737 {
738 $(cond_child).fadeOut('fast');
739 }
740
741 }
742
743 maxAdmin.prototype.updateRange = function (event)
744 {
745 if (typeof event == 'undefined' || event === null )
746 {
747 var targets = $('input[type="range"]');
748 }
749 else
750 {
751 var targets = [event.target];
752 }
753
754 $(targets).each(function () {
755 var value = $(this).val();
756 $(this).parents('.input').find('.range_value output').val(value + '%');
757
758 });
759
760 }
761
762 maxAdmin.prototype.saveIndicator = function(toggle)
763 {
764
765 if (toggle)
766 this.form_updated = true;
767 else
768 this.form_updated = false;
769 }
770
771 // General AJAX form save
772 maxAdmin.prototype.formAjaxSave = function (e)
773 {
774 e.preventDefault();
775 var url = mb_ajax.ajaxurl;
776 var form = $(e.target);
777
778 var data = form.serialize();
779
780
781 $.ajax({
782 type: "POST",
783 url: url,
784 data: data,
785
786 }).done($.proxy(this.saveDone, this));
787 }
788
789 /*
790 maxAdmin.prototype.buttonSubmit = function (e)
791 {
792
793 e.preventDefault();
794 $('[data-form]').prop('disabled', true);
795 var formName = $(e.target).data('form');
796 $('#' + formName).submit();
797
798 }
799 */
800
801 maxAdmin.prototype.saveDone = function (res)
802 {
803 $('[data-form]').prop('disabled', false);
804
805 var json = $.parseJSON(res);
806
807 var result = json.result;
808 var title = json.title;
809
810
811 var collection_id = json.data.id;
812
813 if (typeof json.data.new_nonce !== 'undefined')
814 {
815 var nonce = json.data.new_nonce;
816 $('input[name="nonce"]').val(json.data.new_nonce);
817 }
818
819 if (result)
820 {
821 // if collection is new - add collection_id to the field
822 $('input[name="collection_id"]').val(collection_id);
823
824 // replace the location to the correct collection
825 var href = window.location.href;
826 if (href.indexOf('collection_id') === -1)
827 window.history.replaceState({}, '', href + '&collection_id=' + collection_id);
828
829 // trigger other updates if needed
830 $(document).trigger('mbFormSaved');
831
832 // update previous selection to current state;
833 var order = $('input[name="sorted"]').val();
834 $('input[name="previous_selection"]').val(order);
835
836 // in case the interface needs to be reloaded.
837 if (json.data.reload)
838 {
839 document.location.reload(true);
840 }
841
842 }
843 if (! result)
844 {
845 $modal = window.maxFoundry.maxModal;
846 $modal.newModal('collection_error');
847 $modal.setTitle(title);
848 $modal.setContent(json.body);
849
850 $modal.setControls('<button class="modal_close button-primary">' + json.close_text + '</button>');
851 $modal.show();
852
853 }
854 }
855