2015-09-06 09:35:53 -04:00
|
|
|
@extends('base')
|
|
|
|
|
2015-12-30 13:38:18 -05:00
|
|
|
@section('head')
|
2016-08-14 07:29:35 -04:00
|
|
|
<script src="{{ baseUrl("/libs/jquery-sortable/jquery-sortable.min.js") }}"></script>
|
2015-12-30 13:38:18 -05:00
|
|
|
@stop
|
|
|
|
|
2015-09-06 09:35:53 -04:00
|
|
|
@section('content')
|
|
|
|
|
2015-12-30 16:38:20 -05:00
|
|
|
<div class="container" ng-non-bindable>
|
2015-09-06 09:35:53 -04:00
|
|
|
<h1>Sorting Pages & Chapters<span class="subheader">For {{ $book->name }}</span></h1>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-8" id="sort-boxes">
|
|
|
|
|
2015-11-29 12:33:25 -05:00
|
|
|
@include('books/sort-box', ['book' => $book, 'bookChildren' => $bookChildren])
|
2015-09-06 09:35:53 -04:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2015-09-29 16:25:03 -04:00
|
|
|
@if(count($books) > 1)
|
|
|
|
<div class="col-md-4">
|
|
|
|
<h3>Show Other Books</h3>
|
2015-10-22 14:06:50 -04:00
|
|
|
<div id="additional-books">
|
2015-09-29 16:25:03 -04:00
|
|
|
@foreach($books as $otherBook)
|
|
|
|
@if($otherBook->id !== $book->id)
|
2015-10-22 14:06:50 -04:00
|
|
|
<div>
|
2016-08-14 07:29:35 -04:00
|
|
|
<a href="{{ $otherBook->getUrl('/sort-item') }}" class="text-book"><i class="zmdi zmdi-book"></i>{{ $otherBook->name }}</a>
|
2015-09-29 16:25:03 -04:00
|
|
|
</div>
|
|
|
|
@endif
|
|
|
|
@endforeach
|
2015-10-22 14:06:50 -04:00
|
|
|
</div>
|
2015-09-29 16:25:03 -04:00
|
|
|
</div>
|
|
|
|
@endif
|
2015-09-06 09:35:53 -04:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2016-08-14 07:29:35 -04:00
|
|
|
<form action="{{ $book->getUrl('/sort') }}" method="POST">
|
2015-09-06 09:35:53 -04:00
|
|
|
{!! csrf_field() !!}
|
|
|
|
<input type="hidden" name="_method" value="PUT">
|
|
|
|
<input type="hidden" id="sort-tree-input" name="sort-tree">
|
|
|
|
<div class="list">
|
2016-08-14 07:29:35 -04:00
|
|
|
<a href="{{ $book->getUrl() }}" class="button muted">Cancel</a>
|
2015-09-06 09:35:53 -04:00
|
|
|
<button class="button pos" type="submit">Save Order</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
|
|
|
var sortableOptions = {
|
|
|
|
group: 'serialization',
|
|
|
|
onDrop: function($item, container, _super) {
|
2016-08-26 15:20:58 -04:00
|
|
|
var pageMap = buildEntityMap();
|
2015-09-06 09:35:53 -04:00
|
|
|
$('#sort-tree-input').val(JSON.stringify(pageMap));
|
|
|
|
_super($item, container);
|
|
|
|
},
|
|
|
|
isValidTarget: function ($item, container) {
|
|
|
|
// Prevent nested chapters
|
|
|
|
return !($item.is('[data-type="chapter"]') && container.target.closest('li').attr('data-type') == 'chapter');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var group = $('.sort-list').sortable(sortableOptions);
|
|
|
|
|
|
|
|
$('#additional-books').on('click', 'a', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var $link = $(this);
|
|
|
|
var url = $link.attr('href');
|
|
|
|
$.get(url, function(data) {
|
|
|
|
$('#sort-boxes').append(data);
|
|
|
|
group.sortable("destroy");
|
|
|
|
$('.sort-list').sortable(sortableOptions);
|
|
|
|
});
|
|
|
|
$link.remove();
|
|
|
|
});
|
|
|
|
|
2016-08-26 15:20:58 -04:00
|
|
|
/**
|
|
|
|
* Build up a mapping of entities with their ordering and nesting.
|
|
|
|
* @returns {Array}
|
|
|
|
*/
|
|
|
|
function buildEntityMap() {
|
|
|
|
var entityMap = [];
|
2015-09-06 09:35:53 -04:00
|
|
|
var $lists = $('.sort-list');
|
|
|
|
$lists.each(function(listIndex) {
|
|
|
|
var list = $(this);
|
|
|
|
var bookId = list.closest('[data-type="book"]').attr('data-id');
|
2016-08-26 15:20:58 -04:00
|
|
|
var $directChildren = list.find('> [data-type="page"], > [data-type="chapter"]');
|
|
|
|
$directChildren.each(function(directChildIndex) {
|
2015-09-06 09:35:53 -04:00
|
|
|
var $childElem = $(this);
|
|
|
|
var type = $childElem.attr('data-type');
|
|
|
|
var parentChapter = false;
|
2016-08-26 15:20:58 -04:00
|
|
|
var childId = $childElem.attr('data-id');
|
|
|
|
entityMap.push({
|
|
|
|
id: childId,
|
|
|
|
sort: directChildIndex,
|
2015-09-06 09:35:53 -04:00
|
|
|
parentChapter: parentChapter,
|
|
|
|
type: type,
|
|
|
|
book: bookId
|
|
|
|
});
|
2016-08-26 15:20:58 -04:00
|
|
|
$chapterChildren = $childElem.find('[data-type="page"]').each(function(pageIndex) {
|
|
|
|
var $chapterChild = $(this);
|
|
|
|
entityMap.push({
|
|
|
|
id: $chapterChild.attr('data-id'),
|
|
|
|
sort: pageIndex,
|
|
|
|
parentChapter: childId,
|
|
|
|
type: 'page',
|
|
|
|
book: bookId
|
|
|
|
});
|
|
|
|
});
|
2015-09-06 09:35:53 -04:00
|
|
|
});
|
|
|
|
});
|
2016-08-26 15:20:58 -04:00
|
|
|
return entityMap;
|
2015-09-06 09:35:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
@stop
|