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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. luBusy: '&'
  10. },
  11. link: function($scope, element, attrs) {
  12. var position = element.css('position');
  13. if (position === 'static' || position === '' || typeof position === 'undefined'){
  14. element.css('position','relative');
  15. }
  16. $scope.isLoading = false;
  17. $scope.hasError = false;
  18. var options = {
  19. group: attrs.luBusy,
  20. templateLoader: "luticate-loader.html",
  21. templateError: "luticate-error.html"
  22. };
  23. var o = $scope.luBusy();
  24. if (o != null) {
  25. angular.extend(options, o);
  26. }
  27. console.log(options);
  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. function addTemplate(template, ngShow) {
  54. $http.get(template, {cache: $templateCache}).success(function (indicatorTemplate) {
  55. var templateScope = $scope.$new();
  56. var backdrop = '<div class="lu-busy lu-busy-backdrop lu-busy-backdrop-animation ng-hide" ng-show="' + ngShow + '"></div>';
  57. var backdropElement = $compile(backdrop)(templateScope);
  58. element.append(backdropElement);
  59. var template = '<div class="lu-busy lu-busy-animation" ng-show="' + ngShow + '">' + indicatorTemplate + '</div>';
  60. var templateElement = $compile(template)(templateScope);
  61. element.append(templateElement);
  62. }).error(function (data) {
  63. throw new Error('Template specified for luBusy (' + template + ') could not be loaded. ' + data);
  64. });
  65. }
  66. addTemplate(options.templateLoader, 'loaderSplashIsActive()');
  67. addTemplate(options.templateError, 'errorSplashIsActive()');
  68. }
  69. };
  70. }
  71. ]);
  72. angular.module('luticateUtils').run(['$templateCache', function($templateCache) {
  73. 'use strict';
  74. $templateCache.put('luticate-loader.html',
  75. "<div class=\"lu-busy-default-wrapper\" style=\"position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px;\">\n" +
  76. "\n" +
  77. " <div class=\"lu-busy-default-sign\">\n" +
  78. "\n" +
  79. " <div class=\"lu-busy-default-spinner\">\n" +
  80. " <div class=\"bar1\"></div>\n" +
  81. " <div class=\"bar2\"></div>\n" +
  82. " <div class=\"bar3\"></div>\n" +
  83. " <div class=\"bar4\"></div>\n" +
  84. " <div class=\"bar5\"></div>\n" +
  85. " <div class=\"bar6\"></div>\n" +
  86. " <div class=\"bar7\"></div>\n" +
  87. " <div class=\"bar8\"></div>\n" +
  88. " <div class=\"bar9\"></div>\n" +
  89. " <div class=\"bar10\"></div>\n" +
  90. " <div class=\"bar11\"></div>\n" +
  91. " <div class=\"bar12\"></div>\n" +
  92. " </div>\n" +
  93. "\n" +
  94. " <div class=\"lu-busy-default-text\">Please wait...</div>\n" +
  95. "\n" +
  96. " </div>\n" +
  97. "\n" +
  98. "</div>"
  99. );
  100. $templateCache.put('luticate-error.html',
  101. "<div class=\"lu-busy-default-wrapper\" style=\"position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px;\">\n" +
  102. "\n" +
  103. " <div class=\"lu-busy-default-sign\">\n" +
  104. "\n" +
  105. " <div class=\"lu-busy-default-error-text\">Error</div>\n" +
  106. "\n" +
  107. " </div>\n" +
  108. "\n" +
  109. "</div>"
  110. );
  111. }]);