SampleSelectWidget.js 2.7 KB

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