SampleSelectControl.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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, xhr, 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,
  39. style: {
  40. overflow: "overflow: visible !important",
  41. padding: 0
  42. },
  43. onChange: function () {
  44. var filename = dijit.byId(this.id).get("value");
  45. xhr.get({
  46. url: "ecl/" + filename,
  47. handleAs: "text",
  48. load: function (eclText) {
  49. context.onNewSelection(eclText);
  50. },
  51. error: function () {
  52. }
  53. });
  54. }
  55. }, this.id);
  56. try {
  57. select.startup();
  58. } catch (e) {
  59. }
  60. }
  61. });
  62. });