<?php $url = str_replace('admin.', '', $request->base()); ?>
<div class="clear">
    <?php foreach ($item as $i) : ?>
        <div class="icon" id="menu_item_<?php echo htmlspecialchars($i['id']); ?>">
            <div class="content">
                <a href="menu_item/edit/<?php echo htmlspecialchars($i['id']); ?>" title="<?php echo htmlspecialchars($i['name']); ?>">
                    <img src="admin/skin/icon/file3.png" /><br /><?php echo htmlspecialchars((strlen($i['name']) > 20) ? substr($i['name'], 0, 17) . '...' : $i['name']); ?>
                </a>
            </div>
            <div class="action">
                <?php
                $view = $url;
                
                if ($i['menu_item_type_id'] == 1) {
                    if (preg_match('/^https?:\/\//i', $i['data']->url)) {
                        $view = $i['data']->url;
                    } else {
                        $view .= $i['data']->url;
                    }
                } else {
                    $view .= $i['alias'];
                }
                ?>
                <a target="_blank" href="<?php echo htmlspecialchars($view); ?>">View</a>
                <a href="menu_item/edit/<?php echo htmlspecialchars($i['id']); ?>">Edit</a>
                <a href="meta/edit/menu_item/<?php echo urlencode($i['id']); ?>" class="<?php if (!$i['meta']) : echo 'missing'; endif; ?>">Meta</a>
                <a href="javascript:delete_menu_item(<?php echo htmlspecialchars($i['id']); ?>);">Delete</a>
            </div>
        </div>
    <?php endforeach; ?>
</div>

<script type="text/javascript">
    function delete_menu_item(id)
    {
        if (confirm('Are you sure?'))
        {
            $.post('menu_item/delete', { id:id },
                function(data, status) {
                    if (data.error != '')
                    {
                        alert(data.error);
                    }
                    else
                    {
                        $('#menu_item_' + id).remove();
                    }
                }, 'json');
        }
    }
</script>