Browse Source

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

tags/v0.3.0
Robin Thoni 8 years ago
parent
commit
ee24fa82e3

+ 9
- 0
src/Business/lu-webapi-crud-business.js View File

54
                     return Business.dataAccess.getMultiple(orderBy, filter, page, perPage, luBusyGroups);
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
                 Business.addDbo = function(data, luBusyGroups) {
66
                 Business.addDbo = function(data, luBusyGroups) {
58
                     return Business.dataAccess.addDbo(data, luBusyGroups);
67
                     return Business.dataAccess.addDbo(data, luBusyGroups);
59
                 };
68
                 };

+ 17
- 15
src/DataAccess/lu-webapi-crud-dataaccess.js View File

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

Loading…
Cancel
Save