Sha256: d59b8da38c8993c7ae16b74f393d90c79d4eff4caff148322b5ebb3a1635770f

Contents?: true

Size: 1.66 KB

Versions: 15

Compression:

Stored size: 1.66 KB

Contents

var fixHelper;

fixHelper = function(e, ui) {
  ui.children().each(function() {
    return $(this).width($(this).width());
  });
  return ui;
};

function initSortables() {
  if ($(".sortables").length > 0) {
    $(".sortables").sortable({
      items: ".sortable",
      handle: ".handle",
      helper: fixHelper,
      forceHelperSize: true,
      start: function(e, ui) {
        ui.placeholder.height(ui.item.height());
      },
      update: function(e, ui) {
        if ($(this).data("rel") == null) {
          return;
        }
        var elem = ui.item
        return $.ajax({
          type: 'POST',
          url: $(this).data("rel"),
          dataType: 'json',
          data: $(this).sortable("serialize"),
          success: function(sortedArrayOfModelIds) { // eg ["4", "3", "1", "2"]
            $(elem).effect("highlight", {}, 1000);
            // If the the sorted element and its siblings have a child element with a
            // .sortable-position-for-model-id-X class, update the content of each
            // with the new position returned from the server.
            // This lets us display the new sort order position eg for each row in a table
            // without having to reload all the sortables.
            var parent = $(elem).parent(".sortables")
            for (var position = 0; position < sortedArrayOfModelIds.length; position++) {
              modelId = sortedArrayOfModelIds[position];
              var sortable = $(".sortable-position-for-model-id-" + modelId, parent);
              $(sortable, parent).html(position + 1);
            };
          }
        });
      }
    }).disableSelection();
  }
}

$(function() {
  initSortables();
});

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/assets/javascripts/renalware/components/sortable.js
renalware-core-2.1.0 app/assets/javascripts/renalware/components/sortable.js
renalware-core-2.0.167 app/assets/javascripts/renalware/components/sortable.js
renalware-core-2.0.166 app/assets/javascripts/renalware/components/sortable.js
renalware-core-2.0.165 app/assets/javascripts/renalware/components/sortable.js
renalware-core-2.0.164 app/assets/javascripts/renalware/components/sortable.js
renalware-core-2.0.163 app/assets/javascripts/renalware/components/sortable.js
renalware-core-2.0.162 app/assets/javascripts/renalware/components/sortable.js
renalware-core-2.0.161 app/assets/javascripts/renalware/components/sortable.js
renalware-core-2.0.160 app/assets/javascripts/renalware/components/sortable.js
renalware-core-2.0.159 app/assets/javascripts/renalware/components/sortable.js
renalware-core-2.0.158 app/assets/javascripts/renalware/components/sortable.js
renalware-core-2.0.157 app/assets/javascripts/renalware/components/sortable.js
renalware-core-2.0.156 app/assets/javascripts/renalware/components/sortable.js
renalware-core-2.0.155 app/assets/javascripts/renalware/components/sortable.js