2015-07-21 15:13:29 -04:00
|
|
|
@extends('base')
|
|
|
|
|
|
|
|
@section('content')
|
|
|
|
|
2015-07-30 17:27:35 -04:00
|
|
|
<div class="page-content">
|
|
|
|
<h1>{{ $book->name }} <span class="subheader">Sort Pages</span></h1>
|
2015-07-21 15:13:29 -04:00
|
|
|
|
2015-07-30 17:27:35 -04:00
|
|
|
<ul class="sortable-page-list" id="sort-list">
|
|
|
|
@foreach($book->children() as $bookChild)
|
|
|
|
<li data-id="{{$bookChild->id}}" data-type="{{ is_a($bookChild, 'Oxbow\Chapter') ? 'chapter' : 'page' }}">
|
|
|
|
{{ $bookChild->name }}
|
|
|
|
@if(is_a($bookChild, 'Oxbow\Chapter'))
|
|
|
|
<ul>
|
|
|
|
@foreach($bookChild->pages as $page)
|
|
|
|
<li data-id="{{$page->id}}" data-type="page">
|
|
|
|
{{ $page->name }}
|
|
|
|
</li>
|
|
|
|
@endforeach
|
|
|
|
</ul>
|
|
|
|
@endif
|
|
|
|
</li>
|
|
|
|
@endforeach
|
|
|
|
</ul>
|
2015-07-21 15:13:29 -04:00
|
|
|
|
2015-07-30 17:27:35 -04:00
|
|
|
<form action="{{$book->getUrl()}}/sort" method="POST">
|
|
|
|
{!! csrf_field() !!}
|
|
|
|
<input type="hidden" name="_method" value="PUT">
|
|
|
|
<input type="hidden" id="sort-tree-input" name="sort-tree">
|
|
|
|
<div class="list">
|
2015-08-08 16:38:11 -04:00
|
|
|
<a href="{{$book->getUrl()}}" class="button muted">Cancel</a>
|
2015-07-30 17:27:35 -04:00
|
|
|
<button class="button pos" type="submit">Save Ordering</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
2015-07-21 15:13:29 -04:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
|
|
|
var group = $('#sort-list').sortable({
|
|
|
|
group: 'serialization',
|
|
|
|
onDrop: function($item, container, _super) {
|
|
|
|
var data = group.sortable('serialize').get();
|
2015-07-30 17:27:35 -04:00
|
|
|
var pageMap = buildPageMap(data[0]);
|
2015-07-21 15:13:29 -04:00
|
|
|
$('#sort-tree-input').val(JSON.stringify(pageMap));
|
|
|
|
_super($item, container);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-07-30 17:27:35 -04:00
|
|
|
function buildPageMap(data) {
|
|
|
|
var pageMap = [];
|
2015-07-21 15:13:29 -04:00
|
|
|
for(var i = 0; i < data.length; i++) {
|
2015-07-30 17:27:35 -04:00
|
|
|
var bookChild = data[i];
|
2015-07-21 15:13:29 -04:00
|
|
|
pageMap.push({
|
2015-07-30 17:27:35 -04:00
|
|
|
id: bookChild.id,
|
|
|
|
parentChapter: false,
|
|
|
|
type: bookChild.type
|
2015-07-21 15:13:29 -04:00
|
|
|
});
|
2015-07-30 17:27:35 -04:00
|
|
|
if(bookChild.type == 'chapter' && bookChild.children) {
|
|
|
|
var chapterId = bookChild.id;
|
|
|
|
var chapterChildren = bookChild.children[0];
|
|
|
|
for(var j = 0; j < chapterChildren.length; j++) {
|
|
|
|
var page = chapterChildren[j];
|
|
|
|
pageMap.push({
|
|
|
|
id: page.id,
|
|
|
|
parentChapter: chapterId,
|
|
|
|
type: 'page'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2015-07-21 15:13:29 -04:00
|
|
|
}
|
2015-07-30 17:27:35 -04:00
|
|
|
return pageMap;
|
2015-07-21 15:13:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
@stop
|