From a9c20f5d950451ce6b280a2b57db88bed2cdc0b4 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 30 Apr 2018 00:23:02 +1000 Subject: [PATCH] Added modal form success messages - More to be done, just a start - Create / edit / delete --- InvenTree/company/views.py | 15 +++++++++++++ InvenTree/part/templates/part/detail.html | 5 +++-- InvenTree/part/views.py | 21 ++++++++++++------ InvenTree/static/script/notification.js | 26 +++++++++++------------ 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/InvenTree/company/views.py b/InvenTree/company/views.py index ab2f15d912..bef157af70 100644 --- a/InvenTree/company/views.py +++ b/InvenTree/company/views.py @@ -43,6 +43,11 @@ class CompanyEdit(AjaxUpdateView): ajax_template_name = 'modal_form.html' ajax_form_title = 'Edit Company' + def get_data(self): + return { + 'info': 'Edited company information', + } + class CompanyCreate(AjaxCreateView): model = Company @@ -52,9 +57,19 @@ class CompanyCreate(AjaxCreateView): ajax_template_name = 'modal_form.html' ajax_form_title = "Create new Company" + def get_data(self): + return { + 'success': "Created new company", + } + class CompanyDelete(AjaxDeleteView): model = Company success_url = '/company/' template_name = 'company/delete.html' ajax_form_title = 'Delete Company' + + def get_data(self): + return { + 'danger': 'Company was deleted', + } diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index 9dcac2533e..7436105ba0 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -99,7 +99,8 @@ $('#delete-part').click(function() { launchDeleteForm("#modal-delete", "{% url 'part-delete' part.id %}", - {redirect: "{% url 'part-index' %}"} - ); + { + redirect: {% if part.category %}"{% url 'category-detail' part.category.id %}"{% else %}"{% url 'part-index' %}"}{% endif %} + }); }); {% endblock %} diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 5a432df4f3..f74836197c 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -52,6 +52,11 @@ class PartCreate(AjaxCreateView): ajax_form_title = 'Create new part' ajax_template_name = 'modal_form.html' + def get_data(self): + return { + 'success': "Created new part", + } + def get_category_id(self): return self.request.GET.get('category', None) @@ -108,13 +113,10 @@ class PartDelete(AjaxDeleteView): success_url = '/part/' - """ - def post(self, request, *args, **kwargs): - if 'confirm' in request.POST: - return super(PartDelete, self).post(request, *args, **kwargs) - else: - return HttpResponseRedirect(self.get_object().get_absolute_url()) - """ + def get_data(self): + return { + 'danger': 'Part was deleted', + } class CategoryDetail(DetailView): @@ -145,6 +147,11 @@ class CategoryDelete(AjaxDeleteView): context_object_name = 'category' success_url = '/part/' + def get_data(self): + return { + 'danger': 'Part category was deleted', + } + class CategoryCreate(AjaxCreateView): model = PartCategory diff --git a/InvenTree/static/script/notification.js b/InvenTree/static/script/notification.js index 0cfc43fc20..01754bceaf 100644 --- a/InvenTree/static/script/notification.js +++ b/InvenTree/static/script/notification.js @@ -9,7 +9,7 @@ function showAlert(target, message, timeout=5000) { function showAlertOrCache(alertType, message, cache, timeout=5000) { if (cache) { - sessionStorage.setItem(alertType, message); + sessionStorage.setItem("inventree-" + alertType, message); } else { showAlert('#' + alertType, message, timeout); @@ -19,26 +19,26 @@ function showAlertOrCache(alertType, message, cache, timeout=5000) { function showCachedAlerts() { // Success Message - if (sessionStorage.getItem("alert-success")) { - showAlert("#alert-success", sessionStorage.getItem("alert-success")); - sessionStorage.removeItem("alert-success"); + if (sessionStorage.getItem("inventree-alert-success")) { + showAlert("#alert-success", sessionStorage.getItem("inventree-alert-success")); + sessionStorage.removeItem("inventree-alert-success"); } // Info Message - if (sessionStorage.getItem("alert-info")) { - showAlert("#alert-info", sessionStorage.getItem("alert-info")); - sessionStorage.removeItem("alert-info"); + if (sessionStorage.getItem("inventree-alert-info")) { + showAlert("#alert-info", sessionStorage.getItem("inventree-alert-info")); + sessionStorage.removeItem("inventree-alert-info"); } // Warning Message - if (sessionStorage.getItem("alert-warning")) { - showAlert("#alert-warning", sessionStorage.getItem("alert-warning")); - sessionStorage.removeItem("alert-warning"); + if (sessionStorage.getItem("inventree-alert-warning")) { + showAlert("#alert-warning", sessionStorage.getItem("inventree-alert-warning")); + sessionStorage.removeItem("inventree-alert-warning"); } // Danger Message - if (sessionStorage.getItem("alert-danger")) { - showAlert("#alert-danger", sessionStorage.getItem("alert-danger")); - sessionStorage.removeItem("alert-danger"); + if (sessionStorage.getItem("inventree-alert-danger")) { + showAlert("#alert-danger", sessionStorage.getItem("inventree-alert-danger")); + sessionStorage.removeItem("inventree-alert-danger"); } } \ No newline at end of file