-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-service.js
executable file
·79 lines (74 loc) · 2.68 KB
/
app-service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
angular.module('app').service('HTTPService', HTTPService);
HTTPService.$inject = ['$http'];
function HTTPService($http) {
var service = {
get: function (type, sub_layer, id, match_perspective_id) {
var t = typeof type !== 'undefined' ? type : null;
var s = typeof sub_layer !== 'undefined' ? sub_layer : 0;
var i = typeof id !== 'undefined' ? id : null;
var m_id =
typeof match_perspective_id !== 'undefined' ? match_perspective_id : null;
var config = {params:
{type: t, sub_layer: s, id: i, match_perspective_id: m_id}};
return $http.get('backend/php/query.php', config).then(
function successCallback(response) {
console.log(response);
return response.data;
},
function errorCallback(response) {
service.handleError(response);
});
},
save: function (obj, type, sub_layer) {
var o = typeof obj !== 'undefined' ? obj : null;
var t = typeof type !== 'undefined' ? type : null;
var s = typeof sub_layer !== 'undefined' ? sub_layer : 0;
var config = {params: {mode: 'save', type: t, sub_layer: s}};
return $http.post('backend/php/post.php', {obj: o}, config).then(
function successCallback(response) {
console.log(response);
return response;
},
function errorCallback(response) {
service.handleError(response);
});
},
delete: function (type, obj) {
var t = typeof type !== 'undefined' ? type : null;
var o = typeof obj !== 'undefined' ? obj : null;
var config = {params: {mode: 'delete', type: t}};
return $http.post('backend/php/post.php', {obj: o}, config).then(
function successCallback(response) {
console.log(response);
return response;
},
function errorCallback(response) {
service.handleError(response);
});
},
img_upload: function (file, old_image) {
var myFormData = new FormData();
myFormData.append('file', file);
config = {headers: {'Content-Type': undefined},
params: {old_image: old_image}};
return $http.post('backend/php/upload.php', myFormData, config).then(
function successCallback(response) {
console.log(response);
return response;
},
function errorCallback(response) {
service.handleError(response);
});
},
handleError: function (response) {
console.log('Error in HTTP query or post!');
console.log('HTTP Status Text: ' + response.statusText);
console.log('HTTP Status: ' + response.status);
console.log('Transmitted configuration object:');
console.log(response.config);
console.log('Returned data object (if present):');
console.log(response.data);
}
};
return service;
}