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

Version Path
navi-0.2.1 spec/dummy/app/assets/javascripts/menu_items/index.js
navi-0.2.0 spec/dummy/app/assets/javascripts/menu_items/index.js
navi-0.1.4 spec/dummy/app/assets/javascripts/menu_items/index.js
navi-0.1.3 spec/dummy/app/assets/javascripts/menu_items/index.js
navi-0.0.17 spec/dummy/public/javascripts/menu_items/index.js
navi-0.0.16 spec/dummy/public/javascripts/menu_items/index.js
navi-0.0.15 spec/dummy/public/javascripts/menu_items/index.js
navi-0.0.14 spec/dummy/public/javascripts/menu_items/index.js
navi-0.0.13 spec/dummy/public/javascripts/menu_items/index.js
navi-0.0.12 spec/dummy/public/javascripts/menu_items/index.js
navi-0.0.11 spec/dummy/public/javascripts/menu_items/index.js
navi-0.0.10 spec/dummy/public/javascripts/menu_items/index.js
navi-0.0.9 spec/dummy/public/javascripts/menu_items/index.js
navi-0.0.6 spec/dummy/public/javascripts/menu_items/index.js
navi-0.0.2 spec/dummy/public/javascripts/menu_items/index.js