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 @@