ResultWidget.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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/dom",
  20. "dojo/request/iframe",
  21. "dijit/layout/_LayoutWidget",
  22. "dijit/_TemplatedMixin",
  23. "dijit/_WidgetsInTemplateMixin",
  24. "dijit/registry",
  25. "dojox/grid/enhanced/plugins/Pagination",
  26. "hpcc/ESPBase",
  27. "dojo/text!../templates/ResultWidget.html",
  28. "dijit/layout/BorderContainer",
  29. "dijit/Toolbar",
  30. "dijit/form/Button",
  31. "dijit/ToolbarSeparator",
  32. "dojox/grid/EnhancedGrid"
  33. ], function (declare, lang, dom, iframe,
  34. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, registry,
  35. Pagination,
  36. ESPBase,
  37. template) {
  38. return declare("ResultWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  39. templateString: template,
  40. baseClass: "ResultWidget",
  41. borderContainer: null,
  42. grid: null,
  43. initalized: false,
  44. loaded: false,
  45. buildRendering: function (args) {
  46. this.inherited(arguments);
  47. },
  48. postCreate: function (args) {
  49. this.inherited(arguments);
  50. this.borderContainer = registry.byId(this.id + "BorderContainer");
  51. this.grid = registry.byId(this.id + "Grid");
  52. },
  53. startup: function (args) {
  54. this.inherited(arguments);
  55. },
  56. resize: function (args) {
  57. this.inherited(arguments);
  58. this.borderContainer.resize();
  59. },
  60. layout: function (args) {
  61. this.inherited(arguments);
  62. },
  63. destroy: function (args) {
  64. this.inherited(arguments);
  65. },
  66. _doDownload: function (type) {
  67. //TODO Fix
  68. var base = new ESPBase();
  69. if (lang.exists("result.Sequence", this)) {
  70. var sequence = this.result.Sequence;
  71. var downloadPdfIframeName = "downloadIframe_" + sequence;
  72. var frame = iframe.create(downloadPdfIframeName);
  73. var url = base.getBaseURL() + "/WUResultBin?Format=" + type + "&Wuid=" + this.result.Wuid + "&Sequence=" + sequence;
  74. iframe.setSrc(frame, url, true);
  75. } else if (lang.exists("result.Name", this)) {
  76. var logicalName = this.result.Name;
  77. var downloadPdfIframeName = "downloadIframe_" + logicalName;
  78. var frame = iframe.create(downloadPdfIframeName);
  79. var url = base.getBaseURL() + "/WUResultBin?Format=" + type + "&Wuid=" + this.result.Wuid + "&LogicalName=" + logicalName;
  80. iframe.setSrc(frame, url, true);
  81. }
  82. },
  83. _onDownloadZip: function (args) {
  84. this._doDownload("zip");
  85. },
  86. _onDownloadGZip: function (args) {
  87. this._doDownload("gzip");
  88. },
  89. _onDownloadXLS: function (args) {
  90. this._doDownload("xls");
  91. },
  92. _onFileDetails: function (args) {
  93. alert("todo");
  94. },
  95. // Implementation ---
  96. onErrorClick: function (line, col) {
  97. },
  98. init: function (params) {
  99. if (this.initalized) {
  100. return;
  101. }
  102. this.initalized = true;
  103. this.result = params.result;
  104. //TODO: Encapsulate this IF into ESPResult.js
  105. if (params.result && params.result.canShowResults()) {
  106. this.grid.setStructure(params.result.getStructure());
  107. this.grid.setStore(params.result.getObjectStore());
  108. this.refresh();
  109. } else {
  110. this.grid.setStructure([
  111. {
  112. name: "##", width: "6"
  113. }
  114. ]);
  115. this.grid.showMessage("[undefined]");
  116. }
  117. },
  118. refresh: function () {
  119. if (this.result && !this.result.isComplete()) {
  120. this.grid.showMessage(this.result.getLoadingMessage());
  121. } else if (!this.loaded) {
  122. this.loaded = true;
  123. this.grid.setQuery({
  124. id: "*"
  125. });
  126. }
  127. }
  128. });
  129. });