12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- (function () {
- 'use strict';
- angular.module('appSdk')
- .factory('RequestDataAccess', ['$q', '$http', 'PromisesDataAccess', function ($q, $http, PromisesDataAccess) {
-
- var DataAccess = {};
-
- DataAccess.get = function(url, dataGet, promise)
- {
- return DataAccess.request(url, 'GET', dataGet, null, promise);
- };
-
- DataAccess.post = function(url, dataPost, dataGet, promise)
- {
- return DataAccess.request(url, 'POST', dataGet, dataPost, promise);
- };
-
- DataAccess.put = function(url, dataPost, dataGet, promise)
- {
- return DataAccess.request(url, 'PUT', dataGet, dataPost, promise);
- };
-
- DataAccess.delete = function(url, dataPost, dataGet, promise)
- {
- return DataAccess.request(url, 'DELETE', dataGet, dataPost, promise);
- };
-
- function reject(defered, data, status, promise)
- {
- var obj = {
- Data: data,
- Status: status
- };
- defered.reject(obj);
- if (promise != null) {
- PromisesDataAccess.reject(promise, obj);
- }
- }
-
- function resolve(defered, data, promise)
- {
- defered.resolve(data);
- if (promise != null) {
- PromisesDataAccess.resolve(promise, data);
- }
- }
-
- DataAccess.request = function(url, method, dataGet, dataPost, promise)
- {
- if (promise != null) {
- PromisesDataAccess.initPromise(promise);
- }
- var defered = $q.defer();
-
- url = url.replace(/\/+$/, '');
-
- var params = {
- url: url,
- method: method,
- params: dataGet,
- data: dataPost == null ? null : $.param(dataPost),
- headers: {
- 'Content-Type': "application/x-www-form-urlencoded"
- }
- };
-
- $http(params)
- .success(function (result, status) {
- resolve(defered, result, promise);
- })
- .error(function (result, status) {
- reject(defered, result, status, promise);
- });
- return defered.promise;
- };
-
- return DataAccess;
- }]);
- })();
|