1 //require <jquery.packed.js> 2 (function(){ 3 4 5 jQuery(document).ready(function($){ 6 7 var form = $('#change-password-form'); 8 var successPage = $('#change-password-complete'); 9 10 form.show(); 11 successPage.hide(); 12 13 var oldPasswordField = $('#--current-password'); 14 var newPasswordField1 = $('#--password1'); 15 var newPasswordField2 = $('#--password2'); 16 var submitBtn = $('#change-password-submit'); 17 submitBtn.click(function(){ 18 return handleSubmitClicked(this); 19 }); 20 21 function handleSubmitClicked(btn){ 22 23 if ( !newPasswordField1.val() ){ 24 alert('You cannot enter a blank password.'); 25 return false; 26 } 27 28 if ( newPasswordField1.val() != newPasswordField2.val() ){ 29 alert('Your passwords do not match. Please ensure that you type your new password the same in both fields.'); 30 return false; 31 } 32 33 var query = { 34 '-action': 'change_password', 35 '--current-password': oldPasswordField.val(), 36 '--password1': newPasswordField1.val(), 37 '--password2': newPasswordField2.val() 38 }; 39 40 submitBtn.attr('disabled',1); 41 submitBtn.after('<img class="progress-image" src="'+DATAFACE_URL+'/images/progress.gif" alt="please wait ..."/>'); 42 $.post(DATAFACE_SITE_HREF, query, function(response){ 43 44 handleChangePasswordResponse(response); 45 submitBtn.attr('disabled',0); 46 $('.progress-image').remove(); 47 48 }); 49 return false; 50 51 } 52 53 54 function handleChangePasswordResponse(response){ 55 56 try { 57 if ( typeof(response) == 'string' ){ 58 eval('response='+response+';'); 59 } 60 61 if ( response.code == 200 ){ 62 successPage.show(); 63 form.hide(); 64 } else if ( response.message ){ 65 throw response.message; 66 } else { 67 throw "Password was not changed due to a server error. Please check the server logs for more details."; 68 } 69 70 } catch (e){ 71 alert(e); 72 } 73 74 } 75 76 }); 77 78 79 })();