1 2/* BASE - account */ 3 4 5/* profile functions */ 6 7 8function initProfile(context) // called from context JS file 9{ 10 assignProfileListeners(context); 11 configureFormFields(context); 12} 13 14 15function assignProfileListeners(context) 16{ 17 $('.delete-profile-picture').on('click', function() 18 { 19 if (confirm('Are you sure you want to delete?')) 20 { 21 remove_profile_picture(context); 22 } 23 }); 24 25 $('.send-verification-email').on('click', function() 26 { 27 send_verification_email(context); 28 }); 29 30 $('.profile-content').on('click','.btn-edit', function() 31 { 32 var $section = $(this).parents('.panel:first'); 33 $section.find('.btn-edit').hide(); 34 $section.find('.save').show(); 35 $section.find('.overview').hide(); 36 $section.find('.form-fields').show(); 37 return false; 38 }); 39 40 // flag email amendment 41 $('.profile-content').on('keyup change','#email', function() 42 { 43 var newEmail = $(this).val(); 44 var originalEmail = $('form #original-email').val(); 45 if (newEmail != originalEmail) 46 { 47 $(this).parents('form:first').addClass('email-amended'); 48 } 49 else 50 { 51 $(this).parents('form:first').removeClass('email-amended'); 52 } 53 }); 54 55 // profile submission - check for amended email 56 $('form').on('click', '.btn-profile-save', function() 57 { 58 var $form = $(this).parents('form:first'); 59 var saveResponse = saveForm($form, context); 60 61 // was email amended? 62 var emailAmended = $(this).parents('form:first').hasClass('email-amended'); 63 if (emailAmended && saveResponse.result == 'SUCCESS') 64 { 65 // set pending email field 66 $('form #pending_email').val($('form #email').val()); 67 68 // reveal pending form data 69 $('form #email').parents('.form-group:first').css('display','none') 70 $('form #pending_email').parents('.form-group:first').css('display','block'); 71 $('.pending-email-actions').css('display','block'); 72 73 // reset email field 74 $('form #email').val($('form #original-email').val()); 75 } 76 return false; 77 }); 78} 79 80 81/* supporting functions */ 82 83 84function configureFormFields() 85{ 86 // username 87 $('form #username').addClass('is-unique-field'); // applies ajax lookup & validation 88 $('form #username').addClass('is-unique'); // set post validation 89 $('form #username').data('ci-controller', 'user_login'); 90 $('form #username').data('field-key', 'username'); 91 92 // email addresss 93 $('form #email').addClass('is-unique-field'); // applies ajax lookup & validation 94 $('form #email').addClass('is-unique'); // set post validation 95 $('form #email').data('ci-controller', 'contact'); 96 $('form #email').data('field-key', 'email'); 97 98 // password 99 $('form #repeat_password').addClass('validate'); // applies validation 100 $('form #repeat_password').addClass('match-field'); // applies validation 101 $('form #repeat_password').data('match-field', '#password'); 102 103 // pending email 104 if ($('form #pending_email').val() != '') 105 { 106 $('form #email').parents('.form-group:first').css('display','none'); 107 } 108 else 109 { 110 $('form #pending_email').parents('.form-group:first').css('display','none'); 111 $('.pending-email-actions').css('display','none'); 112 } 113} 114 115function refresh_profile_picture(context) 116{ 117 closeModal(); 118 119 var baseURL = $('body').data('url'); 120 $.ajax( 121 {
122 type : "POST", 123 url : baseURL + context + '/account/ajax_update_profile_picture', 124 error : function() 125 { 126 $(".profile-picture").notify('An error occurred, please try again later', 'error'); 127 }, 128 success : function(data) 129 { 130 var d = new Date(); 131 $('.profile-picture').attr('src', data + '?' + d.getTime()); 132 $(".profile-picture").notify('Your profile picture has been successfully updated', 'success'); 133 } 134 }); 135} 136 137 138function remove_profile_picture(context) 139{ 140 var baseURL = $('body').data('url'); 141 $.ajax( 142 { 143 type : "POST", 144 url : baseURL + context + '/account/ajax_remove_profile_picture', 145 error : function() 146 { 147 $(".profile-picture").notify('An error occurred, please try again later', 'error'); 148 }, 149 success : function(data) 150 { 151 var d = new Date(); 152 $('.profile-picture').attr('src', data + '?' + d.getTime()); 153 } 154 }); 155} 156 157 158function send_verification_email(context) 159{ 160 var baseURL = $('body').data('url'); 161 $.ajax( 162 { 163 type : "POST", 164 url : baseURL + context + '/account/ajax_send_verification_email', 165 error : function() 166 { 167 $.notify('An error occurred, please try again later', 'error'); 168 }, 169 success : function(data) 170 { 171 $.notify('Email sent', 'success'); 172 } 173 }); 174} 175 176// close modal 177function closeModal() 178{ 179 $.colorbox.close(); 180}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.