/** * Created by robin on 10/24/15. */ angular.module('appSdk') .directive('luBusy', ['$compile', '$http', 'PromisesDataAccess', '$templateCache', function($compile, $http, PromisesDataAccess, $templateCache){ return { restrict: 'A', scope: { luBusy: '&' }, link: function($scope, element, attrs) { /*var position = element.css('position'); if (position === 'static' || position === '' || typeof position === 'undefined'){ element.css('position','relative'); }*/ $scope.isLoading = false; $scope.hasError = false; var options = { group: attrs.luBusy, templateLoader: "/luticate/lubusy-loader.html", templateError: "/luticate/lubusy-error.html" }; $scope.update = function() { var o = $scope.luBusy(); if (o != null) { if (typeof o == 'string') { options.group = o; } else { angular.extend(options, o); } } var loaders = PromisesDataAccess.getLoadersGroup(options.group); $scope.isLoading = false; if (loaders != null) { $scope.isLoading = loaders.some(function (promise) { return promise.status == 0; }); } var errors = PromisesDataAccess.getErrorsGroup(options.group); $scope.hasError = false; if (errors != null) { $scope.hasError = errors.some(function (promise) { return promise.status == 2; }); } }; $scope.loaderSplashIsActive = function() { $scope.update(); return $scope.isLoading && !$scope.hasError; }; $scope.errorSplashIsActive = function() { $scope.update(); return $scope.hasError; }; $scope.showError = function() { var errors = PromisesDataAccess.getErrorsGroup(options.group); var error = null; if (errors != null) { error = errors.find(function (promise) { return promise.status == 2; }); } if (error != null) { //luticateDialogErrorHelper.errorDialog(error.value); } }; function addTemplate(template, ngShow) { $http.get(template, {cache: $templateCache}).success(function (indicatorTemplate) { var templateScope = $scope.$new(); var backdrop = '
'; var backdropElement = $compile(backdrop)(templateScope); element.append(backdropElement); var template = '