Fix form error popovers in all forms

This commit is contained in:
Joseph Schorr 2014-04-07 18:55:39 -04:00
parent 8076ad0a20
commit 3d18ddf2a5
5 changed files with 63 additions and 41 deletions

View file

@ -1,13 +1,13 @@
<div class="signup-form-element"> <div class="signup-form-element">
<form class="form-signup" name="signupForm" ng-submit="register()" data-trigger="manual" <form class="form-signup" name="signupForm" ng-submit="register()" ngshow="!awaitingConfirmation && !registering">
data-content="{{ registerError }}" data-placement="left" ng-show="!awaitingConfirmation && !registering">
<input type="text" class="form-control" placeholder="Create a username" name="username" ng-model="newUser.username" autofocus required> <input type="text" class="form-control" placeholder="Create a username" name="username" ng-model="newUser.username" autofocus required>
<input type="email" class="form-control" placeholder="Email address" ng-model="newUser.email" required> <input type="email" class="form-control" placeholder="Email address" ng-model="newUser.email" required>
<input type="password" class="form-control" placeholder="Create a password" ng-model="newUser.password" required> <input type="password" class="form-control" placeholder="Create a password" ng-model="newUser.password" required>
<input type="password" class="form-control" placeholder="Verify your password" ng-model="newUser.repeatPassword" <input type="password" class="form-control" placeholder="Verify your password" ng-model="newUser.repeatPassword"
match="newUser.password" required> match="newUser.password" required>
<div class="form-group signin-buttons"> <div class="form-group signin-buttons">
<button class="btn btn-primary btn-block landing-signup-button" ng-disabled="signupForm.$invalid" type="submit" <button id="signupButton"
class="btn btn-primary btn-block landing-signup-button" ng-disabled="signupForm.$invalid" type="submit"
analytics-on analytics-event="register">Sign Up for Free!</button> analytics-on analytics-event="register">Sign Up for Free!</button>
<span class="social-alternate"> <span class="social-alternate">
<i class="fa fa-circle"></i> <i class="fa fa-circle"></i>

View file

