| 
									
										
										
										
											2017-08-26 20:24:55 +08:00
										 |  |  | @extends('simple-layout') | 
					
						
							| 
									
										
										
										
											2015-09-06 21:35:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-26 20:24:55 +08:00
										 |  |  | @section('toolbar') | 
					
						
							|  |  |  |     <div class="col-sm-12 faded"> | 
					
						
							|  |  |  |         @include('books._breadcrumbs', ['book' => $book]) | 
					
						
							| 
									
										
										
										
											2016-12-04 02:35:40 +08:00
										 |  |  |     </div> | 
					
						
							| 
									
										
										
										
											2017-08-26 20:24:55 +08:00
										 |  |  | @stop | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @section('body') | 
					
						
							| 
									
										
										
										
											2016-12-04 02:35:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-31 05:38:20 +08:00
										 |  |  |     <div class="container" ng-non-bindable> | 
					
						
							| 
									
										
										
										
											2015-09-06 21:35:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-26 20:24:55 +08:00
										 |  |  |         <div class="row"> | 
					
						
							|  |  |  |             <div class="col-md-8"> | 
					
						
							|  |  |  |                 <div class="card"> | 
					
						
							| 
									
										
										
										
											2018-02-18 03:49:00 +08:00
										 |  |  |                     <h3>@icon('sort') {{ trans('entities.books_sort') }}</h3> | 
					
						
							| 
									
										
										
										
											2017-08-26 20:24:55 +08:00
										 |  |  |                     <div class="body"> | 
					
						
							|  |  |  |                         <div id="sort-boxes"> | 
					
						
							|  |  |  |                             @include('books/sort-box', ['book' => $book, 'bookChildren' => $bookChildren]) | 
					
						
							|  |  |  |                         </div> | 
					
						
							| 
									
										
										
										
											2015-09-06 21:35:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-26 20:24:55 +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"> | 
					
						
							|  |  |  |                                 <a href="{{ $book->getUrl() }}" class="button outline">{{ trans('common.cancel') }}</a> | 
					
						
							|  |  |  |                                 <button class="button pos" type="submit">{{ trans('entities.books_sort_save') }}</button> | 
					
						
							|  |  |  |                             </div> | 
					
						
							|  |  |  |                         </form> | 
					
						
							|  |  |  |                     </div> | 
					
						
							|  |  |  |                 </div> | 
					
						
							| 
									
										
										
										
											2015-09-06 21:35:53 +08:00
										 |  |  |             </div> | 
					
						
							| 
									
										
										
										
											2015-09-30 04:25:03 +08:00
										 |  |  |             @if(count($books) > 1) | 
					
						
							| 
									
										
										
										
											2017-08-26 20:24:55 +08:00
										 |  |  |             <div class="col-md-4"> | 
					
						
							|  |  |  |                 <div class="card"> | 
					
						
							| 
									
										
										
										
											2018-02-17 21:30:52 +08:00
										 |  |  |                     <h3>@icon('book') {{ trans('entities.books_sort_show_other') }}</h3> | 
					
						
							| 
									
										
										
										
											2017-08-26 20:24:55 +08:00
										 |  |  |                     <div class="body" id="additional-books"> | 
					
						
							|  |  |  |                         @foreach($books as $otherBook) | 
					
						
							|  |  |  |                             @if($otherBook->id !== $book->id) | 
					
						
							|  |  |  |                                 <div> | 
					
						
							| 
									
										
										
										
											2018-02-17 21:30:52 +08:00
										 |  |  |                                     <a href="{{ $otherBook->getUrl('/sort-item') }}" class="text-book">@icon('book'){{ $otherBook->name }}</a> | 
					
						
							| 
									
										
										
										
											2017-08-26 20:24:55 +08:00
										 |  |  |                                 </div> | 
					
						
							|  |  |  |                             @endif | 
					
						
							|  |  |  |                         @endforeach | 
					
						
							| 
									
										
										
										
											2015-10-23 02:06:50 +08:00
										 |  |  |                     </div> | 
					
						
							| 
									
										
										
										
											2015-09-30 04:25:03 +08:00
										 |  |  |                 </div> | 
					
						
							| 
									
										
										
										
											2017-08-26 20:24:55 +08:00
										 |  |  |             </div> | 
					
						
							| 
									
										
										
										
											2015-09-30 04:25:03 +08:00
										 |  |  |             @endif | 
					
						
							| 
									
										
										
										
											2015-09-06 21:35:53 +08:00
										 |  |  |         </div> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-17 23:20:15 +08:00
										 |  |  | @stop | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @section('scripts') | 
					
						
							|  |  |  |     <script src="{{ baseUrl("/libs/jquery-sortable/jquery-sortable.min.js") }}"></script> | 
					
						
							| 
									
										
										
										
											2015-09-06 21:35:53 +08:00
										 |  |  |     <script> | 
					
						
							|  |  |  |         $(document).ready(function() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             var sortableOptions = { | 
					
						
							|  |  |  |                 group: 'serialization', | 
					
						
							|  |  |  |                 onDrop: function($item, container, _super) { | 
					
						
							| 
									
										
										
										
											2016-08-27 03:20:58 +08:00
										 |  |  |                     var pageMap = buildEntityMap(); | 
					
						
							| 
									
										
										
										
											2015-09-06 21:35:53 +08: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-27 03:20:58 +08:00
										 |  |  |             /** | 
					
						
							|  |  |  |              * Build up a mapping of entities with their ordering and nesting. | 
					
						
							|  |  |  |              * @returns {Array} | 
					
						
							|  |  |  |              */ | 
					
						
							|  |  |  |             function buildEntityMap() { | 
					
						
							|  |  |  |                 var entityMap = []; | 
					
						
							| 
									
										
										
										
											2015-09-06 21:35:53 +08:00
										 |  |  |                 var $lists = $('.sort-list'); | 
					
						
							|  |  |  |                 $lists.each(function(listIndex) { | 
					
						
							|  |  |  |                     var list = $(this); | 
					
						
							|  |  |  |                     var bookId = list.closest('[data-type="book"]').attr('data-id'); | 
					
						
							| 
									
										
										
										
											2016-08-27 03:20:58 +08:00
										 |  |  |                     var $directChildren = list.find('> [data-type="page"], > [data-type="chapter"]'); | 
					
						
							|  |  |  |                     $directChildren.each(function(directChildIndex) { | 
					
						
							| 
									
										
										
										
											2015-09-06 21:35:53 +08:00
										 |  |  |                         var $childElem = $(this); | 
					
						
							|  |  |  |                         var type = $childElem.attr('data-type'); | 
					
						
							|  |  |  |                         var parentChapter = false; | 
					
						
							| 
									
										
										
										
											2016-08-27 03:20:58 +08:00
										 |  |  |                         var childId = $childElem.attr('data-id'); | 
					
						
							|  |  |  |                         entityMap.push({ | 
					
						
							|  |  |  |                             id: childId, | 
					
						
							|  |  |  |                             sort: directChildIndex, | 
					
						
							| 
									
										
										
										
											2015-09-06 21:35:53 +08:00
										 |  |  |                             parentChapter: parentChapter, | 
					
						
							|  |  |  |                             type: type, | 
					
						
							|  |  |  |                             book: bookId | 
					
						
							|  |  |  |                         }); | 
					
						
							| 
									
										
										
										
											2016-08-27 03:20:58 +08: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 21:35:53 +08:00
										 |  |  |                     }); | 
					
						
							|  |  |  |                 }); | 
					
						
							| 
									
										
										
										
											2016-08-27 03:20:58 +08:00
										 |  |  |                 return entityMap; | 
					
						
							| 
									
										
										
										
											2015-09-06 21:35:53 +08:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     </script> | 
					
						
							|  |  |  | @stop |