BookStack/resources/views/pages/sort.blade.php

77 lines
2.8 KiB
PHP
Raw Normal View History

2015-07-22 03:13:29 +08:00
@extends('base')
@section('content')
<div class="page-content">
<h1>{{ $book->name }} <span class="subheader">Sort Pages</span></h1>
2015-07-22 03:13:29 +08: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-22 03:13:29 +08: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">
<button class="button pos" type="submit">Save Ordering</button>
</div>
</form>
2015-07-22 03:13:29 +08:00
</div>
<script>
$(document).ready(function() {
var group = $('#sort-list').sortable({
group: 'serialization',
onDrop: function($item, container, _super) {
var data = group.sortable('serialize').get();
var pageMap = buildPageMap(data[0]);
2015-07-22 03:13:29 +08:00
$('#sort-tree-input').val(JSON.stringify(pageMap));
_super($item, container);
}
});
function buildPageMap(data) {
var pageMap = [];
2015-07-22 03:13:29 +08:00
for(var i = 0; i < data.length; i++) {
var bookChild = data[i];
2015-07-22 03:13:29 +08:00
pageMap.push({
id: bookChild.id,
parentChapter: false,
type: bookChild.type
2015-07-22 03:13:29 +08: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-22 03:13:29 +08:00
}
return pageMap;
2015-07-22 03:13:29 +08:00
}
});
</script>
@stop