Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

lubusy.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * Created by robin on 10/24/15.
  3. */
  4. angular.module('luticateUtils')
  5. .directive('luBusy', ['$compile', '$http', 'luticatePromises', '$templateCache', 'luticateDialogErrorHelper',
  6. function($compile, $http, luticatePromises, $templateCache, luticateDialogErrorHelper){
  7. return {
  8. restrict: 'A',
  9. scope: {
  10. luBusy: '&'
  11. },
  12. link: function($scope, element, attrs) {
  13. var position = element.css('position');
  14. if (position === 'static' || position === '' || typeof position === 'undefined'){
  15. element.css('position','relative');
  16. }
  17. $scope.isLoading = false;
  18. $scope.hasError = false;
  19. var options = {
  20. group: attrs.luBusy,
  21. templateLoader: "luticate-loader.html",
  22. templateError: "luticate-error.html"
  23. };
  24. var o = $scope.luBusy();
  25. if (o != null) {
  26. angular.extend(options, o);
  27. }
  28. $scope.update = function()
  29. {
  30. var loaders = luticatePromises.getLoadersGroup(options.group);
  31. $scope.isLoading = false;
  32. if (loaders != null) {
  33. $scope.isLoading = loaders.some(function (promise) {
  34. return promise.status == 0;
  35. });
  36. }
  37. var errors = luticatePromises.getErrorsGroup(options.group);
  38. $scope.hasError = false;
  39. if (errors != null) {
  40. $scope.hasError = errors.some(function (promise) {
  41. return promise.status == 2;
  42. });
  43. }
  44. };
  45. $scope.loaderSplashIsActive = function() {
  46. $scope.update();
  47. return $scope.isLoading && !$scope.hasError;
  48. };
  49. $scope.errorSplashIsActive = function() {
  50. $scope.update();
  51. return $scope.hasError;
  52. };
  53. $scope.showError = function()
  54. {
  55. var errors = luticatePromises.getErrorsGroup(options.group);
  56. var error = null;
  57. if (errors != null) {
  58. error = errors.find(function (promise) {
  59. return promise.status == 2;
  60. });
  61. }
  62. if (error != null) {
  63. luticateDialogErrorHelper.errorDialog(error.value);
  64. }
  65. };
  66. function addTemplate(template, ngShow) {
  67. $http.get(template, {cache: $templateCache}).success(function (indicatorTemplate) {
  68. var templateScope = $scope.$new();
  69. var backdrop = '<div class="lu-busy lu-busy-backdrop lu-busy-backdrop-animation ng-hide" ng-show="' + ngShow + '"></div>';
  70. var backdropElement = $compile(backdrop)(templateScope);
  71. element.append(backdropElement);
  72. var template = '<div class="lu-busy lu-busy-animation" ng-show="' + ngShow + '">' + indicatorTemplate + '</div>';
  73. var templateElement = $compile(template)(templateScope);
  74. element.append(templateElement);
  75. }).error(function (data) {
  76. throw new Error('Template specified for luBusy (' + template + ') could not be loaded. ' + data);
  77. });
  78. }
  79. addTemplate(options.templateLoader, 'loaderSplashIsActive()');
  80. addTemplate(options.templateError, 'errorSplashIsActive()');
  81. }
  82. };
  83. }
  84. ]);
  85. angular.module('luticateUtils').run(['$templateCache', function($templateCache) {
  86. 'use strict';
  87. $templateCache.put('luticate-loader.html',
  88. "<div class=\"lu-busy-default-wrapper\" style=\"position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px;\">\n" +
  89. "\n" +
  90. " <div class=\"lu-busy-default-sign\">\n" +
  91. "\n" +
  92. " <div class=\"lu-busy-default-spinner\">\n" +
  93. " <div class=\"bar1\"></div>\n" +
  94. " <div class=\"bar2\"></div>\n" +
  95. " <div class=\"bar3\"></div>\n" +
  96. " <div class=\"bar4\"></div>\n" +
  97. " <div class=\"bar5\"></div>\n" +
  98. " <div class=\"bar6\"></div>\n" +
  99. " <div class=\"bar7\"></div>\n" +
  100. " <div class=\"bar8\"></div>\n" +
  101. " <div class=\"bar9\"></div>\n" +
  102. " <div class=\"bar10\"></div>\n" +
  103. " <div class=\"bar11\"></div>\n" +
  104. " <div class=\"bar12\"></div>\n" +
  105. " </div>\n" +
  106. "\n" +
  107. " <div class=\"lu-busy-default-text\">Please wait...</div>\n" +
  108. "\n" +
  109. " </div>\n" +
  110. "\n" +
  111. "</div>"
  112. );
  113. $templateCache.put('luticate-error.html',
  114. "<div class=\"lu-busy-default-wrapper\" style=\"position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px;\">\n" +
  115. "\n" +
  116. " <div class=\"lu-busy-default-sign\">\n" +
  117. "\n" +
  118. " <div class=\"lu-busy-default-error-text\"><a href=\"\" ng-click=\"showError()\">Error</a></div>\n" +
  119. "\n" +
  120. " </div>\n" +
  121. "\n" +
  122. "</div>"
  123. );
  124. }]);