Fix angular style issues.

This commit is contained in:
Alexis Lahouze 2016-10-14 07:50:06 +02:00
parent a872788def
commit edac1ee6a9
1 changed files with 65 additions and 62 deletions

View File

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