TargetSelectWidget.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. require([
  17. "dojo/_base/declare",
  18. "dojo/_base/xhr",
  19. "dojo/dom",
  20. "dijit/layout/_LayoutWidget",
  21. "dijit/_TemplatedMixin",
  22. "dijit/_WidgetsInTemplateMixin",
  23. "dijit/form/Select",
  24. "dijit/registry",
  25. "hpcc/ESPBase",
  26. "dojo/text!./templates/TargetSelectWidget.html"
  27. ], function (declare, xhr, dom,
  28. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, Select, registry,
  29. ESPBase, template) {
  30. return declare("TargetSelectWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  31. templateString: template,
  32. baseClass: "TargetSelectWidget",
  33. targetSelectControl: null,
  34. _value: "",
  35. postCreate: function (args) {
  36. this.inherited(arguments);
  37. this._initControls();
  38. },
  39. resize: function (args) {
  40. this.inherited(arguments);
  41. },
  42. layout: function (args) {
  43. this.inherited(arguments);
  44. },
  45. // Implementation ---
  46. _initControls: function () {
  47. var context = this;
  48. this.targetSelectControl = registry.byId(this.id + "TargetSelect");
  49. this.targetSelectControl.onChange = function () {
  50. context.onChange(this.get("value"));
  51. };
  52. },
  53. init: function (params) {
  54. if (params.Target) {
  55. this._value = params.Target;
  56. }
  57. this.loadTargets();
  58. },
  59. onChange: function (target) {
  60. this._value = target;
  61. },
  62. setValue: function (target) {
  63. if (target && this._value != target) {
  64. this._value = target;
  65. this.targetSelectControl.set("value", target);
  66. }
  67. },
  68. getValue: function () {
  69. return this._value;
  70. },
  71. loadTargets: function () {
  72. var base = new ESPBase({
  73. });
  74. var request = {
  75. rawxml_: true
  76. };
  77. var context = this;
  78. xhr.post({
  79. url: base.getBaseURL("WsTopology") + "/TpTargetClusterQuery",
  80. handleAs: "xml",
  81. content: request,
  82. load: function (xmlDom) {
  83. var targetData = base.getValues(xmlDom, "TpTargetCluster");
  84. context.targetSelectControl.options = [];
  85. var has_hthor = false;
  86. for (var i = 0; i < targetData.length; ++i) {
  87. context.targetSelectControl.options.push({
  88. label: targetData[i].Name,
  89. value: targetData[i].Name
  90. });
  91. if (targetData[i].Name == "hthor") {
  92. has_hthor = true;
  93. }
  94. }
  95. if (context._value == "") {
  96. if (has_hthor) {
  97. context.setValue("hthor");
  98. } else {
  99. context._value = context.targetSelectControl.options[0].value;
  100. }
  101. } else {
  102. context.targetSelectControl.set("value", context._value);
  103. }
  104. },
  105. error: function () {
  106. }
  107. });
  108. }
  109. });
  110. });