You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lu-notifications-business.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Created by robin on 12/11/16.
  3. */
  4. (function () {
  5. 'use strict';
  6. angular.module('luticate2Utils')
  7. .factory('luNotificationsBusiness', ['luNotificationsDataAccess', function(luNotificationsDataAccess) {
  8. var luNotificationsBusiness = {};
  9. luNotificationsBusiness.EVENT_CREATE = 'EVENT_CREATE';
  10. luNotificationsBusiness.EVENT_UPDATE = 'EVENT_UPDATE';
  11. luNotificationsBusiness.EVENT_DELETE = 'EVENT_DELETE';
  12. luNotificationsBusiness.dataAccesses = {};
  13. function callbackWrapper(callback) {
  14. return function (eventName, entityType, oldEntity, newEntity) {
  15. var dataAccess = luNotificationsBusiness.dataAccesses[entityType];
  16. if (dataAccess != null && dataAccess.initDbo != null) {
  17. oldEntity = dataAccess.initDbo(oldEntity, dataAccess.TYPE_MODEL);
  18. newEntity = dataAccess.initDbo(newEntity, dataAccess.TYPE_MODEL);
  19. }
  20. return callback(eventName, entityType, oldEntity, newEntity);
  21. };
  22. }
  23. luNotificationsBusiness.init = function (dataAccesses) {
  24. luNotificationsBusiness.dataAccesses = dataAccesses;
  25. luNotificationsDataAccess.init();
  26. };
  27. luNotificationsBusiness.addEventCreateCallback = function (entityType, callback) {
  28. luNotificationsDataAccess.addCallback(luNotificationsBusiness.EVENT_CREATE, entityType,
  29. callbackWrapper(callback));
  30. };
  31. luNotificationsBusiness.addEventUpdateCallback = function (entityType, callback) {
  32. luNotificationsDataAccess.addCallback(luNotificationsBusiness.EVENT_UPDATE, entityType,
  33. callbackWrapper(callback));
  34. };
  35. luNotificationsBusiness.addEventDeleteCallback = function (entityType, callback) {
  36. luNotificationsDataAccess.addCallback(luNotificationsBusiness.EVENT_DELETE, entityType,
  37. callbackWrapper(callback));
  38. };
  39. luNotificationsBusiness.addEventCrudCallback = function (entityType, callback) {
  40. luNotificationsBusiness.addEventCreateCallback(entityType, callback);
  41. luNotificationsBusiness.addEventUpdateCallback(entityType, callback);
  42. luNotificationsBusiness.addEventDeleteCallback(entityType, callback);
  43. };
  44. return luNotificationsBusiness;
  45. }]);
  46. })();