SampleSelectWidget.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. require([
  18. "dojo/_base/declare",
  19. "dojo/_base/xhr",
  20. "dojo/dom",
  21. "dijit/layout/_LayoutWidget",
  22. "dijit/_TemplatedMixin",
  23. "dijit/_WidgetsInTemplateMixin",
  24. "dijit/form/Select",
  25. "dijit/registry",
  26. "hpcc/ESPBase",
  27. "dojo/text!./templates/SampleSelectWidget.html"
  28. ], function (declare, xhr, dom,
  29. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, Select, registry,
  30. ESPBase, template) {
  31. return declare("SampleSelectWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  32. templateString: template,
  33. baseClass: "SampleSelectWidget",
  34. selectControl: null,
  35. _value: "",
  36. postCreate: function (args) {
  37. this.inherited(arguments);
  38. this._initControls();
  39. },
  40. resize: function (args) {
  41. this.inherited(arguments);
  42. },
  43. layout: function (args) {
  44. this.inherited(arguments);
  45. },
  46. // Implementation ---
  47. _initControls: function () {
  48. this.selectControl = registry.byId(this.id + "SampleSelect");
  49. this.selectControl.maxHeight = 480;
  50. },
  51. load: function () {
  52. var sampleStore = new dojo.data.ItemFileReadStore({
  53. url: "ecl/ECLPlaygroundSamples.json"
  54. });
  55. this.selectControl.setStore(sampleStore);
  56. var context = this;
  57. this.selectControl.onChange = function () {
  58. var filename = this.getValue();
  59. xhr.get({
  60. url: "ecl/" + filename,
  61. handleAs: "text",
  62. load: function (eclText) {
  63. context.onNewSelection(eclText);
  64. },
  65. error: function () {
  66. }
  67. });
  68. };
  69. this.selectControl.set("value", "default.ecl");
  70. },
  71. onNewSelection: function (eclText) {
  72. }
  73. });
  74. });