Fix angular style issues.

This commit is contained in:
Alexis Lahouze 2016-10-14 07:50:06 +02:00
parent a872788def
commit edac1ee6a9

View File

@ -27,7 +27,7 @@ angular.module('accountant', [
'Storage.Service' 'Storage.Service'
]) ])
.factory('sessionInjector', ['$storage', function($storage) { .factory('sessionInjector', function($storage) {
var sessionInjector = { var sessionInjector = {
request: function(config) { request: function(config) {
var token = $storage.get('token'); var token = $storage.get('token');
@ -43,14 +43,14 @@ angular.module('accountant', [
}; };
return sessionInjector; return sessionInjector;
}]) })
.config(['$httpProvider', function($httpProvider) { .config(function($httpProvider) {
// Define interceptors. // Define interceptors.
$httpProvider.interceptors.push('sessionInjector'); $httpProvider.interceptors.push('sessionInjector');
}]) })
.config(['$routeProvider', function($routeProvider) { .config(function($routeProvider) {
// Defining template and controller in function of route. // Defining template and controller in function of route.
$routeProvider $routeProvider
.when('/account/:accountId/operations', { .when('/account/:accountId/operations', {
@ -71,9 +71,9 @@ angular.module('accountant', [
.otherwise({ .otherwise({
redirectTo: '/accounts' redirectTo: '/accounts'
}); });
}]) })
.config(['$storageProvider', function($storageProvider) { .config(function($storageProvider) {
// Configure storage // Configure storage
// Set global prefix for stored keys // Set global prefix for stored keys
$storageProvider.setPrefix('accountant'); $storageProvider.setPrefix('accountant');
@ -85,74 +85,77 @@ angular.module('accountant', [
// Change the enabled storage engines // Change the enabled storage engines
// Defaults to ['memory', 'cookie', 'session', 'local'] // Defaults to ['memory', 'cookie', 'session', 'local']
$storageProvider.setEnabledStorageEngines(['local', 'session']); $storageProvider.setEnabledStorageEngines(['local', 'session']);
}]) })
.run(function(editableOptions) { .run(function(editableOptions) {
editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default' editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
}) })
.controller('MainController', [ .controller('MainController', function($scope, $rootScope, $http, authService, $storage, $ngBootbox) {
'$scope', '$rootScope', '$http', 'authService', '$storage', '$ngBootbox', var vm = this;
function($scope, $rootScope, $http, authService, $storage, $ngBootbox) {
$scope.dialogShown = false;
$scope.showLoginForm = function() { vm.dialogShown = false;
// First, if there are registered credentials, use them
if ($scope.dialogShown) {
return;
}
$scope.dialogShown = true; vm.showLoginForm = function() {
// First, if there are registered credentials, use them
if ($scope.dialogShown) {
return;
}
$storage.clear(); vm.dialogShown = true;
$ngBootbox.customDialog({ $storage.clear();
title: 'Authentification requise',
templateUrl: 'views/login.tmpl.html',
buttons: {
login: {
label: 'Login',
className: 'btn-primary',
callback: function() {
$scope.dialogShown = false;
var email = $('#email').val(); $ngBootbox.customDialog({
var password = $('#password').val(); title: 'Authentification requise',
$http.post( templateUrl: 'views/login.tmpl.html',
'/api/user/login', buttons: {
{ login: {
email: email, label: 'Login',
password: password className: 'btn-primary',
} callback: function() {
).success(function(result) { vm.dialogShown = false;
// TODO Alexis Lahouze 2015-08-28 Handle callback.
// Call to /api/login to retrieve the token
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
$storage.set('token_type', result.token_type);
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
$storage.set('token', result.token);
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
$storage.set('expiration_date', result.expiration_date);
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
authService.loginConfirmed(); var email = $('#email').val();
}); var password = $('#password').val();
} $http.post(
}, '/api/user/login',
cancel: { {
label: 'Annuler', email: email,
className: 'btn-default', password: password
callback: function() { }
authService.loginCancelled(null, 'Login cancelled by user action.'); ).success(function(result) {
$scope.dialogShown = false; // TODO Alexis Lahouze 2015-08-28 Handle callback.
} // Call to /api/login to retrieve the token
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
$storage.set('token_type', result.token_type);
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
$storage.set('token', result.token);
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
$storage.set('expiration_date', result.expiration_date);
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
authService.loginConfirmed();
});
}
},
cancel: {
label: 'Annuler',
className: 'btn-default',
callback: function() {
authService.loginCancelled(null, 'Login cancelled by user action.');
vm.dialogShown = false;
} }
} }
}); }
}; });
};
$rootScope.$on('event:auth-loginRequired', $scope.showLoginForm); var onAuthLoginRequired = $rootScope.$on('event:auth-loginRequired', $scope.showLoginForm);
}
]) $scope.$on('$destroy', function() {
onAuthLoginRequired = angular.noop();
});
})
; ;