stub.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. var hpccWidget = params.Widget ? params.Widget : "HPCCPlatformWidget";
  35. require(
  36. ["hpcc/" + hpccWidget],
  37. function (WidgetClass) {
  38. var webParams = {
  39. id: "stub",
  40. "class": "hpccApp"
  41. };
  42. if (params.TabPosition) {
  43. lang.mixin(webParams, {
  44. TabPosition: params.TabPosition
  45. });
  46. }
  47. if (params.ReadOnly) {
  48. lang.mixin(webParams, {
  49. readOnly: params.ReadOnly
  50. });
  51. }
  52. var widget = WidgetClass.fixCircularDependency ? new WidgetClass.fixCircularDependency(webParams) : new WidgetClass(webParams);
  53. var standbyBackground = new Standby({
  54. color: "#FAFAFA",
  55. text: "",
  56. centerIndicator: "text",
  57. target: "stub"
  58. });
  59. dojo.body().appendChild(standbyBackground.domNode);
  60. standbyBackground.startup();
  61. standbyBackground.hpccShowCount = 0;
  62. topic.subscribe("hpcc/standbyBackgroundShow", function () {
  63. if (standbyBackground.hpccShowCount++ == 0) {
  64. standbyBackground.show();
  65. }
  66. });
  67. topic.subscribe("hpcc/standbyBackgroundHide", function () {
  68. if (--standbyBackground.hpccShowCount <= 0) {
  69. standbyBackground.hpccShowCount = 0;
  70. standbyBackground.hide();
  71. }
  72. });
  73. var standbyForeground = new Standby({
  74. zIndex: 1000,
  75. target: "stub"
  76. });
  77. dojo.body().appendChild(standbyForeground.domNode);
  78. standbyForeground.startup();
  79. standbyForeground.hpccShowCount = 0;
  80. topic.subscribe("hpcc/standbyForegroundShow", function () {
  81. standbyForeground.show();
  82. ++standbyForeground.hpccShowCount;
  83. });
  84. topic.subscribe("hpcc/standbyForegroundHide", function () {
  85. if (--standbyForeground.hpccShowCount <= 0) {
  86. standbyForeground.hpccShowCount = 0;
  87. standbyForeground.hide();
  88. }
  89. });
  90. var myToaster = new Toaster({
  91. id: 'hpcc_toaster',
  92. positionDirection: 'br-left'
  93. });
  94. topic.subscribe("hpcc/brToaster", function (topic) {
  95. if (lang.exists("Exceptions", topic)) {
  96. var context = this;
  97. arrayUtil.forEach(topic.Exceptions, function (_item, idx) {
  98. var item = lang.mixin({
  99. Severity: topic.Severity,
  100. Source: topic.Source
  101. }, _item);
  102. if ((item.Source === "WsWorkunits.WUInfo" && item.Code === 20080) ||
  103. (item.Source === "WsWorkunits.WUQuery" && item.Code === 20081)) {
  104. } else {
  105. var message = "<h4>" + entities.encode(item.Source) + "</h4><p>" + entities.encode(item.Message) + "</p>";
  106. myToaster.setContent(message, item.Severity, item.Severity === "Error" ? -1 : null);
  107. myToaster.show();
  108. }
  109. });
  110. }
  111. });
  112. if (widget) {
  113. widget.placeAt(dojo.body(), "last");
  114. widget.startup();
  115. widget.init(params);
  116. }
  117. document.title = widget.getTitle ? widget.getTitle() : params.Widget;
  118. stopLoading();
  119. }
  120. );
  121. },
  122. startLoading = function (targetNode) {
  123. domStyle.set(dom.byId("loadingOverlay"), "display", "block");
  124. domStyle.set(dom.byId("loadingOverlay"), "opacity", "255");
  125. },
  126. stopLoading = function () {
  127. fx.fadeOut({
  128. node: dom.byId("loadingOverlay"),
  129. onEnd: function (node) {
  130. domStyle.set(node, "display", "none");
  131. }
  132. }).play();
  133. };
  134. return {
  135. init: function () {
  136. ready(function () {
  137. initUi();
  138. });
  139. }
  140. };
  141. });