<?php $__env->startSection('content'); ?>
    <div class="row">
        <div class="col-md-10">
            <?php echo Form::open(); ?>

            <div class="form-group">
                <label for="addnew">Add New Post Types</label>
                <?php echo Form::text('addnew',null,['class'=>'form-control','placeholder'=>'Name of category']); ?>

            </div>
            <div class="form-group">
                <?php echo Form::submit('Add new category',['class'=>'btn btn-success']); ?>

            </div>
            <?php echo Form::close(); ?>



            <div class="page-header">
                <h3 class="content-heading">Current Types
                    <small>You can create as many type as needed, and rearrange them by dragging and dropping below.</small>
                </h3>
            </div>

            <div class='area' id='adminChannels'>
                <ol class='sortable list channelList list-group'>

                    <?php

                    $curDepth = 0;
                    $counter = 0;

                    foreach (\App\Jobshunt\Models\PostType::orderBy('lft', 'asc')->get() as $category):
                    if ($category->depth == $curDepth)
                    {
                        if ($counter > 0) echo "</li>";
                    }
                    elseif ($category->depth > $curDepth)
                    {
                        echo "<ol>";
                        $curDepth = $category->depth;
                    }
                    elseif ($category->depth < $curDepth)
                    {
                        echo str_repeat("</li></ol>", $curDepth - $category->depth), "</li>";
                        $curDepth = $category->depth;
                    }

                    ?>
                    <li id='channel_<?php echo e($category->id); ?>' data-id='<?php echo e($category->id); ?>' class="list-group-item mjs-nestedSortable-no-nesting" style="cursor: move">
                        <i class="fa fa-arrows-alt pull-left">&nbsp;</i>
                        <a href="" class="pull-right" data-toggle="modal" data-target="#categoryMode-<?php echo e($category->id); ?>"><i class="fa fa-edit pull-right" data-toggle="tooltip" data-placement="top" data-original-title="Click to edit this category"></i></a>

                        <div class='info'>
                            <span class='channel channel-1'><?php echo e($category->name); ?></span>
                        </div>

                    <?php $counter++; ?>

                    <?php endforeach;

                    echo str_repeat("</li></ol>", $curDepth), "</li>";
                    ?>
                </ol>
            </div>
        </div>

        <?php foreach(\App\Jobshunt\Models\PostType::orderBy('lft','asc')->get() as $category): ?>
            <div class="modal fade" id="categoryMode-<?php echo e($category->id); ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">Editing Category</h4>
                        </div>
                        <div class="modal-body">
                            <?php echo Form::open(['url'=>'admin/posttype/update']); ?>

                            <div class="form-group">
                                <?php echo Form::text('id',$category->id,['class'=>'hidden']); ?>

                                <label for="addnew">Category Name</label>
                                <?php echo Form::text('name',$category->name,['class'=>'form-control','placeholder'=>'Name of category','required'=>'required']); ?>

                            </div>


                            <div class="form-group">
                                <label for="slug">Slug ( url of category )
                                    <small>English characters are allowed in url, space is seperate by dash</small>
                                </label>
                                <?php echo Form::text('slug',$category->slug,['class'=>'form-control','placeholder'=>'Slug','required'=>'required']); ?>

                            </div>
                            <?php if($category->id == 1 || $category->name == 'Uncategorized'): ?>
                                <p>You can't delete this category, this is default category.</p>
                            <?php else: ?>
                                <div class="form-group">
                                    <label for="addnew">Delete this category
                                        <small> ( At your own risk )</small>
                                    </label><br/>
                                    <?php echo Form::checkbox('delete',true,false,['rel' => 'delete']); ?>

                                </div>
                            <?php endif; ?>
                            <div class="form-group">
                                <p><strong>Shift posts and users from this category to new category</strong></p>
                                <select name="shiftCategory" class="form-control" disabled rel="shiftToCategory">
                                    <?php foreach(\App\Jobshunt\Models\PostType::whereNotIn('id', [$category->id])->orderBy('lft','asc')->get() as $category): ?>
                                        <option value="<?php echo e($category->id); ?>"><?php echo e($category->name); ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </div>

                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                <?php echo Form::submit('Update',['class'=>'btn btn-success']); ?>

                                <?php echo Form::close(); ?>

                            </div>

                        </div>
                    </div>
                </div>
            </div>

        <?php endforeach; ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('extra-js'); ?>
            <script type="text/javascript">

                $(function () {
                    $("[rel=delete]").click(function () {
                        $("[rel=shiftToCategory]").attr("disabled", false);
                    });
                });
                $("#adminChannels .channelList").nestedSortable({
                    forcePlaceholderSize: true,
                    disableNestingClass: 'mjs-nestedSortable-no-nesting',
                    handle: 'div',
                    helper: 'clone',
                    items: 'li',
                    maxLevels: 0,
                    opacity: .6,
                    placeholder: 'placeholder',
                    revert: 250,
                    tabSize: 25,
                    tolerance: 'pointer',
                    toleranceElement: '> div',
                    update: function () {
                        $.ajax({
                            type: "POST",
                            url: "<?php echo e(url('admin/posttype/reorder')); ?>",
                            data: {tree: $("#adminChannels .channelList").nestedSortable("toArray", {startDepthCount: -1})},
                            globalLoading: true
                        });
                    }
                });

            </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin/master/index', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>