diff --git a/composer.json b/composer.json index 820066e93838030f885a12026a0faf8c4136a68a..626d792d3764b86fad069f0e89de76dfd02a38c1 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "doctrine/doctrine-bundle": "^2.7", "doctrine/doctrine-migrations-bundle": "^3.2", "doctrine/orm": "^2.13", + "friendsofsymfony/jsrouting-bundle": "^2.8", "justinrainbow/json-schema": "^5.2", "league/oauth2-server-bundle": "^0.4.0", "nelmio/api-doc-bundle": "^4.10", diff --git a/config/bundles.php b/config/bundles.php index c457161d92d900499400f5a64196d6786ddba2e1..e810766519fbe9b238693db8436634f39f7f47d8 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -18,4 +18,5 @@ return [ SymfonyCasts\Bundle\VerifyEmail\SymfonyCastsVerifyEmailBundle::class => ['all' => true], Vich\UploaderBundle\VichUploaderBundle::class => ['all' => true], SymfonyCasts\Bundle\ResetPassword\SymfonyCastsResetPasswordBundle::class => ['all' => true], + FOS\JsRoutingBundle\FOSJsRoutingBundle::class => ['all' => true], ]; diff --git a/config/routes/fos_js_routing.yaml b/config/routes/fos_js_routing.yaml new file mode 100644 index 0000000000000000000000000000000000000000..79d25e2cd7b287204a5d77198b71e18979270606 --- /dev/null +++ b/config/routes/fos_js_routing.yaml @@ -0,0 +1,2 @@ +fos_js_routing: + resource: "@FOSJsRoutingBundle/Resources/config/routing/routing-sf4.xml" diff --git a/src/Controller/EntryController.php b/src/Controller/EntryController.php index 8955781c994dcfbdf67bacd783b13a5e0e11e453..f52b0c387c703f623be1ad3d7d0f1d5c51ae86eb 100644 --- a/src/Controller/EntryController.php +++ b/src/Controller/EntryController.php @@ -327,4 +327,15 @@ class EntryController extends AppBaseController } } + /** + * @Route("/{id}/reorder", name="app_entry_reorder", methods={"GET"}, options={"expose" = true}) + */ + public function reorder(Request $request, Entry $entry): Response + { + $serialized = $request->get('serialized'); +dump($serialized);die(); + + return $this->render('entry/show.html.twig', ['id' => $entry->getId()]); + } + } diff --git a/templates/base.html.twig b/templates/base.html.twig index b92e34eede3a51f989c72db0507ddffeadf49794..28ca96c8a6f146ce5d1cba2c1e1628dec21acb77 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -22,6 +22,8 @@ <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script> {% include "js_translations.html.twig" %} <script src="{{ asset('assets/js/jquery.mjs.nestedSortable.js') }}"></script> + <script src="{{ asset('bundles/fosjsrouting/js/router.min.js') }}"></script> + <script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script> <script src="{{ asset('assets/js/app.js') }}"></script> {% endblock %} </head> diff --git a/templates/entry/_entryAttributes.html.twig b/templates/entry/_entryAttributes.html.twig index 95dd7467eb58385edfef866b4c51503ef41c5aa1..bd796838e7c1caa515ca1e97572c00dc35a7949e 100644 --- a/templates/entry/_entryAttributes.html.twig +++ b/templates/entry/_entryAttributes.html.twig @@ -110,8 +110,25 @@ }); $("#serialize").click(function(e) { - e.preventDefault();console.log($('ol.sortable').nestedSortable('serialize')); - // $("#output").text($('ol.sortable').nestedSortable('serialize')); + e.preventDefault(); +console.log($('ol.sortable').nestedSortable('serialize')); + var $overlay = $('#overlay').show(); + var serialized = $('ol.sortable').nestedSortable('serialize'); + var target = $('#entryAttributes'); + var entryId = {{ entry.id }} + var url = Routing.generate('app_entry_reorder', {id: entryId, serialized: serialized}); + + $.ajax({ + url: url, + method: "GET", + data: {serialized: serialized}, + success: function(res) { + target.replaceWith($(res).find('#entryAttributes')); + }, + complete: function () { + $overlay.hide(); + } + }); }); });