<script type="text/javascript">
$(document).ready(function(){
  $('a.del_field').click(function(e){
    return confirm('{$mod->Lang('confirm_delete_field')}');
  });

  $('table#fieldlist > tbody').sortable({
    axis: 'y',
    cursor: 'move',
    stop: function(event,ui) {
      var data = $(this).sortable('serialize');
      $.ajax({
        data: data,
        type: 'POST',
        url:  '{module_action_link action='admin_order_fielddef' jsfriendly=1}'
      });
    }
  });
});
</script>

<div class="pageoptions">
  <a href="{$add_url}">{cgimage image='icons/system/newobject.gif'} {$mod->Lang('addfielddef')}</a>
</div>

{if isset($fielddefs) && count($fielddefs)}
  <table id="fieldlist" class="pagetable">
    <thead>
      <tr>
        <th>{$mod->Lang('id')}</th>
        <th>{$mod->Lang('name')}</th>
        <th>{$mod->Lang('type')}</th>
        <th>{$mod->Lang('prompt')}</th>
        <th>{$mod->Lang('required')}</th>
        <th class="pageicon">{* edit *}</th>
        <th class="pageicon">{* delete *}</th>
      </tr>
    </thead>
    <tbody>
    {foreach $fielddefs as $row}
      {module_action_link action='admin_edit_fielddef' op=edit fld=$row.id urlonly=1 assign='edit_url'}
      {module_action_link action='admin_edit_fielddef' op=del fld=$row.id urlonly=1 assign='del_url'}
      <tr id="fld_{$row.id}">
        <td><a href="{$edit_url}" title="{$mod->Lang('edit_fielddef')}">{$row.id}</a></td>
        <td><a href="{$edit_url}" title="{$mod->Lang('edit_fielddef')}">{$row.name}</a></td>
        <td>{$row.type}</td>
        <td>{$row.prompt}</td>
        <td>{if $row.required}{$mod->Lang('yes')}{/if}</td>
        <td><a href="{$edit_url}">{cgimage image='icons/system/edit.gif' alt=$mod->Lang('edit_fielddef')}</a></td>
        <td><a class="del_field" href="{$del_url}">{cgimage image='icons/system/delete.gif' alt=$mod->Lang('delete_fielddef')}</a></td>
      </tr>
    {/foreach}
    </tbody>
  </table>
{/if}