diff --git a/assets/js/app.js b/assets/js/app.js index e84b9a37..62f2ae18 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -46,6 +46,8 @@ require('patternfly-bootstrap-treeview/src/js/bootstrap-treeview') require('./datatables.js'); +window.bootbox = require('bootbox') + require('../ts_src/ajax_ui'); import {ajaxUI} from "../ts_src/ajax_ui"; diff --git a/assets/ts_src/ajax_ui.ts b/assets/ts_src/ajax_ui.ts index d8763682..2b3f1ca5 100644 --- a/assets/ts_src/ajax_ui.ts +++ b/assets/ts_src/ajax_ui.ts @@ -256,12 +256,9 @@ class AjaxUI { console.debug('Links registered!'); } - /** - * Register all forms for loading via ajax. - */ - public registerForm() + protected getFormOptions() : JQueryFormOptions { - let options : JQueryFormOptions = { + return { success: this.onAjaxComplete, beforeSerialize: function() : boolean { @@ -285,12 +282,34 @@ class AjaxUI { return true; } }; + } + + /** + * Register all forms for loading via ajax. + */ + public registerForm() + { + + let options = this.getFormOptions(); + $('form').not('[data-no-ajax]').ajaxForm(options); console.debug('Forms registered!'); } + /** + * Submits the given form via ajax. + * @param form The form that will be submmitted. + */ + public submitForm(form) + { + let options = ajaxUI.getFormOptions(); + + $(form).ajaxSubmit(options); + } + + /** * Show the progressbar */ diff --git a/assets/ts_src/event_listeners.ts b/assets/ts_src/event_listeners.ts index 63b2b4c4..4b418615 100644 --- a/assets/ts_src/event_listeners.ts +++ b/assets/ts_src/event_listeners.ts @@ -29,6 +29,7 @@ */ import {ajaxUI} from "./ajax_ui"; +import "bootbox"; /************************************ * @@ -188,6 +189,29 @@ $(document).on("ajaxUI:start ajaxUI:reload", function() { }); }); +$(document).on("ajaxUI:start ajaxUI:reload", function() { + $("[data-delete-form]").unbind('submit').submit(function(event) { + event.preventDefault(); + + let form = this; + + let title = $(this).data("title"); + let message = $(this).data("message"); + + bootbox.confirm({ + message: message, + title: title, + callback: function(result) { + //If the dialog was confirmed, then submit the form. + if(result) { + ajaxUI.submitForm(form); + } + }}); + + return false; + }); +}); + /** * Register the button, to jump to the top of the page. diff --git a/assets/tsconfig.json b/assets/tsconfig.json index 1dbb6fc8..94e01953 100644 --- a/assets/tsconfig.json +++ b/assets/tsconfig.json @@ -4,7 +4,7 @@ "target": "es5", "sourceMap": true, "typeRoots": ["../node_modules"], - "types": ["jquery", "js-cookie", "bootstrap", "jquery.form", "bootstrap-treeview"] + "types": ["jquery", "js-cookie", "bootstrap", "jquery.form", "bootstrap-treeview", "bootbox"] }, "exclude": [ "node_modules" diff --git a/package.json b/package.json index e132664f..3da3488f 100644 --- a/package.json +++ b/package.json @@ -17,12 +17,14 @@ }, "dependencies": { "@ckeditor/ckeditor5-build-classic": "^12.0.0", + "@types/bootbox": "^4.4.36", "@types/bootstrap": "^4.3.0", "@types/bootstrap-treeview": "^1.20.0", "@types/jquery": "^3.3.29", "@types/jquery.form": "^3.26.30", "@types/js-cookie": "^2.2.1", "awesome-bootstrap-checkbox": "^1.0.1", + "bootbox": "^5.1.0", "bootstrap-select": "^1.13.8", "datatables.net-bs4": "^1.10.19", "datatables.net-buttons-bs4": "^1.5.4", diff --git a/src/Controller/AttachmentTypeController.php b/src/Controller/AttachmentTypeController.php index 7640f6cc..58719aa1 100644 --- a/src/Controller/AttachmentTypeController.php +++ b/src/Controller/AttachmentTypeController.php @@ -94,4 +94,29 @@ class AttachmentTypeController extends AbstractController 'form' => $form->createView() ]); } + + /** + * @Route("/{id}", name="attachment_type_delete", methods={"DELETE"}) + */ + public function delete(Request $request, AttachmentType $entity) + { + if ($this->isCsrfTokenValid('delete'.$entity->getId(), $request->request->get('_token'))) { + $entityManager = $this->getDoctrine()->getManager(); + + $parent = $entity->getParent(); + + //Move all sub entities to the current parent + foreach($entity->getSubelements() as $subelement) { + $subelement->setParent($parent); + $entityManager->persist($subelement); + } + + //Remove current element + $entityManager->remove($entity); + $entityManager->flush(); + $this->addFlash('success', 'attachment_type.deleted'); + } + + return $this->redirectToRoute('attachment_type_new'); + } } \ No newline at end of file diff --git a/src/Services/EntityURLGenerator.php b/src/Services/EntityURLGenerator.php index f78fa399..f29b79eb 100644 --- a/src/Services/EntityURLGenerator.php +++ b/src/Services/EntityURLGenerator.php @@ -73,6 +73,8 @@ class EntityURLGenerator case 'list': case 'list_parts': return $this->listPartsURL($entity); + case 'delete': + return $this->deleteURL($entity); } throw new \InvalidArgumentException('Method is not supported!'); @@ -169,6 +171,15 @@ class EntityURLGenerator } + public function deleteURL($entity) : string + { + if($entity instanceof AttachmentType) { + return $this->urlGenerator->generate('attachment_type_delete', ['id' => $entity->getID()]); + } + + throw new EntityNotSupported('The given entity is not supported yet!'); + } + /** * Generates an HTML link to the info page about the given entity. * diff --git a/templates/AdminPages/EntityAdminBase.html.twig b/templates/AdminPages/EntityAdminBase.html.twig index d11bfd41..b76a48eb 100644 --- a/templates/AdminPages/EntityAdminBase.html.twig +++ b/templates/AdminPages/EntityAdminBase.html.twig @@ -8,16 +8,16 @@
-
- - -
+
+ + +
{{ form_end(form) }} + + {# Only include on existing parts #} + {% if entity.id %} + {{ include('AdminPages/_delete_form.html.twig') }} + {% endif %}
diff --git a/templates/AdminPages/_delete_form.html.twig b/templates/AdminPages/_delete_form.html.twig new file mode 100644 index 00000000..bdbf1d20 --- /dev/null +++ b/templates/AdminPages/_delete_form.html.twig @@ -0,0 +1,12 @@ +
+ + +
+
+
+ +
+
+
diff --git a/yarn.lock b/yarn.lock index 0c68d0fc..961a99ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -650,6 +650,13 @@ resolved "https://registry.yarnpkg.com/@types/anymatch/-/anymatch-1.3.1.tgz#336badc1beecb9dacc38bea2cf32adf627a8421a" integrity sha512-/+CRPXpBDpo2RK9C68N3b2cOvO0Cf5B9aPijHsoDQTHivnGSObdOF2BRQOYjojWTDy6nQvMjmqRXIxH55VjxxA== +"@types/bootbox@^4.4.36": + version "4.4.36" + resolved "https://registry.yarnpkg.com/@types/bootbox/-/bootbox-4.4.36.tgz#e93f34884b3a55aa21b189a2b967e7d1c9196a94" + integrity sha512-RNNb0guOAm9RXPMOHlRILqLfuNaSjL/VEXej6izAwpWrN7pTtHLLhmh/eCkCLaItcrXuivXNdJLQT2okBT0Dog== + dependencies: + "@types/jquery" "*" + "@types/bootstrap-treeview@^1.20.0": version "1.20.0" resolved "https://registry.yarnpkg.com/@types/bootstrap-treeview/-/bootstrap-treeview-1.20.0.tgz#08157e2f26b5b278dfd70e2054bbf8aa7d6f0b2d" @@ -1229,6 +1236,14 @@ boolbase@^1.0.0, boolbase@~1.0.0: resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e" integrity sha1-aN/1++YMUes3cl6p4+0xDcwed24= +bootbox@^5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/bootbox/-/bootbox-5.1.0.tgz#34cd80ca20fc9103b66d7068119eb3dc5384e4fd" + integrity sha512-yclcgJGr56BOzY6an1+EmBxoCAnM+aEnmlo66CQaWUCenrcRBElCVOpsY4stjb0Z/X9oBx3Md0ynhCy7ZUx6aQ== + dependencies: + bootstrap ">=3.0.0" + jquery ">=1.9.1" + bootstrap-select@^1.13.8: version "1.13.8" resolved "https://registry.yarnpkg.com/bootstrap-select/-/bootstrap-select-1.13.8.tgz#c47047410511f6d8a8917a7738d1b03c95717d5d" @@ -1239,7 +1254,7 @@ bootstrap@3.4.x: resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-3.4.1.tgz#c3a347d419e289ad11f4033e3c4132b87c081d72" integrity sha512-yN5oZVmRCwe5aKwzRj6736nSmKDX7pLYwsXiCj/EYmo16hODaBiT4En5btW/jhBF/seV+XMx3aYwukYC3A49DA== -bootstrap@^4.3.1: +bootstrap@>=3.0.0, bootstrap@^4.3.1: version "4.3.1" resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-4.3.1.tgz#280ca8f610504d99d7b6b4bfc4b68cec601704ac" integrity sha512-rXqOmH1VilAt2DyPzluTi2blhk17bO7ef+zLLPlWvG494pDxcM234pJ8wTc/6R40UWizAIIMgxjvxZg5kmsbag== @@ -3665,7 +3680,7 @@ jquery-form@^4.2.2: dependencies: jquery ">=1.7.2" -"jquery@>= 2.1.x", jquery@>=1.7, jquery@>=1.7.2, jquery@^3.3.1: +"jquery@>= 2.1.x", jquery@>=1.7, jquery@>=1.7.2, jquery@>=1.9.1, jquery@^3.3.1: version "3.3.1" resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.3.1.tgz#958ce29e81c9790f31be7792df5d4d95fc57fbca" integrity sha512-Ubldcmxp5np52/ENotGxlLe6aGMvmF4R8S6tZjsP6Knsaxd/xp3Zrh50cG93lR6nPXyUFwzN3ZSOQI0wRJNdGg==