|
| 1 | +var midas = midas || {}; |
| 2 | +midas.user = midas.user || {}; |
| 3 | +midas.user.deletedialog = {}; |
| 4 | + |
| 5 | +/** |
| 6 | + * Toggles the Delete button based on the state of the agreement checkbox |
| 7 | + * in order to make the operation safer |
| 8 | + */ |
| 9 | +midas.user.deletedialog.agreeCheckboxChanged = function() |
| 10 | + { |
| 11 | + if($(this).attr('checked') == 'checked') |
| 12 | + { |
| 13 | + $('#deleteDialogDeleteButton').removeAttr('disabled'); |
| 14 | + } |
| 15 | + else |
| 16 | + { |
| 17 | + $('#deleteDialogDeleteButton').attr('disabled', 'disabled'); |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | +/** |
| 22 | + * When the user confirms deletion request, this will get called before ajax submission |
| 23 | + */ |
| 24 | +midas.user.deletedialog.confirm = function() |
| 25 | + { |
| 26 | + $('#deleteDialogDeleteButton').attr('disabled', 'disabled'); |
| 27 | + $('#deleteDialogCancelButton').attr('disabled', 'disabled'); |
| 28 | + $('#deleteDialogAgreeCheckbox').attr('disabled', 'disabled'); |
| 29 | + $('img#deleteDialogLoadingGif').show(); |
| 30 | + // TODO add please wait message? |
| 31 | + } |
| 32 | + |
| 33 | +/** |
| 34 | + * Called when our ajax request to delete the user returns |
| 35 | + */ |
| 36 | +midas.user.deletedialog.success = function(responseText, statusText, xhr, form) |
| 37 | + { |
| 38 | + $('div.MainDialog').dialog('close'); |
| 39 | + $('#deleteDialogCancelButton').removeAttr('disabled'); |
| 40 | + $('#deleteDialogAgreeCheckbox').removeAttr('disabled'); |
| 41 | + $('#deleteDialogAgreeCheckbox').removeAttr('checked'); |
| 42 | + $('input#declineApplyRecursive').removeAttr('disabled'); |
| 43 | + $('img#deleteDialogLoadingGif').hide(); |
| 44 | + jsonResponse = $.parseJSON(responseText); |
| 45 | + |
| 46 | + if(jsonResponse == null) |
| 47 | + { |
| 48 | + createNotice('Error', 4000); |
| 49 | + return; |
| 50 | + } |
| 51 | + createNotice(jsonResponse[1], 4000); |
| 52 | + window.location.replace(json.global.webroot + '/user/index'); |
| 53 | + } |
| 54 | + |
| 55 | +$(document).ready(function() { |
| 56 | + $('#deleteDialogAgreeCheckbox').change(midas.user.deletedialog.agreeCheckboxChanged); |
| 57 | + $('#deleteDialogCancelButton').click(function() { |
| 58 | + $('div.MainDialog').dialog('close'); |
| 59 | + }); |
| 60 | + |
| 61 | + $('#deleteDialogForm').ajaxForm({ |
| 62 | + beforeSubmit: midas.user.deletedialog.confirm, |
| 63 | + success: midas.user.deletedialog.success |
| 64 | + }); |
| 65 | +}); |
0 commit comments