/** * Created by robin on 10/24/15. */ angular.module('luticateUtils') .directive('luBusy', ['$compile', '$http', 'luticatePromises', '$templateCache', 'luticateDialogErrorHelper', function($compile, $http, luticatePromises, $templateCache, luticateDialogErrorHelper){ 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 = luticatePromises.getLoadersGroup(options.group); $scope.isLoading = false; if (loaders != null) { $scope.isLoading = loaders.some(function (promise) { return promise.status == 0; }); } var errors = luticatePromises.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 = luticatePromises.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 = '
' + indicatorTemplate + '
'; var templateElement = $compile(template)(templateScope); element.append(templateElement); }).error(function (data) { throw new Error('Template specified for luBusy (' + template + ') could not be loaded. ' + data); }); } addTemplate(options.templateLoader, 'loaderSplashIsActive()'); addTemplate(options.templateError, 'errorSplashIsActive()'); } }; } ]); angular.module('luticateUtils').run(['$templateCache', function($templateCache) { 'use strict'; $templateCache.put('/luticate/lubusy-loader.html', "
\n" + "\n" + "
\n" + "\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "\n" + "
Please wait...
\n" + "\n" + "
\n" + "\n" + "
" ); $templateCache.put('/luticate/lubusy-error.html', "
\n" + "\n" + "
\n" + "\n" + " \n" + "\n" + "
\n" + "\n" + "
" ); }]);