summaryrefslogtreecommitdiff
path: root/client/js
diff options
context:
space:
mode:
authorYoggzo <yogg@epsina.com>2016-02-08 17:10:24 +0100
committerYoggzo <yogg@epsina.com>2016-02-08 17:10:24 +0100
commitf1585a13323d408b6917a514bed1920aec3780f0 (patch)
treeb98a23443d20af008cbb8eca16a7aff7c9aa823c /client/js
parent43b65e1dbb53300d076f5885b5393ff68e248dd1 (diff)
parent1cd1ae92f414573942262f65dc1644e8ff9bb8f6 (diff)
Merge branch 'develop' into Evan
mise a jour
Diffstat (limited to 'client/js')
-rw-r--r--client/js/app.js22
-rw-r--r--client/js/controllers/home/main.js9
-rw-r--r--client/js/controllers/login.js67
-rw-r--r--client/js/controllers/network/main.js9
-rw-r--r--client/js/controllers/status.js34
-rw-r--r--client/js/requests/identity.js86
-rw-r--r--client/js/services/sharedProfile.js13
7 files changed, 142 insertions, 98 deletions
diff --git a/client/js/app.js b/client/js/app.js
index 0e9c423..90fae89 100644
--- a/client/js/app.js
+++ b/client/js/app.js
@@ -1,9 +1,16 @@
-// Declare main app
+/**
+ * The main app module instance
+ * @type angular.module.angular-1_3_6_L1749.moduleInstance
+ */
var mainApp=angular.module("mainApp",['ngRoute', 'ngSanitize']);
-
+/**
+ * Configure routeProvider
+ */
mainApp.config(['$routeProvider', function($routeProvider){
+
+
$routeProvider.
when('/home',{
templateUrl: 'partials/home/main.html',
@@ -15,4 +22,13 @@ mainApp.config(['$routeProvider', function($routeProvider){
}).otherwise({
redirectTo: '/home'
});
-}]); \ No newline at end of file
+}]);
+
+/**
+ * Configure httpProvider
+ */
+mainApp.config(['$httpProvider', function($httpProvider){
+ $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
+
+}]);
+
diff --git a/client/js/controllers/home/main.js b/client/js/controllers/home/main.js
index 2898de2..e629779 100644
--- a/client/js/controllers/home/main.js
+++ b/client/js/controllers/home/main.js
@@ -1,9 +1,8 @@
-/*
- * home Controller
+/**
+ * The home controller
+ *
+ * @param {$scope} $scope The $scope service from angular
*/
-
-
-
mainApp.controller('homeCtrl', function ($scope)
{
diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js
index 2f74414..751bd09 100644
--- a/client/js/controllers/login.js
+++ b/client/js/controllers/login.js
@@ -1,39 +1,60 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
/**
- * Represents a book.
- * @constructor
+ * The login controler
+ * @param {$scope} $scope The $scope angular service
+ * @param {$sce} $sce The $sce angular service
+ * @param {$http} $http The $http angular service
+ * @param {sharedProfile} sharedProfile The sharedProfile service
+
*/
-mainApp.controller('loginCtrl', function ($scope,$interval,$sce)
+mainApp.controller('loginCtrl', ['$scope','$sce','$http', 'sharedProfile', function ($scope,$sce, $http, sharedProfile)
{
- // Define default states
- $('#loginModal').modal({backdrop: 'static', keyboard: false});
- $('#loadingLoginButton').hide();
- $('#failedToLoginAlert').hide();
-
+ // Define default states
+ $('#loginModal').modal({backdrop: 'static', keyboard: false});
+ $('#loadingLoginButton').hide();
+ $('#failedToLoginAlert').hide();
+
- $('#loginButton').click(function(){
+ $('#loginButton').click(function(){
$('#loginButton').hide();
$('#loadingLoginButton').show();
$('#failedToLoginAlert').hide();
+ var username=$("#loginFormUsername").val();
+ var password=$("#loginFormPassword").val();
+ var projectname=$("#loginFormProjectname").val();
+
+ var result=identity.request.login($http,username, password, projectname);
+
+ result.then(function (response){
+ // Parser result
+ var requestResultObject=identity.requestParser.parseLoginAnswer(response);
+
+ // Check for error
+ if(requestResultObject.status!==0){
+ //alert(result.data)
+ $('#failedToLoginAlert').show();
+ }
+ else {
+ $('#loginModal').modal('hide');
+ sharedProfile.username=username;
+ sharedProfile.projectname=projectname;
- $interval(
- function()
- {
- $('#failedToLoginAlert').show();
+ }
+ // Reset button state
$('#loginButton').show();
- $('#loadingLoginButton').hide();
-
- }, 2000,1);
-
+ $('#loadingLoginButton').hide();
+ },function(response){
+ $('#failedToLoginAlert').show();
+
+ // Reset button state
+ $('#loginButton').show();
+ $('#loadingLoginButton').hide();
+ });
+
});
-})
+}]);
diff --git a/client/js/controllers/network/main.js b/client/js/controllers/network/main.js
index 6c916ae..7264aec 100644
--- a/client/js/controllers/network/main.js
+++ b/client/js/controllers/network/main.js
@@ -1,9 +1,8 @@
-/*
- * network Controller
+/**
+ * The network controller
+ *
+ * @param {$scope} $scope The $scope service from angular
*/
-
-
-
mainApp.controller('networkCtrl', function ($scope)
{
}); \ No newline at end of file
diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js
index 42a54d4..ce6882e 100644
--- a/client/js/controllers/status.js
+++ b/client/js/controllers/status.js
@@ -1,28 +1,14 @@
-/*
- * mainApp Controller
- */
-
-mainApp.controller('statusCtrl', function ($scope,$interval,$sce)
+/**
+ * The status controller
+ *
+ * @param {$scope} $scope The $scope service from angular
+ * @param {sharedProfile} sharedProfile The sharedProfile build by ourself
+ */
+mainApp.controller('statusCtrl', ['$scope','sharedProfile', function ($scope, sharedProfile)
{
- $scope.username="John Doe";
- $scope.projectname="Web Server";
- // Update status every 2 seconds
- /*$interval(function(){
- var status=identity.fetchStatus();
- $scope.username=status[1];
- $scope.lastconnection=status[2];
- if(status[0] == "1"){
- $scope.connection=$sce.trustAsHtml("<span style=\"color:green;\">Online</span>");
- }
- else{
- $scope.connection=$sce.trustAsHtml("<span style=\"color:red;\">Offline</span>");
- }
- }, 2000);*/
-
-
-
-
+ $scope.profile=sharedProfile;
+
-}); \ No newline at end of file
+}]); \ No newline at end of file
diff --git a/client/js/requests/identity.js b/client/js/requests/identity.js
index cad1261..be3f4f8 100644
--- a/client/js/requests/identity.js
+++ b/client/js/requests/identity.js
@@ -1,42 +1,52 @@
-// Make Namespace
-var identity = {} ;
-
-
-
-
-
-
-/*
-mainApp.controller('identityCtrl', function($scope, $http) {
-
- $scope.identityFormData = {};
-
- $scope.processForm = function() {
-
- $http({
- method : 'POST',
- url : 'http://148.60.11.31/',
- data : $.param($scope.identityFormData),
- headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
- })
- .success(function(data) {
- console.log(data);
-
- if (!data.success) {
- // if not successful, bind errors to error variables
- //$scope.errorName = data.errors.name;
- //$scope.errorSuperhero = data.errors.superheroAlias;
- } else {
- // if successful, bind success message to message
- //$scope.message = data.message;
- }
- });
- };
-
-
+/**
+ * Client Identity Module
+ * @namespace identity
+ */
+var identity = {};
+
+/**
+ * Contain all request who can be send with http request
+ * @namespace request
+ */
+identity.request = {};
+
+/**
+ * Contain parser for result of request made by {@link identity.request}
+ * @namespace request
+ */
+identity.requestParser = {};
+
+
+/**
+ *
+ * @param {object} $http Angular $http service
+ * @param {string} username The user name
+ * @param {string} password The user password
+ * @param {string} projectname The user project name
+ * @returns {promise} The result of the request
+ */
+identity.request.login=function($http,username, password,projectname){
+ return $http.post('../server/index.php',
+ $.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname}));
+};
+
+
+/**
+ *
+ * @param {string} response The response to parse
+ * @returns {requestParserResult} Formated data
+ */
+identity.requestParser.parseLoginAnswer=function(response){
+ var requestParserResult={};
+
+ requestParserResult.status=0;
+ requestParserResult.data=response.data;
-});*/
-
+ // TODO
+
+
+ return requestParserResult;
+};
diff --git a/client/js/services/sharedProfile.js b/client/js/services/sharedProfile.js
new file mode 100644
index 0000000..6e78cf6
--- /dev/null
+++ b/client/js/services/sharedProfile.js
@@ -0,0 +1,13 @@
+
+/**
+ * The sharedProfile service
+ * It's used to shared the profile between controller
+ */
+mainApp.factory('sharedProfile',[function(){
+ var profile={};
+
+ profile.username="None";
+ profile.projectname="None";
+
+ return profile;
+}]); \ No newline at end of file