|
1 | 1 | @extends(backpack_view('blank')) |
2 | 2 |
|
3 | 3 | @php |
4 | | - $defaultBreadcrumbs = [ |
5 | | - trans('backpack::crud.admin') => url(config('backpack.base.route_prefix'), 'dashboard'), |
6 | | - $crud->entity_name_plural => url($crud->route), |
7 | | - trans('backpack::crud.reorder') => false, |
8 | | - ]; |
9 | | -
|
10 | | - // if breadcrumbs aren't defined in the CrudController, use the default breadcrumbs |
11 | | - $breadcrumbs = $breadcrumbs ?? $defaultBreadcrumbs; |
| 4 | + $defaultBreadcrumbs = [ |
| 5 | + trans('backpack::crud.admin') => url(config('backpack.base.route_prefix'), 'dashboard'), |
| 6 | + $crud->entity_name_plural => url($crud->route), |
| 7 | + trans('backpack::crud.reorder') => false, |
| 8 | + ]; |
| 9 | +
|
| 10 | + // if breadcrumbs aren't defined in the CrudController, use the default breadcrumbs |
| 11 | + $breadcrumbs = $breadcrumbs ?? $defaultBreadcrumbs; |
12 | 12 | @endphp |
13 | 13 |
|
14 | 14 | @section('header') |
15 | | -<div class="container-fluid"> |
16 | | - <h2> |
17 | | - <span class="text-capitalize">{!! $crud->getHeading() ?? $crud->entity_name_plural !!}</span> |
18 | | - <small>{!! $crud->getSubheading() ?? trans('backpack::crud.reorder').' '.$crud->entity_name_plural !!}.</small> |
19 | | - |
20 | | - @if ($crud->hasAccess('list')) |
21 | | - <small><a href="{{ url($crud->route) }}" class="d-print-none font-sm"><i class="la la-angle-double-left"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></a></small> |
22 | | - @endif |
23 | | - </h2> |
24 | | -</div> |
| 15 | + <div class="container-fluid"> |
| 16 | + <h2> |
| 17 | + <span class="text-capitalize">{!! $crud->getHeading() ?? $crud->entity_name_plural !!}</span> |
| 18 | + <small>{!! $crud->getSubheading() ?? trans('backpack::crud.reorder').' '.$crud->entity_name_plural !!}.</small> |
| 19 | + |
| 20 | + @if ($crud->hasAccess('list')) |
| 21 | + <small><a href="{{ url($crud->route) }}" class="d-print-none font-sm"><i class="la la-angle-double-left"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></a></small> |
| 22 | + @endif |
| 23 | + </h2> |
| 24 | + </div> |
25 | 25 | @endsection |
26 | 26 |
|
27 | 27 | @section('content') |
28 | | -<?php |
29 | | -function tree_element($entry, $key, $all_entries, $crud) |
30 | | -{ |
31 | | - if (! isset($entry->tree_element_shown)) { |
32 | | - // mark the element as shown |
33 | | - $all_entries[$key]->tree_element_shown = true; |
34 | | - $entry->tree_element_shown = true; |
35 | | -
|
36 | | - // show the tree element |
37 | | - echo '<li id="list_'.$entry->getKey().'">'; |
38 | | - echo '<div><span class="disclose"><span></span></span>'.object_get($entry, $crud->get('reorder.label')).'</div>'; |
39 | | -
|
40 | | - // see if this element has any children |
41 | | - $children = []; |
42 | | - foreach ($all_entries as $key => $subentry) { |
43 | | - if ($subentry->parent_id == $entry->getKey()) { |
44 | | - $children[] = $subentry; |
| 28 | + <?php |
| 29 | + function tree_element($entry, $key, $all_entries, $crud) |
| 30 | + { |
| 31 | + if (! isset($entry->tree_element_shown)) { |
| 32 | + // mark the element as shown |
| 33 | + $all_entries[$key]->tree_element_shown = true; |
| 34 | + $entry->tree_element_shown = true; |
| 35 | +
|
| 36 | + // show the tree element |
| 37 | + echo '<li id="list_'.$entry->getKey().'">'; |
| 38 | + echo '<div><span class="disclose"><span></span></span>'.object_get($entry, $crud->get('reorder.label')).'</div>'; |
| 39 | +
|
| 40 | + // see if this element has any children |
| 41 | + $children = []; |
| 42 | + foreach ($all_entries as $key => $subentry) { |
| 43 | + if ($subentry->parent_id == $entry->getKey()) { |
| 44 | + $children[] = $subentry; |
| 45 | + } |
45 | 46 | } |
46 | | - } |
47 | 47 |
|
48 | | - $children = collect($children)->sortBy('lft'); |
| 48 | + $children = collect($children)->sortBy('lft'); |
49 | 49 |
|
50 | | - // if it does have children, show them |
51 | | - if (count($children)) { |
52 | | - echo '<ol>'; |
53 | | - foreach ($children as $key => $child) { |
54 | | - $children[$key] = tree_element($child, $child->getKey(), $all_entries, $crud); |
| 50 | + // if it does have children, show them |
| 51 | + if (count($children)) { |
| 52 | + echo '<ol>'; |
| 53 | + foreach ($children as $key => $child) { |
| 54 | + $children[$key] = tree_element($child, $child->getKey(), $all_entries, $crud); |
| 55 | + } |
| 56 | + echo '</ol>'; |
55 | 57 | } |
56 | | - echo '</ol>'; |
| 58 | + echo '</li>'; |
57 | 59 | } |
58 | | - echo '</li>'; |
59 | | - } |
60 | | -
|
61 | | - return $entry; |
62 | | -} |
63 | | -
|
64 | | -?> |
65 | | - |
66 | | -<div class="row mt-4"> |
67 | | - <div class="{{ $crud->getReorderContentClass() }}"> |
68 | | - <div class="card p-4"> |
69 | | - <p>{{ trans('backpack::crud.reorder_text') }}</p> |
70 | | - |
71 | | - <ol class="sortable mt-0"> |
72 | | - <?php |
73 | | - $all_entries = collect($entries->all())->sortBy('lft')->keyBy($crud->getModel()->getKeyName()); |
74 | | - $root_entries = $all_entries->filter(function ($item) { |
75 | | - return $item->parent_id == 0; |
76 | | - }); |
77 | | - foreach ($root_entries as $key => $entry) { |
78 | | - $root_entries[$key] = tree_element($entry, $key, $all_entries, $crud); |
79 | | - } |
80 | | - ?> |
81 | | - </ol> |
82 | 60 |
|
83 | | - </div>{{-- /.card --}} |
| 61 | + return $entry; |
| 62 | + } |
84 | 63 |
|
85 | | - <button id="toArray" class="btn btn-success" data-style="zoom-in"><i class="la la-save"></i> {{ trans('backpack::crud.save') }}</button> |
| 64 | + ?> |
| 65 | + |
| 66 | + <div class="row mt-4"> |
| 67 | + <div class="{{ $crud->getReorderContentClass() }}"> |
| 68 | + <div class="card p-4"> |
| 69 | + <p>{{ trans('backpack::crud.reorder_text') }}</p> |
| 70 | + |
| 71 | + <ol class="sortable mt-0"> |
| 72 | + <?php |
| 73 | + $all_entries = collect($entries->all())->sortBy('lft')->keyBy($crud->getModel()->getKeyName()); |
| 74 | + $root_entries = $all_entries->filter(function ($item) { |
| 75 | + return $item->parent_id == 0; |
| 76 | + }); |
| 77 | + foreach ($root_entries as $key => $entry) { |
| 78 | + $root_entries[$key] = tree_element($entry, $key, $all_entries, $crud); |
| 79 | + } |
| 80 | + ?> |
| 81 | + </ol> |
| 82 | + |
| 83 | + </div>{{-- /.card --}} |
| 84 | + |
| 85 | + <button id="toArray" class="btn btn-success" data-style="zoom-in"><i class="la la-save"></i> {{ trans('backpack::crud.save') }}</button> |
| 86 | + </div> |
86 | 87 | </div> |
87 | | -</div> |
88 | 88 | @endsection |
89 | 89 |
|
90 | 90 |
|
@@ -221,77 +221,77 @@ function tree_element($entry, $key, $all_entries, $crud) |
221 | 221 | @endsection |
222 | 222 |
|
223 | 223 | @section('after_scripts') |
224 | | -<script src="{{ asset('packages/jquery-ui-dist/jquery-ui.min.js') }}" type="text/javascript" ></script> |
225 | | -<script src="{{ asset('packages/nestedSortable/jquery.mjs.nestedSortable2.js') }}" type="text/javascript" ></script> |
226 | | - |
227 | | -<script type="text/javascript"> |
228 | | - jQuery(document).ready(function($) { |
229 | | - var isRtl = ($('html').attr('dir') == 'rtl') ? true : false; |
230 | | - if(isRtl) { |
231 | | - $( " <style> .ui-sortable ol {margin: 0;padding: 0;padding-right: 30px;}ol.sortable, ol.sortable ol {margin: 0 25px 0 0;padding: 0;list-style-type: none;}.ui-sortable dd {margin: 0;padding: 0 1.5em 0 0;}</style>" ).appendTo( "head" ) |
232 | | - } |
233 | | - // initialize the nested sortable plugin |
234 | | - $('.sortable').nestedSortable({ |
235 | | - forcePlaceholderSize: true, |
236 | | - handle: 'div', |
237 | | - helper: 'clone', |
238 | | - items: 'li', |
239 | | - opacity: .6, |
240 | | - placeholder: 'placeholder', |
241 | | - revert: 250, |
242 | | - tabSize: 25, |
243 | | - rtl: isRtl, |
244 | | - tolerance: 'pointer', |
245 | | - toleranceElement: '> div', |
246 | | - maxLevels: {{ $crud->get('reorder.max_level') ?? 3 }}, |
247 | | - isTree: true, |
248 | | - expandOnHover: 700, |
249 | | - startCollapsed: false |
250 | | - }); |
251 | | -
|
252 | | - $('.disclose').on('click', function() { |
253 | | - $(this).closest('li').toggleClass('mjs-nestedSortable-collapsed').toggleClass('mjs-nestedSortable-expanded'); |
254 | | - }); |
255 | | -
|
256 | | - $('#toArray').click(function(e){ |
257 | | - // get the current tree order |
258 | | - arraied = $('ol.sortable').nestedSortable('toArray', {startDepthCount: 0}); |
259 | | -
|
260 | | - // log it |
261 | | - //console.log(arraied); |
262 | | -
|
263 | | - // send it with POST |
264 | | - $.ajax({ |
265 | | - url: '{{ url(Request::path()) }}', |
266 | | - type: 'POST', |
267 | | - data: { tree: JSON.stringify(arraied) }, |
268 | | - }) |
269 | | - .done(function() { |
270 | | - new Noty({ |
271 | | - type: "success", |
272 | | - text: "<strong>{{ trans('backpack::crud.reorder_success_title') }}</strong><br>{{ trans('backpack::crud.reorder_success_message') }}" |
273 | | - }).show(); |
274 | | - }) |
275 | | - .fail(function() { |
276 | | - new Noty({ |
277 | | - type: "error", |
278 | | - text: "<strong>{{ trans('backpack::crud.reorder_error_title') }}</strong><br>{{ trans('backpack::crud.reorder_error_message') }}" |
279 | | - }).show(); |
280 | | - }) |
281 | | - .always(function() { |
282 | | - console.log("complete"); |
283 | | - }); |
284 | | -
|
285 | | - }); |
286 | | -
|
287 | | - $.ajaxPrefilter(function(options, originalOptions, xhr) { |
288 | | - var token = $('meta[name="csrf_token"]').attr('content'); |
289 | | -
|
290 | | - if (token) { |
291 | | - return xhr.setRequestHeader('X-XSRF-TOKEN', token); |
292 | | - } |
293 | | - }); |
| 224 | + <script src="{{ asset('packages/jquery-ui-dist/jquery-ui.min.js') }}" type="text/javascript" ></script> |
| 225 | + <script src="{{ asset('packages/nestedSortable/jquery.mjs.nestedSortable2.js') }}" type="text/javascript" ></script> |
| 226 | + |
| 227 | + <script type="text/javascript"> |
| 228 | + jQuery(document).ready(function($) { |
| 229 | + var isRtl = Boolean("{{ (config('backpack.base.html_direction') === 'rtl') ? true : false }}"); |
| 230 | + if(isRtl) { |
| 231 | + $( " <style> .ui-sortable ol {margin: 0;padding: 0;padding-right: 30px;}ol.sortable, ol.sortable ol {margin: 0 25px 0 0;padding: 0;list-style-type: none;}.ui-sortable dd {margin: 0;padding: 0 1.5em 0 0;}</style>" ).appendTo( "head" ) |
| 232 | + } |
| 233 | + // initialize the nested sortable plugin |
| 234 | + $('.sortable').nestedSortable({ |
| 235 | + forcePlaceholderSize: true, |
| 236 | + handle: 'div', |
| 237 | + helper: 'clone', |
| 238 | + items: 'li', |
| 239 | + opacity: .6, |
| 240 | + placeholder: 'placeholder', |
| 241 | + revert: 250, |
| 242 | + tabSize: 25, |
| 243 | + rtl: isRtl, |
| 244 | + tolerance: 'pointer', |
| 245 | + toleranceElement: '> div', |
| 246 | + maxLevels: {{ $crud->get('reorder.max_level') ?? 3 }}, |
| 247 | + isTree: true, |
| 248 | + expandOnHover: 700, |
| 249 | + startCollapsed: false |
| 250 | + }); |
| 251 | +
|
| 252 | + $('.disclose').on('click', function() { |
| 253 | + $(this).closest('li').toggleClass('mjs-nestedSortable-collapsed').toggleClass('mjs-nestedSortable-expanded'); |
| 254 | + }); |
| 255 | +
|
| 256 | + $('#toArray').click(function(e){ |
| 257 | + // get the current tree order |
| 258 | + arraied = $('ol.sortable').nestedSortable('toArray', {startDepthCount: 0}); |
| 259 | +
|
| 260 | + // log it |
| 261 | + //console.log(arraied); |
| 262 | +
|
| 263 | + // send it with POST |
| 264 | + $.ajax({ |
| 265 | + url: '{{ url(Request::path()) }}', |
| 266 | + type: 'POST', |
| 267 | + data: { tree: JSON.stringify(arraied) }, |
| 268 | + }) |
| 269 | + .done(function() { |
| 270 | + new Noty({ |
| 271 | + type: "success", |
| 272 | + text: "<strong>{{ trans('backpack::crud.reorder_success_title') }}</strong><br>{{ trans('backpack::crud.reorder_success_message') }}" |
| 273 | + }).show(); |
| 274 | + }) |
| 275 | + .fail(function() { |
| 276 | + new Noty({ |
| 277 | + type: "error", |
| 278 | + text: "<strong>{{ trans('backpack::crud.reorder_error_title') }}</strong><br>{{ trans('backpack::crud.reorder_error_message') }}" |
| 279 | + }).show(); |
| 280 | + }) |
| 281 | + .always(function() { |
| 282 | + console.log("complete"); |
| 283 | + }); |
| 284 | +
|
| 285 | + }); |
| 286 | +
|
| 287 | + $.ajaxPrefilter(function(options, originalOptions, xhr) { |
| 288 | + var token = $('meta[name="csrf_token"]').attr('content'); |
| 289 | +
|
| 290 | + if (token) { |
| 291 | + return xhr.setRequestHeader('X-XSRF-TOKEN', token); |
| 292 | + } |
| 293 | + }); |
294 | 294 |
|
295 | | -}); |
296 | | -</script> |
| 295 | + }); |
| 296 | + </script> |
297 | 297 | @endsection |
0 commit comments