Skip to content

Commit

Permalink
Merge pull request #1160 from kobotoolbox/issue-1159
Browse files Browse the repository at this point in the history
only display strong confirmation dialog when deleting deployed assets
  • Loading branch information
Esmail authored Feb 23, 2017
2 parents fc5cf3d + 7044cb9 commit 435b98f
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions jsapp/js/mixins.es6
Original file line number Diff line number Diff line change
Expand Up @@ -1335,39 +1335,51 @@ mixins.clickAssets = {
delete: function(uid/*, evt*/){
let asset = stores.selectedAsset.asset;
let dialog = alertify.dialog('confirm');
let opts = {
title: t('Delete Project'),
message: `${t('You are about to permanently delete this form.')}
let deployed = asset.has_deployment;
let msg, onshow;
let onok = (evt, val) => {
actions.resources.deleteAsset({uid: uid}, {
onComplete: ()=> {
this.refreshSearch && this.refreshSearch();
}
});
};

if (!deployed) {
msg = t('You are about to permanently delete this draft.');
} else {
msg = `
${t('You are about to permanently delete this form.')}
<label class="alertify-toggle"><input type="checkbox"/> ${t('All data gathered for this form will be deleted.')}</label>
<label class="alertify-toggle"><input type="checkbox"/> ${t('All questions created for this form will be deleted.')}</label>
<label class="alertify-toggle"><input type="checkbox"/> ${t('The form associated with this project will be deleted.')}</label>
<label class="alertify-toggle alertify-toggle-important"><input type="checkbox" /> ${t('I understand that if I delete this project I will not be able to recover it.')}</label> `,
labels: {ok: t('Delete'), cancel: t('Cancel')},
onshow: (evt) => {
<label class="alertify-toggle alertify-toggle-important"><input type="checkbox" /> ${t('I understand that if I delete this project I will not be able to recover it.')}</label>
`;
onshow = (evt) => {
let ok_button = dialog.elements.buttons.primary.firstChild;
let $els = $('.alertify-toggle input');
ok_button.disabled = true;
var $els = $('.alertify-toggle input');
$($els).change(function() {
$els.change(function () {
ok_button.disabled = false;
$($els).each(function( index ) {
$els.each(function ( index ) {
if (!$(this).prop('checked')) {
ok_button.disabled = true;
}
}
});
});
$()
},
onok: (evt, val) => {
actions.resources.deleteAsset({uid: uid}, {
onComplete: ()=> {
this.refreshSearch && this.refreshSearch();
$('.alertify-toggle input').prop("checked", false);
}
});
};
}
let opts = {
title: t('Delete Project'),
message: msg,
labels: {
ok: t('Delete'),
cancel: t('Cancel')
},
onshow: onshow,
onok: onok,
oncancel: () => {
dialog.destroy();
$('.alertify-toggle input').prop("checked", false);
}
};
dialog.set(opts).show();
Expand Down

0 comments on commit 435b98f

Please sign in to comment.