From 6d6307f9c9e5c78b753fdcfffa102dd6724422b6 Mon Sep 17 00:00:00 2001 From: Steven Miers Date: Thu, 7 May 2015 18:01:12 -0500 Subject: [PATCH] VRFS-3047 : Polish Save & Next buttons on profile editing screens. --- .../assets/javascripts/accounts_profile.js | 33 ++++++++++++++----- .../javascripts/accounts_profile_avatar.js | 21 +++++++++--- .../accounts_profile_experience.js | 19 +++++++++-- .../javascripts/accounts_profile_interests.js | 23 ++++++++++--- .../javascripts/accounts_profile_samples.js | 23 +++++++++---- 5 files changed, 91 insertions(+), 28 deletions(-) diff --git a/web/app/assets/javascripts/accounts_profile.js b/web/app/assets/javascripts/accounts_profile.js index c791fb567..584fb6ff8 100644 --- a/web/app/assets/javascripts/accounts_profile.js +++ b/web/app/assets/javascripts/accounts_profile.js @@ -223,15 +223,10 @@ navToAccount(); return false; }); - - $btnSubmit.click(function(evt) { - evt.stopPropagation(); - handleUpdateProfile(); - return false; - }); - - $('#account-profile-content-scroller').on('submit', '#account-edit-email-form', function(evt) { evt.stopPropagation(); handleUpdateProfile(); return false; } ); + $('#account-profile-content-scroller').on('click', '#account-change-avatar', function(evt) { evt.stopPropagation(); navToAvatar(); return false; } ); + + enableSubmits(); } function renderAccountProfile() { @@ -258,6 +253,7 @@ } function handleUpdateProfile() { + disableSubmits(); resetForm(); var country = getCountryElement().val(); @@ -283,6 +279,25 @@ }) .done(postUpdateProfileSuccess) .fail(postUpdateProfileFailure) + .always(enableSubmits) + } + + function enableSubmits() { + $btnSubmit.click(function(evt) { + evt.stopPropagation(); + handleUpdateProfile(); + return false; + }); + $btnSubmit.removeClass("disabled"); + $('#account-profile-content-scroller').on('submit', '#account-edit-email-form', function(evt) { evt.stopPropagation(); handleUpdateProfile(); return false; } ); + $("#account-edit-email-form").removeClass("disabled"); + } + + function disableSubmits() { + $("#account-edit-email-form").addClass("disabled") + $("#account-edit-email-form").off("click") + $btnSubmit.addClass("disabled") + $btnSubmit.off("click") } function postUpdateProfileSuccess(response) { @@ -339,7 +354,7 @@ } else { app.ajaxError(xhr, textStatus, errorMessage) - } + } } function handleCountryChanged() { diff --git a/web/app/assets/javascripts/accounts_profile_avatar.js b/web/app/assets/javascripts/accounts_profile_avatar.js index c89039d97..63d1aca1f 100644 --- a/web/app/assets/javascripts/accounts_profile_avatar.js +++ b/web/app/assets/javascripts/accounts_profile_avatar.js @@ -59,11 +59,21 @@ // wire up main panel clicks $('#account-profile-avatar-content-scroller').on('click', '#account-edit-avatar-upload', function(evt) { evt.stopPropagation(); handleFilePick(); return false; } ); $('#account-profile-avatar-content-scroller').on('click', '#account-edit-avatar-delete', function(evt) { evt.stopPropagation(); handleDeleteAvatar(); return false; } ); - $('#account-profile-avatar-content-scroller').on('click', '#account-edit-avatar-cancel', function(evt) { evt.stopPropagation(); navToEditProfile(); return false; } ); - $('#account-profile-avatar-content-scroller').on('click', '#account-edit-avatar-submit', function(evt) { evt.stopPropagation(); handleUpdateAvatar(); return false; } ); + $('#account-profile-avatar-content-scroller').on('click', '#account-edit-avatar-cancel', function(evt) { evt.stopPropagation(); navToEditProfile(); return false; } ); + enableSubmits() //$('#account-profile-avatar-content-scroller').on('change', 'input[type=filepicker-dragdrop]', function(evt) { evt.stopPropagation(); afterImageUpload(evt.originalEvent.fpfile); return false; } ); } + function enableSubmits() { + $('#account-profile-avatar-content-scroller').on('click', '#account-edit-avatar-submit', function(evt) { evt.stopPropagation(); handleUpdateAvatar(); return false; } ); + $("#account-edit-avatar-submit").removeClass("disabled") + } + + function disableSubmits() { + $("#account-edit-avatar-submit").addClass("disabled") + $("#account-edit-avatar-submit").off("click") + } + function handleDeleteAvatar() { if(self.updatingAvatar) { @@ -277,7 +287,7 @@ } function handleUpdateAvatar(event) { - + disableSubmits() if(self.updatingAvatar) { // protect against concurrent update attempts return; @@ -373,10 +383,11 @@ }, null, true); - } + } + enableSubmits() } - function updateAvatarSuccess(response) { + function updateAvatarSuccess(response) { $.cookie('original_fpfile', null); self.userDetail = response; diff --git a/web/app/assets/javascripts/accounts_profile_experience.js b/web/app/assets/javascripts/accounts_profile_experience.js index 4e13c3d79..6bb22fbab 100644 --- a/web/app/assets/javascripts/accounts_profile_experience.js +++ b/web/app/assets/javascripts/accounts_profile_experience.js @@ -124,12 +124,23 @@ navigateTo('/client#/account/profile/'); return false; }); - - $btnSubmit.click(function(evt) { + + enableSubmits() + } + + function enableSubmits() { + $btnSubmit.on("click", function(evt) { evt.stopPropagation(); handleUpdateProfile(); return false; }); + + $btnSubmit.removeClass("disabled") + } + + function disableSubmits() { + $btnSubmit.addClass("disabled") + $btnSubmit.off("click") } function renderExperience() { @@ -148,6 +159,7 @@ } function handleUpdateProfile() { + disableSubmits() resetForm(); var instruments = getSelectedInstruments(); @@ -161,7 +173,8 @@ studio_session_count: $screen.find('select[name=studio_session_count]').val() }) .done(postUpdateProfileSuccess) - .fail(postUpdateProfileFailure); + .fail(postUpdateProfileFailure) + .always(enableSubmits) } function postUpdateProfileSuccess(response) { diff --git a/web/app/assets/javascripts/accounts_profile_interests.js b/web/app/assets/javascripts/accounts_profile_interests.js index a52d65987..41000beb7 100644 --- a/web/app/assets/javascripts/accounts_profile_interests.js +++ b/web/app/assets/javascripts/accounts_profile_interests.js @@ -189,15 +189,26 @@ return false; }); - $btnSubmit.click(function(evt) { + enableSubmits(); + + context.JK.dropdown($virtualBandCommitment); + context.JK.dropdown($traditionalBandCommitment); + context.JK.dropdown($cowritingPurpose); + } + + function enableSubmits() { + $btnSubmit.on("click", function(evt) { evt.stopPropagation(); handleUpdateProfile(); return false; }); - context.JK.dropdown($virtualBandCommitment); - context.JK.dropdown($traditionalBandCommitment); - context.JK.dropdown($cowritingPurpose); + $btnSubmit.removeClass("disabled") + } + + function disableSubmits() { + $btnSubmit.addClass("disabled") + $btnSubmit.off("click") } function renderInterests() { @@ -212,6 +223,7 @@ } function handleUpdateProfile() { + disableSubmits() resetForm(); api.updateUser({ @@ -237,7 +249,8 @@ cowriting_purpose: $cowritingPurpose.val() }) .done(postUpdateProfileSuccess) - .fail(postUpdateProfileFailure); + .fail(postUpdateProfileFailure) + .always(enableSubmits); } function postUpdateProfileSuccess(response) { diff --git a/web/app/assets/javascripts/accounts_profile_samples.js b/web/app/assets/javascripts/accounts_profile_samples.js index 51cb3e632..3aa544610 100644 --- a/web/app/assets/javascripts/accounts_profile_samples.js +++ b/web/app/assets/javascripts/accounts_profile_samples.js @@ -201,12 +201,22 @@ return false; }); - $btnSubmit.click(function(evt) { - if (validate()) { - handleUpdateProfile(); - } + enableSubmits(); + } + + function enableSubmits() { + $btnSubmit.on("click", function(evt) { + evt.stopPropagation(); + handleUpdateProfile(); return false; }); + + $btnSubmit.removeClass("disabled") + } + + function disableSubmits() { + $btnSubmit.addClass("disabled") + $btnSubmit.off("click") } function validate() { @@ -259,7 +269,7 @@ } function handleUpdateProfile() { - + disableSubmits() // extract online presences var op = []; var presenceTypes = profileUtils.ONLINE_PRESENCE_TYPES; @@ -284,7 +294,8 @@ performance_samples: ps }) .done(postUpdateProfileSuccess) - .fail(postUpdateProfileFailure); + .fail(postUpdateProfileFailure) + .always(enableSubmits); } function postUpdateProfileSuccess(response) {