summaryrefslogtreecommitdiff
path: root/client/js/services
diff options
context:
space:
mode:
Diffstat (limited to 'client/js/services')
-rw-r--r--client/js/services/Image.js214
-rw-r--r--client/js/services/Loading.js45
-rw-r--r--client/js/services/Network.js50
3 files changed, 163 insertions, 146 deletions
diff --git a/client/js/services/Image.js b/client/js/services/Image.js
index 4947a1d..795f85e 100644
--- a/client/js/services/Image.js
+++ b/client/js/services/Image.js
@@ -1,102 +1,114 @@
-mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){
-
- var data={};
- data.images=null;
-
-
- var parseUploadImageAnswer=function(response, failedToSendRequest){
-
- // Defined return object
- var requestParserResult={};
- requestParserResult.status=1;
- requestParserResult.failReason=null;
-
-
- if (typeof response.data.Images !== 'undefined') {
- // Set status code
- requestParserResult.status=0;
- data.images=response.data.Images;
-
- }
- else if(failedToSendRequest){
- requestParserResult.failReason="Failed to send request";
- }
- else{
- requestParserResult.failReason="Error";
- }
- return requestParserResult;
- };
-
-
- var getImages=function(callback){
-
- var result=$http.post('../server/index.php',
- $.param({"token" : Identity.getToken(), "task" : "image", 'action':'listImage'}));
-
- // Wait and handle the response
- result.then(function (response){
- callback(parseUploadImageAnswer(response, false));
- },function(response){
- callback(parseUploadImageAnswer(response, true));
- });
-
-
- };
-
- var uploadImage=function(fileToUpload, callback) {
- var form_data = new FormData();
- form_data.append('file', fileToUpload);
- console.log(fileToUpload);
- form_data.append("task" , "image");
- form_data.append("token" , Identity.getToken());
- form_data.append('action',"uploadImage");
- form_data.append('id','6564');
- form_data.append('file_name', fileToUpload);
-
- $.ajax({
- url: "../server/index.php", // Url to which the request is send
- type: "POST", // Type of request to be send, called as method
- data: form_data, // Data sent to server, a set of key/value pairs (i.e. form fields and values)
- file_name:fileToUpload,
- token : Identity.getToken(),
- task : "image",
- action:'uploadImage',
- id:'6564',
- contentType: false, // The content type used when sending data to the server.
- cache: false, // To unable request pages to be cached
- processData:false, // To send DOMDocument or non processed data file it is set to false
- success: function(data) // A function to be called if request succeeds
- {
- alert("success");
- }
- });
-
- //var result=$http.post('../server/index.php',
- // $.param({"token" : Identity.getToken(), "task" : "image", 'action':'uploadImage', 'file_name':form_data, 'id':'6564'}));
-
- // Wait and handle the response
- /* result.then(function (response){
- callback(parseUploadImageAnswer(response, false));
- },function(response){
- callback(parseUploadImageAnswer(response, true));
- });*/
-
-
-
- }
-
-
- var getData=function(response){
- return data;
- };
-
- // Return services objects
- return {
- getImages:getImages,
- getData:getData,
- uploadImage:uploadImage
- };
-
-
-}]);
+mainApp.factory('Image', ['$http', 'Identity', function ($http, Identity) {
+
+ // Data object
+ var data = {};
+ data.images = null; // Images
+
+ /**
+ * Parse uploadImage anwser
+ * @param {type} response
+ * @param {type} failedToSendRequest
+ * @returns {Image_L2.parseUploadImageAnswer.requestParserResult}
+ */
+ var parseUploadImageAnswer = function (response, failedToSendRequest) {
+
+ // Defined return object
+ var requestParserResult = {};
+ requestParserResult.status = 1;
+ requestParserResult.failReason = null;
+
+
+ if (typeof response.data.Images !== 'undefined') {
+ // Set status code
+ requestParserResult.status = 0;
+ data.images = response.data.Images;
+
+ } else if (failedToSendRequest) {
+ requestParserResult.failReason = "Failed to send request";
+ } else {
+ requestParserResult.failReason = "Error";
+ }
+ return requestParserResult;
+ };
+
+
+ /**
+ * Get images
+ * @param {type} callback
+ * @returns {undefined}
+ */
+ var getImages = function (callback) {
+
+ var result = $http.post('../server/index.php',
+ $.param({"token": Identity.getToken(), "task": "image", 'action': 'listImage'}));
+
+ // Wait and handle the response
+ result.then(function (response) {
+ callback(parseUploadImageAnswer(response, false));
+ }, function (response) {
+ callback(parseUploadImageAnswer(response, true));
+ });
+
+
+ };
+
+ /**
+ * Upload an image
+ * @param {type} fileToUpload
+ * @param {type} callback
+ * @returns {undefined}
+ */
+ var uploadImage = function (fileToUpload, callback) {
+ var form_data = new FormData();
+ form_data.append('file', fileToUpload);
+ console.log(fileToUpload);
+ form_data.append("task", "image");
+ form_data.append("token", Identity.getToken());
+ form_data.append('action', "uploadImage");
+ form_data.append('id', '6564');
+ form_data.append('file_name', fileToUpload);
+
+ $.ajax({
+ url: "../server/index.php", // Url to which the request is send
+ type: "POST", // Type of request to be send, called as method
+ data: form_data, // Data sent to server, a set of key/value pairs (i.e. form fields and values)
+ file_name: fileToUpload,
+ token: Identity.getToken(),
+ task: "image",
+ action: 'uploadImage',
+ id: '6564',
+ contentType: false, // The content type used when sending data to the server.
+ cache: false, // To unable request pages to be cached
+ processData: false, // To send DOMDocument or non processed data file it is set to false
+ success: function (data) // A function to be called if request succeeds
+ {
+ alert("success");
+ }
+ });
+
+ //var result=$http.post('../server/index.php',
+ // $.param({"token" : Identity.getToken(), "task" : "image", 'action':'uploadImage', 'file_name':form_data, 'id':'6564'}));
+
+ // Wait and handle the response
+ /* result.then(function (response){
+ callback(parseUploadImageAnswer(response, false));
+ },function(response){
+ callback(parseUploadImageAnswer(response, true));
+ });*/
+ };
+
+
+ var getData = function (response) {
+ return data;
+ };
+
+ // Return services objects
+ return {
+ getImages: getImages,
+ getData: getData,
+ uploadImage: uploadImage
+ };
+
+
+ }]);
diff --git a/client/js/services/Loading.js b/client/js/services/Loading.js
index db06194..7ea2b42 100644
--- a/client/js/services/Loading.js
+++ b/client/js/services/Loading.js
@@ -1,23 +1,26 @@
+/**
+ * Loading service
+ * @param {type} param1
+ * @param {type} param2
+ */
+mainApp.factory('Loading', [function () {
+ /**
+ * Display Loading modal
+ */
+ var start = function () {
+ $('#loadingModal').modal({backdrop: 'static', keyboard: false});
+ };
-mainApp.factory('Loading',[ function(){
- /**
- * Display Loading modal
- */
- var start=function(){
- $('#loadingModal').modal({backdrop: 'static', keyboard: false});
- };
+ /**
+ * Hide Loading modal
+ */
+ var stop = function () {
+ $('#loadingModal').modal('hide');
+ };
- /**
- * Hide Loading modal
- */
- var stop=function(){
- $('#loadingModal').modal('hide');
- }
-
-
- // Service returns
- return {
- start:start,
- stop:stop
- };
-}]);
+ // Service returns
+ return {
+ start: start,
+ stop: stop
+ };
+ }]);
diff --git a/client/js/services/Network.js b/client/js/services/Network.js
index bd2a24f..a0cd5a4 100644
--- a/client/js/services/Network.js
+++ b/client/js/services/Network.js
@@ -1,27 +1,29 @@
-mainApp.factory('Network',[ '$http', 'Identity', function($http, Identity){
-
- var data={};
- data.networks=null;
-
-var ListId=function(fileToUpload, callback) {
-
-
- var result=$http.post('../server/index.php',
- $.param({"token" : Identity.getToken(), "task" : "network", 'action':'list_network_ids'}));
-
- // Wait and handle the response
- result.then(function (response){
- callback(parseUploadImageAnswer(response, false));
- },function(response){
- callback(parseUploadImageAnswer(response, true));
- });
-
- console.log(result)
-
- }
-
-
-}]);
+mainApp.factory('Network', ['$http', 'Identity', function ($http, Identity) {
+
+ // Data object
+ var data = {};
+ data.networks = null; // Networks
+
+ /**
+ * ListId
+ * @param {type} fileToUpload
+ * @param {type} callback
+ * @returns {undefined}
+ */
+ var ListId = function (fileToUpload, callback) {
+ var result = $http.post('../server/index.php',
+ $.param({"token": Identity.getToken(), "task": "network", 'action': 'list_network_ids'}));
+
+ // Wait and handle the response
+ result.then(function (response) {
+ callback(parseUploadImageAnswer(response, false));
+ }, function (response) {
+ callback(parseUploadImageAnswer(response, true));
+ });
+ };
+
+
+ }]);