FullResultWidget.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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/declare",
  18. "dojo/_base/lang",
  19. "dojo/i18n",
  20. "dojo/i18n!./nls/common",
  21. "dojo/i18n!./nls/FullResultWidget",
  22. "dojo/_base/array",
  23. "dojo/dom",
  24. "dojo/request/iframe",
  25. "dojo/store/Memory",
  26. "dojo/store/Observable",
  27. "dijit/registry",
  28. "dgrid/OnDemandGrid",
  29. "dgrid/Keyboard",
  30. "dgrid/Selection",
  31. "dgrid/selector",
  32. "dgrid/extensions/ColumnResizer",
  33. "dgrid/extensions/DijitRegistry",
  34. "hpcc/_Widget",
  35. "hpcc/ESPBase",
  36. "hpcc/ESPWorkunit",
  37. "hpcc/ESPLogicalFile",
  38. "hpcc/ESPUtil",
  39. "dojo/text!../templates/FullResultWidget.html",
  40. "dijit/layout/BorderContainer",
  41. "dijit/layout/ContentPane",
  42. "dijit/Toolbar",
  43. "dijit/form/Button",
  44. "dijit/ToolbarSeparator"
  45. ], function (declare, lang, i18n, nlsCommon, nlsSpecific, arrayUtil, dom, iframe, Memory, Observable,
  46. registry,
  47. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  48. _Widget, ESPBase, ESPWorkunit, ESPLogicalFile, ESPUtil,
  49. template) {
  50. return declare("FullResultWidget", [_Widget], {
  51. templateString: template,
  52. baseClass: "FullResultWidget",
  53. i18n: lang.mixin(nlsCommon, nlsSpecific),
  54. borderContainer: null,
  55. grid: null,
  56. loaded: false,
  57. buildRendering: function (args) {
  58. this.inherited(arguments);
  59. },
  60. postCreate: function (args) {
  61. this.inherited(arguments);
  62. this.borderContainer = registry.byId(this.id + "BorderContainer");
  63. this.grid = registry.byId(this.id + "Grid");
  64. },
  65. startup: function (args) {
  66. this.inherited(arguments);
  67. },
  68. resize: function (args) {
  69. this.inherited(arguments);
  70. this.borderContainer.resize();
  71. },
  72. layout: function (args) {
  73. this.inherited(arguments);
  74. },
  75. destroy: function (args) {
  76. this.inherited(arguments);
  77. },
  78. _doDownload: function (type) {
  79. //TODO Fix
  80. var base = new ESPBase();
  81. if (lang.exists("result.Sequence", this)) {
  82. var sequence = this.result.Sequence;
  83. var downloadPdfIframeName = "downloadIframe_" + sequence;
  84. var frame = iframe.create(downloadPdfIframeName);
  85. var url = base.getBaseURL() + "/WUResultBin?Format=" + type + "&Wuid=" + this.result.Wuid + "&Sequence=" + sequence;
  86. iframe.setSrc(frame, url, true);
  87. } else if (lang.exists("result.Name", this)) {
  88. var logicalName = this.result.Name;
  89. var downloadPdfIframeName = "downloadIframe_" + logicalName;
  90. var frame = iframe.create(downloadPdfIframeName);
  91. var url = base.getBaseURL() + "/WUResultBin?Format=" + type + "&Wuid=" + this.result.Wuid + "&LogicalName=" + logicalName;
  92. iframe.setSrc(frame, url, true);
  93. }
  94. },
  95. _onDownloadZip: function (args) {
  96. this._doDownload("zip");
  97. },
  98. _onDownloadGZip: function (args) {
  99. this._doDownload("gzip");
  100. },
  101. _onDownloadXLS: function (args) {
  102. this._doDownload("xls");
  103. },
  104. _onFileDetails: function (args) {
  105. alert("todo");
  106. },
  107. // Implementation ---
  108. onErrorClick: function (line, col) {
  109. },
  110. init: function (params) {
  111. if (this.inherited(arguments))
  112. return;
  113. if (params.FullResult) {
  114. this.initResult(params.FullResult);
  115. } else {
  116. this.initResult(null);
  117. }
  118. },
  119. initResult: function (result) {
  120. if (result && result.length) {
  121. var columns = [];
  122. for (var key in result[0]) {
  123. if (key.indexOf("__") != 0) {
  124. columns.push({
  125. field: key,
  126. label: key
  127. });
  128. }
  129. }
  130. arrayUtil.forEach(result, function (item, idx) {
  131. item["__hpcc_id"] = idx;
  132. });
  133. var store = new Memory({
  134. idProperty: "__hpcc_id",
  135. data: result
  136. });
  137. this.store = Observable(store);
  138. this.grid = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  139. columns: columns,
  140. store: this.store
  141. }, this.id + "Grid");
  142. this.grid.startup();
  143. } else {
  144. this.grid = new declare([Grid, DijitRegistry])({
  145. columns: [
  146. {
  147. label: "##",
  148. width: 54
  149. }
  150. ]
  151. }, this.id + "Grid");
  152. this.grid.set("noDataMessage", "<span class='dojoxGridNoData'>[" + this.i18n.undefined + "]</span>");
  153. this.grid.startup();
  154. }
  155. },
  156. refresh: function () {
  157. if (this.result && !this.result.isComplete()) {
  158. this.grid.showMessage(this.result.getLoadingMessage());
  159. } else if (!this.loaded) {
  160. this.loaded = true;
  161. this.grid.set("query", {
  162. id: "*"
  163. });
  164. }
  165. }
  166. });
  167. });