A generic helper method to execute a HTTP request to the backend
(url, method, model)
| 71 | |
| 72 | /** A generic helper method to execute a HTTP request to the backend */ |
| 73 | function _request(url, method, model){ |
| 74 | var def = $q.defer(), |
| 75 | req = { |
| 76 | method: method, |
| 77 | url: url +suffix |
| 78 | }; |
| 79 | |
| 80 | if(!method) { |
| 81 | req.method = 'GET'; |
| 82 | } |
| 83 | |
| 84 | if(model) { |
| 85 | req.data = model; |
| 86 | } |
| 87 | $http(req).success(function(data) { |
| 88 | def.resolve(data); |
| 89 | }).error(function(data, code) { |
| 90 | def.reject(data); |
| 91 | if(data.actionError) { |
| 92 | $rootScope.$emit('data-error', { msg: data.actionError }); |
| 93 | } |
| 94 | $log.error(data, code); |
| 95 | }); |
| 96 | return def.promise; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | })(); |