Explorar el Código

lu notification init dbo

tags/v0.1.3
Robin Thoni hace 8 años
padre
commit
d0641da427
Se han modificado 1 ficheros con 22 adiciones y 5 borrados
  1. 22
    5
      src/Business/lu-notifications-business.js

+ 22
- 5
src/Business/lu-notifications-business.js Ver fichero

@@ -15,21 +15,38 @@
15 15
 
16 16
             luNotificationsBusiness.EVENT_DELETE = 'EVENT_DELETE';
17 17
 
18
-
19
-            luNotificationsBusiness.init = function () {
18
+            luNotificationsBusiness.businesses = {};
19
+
20
+
21
+            function callbackWrapper(callback) {
22
+                return function (eventName, entityType, oldEntity, newEntity) {
23
+                    var business = luNotificationsBusiness.businesses[entityType];
24
+                    if (business != null && business.initDbo != null) {
25
+                        oldEntity = business.initDbo(oldEntity);
26
+                        newEntity = business.initDbo(newEntity);
27
+                    }
28
+                    return callback(eventName, entityType, oldEntity, newEntity);
29
+                };
30
+            }
31
+
32
+            luNotificationsBusiness.init = function (businesses) {
33
+                luNotificationsBusiness.businesses = businesses;
20 34
                 luNotificationsDataAccess.init();
21 35
             };
22 36
 
23 37
             luNotificationsBusiness.addEventCreateCallback = function (entityType, callback) {
24
-                luNotificationsDataAccess.addCallback(luNotificationsBusiness.EVENT_CREATE, entityType, callback);
38
+                luNotificationsDataAccess.addCallback(luNotificationsBusiness.EVENT_CREATE, entityType,
39
+                    callbackWrapper(callback));
25 40
             };
26 41
 
27 42
             luNotificationsBusiness.addEventUpdateCallback = function (entityType, callback) {
28
-                luNotificationsDataAccess.addCallback(luNotificationsBusiness.EVENT_UPDATE, entityType, callback);
43
+                luNotificationsDataAccess.addCallback(luNotificationsBusiness.EVENT_UPDATE, entityType,
44
+                    callbackWrapper(callback));
29 45
             };
30 46
 
31 47
             luNotificationsBusiness.addEventDeleteCallback = function (entityType, callback) {
32
-                luNotificationsDataAccess.addCallback(luNotificationsBusiness.EVENT_DELETE, entityType, callback);
48
+                luNotificationsDataAccess.addCallback(luNotificationsBusiness.EVENT_DELETE, entityType,
49
+                    callbackWrapper(callback));
33 50
             };
34 51
 
35 52
             luNotificationsBusiness.addEventCrudCallback = function (entityType, callback) {

Loading…
Cancelar
Guardar