@if(!defined('LOAD_NESTABLE'))
    @push('scripts')
        <script src="{{ asset('/assets/plugins/nestable2/jquery.nestable.min.js') }}"></script>

        <script>

			function getPrevious(id, tree)
			{
				var next = _.find(tree, {'id': id}).right + 1;
				var before = _.find(tree, {'left': next});
				return (typeof(before) != 'undefined') ? before.id : false;
			}

			function getAfter(id, tree)
			{
				var previous = _.find(tree, {'id': id}).left - 1;
				var after = _.find(tree, {'right': previous});
				return (typeof(after) != 'undefined') ? after.id : false;
			}

			function nestable_move(id, l, moveBefore, moveAfter, callback) {
				var target_id = getPrevious(id, l.nestable('toArray'));
				if (target_id) {
					var url = moveBefore;
				} else {
					var target_id = getAfter(id, l.nestable('toArray'));
					var url = moveAfter;
				}

				if (target_id) {
					$.ajax({
						url: url,
						method: 'post',
						data: { 
							id : id,
							target_id : target_id, 
						}
					}).done(function() {
						growl("admin.movesuccess", 'success');
						if (callback != 'undefined') {
							eval(callback);
						}
					});
				}
			}

        </script>
    @endpush
    @push('css')
    	<link rel="stylesheet" href="{{ asset('/assets/plugins/nestable2/jquery.nestable.min.css') }}"> 
    @endpush
    @php(define('LOAD_NESTABLE', true))
@endif