SampleSelectControl.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/declare",
  19. "dojo/_base/xhr",
  20. "dojo/data/ItemFileReadStore",
  21. "dijit/form/Select"
  22. ], function (declare, baseXhr, ItemFileReadStore, Select) {
  23. return declare(null, {
  24. id: null,
  25. samplesURL: null,
  26. onNewSelection: function (eclText) {
  27. },
  28. constructor: function (args) {
  29. declare.safeMixin(this, args);
  30. var sampleStore = new dojo.data.ItemFileReadStore({
  31. url: this.samplesURL
  32. });
  33. var context = this;
  34. var select = new dijit.form.Select({
  35. name: this.id,
  36. store: sampleStore,
  37. value: "default.ecl",
  38. //maxHeight: -1 // tells _HasDropDown to fit menu within viewport
  39. onChange: function () {
  40. var filename = dijit.byId(this.id).get("value");
  41. baseXhr.get({
  42. url: "ecl/" + filename,
  43. handleAs: "text",
  44. load: function (eclText) {
  45. context.onNewSelection(eclText);
  46. },
  47. error: function () {
  48. }
  49. });
  50. }
  51. }, this.id);
  52. try {
  53. select.startup();
  54. } catch (e) {
  55. }
  56. }
  57. });
  58. });