You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lubusy.js 4.5KB

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