SampleSelectWidget.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/SampleSelectWidget.html"
  27. ], function (declare, xhr, dom,
  28. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, Select, registry,
  29. ESPBase, template) {
  30. return declare("SampleSelectWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  31. templateString: template,
  32. baseClass: "SampleSelectWidget",
  33. selectControl: 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. this.selectControl = registry.byId(this.id + "SampleSelect");
  48. this.selectControl.maxHeight = 480;
  49. },
  50. load: function () {
  51. var sampleStore = new dojo.data.ItemFileReadStore({
  52. url: "ecl/ECLPlaygroundSamples.json"
  53. });
  54. this.selectControl.setStore(sampleStore);
  55. var context = this;
  56. this.selectControl.onChange = function () {
  57. var filename = this.getValue();
  58. xhr.get({
  59. url: "ecl/" + filename,
  60. handleAs: "text",
  61. load: function (eclText) {
  62. context.onNewSelection(eclText);
  63. },
  64. error: function () {
  65. }
  66. });
  67. };
  68. this.selectControl.set("value", "default.ecl");
  69. },
  70. onNewSelection: function (eclText) {
  71. }
  72. });
  73. });