From 2db5e72bcbe0beb08916d9f7be20a68121d31092 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kasia=20Jarmo=C5=82kowicz?=
Date: Fri, 18 May 2018 17:59:17 +0200
Subject: [PATCH] Add a confirm dialog when deleting templates
---
.../campaign_templates/index.html.erb | 2 +-
client/js/campaign_templates/new/wizard.js | 36 ++++++++++---------
2 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/app/views/nonprofits/campaign_templates/index.html.erb b/app/views/nonprofits/campaign_templates/index.html.erb
index f1890623..70c16c5d 100644
--- a/app/views/nonprofits/campaign_templates/index.html.erb
+++ b/app/views/nonprofits/campaign_templates/index.html.erb
@@ -53,7 +53,7 @@
Delete template
-
+
<% end %>
diff --git a/client/js/campaign_templates/new/wizard.js b/client/js/campaign_templates/new/wizard.js
index c1a79bb8..ca29497a 100644
--- a/client/js/campaign_templates/new/wizard.js
+++ b/client/js/campaign_templates/new/wizard.js
@@ -1,6 +1,7 @@
require('../../common/pikaday-timepicker')
require('../../components/wizard')
require('../../common/image_uploader')
+var confirmation = require('../../common/confirmation')
var format_err = require('../../common/format_response_error')
appl.def('advance_campaign_template_name_step', function(form_obj) {
@@ -50,21 +51,24 @@ function post_campaign_template(form_data) {
}
appl.def('delete_template', function(id) {
- appl.def('loading', true)
- var url = '/nonprofits/' + app.nonprofit_id + '/campaign_templates/' + id
+ var result = confirmation('Are you sure?')
+ result.confirmed = function() {
+ appl.def('loading', true)
+ var url = '/nonprofits/' + app.nonprofit_id + '/campaign_templates/' + id
- return new Promise(function(resolve, reject) {
- var req = new XMLHttpRequest()
- req.open("DELETE", url)
- req.setRequestHeader('X-CSRF-Token', window._csrf)
- req.send({ campaign_template: {id: id} })
- req.onload = function(ev) {
- if(req.status === 204) resolve(req)
- else reject(req)
- }
- }).then(function() {
- appl.def('loading', false)
- appl.notify('Successfully deleted template.')
- appl.redirect('/nonprofits/' + app.nonprofit_id + '/campaign_templates')
- })
+ return new Promise(function(resolve, reject) {
+ var req = new XMLHttpRequest()
+ req.open("DELETE", url)
+ req.setRequestHeader('X-CSRF-Token', window._csrf)
+ req.send({ campaign_template: {id: id} })
+ req.onload = function(ev) {
+ if(req.status === 204) resolve(req)
+ else reject(req)
+ }
+ }).then(function() {
+ appl.def('loading', false)
+ appl.notify('Successfully deleted template.')
+ appl.redirect('/nonprofits/' + app.nonprofit_id + '/campaign_templates')
+ })
+ }
})