1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /**
- * Created by robin on 10/24/15.
- */
-
- (function () {
- 'use strict';
- angular.module('appSdk')
- .factory('PromisesDataAccess', [function() {
-
- var luticatePromises = {};
- luticatePromises.promises = {};
- luticatePromises.loaders = [];
- luticatePromises.errors = [];
-
- luticatePromises.build = function(array)
- {
- luticatePromises[array] = {};
- for (var id in luticatePromises.promises) {
- var promise = luticatePromises.promises[id];
- promise[array].forEach(function(group) {
- if (luticatePromises[array][group] == null) {
- luticatePromises[array][group] = [];
- }
- luticatePromises[array][group].push(promise);
- });
- }
- };
-
- luticatePromises.initPromise = function(data) {
- var p = {
- loaders : [],
- errors: [],
- status: 0,
- id: data.id
- };
- if (data.groups) {
- data.groups.forEach(function (group){
- p.loaders.push(group);
- p.errors.push(group);
- });
- }
- if (data.loaderGroups) {
- data.loaderGroups.forEach(function(group)
- {
- p.loaders.push(group);
- });
- }
- if (data.errorGroups) {
- data.errorGroups.forEach(function(group)
- {
- p.errors.push(group);
- });
- }
- luticatePromises.promises[data.id] = p;
-
- luticatePromises.build("loaders");
- luticatePromises.build("errors");
- };
-
- luticatePromises.getLoadersGroup = function(group) {
- if (luticatePromises.loaders[group] == null) {
- return null;
- }
- return luticatePromises.loaders[group];
- };
-
- luticatePromises.getErrorsGroup = function(group) {
- if (luticatePromises.errors[group] == null) {
- return null;
- }
- return luticatePromises.errors[group];
- };
-
- luticatePromises.reject = function(promise, error) {
- luticatePromises.promises[promise.id].status = 2;
- luticatePromises.promises[promise.id].value = error;
- };
-
- luticatePromises.resolve = function(promise, data) {
- luticatePromises.promises[promise.id].status = 1;
- luticatePromises.promises[promise.id].value = data;
- };
-
- return luticatePromises;
- }]);
- })();
|