Sha256: 1ca2aaebcba9ad8b46098e856dd336f7bb4444586c5b02f996565498e8b4a6f7

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

spud.admin.cms.menu_items = {};

(function() {
  var menu_items = spud.admin.cms.menu_items;
  var val;
  
  var setUrl = function(){
    return '/admin/menus/'+ val +'/menu_items/update_sort';
  };

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

  menu_items.updateStatus = function(delay, shadow) {
    if(!delay) { //Default 300ms delay if not provided
      delay = 300;
    }
    setTimeout(function() {
      $('.detail-wrapper').css({
        boxShadow: shadow
      });
    }, delay);
  };

  var sortableIcons = function() {
    $("#sort tbody").sortable({
      update : function(e, ui) {
        var sortArr = [];
        $("#sort tbody > tr > input").each(function() {
          sortArr.push($(this).attr('value'));
        });
        val = $("#menu-id").val();
        //Update order of menuItems
        $.ajax(setUrl(), { 
          method: 'PUT', 
          data: {
            order: sortArr
          }, 
          dataType: "json",
          success: function(data, status, jqXHR) {
            menu_items.updateStatus(200, '0px 0px 26px 2px rgba(4, 252, -49, 0.59)');
          },
          error: function(XMLHttpRequest, textStatus, errorThrown) {
            menu_items.updateStatus(100, '0px 0px 26px 2px rgba(255, 0, 40, 0.59)');
            alert("Status: " + textStatus); alert("Error: " + errorThrown); 
          }       
        });
      }
    });
  };

  menu_items.init = function() {
    $("#sort tbody").sortable({
      helper: fixHelper,
      cursor: "move",
      activate: function( event, ui ) {
        menu_items.updateStatus(100, '0px 0px 26px 2px rgba(4, 252, 255, 0.59)');
      }
    });
    sortableIcons();
  };

})();

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tb_cms-1.3.0 app/assets/javascripts/admin/cms/menu_items.js
tb_cms-1.3.beta1 app/assets/javascripts/admin/cms/menu_items.js