瀏覽代碼

added operation type to initModel (edit/add); added getMultipleToList

tags/v0.3.0
Robin Thoni 8 年之前
父節點
當前提交
ee24fa82e3
共有 2 個文件被更改,包括 26 次插入15 次删除
  1. 9
    0
      src/Business/lu-webapi-crud-business.js
  2. 17
    15
      src/DataAccess/lu-webapi-crud-dataaccess.js

+ 9
- 0
src/Business/lu-webapi-crud-business.js 查看文件

@@ -54,6 +54,15 @@
54 54
                     return Business.dataAccess.getMultiple(orderBy, filter, page, perPage, luBusyGroups);
55 55
                 };
56 56
 
57
+                Business.getMultipleToList = function (orderBy, filter, page, perPage, luBusyGroups) {
58
+                    var deferred = $q.defer();
59
+                    Business.getMultiple(orderBy, filter, page, perPage, luBusyGroups).then(function(data)
60
+                    {
61
+                        deferred.resolve(data.data);
62
+                    }, deferred.reject);
63
+                    return deferred.promise;
64
+                };
65
+
57 66
                 Business.addDbo = function(data, luBusyGroups) {
58 67
                     return Business.dataAccess.addDbo(data, luBusyGroups);
59 68
                 };

+ 17
- 15
src/DataAccess/lu-webapi-crud-dataaccess.js 查看文件

@@ -13,8 +13,10 @@
13 13
             luWebApiCrudDataAccess.create = function (entry_point) {
14 14
                 var DataAccess = luWebApiDataAccess.create(entry_point);
15 15
 
16
+                DataAccess.OP_EDIT = 'OP_EDIT';
17
+                DataAccess.OP_ADD = 'OP_ADD';
16 18
 
17
-                DataAccess._initModel = function(model)
19
+                DataAccess._initModel = function(model, op)
18 20
                 {
19 21
                     if (model == null) {
20 22
                         return null;
@@ -28,55 +30,55 @@
28 30
                     return model;
29 31
                 };
30 32
 
31
-                DataAccess.initModel = function(model)
33
+                DataAccess.initModel = function(model, op)
32 34
                 {
33
-                    return DataAccess._initModel(model);
35
+                    return DataAccess._initModel(model, op);
34 36
                 };
35 37
 
36
-                DataAccess.initListModel = function(list)
38
+                DataAccess.initListModel = function(list, op)
37 39
                 {
38 40
                     var d = [];
39 41
                     for (var i = 0; i < list.length; ++i) {
40
-                        d.push(DataAccess.initModel(list[i]));
42
+                        d.push(DataAccess.initModel(list[i], op));
41 43
                     }
42 44
                     return d;
43 45
                 };
44 46
 
45
-                DataAccess.initPaginatedModel = function(data)
47
+                DataAccess.initPaginatedModel = function(data, op)
46 48
                 {
47 49
                     var d = {
48 50
                         count: data.count,
49
-                        data: DataAccess.initListModel(data.data)
51
+                        data: DataAccess.initListModel(data.data, op)
50 52
                     };
51 53
                     return d;
52 54
                 };
53 55
 
54
-                DataAccess.thenInitModel = function(promise)
56
+                DataAccess.thenInitModel = function(promise, op)
55 57
                 {
56 58
                     var deferred = $q.defer();
57 59
                     promise.then(function(data)
58 60
                     {
59
-                        deferred.resolve(DataAccess.initModel(data));
61
+                        deferred.resolve(DataAccess.initModel(data, op));
60 62
                     }, deferred.reject);
61 63
                     return deferred.promise;
62 64
                 };
63 65
 
64
-                DataAccess.thenInitListModel = function(promise)
66
+                DataAccess.thenInitListModel = function(promise, op)
65 67
                 {
66 68
                     var deferred = $q.defer();
67 69
                     promise.then(function(data)
68 70
                     {
69
-                        deferred.resolve(DataAccess.initListModel(data));
71
+                        deferred.resolve(DataAccess.initListModel(data, op));
70 72
                     }, deferred.reject);
71 73
                     return deferred.promise;
72 74
                 };
73 75
 
74
-                DataAccess.thenInitPaginatedModel = function(promise)
76
+                DataAccess.thenInitPaginatedModel = function(promise, op)
75 77
                 {
76 78
                     var deferred = $q.defer();
77 79
                     promise.then(function(data)
78 80
                     {
79
-                        deferred.resolve(DataAccess.initPaginatedModel(data));
81
+                        deferred.resolve(DataAccess.initPaginatedModel(data, op));
80 82
                     }, deferred.reject);
81 83
                     return deferred.promise;
82 84
                 };
@@ -189,12 +191,12 @@
189 191
                 };
190 192
 
191 193
                 DataAccess.addDbo = function(data, luBusyGroups) {
192
-                    var model = DataAccess.initModel(data);
194
+                    var model = DataAccess.initModel(data, DataAccess.OP_ADD);
193 195
                     return DataAccess.thenInitDbo(DataAccess.post('', null, model, luBusyGroups));
194 196
                 };
195 197
 
196 198
                 DataAccess.editSingleByIdDbo = function(id, data, luBusyGroups) {
197
-                    var model = DataAccess.initModel(data);
199
+                    var model = DataAccess.initModel(data, DataAccess.OP_EDIT);
198 200
                     return DataAccess.thenInitDbo(DataAccess.post(id, null, model, luBusyGroups));
199 201
                 };
200 202
 

Loading…
取消
儲存