stub.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "dojo/_base/lang",
  18. "dojo/_base/fx",
  19. "dojo/_base/window",
  20. "dojo/dom",
  21. "dojo/dom-style",
  22. "dojo/dom-geometry",
  23. "dojo/io-query",
  24. "dojo/topic",
  25. "dojo/ready",
  26. "dojox/widget/Toaster",
  27. "dojox/widget/Standby"
  28. ], function (lang, fx, baseWindow, dom, domStyle, domGeometry, ioQuery, topic, ready,
  29. Toaster, Standby) {
  30. var initUi = function () {
  31. var params = ioQuery.queryToObject(dojo.doc.location.search.substr((dojo.doc.location.search.substr(0, 1) == "?" ? 1 : 0)));
  32. require(
  33. ["hpcc/" + params.Widget],
  34. function (WidgetClass) {
  35. var webParams = {
  36. id: "stub",
  37. "class": "hpccApp"
  38. };
  39. if (params.TabPosition) {
  40. lang.mixin(webParams, {
  41. TabPosition: params.TabPosition
  42. });
  43. }
  44. if (params.ReadOnly) {
  45. lang.mixin(webParams, {
  46. readOnly: params.ReadOnly
  47. });
  48. }
  49. var widget = WidgetClass.fixCircularDependency ? new WidgetClass.fixCircularDependency(webParams) : new WidgetClass(webParams);
  50. var standbyBackground = new Standby({
  51. color: "#FAFAFA",
  52. text: "",
  53. centerIndicator: "text",
  54. target: "stub"
  55. });
  56. dojo.body().appendChild(standbyBackground.domNode);
  57. standbyBackground.startup();
  58. standbyBackground.hpccShowCount = 0;
  59. topic.subscribe("hpcc/standbyBackgroundShow", function () {
  60. if (standbyBackground.hpccShowCount++ == 0) {
  61. standbyBackground.show();
  62. }
  63. });
  64. topic.subscribe("hpcc/standbyBackgroundHide", function () {
  65. if (--standbyBackground.hpccShowCount <= 0) {
  66. standbyBackground.hpccShowCount = 0;
  67. standbyBackground.hide();
  68. }
  69. });
  70. var standbyForeground = new Standby({
  71. zIndex: 1000,
  72. target: "stub"
  73. });
  74. dojo.body().appendChild(standbyForeground.domNode);
  75. standbyForeground.startup();
  76. standbyForeground.hpccShowCount = 0;
  77. topic.subscribe("hpcc/standbyForegroundShow", function () {
  78. standbyForeground.show();
  79. ++standbyForeground.hpccShowCount;
  80. });
  81. topic.subscribe("hpcc/standbyForegroundHide", function () {
  82. if (--standbyForeground.hpccShowCount <= 0) {
  83. standbyForeground.hpccShowCount = 0;
  84. standbyForeground.hide();
  85. }
  86. });
  87. var myToaster = new Toaster({
  88. id: 'hpcc_toaster',
  89. positionDirection: 'br-left',
  90. messageTopic: 'hpcc/brToaster'
  91. });
  92. if (widget) {
  93. widget.placeAt(dojo.body(), "last");
  94. widget.startup();
  95. widget.init(params);
  96. }
  97. /*
  98. dojo.publish("hpccMessageTopic", {
  99. type: "warning",
  100. message: "testing"
  101. });
  102. */
  103. }
  104. );
  105. },
  106. startLoading = function (targetNode) {
  107. var overlayNode = dom.byId("loadingOverlay");
  108. if ("none" == domStyle.get(overlayNode, "display")) {
  109. var coords = domGeometry.getMarginBox(targetNode || baseWindow.body());
  110. domGeometry.setMarginBox(overlayNode, coords);
  111. domStyle.set(dom.byId("loadingOverlay"), {
  112. display: "block",
  113. opacity: 1
  114. });
  115. }
  116. },
  117. endLoading = function () {
  118. fx.fadeOut({
  119. node: dom.byId("loadingOverlay"),
  120. duration: 175,
  121. onEnd: function (node) {
  122. domStyle.set(node, "display", "none");
  123. }
  124. }).play();
  125. };
  126. return {
  127. init: function () {
  128. startLoading();
  129. ready(function () {
  130. initUi();
  131. endLoading();
  132. });
  133. }
  134. };
  135. });