Ver código fonte

init

tags/0.1.0
Robin Thoni 9 anos atrás
commit
a826f56feb
3 arquivos alterados com 92 adições e 0 exclusões
  1. 1
    0
      .gitignore
  2. 16
    0
      bower.json
  3. 75
    0
      src/request.js

+ 1
- 0
.gitignore Ver arquivo

@@ -0,0 +1 @@
1
+/.idea

+ 16
- 0
bower.json Ver arquivo

@@ -0,0 +1,16 @@
1
+{
2
+  "name": "luticate-utils",
3
+  "version": "0.0.0",
4
+  "authors": [
5
+    "Robin THONI <robin@rthoni.com>"
6
+  ],
7
+  "description": "Luticate front utils",
8
+  "license": "MIT",
9
+  "ignore": [
10
+    "**/.*",
11
+    "node_modules",
12
+    "bower_components",
13
+    "test",
14
+    "tests"
15
+  ]
16
+}

+ 75
- 0
src/request.js Ver arquivo

@@ -0,0 +1,75 @@
1
+/**
2
+ * Created by robin on 10/24/15.
3
+ */
4
+
5
+angular.module('luticate', []);
6
+(function () {
7
+    'use strict';
8
+    angular.module('luticate')
9
+        .factory('luticateUtils', ['$q', '$http', function ($q, $http) {
10
+
11
+            var coPlanningServices = {};
12
+
13
+            coPlanningServices.get = function(url, dataGet)
14
+            {
15
+                return coPlanningServices.request(url, 'GET', dataGet, null);
16
+            };
17
+
18
+            coPlanningServices.post = function(url, dataPost, dataGet)
19
+            {
20
+                return coPlanningServices.request(url, 'POST', dataGet, dataPost);
21
+            };
22
+
23
+            coPlanningServices.put = function(url, dataPost, dataGet)
24
+            {
25
+                return coPlanningServices.request(url, 'PUT', dataGet, dataPost);
26
+            };
27
+
28
+            coPlanningServices.delete = function(url, dataPost, dataGet)
29
+            {
30
+                return coPlanningServices.request(url, 'DELETE', dataGet, dataPost);
31
+            };
32
+
33
+            coPlanningServices.request = function(url, method, dataGet, dataPost)
34
+            {
35
+                var defered = $q.defer();
36
+
37
+                var params = {
38
+                    url: url,
39
+                    method: method,
40
+                    params: dataGet,
41
+                    data: dataPost
42
+                };
43
+
44
+                $http(params)
45
+                    .success(function (result, status) {
46
+                        if (result.Message != null) {
47
+                            defered.reject({
48
+                                data: result.Message,
49
+                                status: status
50
+                            });
51
+                        }
52
+                        else {
53
+                            defered.resolve(result.Data);
54
+                        }
55
+                    })
56
+                    .error(function (result, status) {
57
+                        if (result.Message != null) {
58
+                            defered.reject({
59
+                                data: result.Message,
60
+                                status: status
61
+                            });
62
+                        }
63
+                        else {
64
+                            defered.reject({
65
+                                data: result,
66
+                                status: status
67
+                            });
68
+                        }
69
+                    });
70
+                return defered.promise;
71
+            };
72
+
73
+            return coPlanningServices;
74
+        }]);
75
+})();

Carregando…
Cancelar
Salvar