Added possibillity to delete attachments in admin page.

This commit is contained in:
Jan Böhmer 2019-04-06 18:38:36 +02:00
parent 72cd9a3722
commit 7c43feefbe
10 changed files with 133 additions and 19 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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');
}
}

View file

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

View file

@ -8,16 +8,16 @@
<div class="col-8">
<input id="tree-search" type="search" class="form-control" placeholder="{% trans %}search.placeholder{% endtrans %}">
</div>
<div class="btn-group btn-group-sm col-4" role="group">
<button type="button" class="btn btn-outline-secondary" id="tree-expand"
title="{% trans %}expandAll{% endtrans %}">
<i class="fas fa-plus fa-fw"></i>
</button>
<button type="button" class="btn btn-outline-secondary" id="tree-reduce"
title="{% trans %}reduceAll{% endtrans %}">
<i class="fas fa-minus fa-fw"></i>
</button>
</div>
<div class="btn-group btn-group-sm col-4" role="group">
<button type="button" class="btn btn-outline-secondary" id="tree-expand"
title="{% trans %}expandAll{% endtrans %}">
<i class="fas fa-plus fa-fw"></i>
</button>
<button type="button" class="btn btn-outline-secondary" id="tree-reduce"
title="{% trans %}reduceAll{% endtrans %}">
<i class="fas fa-minus fa-fw"></i>
</button>
</div>
</div>
<div class="treeview-sm mt-2" id="tree" data-tree-data="{{ generateTreeData(entity) }}"
@ -93,10 +93,14 @@
{{ form_row(form.reset) }}
</fieldset>
{{ form_end(form) }}
{# Only include on existing parts #}
{% if entity.id %}
{{ include('AdminPages/_delete_form.html.twig') }}
{% endif %}
</div>
</div>

View file

@ -0,0 +1,12 @@
<form method="post" class="" action="{{ entity|entityURL('delete') }}"
data-delete-form data-title="{% trans with {'%name%': entity.name }%}entity.delete.confirm_title{% endtrans %}"
data-message="{% trans %}entity.delete{% endtrans %}">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ entity.id) }}">
<div class="form-group">
<div class=""></div>
<div class="col-3 offset-2 pl-1">
<button class="btn btn-danger">{% trans %}entity.delete{% endtrans %}</button>
</div>
</div>
</form>

View file

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