Sha256: 434da4f7014944a71e07519711d7e2e403914b2333f423964922da6cdc5e2a53

Contents?: true

Size: 1.32 KB

Versions: 105

Compression:

Stored size: 1.32 KB

Contents

var subtrees = null;

exports.init = function(){
  $('table#index_tree_table_pages tbody > tr')
    .not(':has(td.subtree)')
    .addClass('enabled');

  $('table#index_tree_table_pages tbody')
    .sortable({
      // axis:   "y",
      items:  "> tr.enabled",
      helper: fix_helper,
      update: on_update,
      start:  on_start,
      stop:   on_stop
    })
    .disableSelection();
};

function on_start(e, ui) {
  subtrees = ui.item.siblings(':has(td.subtree)');

  subtrees.each(function(){
    var _this = $(this), id;
    if (_this.prev()[0] == ui.placeholder[0]) {
      id = ui.helper.attr("id");
    } else {
      id = _this.prev().attr("id");
    }
    _this.data("prev-id", id);
  });

  subtrees.detach();
}

function on_stop(e, ui) {
  if (subtrees) {
    var p = $(e.target);

    subtrees.each(function(){
      var _this = $(this);
      var prev  = $("#"+_this.data("prev-id"),p);
      prev.first().after(_this);
    });

    subtrees = null;
  }
}

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

function on_update(e, ui) {
  var ids = [];

  $(e.target).children("tr.enabled").each(function(){
    ids.push($(this).data("id"));
  });

  $.ajax({
    type: "PUT",
    url:  window.location.href + "/order",
    data: {"ordered_ids":ids}
  });
}

Version data entries

105 entries across 105 versions & 1 rubygems

Version Path
lalala-4.1.0.dev.324 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.1.0.dev.322 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.1.0.dev.321 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.1.0.dev.318 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.1.0.dev.316 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.1.0.dev.314 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.0.0.dev.313 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.1.0.dev.309 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.1.0.dev.305 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.1.0.dev.299 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.0.0.dev.291 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.0.0.dev.288 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.0.0.dev.285 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.0.0.dev.284 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.0.0.dev.283 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.0.0.dev.279 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.0.0.dev.277 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.0.0.dev.275 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.0.0.dev.269 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js
lalala-4.0.0.dev.267 app/assets/javascripts/lalala/modules/sorted_pages_tree.module.js