stub.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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/array",
  19. "dojo/_base/fx",
  20. "dojo/_base/window",
  21. "dojo/dom",
  22. "dojo/dom-style",
  23. "dojo/dom-geometry",
  24. "dojo/io-query",
  25. "dojo/topic",
  26. "dojo/ready",
  27. "dojox/html/entities",
  28. "dojox/widget/Toaster",
  29. "dojox/widget/Standby"
  30. ], function (lang, arrayUtil, fx, baseWindow, dom, domStyle, domGeometry, ioQuery, topic, ready,
  31. entities, Toaster, Standby) {
  32. var initUi = function () {
  33. var params = ioQuery.queryToObject(dojo.doc.location.search.substr((dojo.doc.location.search.substr(0, 1) == "?" ? 1 : 0)));
  34. require(
  35. ["hpcc/" + params.Widget],
  36. function (WidgetClass) {
  37. var webParams = {
  38. id: "stub",
  39. "class": "hpccApp"
  40. };
  41. if (params.TabPosition) {
  42. lang.mixin(webParams, {
  43. TabPosition: params.TabPosition
  44. });
  45. }
  46. if (params.ReadOnly) {
  47. lang.mixin(webParams, {
  48. readOnly: params.ReadOnly
  49. });
  50. }
  51. var widget = WidgetClass.fixCircularDependency ? new WidgetClass.fixCircularDependency(webParams) : new WidgetClass(webParams);
  52. var standbyBackground = new Standby({
  53. color: "#FAFAFA",
  54. text: "",
  55. centerIndicator: "text",
  56. target: "stub"
  57. });
  58. dojo.body().appendChild(standbyBackground.domNode);
  59. standbyBackground.startup();
  60. standbyBackground.hpccShowCount = 0;
  61. topic.subscribe("hpcc/standbyBackgroundShow", function () {
  62. if (standbyBackground.hpccShowCount++ == 0) {
  63. standbyBackground.show();
  64. }
  65. });
  66. topic.subscribe("hpcc/standbyBackgroundHide", function () {
  67. if (--standbyBackground.hpccShowCount <= 0) {
  68. standbyBackground.hpccShowCount = 0;
  69. standbyBackground.hide();
  70. }
  71. });
  72. var standbyForeground = new Standby({
  73. zIndex: 1000,
  74. target: "stub"
  75. });
  76. dojo.body().appendChild(standbyForeground.domNode);
  77. standbyForeground.startup();
  78. standbyForeground.hpccShowCount = 0;
  79. topic.subscribe("hpcc/standbyForegroundShow", function () {
  80. standbyForeground.show();
  81. ++standbyForeground.hpccShowCount;
  82. });
  83. topic.subscribe("hpcc/standbyForegroundHide", function () {
  84. if (--standbyForeground.hpccShowCount <= 0) {
  85. standbyForeground.hpccShowCount = 0;
  86. standbyForeground.hide();
  87. }
  88. });
  89. var myToaster = new Toaster({
  90. id: 'hpcc_toaster',
  91. positionDirection: 'br-left'
  92. });
  93. topic.subscribe("hpcc/brToaster", function (topic) {
  94. if (lang.exists("Exceptions", topic)) {
  95. var context = this;
  96. arrayUtil.forEach(topic.Exceptions, function (_item, idx) {
  97. var item = lang.mixin({
  98. Severity: topic.Severity,
  99. Source: topic.Source
  100. }, _item);
  101. if ((item.Source === "WsWorkunits.WUInfo" && item.Code === 20080) ||
  102. (item.Source === "WsWorkunits.WUQuery" && item.Code === 20081)) {
  103. } else {
  104. var message = "<h4>" + entities.encode(item.Source) + "</h4><p>" + entities.encode(item.Message) + "</p>";
  105. myToaster.setContent(message, item.Severity, item.Severity === "Error" ? -1 : null);
  106. myToaster.show();
  107. }
  108. });
  109. }
  110. });
  111. if (widget) {
  112. widget.placeAt(dojo.body(), "last");
  113. widget.startup();
  114. widget.init(params);
  115. }
  116. document.title = widget.getTitle ? widget.getTitle() : params.Widget;
  117. /*
  118. dojo.publish("hpccMessageTopic", {
  119. type: "warning",
  120. message: "testing"
  121. });
  122. */
  123. }
  124. );
  125. },
  126. startLoading = function (targetNode) {
  127. var overlayNode = dom.byId("loadingOverlay");
  128. if ("none" == domStyle.get(overlayNode, "display")) {
  129. var coords = domGeometry.getMarginBox(targetNode || baseWindow.body());
  130. domGeometry.setMarginBox(overlayNode, coords);
  131. domStyle.set(dom.byId("loadingOverlay"), {
  132. display: "block",
  133. opacity: 1
  134. });
  135. }
  136. },
  137. endLoading = function () {
  138. fx.fadeOut({
  139. node: dom.byId("loadingOverlay"),
  140. duration: 175,
  141. onEnd: function (node) {
  142. domStyle.set(node, "display", "none");
  143. }
  144. }).play();
  145. };
  146. return {
  147. init: function () {
  148. startLoading();
  149. ready(function () {
  150. initUi();
  151. endLoading();
  152. });
  153. }
  154. };
  155. });