ESPBase.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*##############################################################################
  2. # Copyright (C) 2011 HPCC Systems.
  3. #
  4. # All rights reserved. This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ############################################################################## */
  17. define([
  18. "dojo/_base/config",
  19. "dojo/_base/declare"
  20. ], function (baseConfig, declare) {
  21. return declare(null, {
  22. constructor: function (args) {
  23. declare.safeMixin(this, args);
  24. },
  25. getParam: function (key) {
  26. var value = dojo.queryToObject(dojo.doc.location.search.substr((dojo.doc.location.search[0] === "?" ? 1 : 0)))[key];
  27. if (value)
  28. return value;
  29. return baseConfig[key];
  30. },
  31. getBaseURL: function () {
  32. var serverIP = this.getParam("serverIP");
  33. if (serverIP)
  34. return "http://" + serverIP + ":8010/WsWorkunits";
  35. return "/WsWorkunits";
  36. },
  37. parseKeyValue: function (xmlDom, nodeLabel) {
  38. var items = xmlDom.getElementsByTagName(nodeLabel);
  39. if (items.length && items[0].childNodes.length) {
  40. return items[0].childNodes[0].nodeValue;
  41. }
  42. return "";
  43. },
  44. parseKeyChildren: function (xmlDom, nodeLabel) {
  45. var items = xmlDom.getElementsByTagName(nodeLabel);
  46. if (items.length && items[0].childNodes.length) {
  47. return items[0].childNodes;
  48. }
  49. return null;
  50. },
  51. parseRows: function (xmlDom, nodeLabel) {
  52. var rows = [];
  53. var items = xmlDom.getElementsByTagName(nodeLabel);
  54. for (var i = 0; i < items.length; ++i) {
  55. var item = items[i];
  56. var cols = {};
  57. for (var c = 0; c < item.childNodes.length; ++c) {
  58. colNode = item.childNodes[c];
  59. if (colNode.childNodes.length && colNode.childNodes[0].nodeValue) {
  60. cols[colNode.nodeName] = colNode.childNodes[0].nodeValue;
  61. } else {
  62. cols[colNode.nodeName] = "";
  63. }
  64. }
  65. rows.push(cols);
  66. }
  67. return rows;
  68. },
  69. // <XXX><YYY/><YYY/><YYY/><YYY/></XXX>
  70. parseDataset: function (xmlDom, _name, nodeLabel) {
  71. var retVal = {};
  72. var retValRows = this.parseRows(xmlDom, nodeLabel);
  73. var retValHeader = [];
  74. if (retValRows.length) {
  75. for (var key in retValRows[0]) {
  76. retValHeader.push(key)
  77. }
  78. }
  79. retVal = {
  80. name: _name,
  81. header: retValHeader,
  82. rows: retValRows
  83. };
  84. return retVal;
  85. },
  86. parseDatasets: function (xmlDom, nodeLabel, innerNodeLabel) {
  87. var retVal = [];
  88. var datasets = xmlDom.getElementsByTagName(nodeLabel);
  89. for (var d = 0; d < datasets.length; ++d) {
  90. var dataset = datasets[d];
  91. var retValRows = this.parseRows(dataset, innerNodeLabel);
  92. var retValHeader = [];
  93. if (retValRows.length) {
  94. for (var key in retValRows[0]) {
  95. retValHeader.push(key)
  96. }
  97. }
  98. retVal.push({
  99. name: dataset.getAttribute("name"),
  100. header: retValHeader,
  101. rows: retValRows
  102. });
  103. }
  104. return retVal;
  105. }
  106. });
  107. });