Sha256: 3f81e26962274160b846b7349a4d2b812feadef3d30e5c38604b9152b9d1a523
Contents?: true
Size: 1.3 KB
Versions: 15
Compression:
Stored size: 1.3 KB
Contents
$(function() { sortable = $('ol.sortable'); sortable.nestedSortable({ disableNesting: 'no-nest', forcePlaceholderSize: true, handle: 'span', helper: 'clone', items: 'li', maxLevels: 3, opacity: .6, placeholder: 'placeholder', revert: 250, tabSize: 25, tolerance: 'pointer', toleranceElement: '> span' }); submitButton = $('#menu_item_tree input#save') submitButton.click(function(event){ $(this).data('original_val', $(this).val()); // Disable the button for a moment $(this).attr('disabled', 'disabled').val("Saving..."); }); // Instead of sending via a custom ajax request, // Just add the serialized data to the button_to form // which was generated by Rails with the button_to helper // This way, we will piggyback on the PUT to the widget form = $('#menu_item_tree form.button_to'); form.live('ajax:beforeSend', function(event, xhr, settings) { settings.data += "&" + sortable.nestedSortable('serialize'); }); form.live('ajax:success', function(xhr, status) { submitButton.attr('disabled', false).val(submitButton.data('original_val')); }); form.live('ajax:error', function(xhr, status) { submitButton.attr('disabled', false).val(submitButton.data('original_val')); alert("There was an error. Try again"); }); });
Version data entries
15 entries across 15 versions & 1 rubygems