-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathBase.js
executable file
·70 lines (59 loc) · 1.49 KB
/
Base.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
(function(){
'use strict';
Base.$inject =['$http','$q'];
function Base($http,$q){
var defaultParams = {};
this.get = get;
this.getById = getById;
this.getNew = getNew;
this.deleteAll = deleteAll;
this.save = save;
this.update = update;
this.del = del;
this.postImage = postImage;
this.deleteImage = deleteImage;
function get(url,params) {
if (!params) {
params = defaultParams;
}
return $http.get(url, params);
}
function getById(url,id) {
return $http.get(url + '/' + id);
}
function getNew(url){
return $http.get(url+'/new');
}
function deleteAll(url,entities) {
var promises = entities.map(function(entity){
return del(url,entity);
});
return $q.all(promises);
}
function save(url,entity) {
return $http.post(url, entity);
}
function update(url,entity) {
return $http.put(url + '/' + entity.id, entity);
}
function del(url,entity) {
return $http.delete(url + '/' + entity.id);
}
function postImage(url, attribute, model) {
var fd = new FormData();
fd.append(attribute, model);
return $http.post(url + '/' + attribute + '/', fd, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
});
}
function deleteImage(url, attribute, value) {
return $http.delete(url + '/' + attribute + '/' + value, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
});
}
}
angular.module('gumga.services.base',[])
.service('GumgaBase',Base);
})();