123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- /**
- * Created by robin on 10/24/15.
- */
-
- angular.module('appSdk')
- .directive('luBusy', ['$compile', '$http', 'PromisesDataAccess', '$templateCache', '$mdDialog',
- function($compile, $http, PromisesDataAccess, $templateCache, $mdDialog){
- 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) {
- $mdDialog.show(
- $mdDialog.alert()
- .parent(angular.element(document.querySelector('#popupContainer')))
- .clickOutsideToClose(true)
- .title('Oops, an error has occurred')
- .textContent(error.value.Data.Message || error.value)
- .ariaLabel('Oops, an error has occurred')
- .ok('Ok')
- );
- }
- };
-
- function addTemplate(template, ngShow) {
-
- $http.get(template, {cache: $templateCache}).success(function (indicatorTemplate) {
- var templateScope = $scope.$new();
- var backdrop = '<div class="lu-busy lu-busy-backdrop lu-busy-backdrop-animation ng-hide" ng-show="' + ngShow + '"></div>';
- var backdropElement = $compile(backdrop)(templateScope);
- element.append(backdropElement);
-
- var template = '<div class="lu-busy lu-busy-animation ng-hide" ng-show="' + ngShow + '">' + indicatorTemplate + '</div>';
- 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('appSdk').run(['$templateCache', function($templateCache) {
- 'use strict';
-
- $templateCache.put('/luticate/lubusy-loader.html',
- "<div class=\"lu-busy-default-wrapper\" style=\"position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px;\">\n" +
- "\n" +
- " <div class=\"lu-busy-default-sign\">\n" +
- "\n" +
- " <div class=\"lu-busy-default-spinner\">\n" +
- " <div class=\"bar1\"></div>\n" +
- " <div class=\"bar2\"></div>\n" +
- " <div class=\"bar3\"></div>\n" +
- " <div class=\"bar4\"></div>\n" +
- " <div class=\"bar5\"></div>\n" +
- " <div class=\"bar6\"></div>\n" +
- " <div class=\"bar7\"></div>\n" +
- " <div class=\"bar8\"></div>\n" +
- " <div class=\"bar9\"></div>\n" +
- " <div class=\"bar10\"></div>\n" +
- " <div class=\"bar11\"></div>\n" +
- " <div class=\"bar12\"></div>\n" +
- " </div>\n" +
- "\n" +
- " <div class=\"lu-busy-default-text\">Please wait...</div>\n" +
- "\n" +
- " </div>\n" +
- "\n" +
- "</div>"
- );
-
- $templateCache.put('/luticate/lubusy-error.html',
- "<div class=\"lu-busy-default-wrapper\" style=\"position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px;\">\n" +
- "\n" +
- " <div class=\"lu-busy-default-sign\">\n" +
- "\n" +
- " <div class=\"lu-busy-default-error-text\"><a href=\"\" ng-click=\"showError()\">Error</a></div>\n" +
- "\n" +
- " </div>\n" +
- "\n" +
- "</div>"
- );
-
- }]);
|