views:

391

answers:

0

Hello

I'm currently developing drag & drop menu management for my CMS, but I ran into a (hopfully) small problem.

My HTML code look like this (copied from Smarty):

<ul class="menu_items" name="parents" style="background-color:red">
{foreach from=$pages item=item}
    <li id="parent_{$item.id};" name="parent" title="{$item.id}">{$item.name}</li>
    <ul class="menu_items" name="{$item.id}" style="min-height:30px; background-color:yellow">
      {if $item.subpages}    
        {foreach from=$item.subpages item=subpage}
          <li id="{$item.id}_{$subpage.id};" name="{$item.id}" title="{$subpage.id}">{$subpage.name}</li
        {/foreach}
      {/if}
    </ul>
{/foreach}

And jQuery:

$('.menu_items li').each(function(){
 if($('ul',this).length)return;
 $('<ul></ul>').appendTo(this);
});
$('.menu_items,.menu_items ul').sortable({
  'connectWith':['.menu_items,.menu_items ul'],
  'tolerance':'pointer',
  'placeholder':'placeholder',
  'accepts': 'menu_items',
  'cursor':'pointer',
  'items':'li',
  'revert': true,
  receive: function(event, ui) { 
    alert(ui.attr('name'));
  },
  update : function (event,ui) {
    var dropped = $(this).attr('name');
    var itemText = ui.item.attr('name');
    var itemId = ui.item.attr('title');
    var serial = $(".menu_items").sortable('serialize');
    $.post("ajax_actions/pages.php", {action:'sortable',order:serial,type:itemText,itemid:itemId,dropped:dropped}, function(data) {
      $('#pages_list').html(data);
      pages_list();
    });
  }
 })

Whay I need is to get the elements (name) of the list item is being dropped to. I tryed to archive this with var dropped = $(this).attr('name'); but with no success.