Add a confirm dialog when deleting templates

This commit is contained in:
Kasia Jarmołkowicz 2018-05-18 17:59:17 +02:00 committed by Eric Schultz
parent bb0bebe8f7
commit 2db5e72bcb
2 changed files with 21 additions and 17 deletions

View file

@ -53,7 +53,7 @@
</p>
<a class="button red">Delete template</a>
<!--= on 'click' (delete_template <%= template.id %>) -->
<!--= on 'click' (delete_template <%= template.id %>) -->
</td>
</tr>
<% end %>

View file

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