@ -325,6 +325,42 @@ quayApp = angular.module('quay', ['ngRoute', 'chieffancypants.loadingBar', 'angu
}]); }]);
$provide.factory('UIService', [function() {
var uiService = {};
uiService.hidePopover = function(elem) {
var popover = $('#signupButton').data('bs.popover');
if (popover) {
popover.hide();
}
};
uiService.showPopover = function(elem, content) {
var popover = $(elem).data('bs.popover');
if (!popover) {
$(elem).popover({'content': '-', 'placement': 'left'});
}
setTimeout(function() {
var popover = $(elem).data('bs.popover');
popover.options.content = content;
popover.show();
}, 500);
};
uiService.showFormError = function(elem, result) {
var message = result.data['message'] || result.data['error_description'] || '';
if (message) {
uiService.showPopover(elem, message);
} else {
uiService.hidePopover(elem);
}
};
return uiService;
}]);
$provide.factory('UtilService', ['$sanitize', function($sanitize) { $provide.factory('UtilService', ['$sanitize', function($sanitize) {
var utilService = {}; var utilService = {};
@ -1582,10 +1618,9 @@ quayApp.directive('signupForm', function () {
scope: { scope: {
}, },
controller: function($scope, $location, $timeout, ApiService, KeyService, UserService) { controller: function($scope, $location, $timeout, ApiService, KeyService, UserService, UIService) {
$('.form-signup').popover();
angulartics.waitForVendorApi(mixpanel, 500, function(loadedMixpanel) {
angulartics.waitForVendorApi(mixpanel, 500, function(loadedMixpanel) {
var mixpanelId = loadedMixpanel.get_distinct_id(); var mixpanelId = loadedMixpanel.get_distinct_id();
$scope.github_state_clause = '&state=' + mixpanelId; $scope.github_state_clause = '&state=' + mixpanelId;
}); });
@ -1594,22 +1629,18 @@ quayApp.directive('signupForm', function () {
$scope.awaitingConfirmation = false; $scope.awaitingConfirmation = false;
$scope.registering = false; $scope.registering = false;
$scope.register = function() { $scope.register = function() {
$('.form-signup').popover('hide'); UIService.hidePopover('#signupButton');
$scope.registering = true; $scope.registering = true;
ApiService.createNewUser($scope.newUser).then(function() { ApiService.createNewUser($scope.newUser).then(function() {
$scope.awaitingConfirmation = true;
$scope.registering = false; $scope.registering = false;
$scope.awaitingConfirmation = true;
mixpanel.alias($scope.newUser.username); mixpanel.alias($scope.newUser.username);
}, function(result) { }, function(result) {
$scope.registering = false; $scope.registering = false;
$scope.registerError = result.data.message; UIService.showFormError('#signupButton', result);
$timeout(function() {
$('.form-signup').popover('show');
});
}); });
}; };
} }

View file

@ -1607,7 +1607,7 @@ function RepoAdminCtrl($scope, Restangular, ApiService, KeyService, $routeParams
} }
function UserAdminCtrl($scope, $timeout, $location, ApiService, PlanService, UserService, CookieService, KeyService, function UserAdminCtrl($scope, $timeout, $location, ApiService, PlanService, UserService, CookieService, KeyService,
$routeParams, $http) { $routeParams, $http, UIService) {
if ($routeParams['migrate']) { if ($routeParams['migrate']) {
$('#migrateTab').tab('show') $('#migrateTab').tab('show')
} }
@ -1640,8 +1640,6 @@ function UserAdminCtrl($scope, $timeout, $location, ApiService, PlanService, Use
$scope.githubClientId = KeyService.githubClientId; $scope.githubClientId = KeyService.githubClientId;
$scope.authorizedApps = null; $scope.authorizedApps = null;
$('.form-change').popover();
$scope.logsShown = 0; $scope.logsShown = 0;
$scope.invoicesShown = 0; $scope.invoicesShown = 0;
@ -1729,7 +1727,8 @@ function UserAdminCtrl($scope, $timeout, $location, ApiService, PlanService, Use
}; };
$scope.changeEmail = function() { $scope.changeEmail = function() {
$('#changeEmailForm').popover('hide'); UIService.hidePopover('#changeEmailForm');
$scope.updatingUser = true; $scope.updatingUser = true;
$scope.changeEmailSent = false; $scope.changeEmailSent = false;
@ -1744,16 +1743,13 @@ function UserAdminCtrl($scope, $timeout, $location, ApiService, PlanService, Use
$scope.changeEmailForm.$setPristine(); $scope.changeEmailForm.$setPristine();
}, function(result) { }, function(result) {
$scope.updatingUser = false; $scope.updatingUser = false;
UIService.showFormError('#changeEmailForm', result);
$scope.changeEmailError = result.data.message;
$timeout(function() {
$('#changeEmailForm').popover('show');
});
}); });
}; };
$scope.changePassword = function() { $scope.changePassword = function() {
$('#changePasswordForm').popover('hide'); UIService.hidePopover('#changePasswordForm');
$scope.updatingUser = true; $scope.updatingUser = true;
$scope.changePasswordSuccess = false; $scope.changePasswordSuccess = false;
@ -1771,11 +1767,7 @@ function UserAdminCtrl($scope, $timeout, $location, ApiService, PlanService, Use
UserService.load(); UserService.load();
}, function(result) { }, function(result) {
$scope.updatingUser = false; $scope.updatingUser = false;
UIService.showFormError('#changePasswordForm', result);
$scope.changePasswordError = result.data.message;
$timeout(function() {
$('#changePasswordForm').popover('show');
});
}); });
}; };
} }
@ -2160,7 +2152,7 @@ function OrgViewCtrl($rootScope, $scope, ApiService, $routeParams) {
loadOrganization(); loadOrganization();
} }
function OrgAdminCtrl($rootScope, $scope, $timeout, Restangular, $routeParams, UserService, PlanService, ApiService) { function OrgAdminCtrl($rootScope, $scope, $timeout, Restangular, $routeParams, UserService, PlanService, ApiService, UIService) {
var orgname = $routeParams.orgname; var orgname = $routeParams.orgname;
// Load the list of plans. // Load the list of plans.
@ -2199,10 +2191,12 @@ function OrgAdminCtrl($rootScope, $scope, $timeout, Restangular, $routeParams, U
}; };
$scope.$watch('organizationEmail', function(e) { $scope.$watch('organizationEmail', function(e) {
$('#changeEmailForm').popover('hide'); UIService.hidePopover('#changeEmailForm');
}); });
$scope.changeEmail = function() { $scope.changeEmail = function() {
UIService.hidePopover('#changeEmailForm');
$scope.changingOrganization = true; $scope.changingOrganization = true;
var params = { var params = {
'orgname': orgname 'orgname': orgname
@ -2218,10 +2212,7 @@ function OrgAdminCtrl($rootScope, $scope, $timeout, Restangular, $routeParams, U
$scope.organization = org; $scope.organization = org;
}, function(result) { }, function(result) {
$scope.changingOrganization = false; $scope.changingOrganization = false;
$scope.changeEmailError = result.data.message; UIService.showFormError('#changeEmailForm', result);
$timeout(function() {
$('#changeEmailForm').popover('show');
});
}); });
}; };

View file

@ -115,8 +115,8 @@
<div class="panel-title">Change e-mail address</div> <div class="panel-title">Change e-mail address</div>
<div class="panel-body"> <div class="panel-body">
<form class="form-change col-md-6" id="changeEmailForm" name="changeEmailForm" ng-submit="changeEmail()" data-trigger="manual" <form class="form-change col-md-6" id="changeEmailForm" name="changeEmailForm" ng-submit="changeEmail()"
data-content="{{ changeEmailError }}" data-placement="right" ng-show="!awaitingConfirmation && !registering"> ng-show="!awaitingConfirmation && !registering">
<input type="email" class="form-control" placeholder="Your new e-mail address" ng-model="cuser.email" required> <input type="email" class="form-control" placeholder="Your new e-mail address" ng-model="cuser.email" required>
<button class="btn btn-primary" ng-disabled="changeEmailForm.$invalid || cuser.email == user.email" type="submit">Change E-mail Address</button> <button class="btn btn-primary" ng-disabled="changeEmailForm.$invalid || cuser.email == user.email" type="submit">Change E-mail Address</button>
</form> </form>
@ -137,8 +137,8 @@
<span class="help-block" ng-show="changePasswordSuccess">Password changed successfully</span> <span class="help-block" ng-show="changePasswordSuccess">Password changed successfully</span>
<div ng-show="!updatingUser" class="panel-body"> <div ng-show="!updatingUser" class="panel-body">
<form class="form-change col-md-6" id="changePasswordForm" name="changePasswordForm" ng-submit="changePassword()" data-trigger="manual" <form class="form-change col-md-6" id="changePasswordForm" name="changePasswordForm" ng-submit="changePassword()"
data-content="{{ changePasswordError }}" data-placement="right" ng-show="!awaitingConfirmation && !registering"> ng-show="!awaitingConfirmation && !registering">
<input type="password" class="form-control" placeholder="Your new password" ng-model="cuser.password" required> <input type="password" class="form-control" placeholder="Your new password" ng-model="cuser.password" required>
<input type="password" class="form-control" placeholder="Verify your new password" ng-model="cuser.repeatPassword" <input type="password" class="form-control" placeholder="Verify your new password" ng-model="cuser.repeatPassword"
match="cuser.password" required> match="cuser.password" required>

View file

@ -50,7 +50,7 @@
<!-- ,typeahead.js@0.10.1 --> <!-- ,typeahead.js@0.10.1 -->
<script src="/static/lib/loading-bar.js"></script> <script src="/static/lib/loading-bar.js"></script>
<script src="/static/lib/angular-strap.min.js"></script> <script src="/static/lib/angular-strap.js"></script>
<script src="/static/lib/angular-strap.tpl.min.js"></script> <script src="/static/lib/angular-strap.tpl.min.js"></script>
<script src="/static/lib/angulartics.js"></script> <script src="/static/lib/angulartics.js"></script>
<script src="/static/lib/angulartics-mixpanel.js"></script> <script src="/static/lib/angulartics-mixpanel.js"></script>