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 5.8KB

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