SampleSelectControl.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. define([
  17. "dojo/_base/declare",
  18. "dojo/_base/xhr",
  19. "dojo/data/ItemFileReadStore",
  20. "dijit/form/Select"
  21. ], function (declare, xhr, ItemFileReadStore, Select) {
  22. return declare(null, {
  23. id: null,
  24. samplesURL: null,
  25. selectControl: 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. this.selectControl = new dijit.form.Select({
  35. name: this.id,
  36. store: sampleStore,
  37. value: "default.ecl",
  38. maxHeight: 480,
  39. style: {
  40. padding: 0
  41. },
  42. onChange: function () {
  43. var filename = dijit.byId(this.id).get("value");
  44. xhr.get({
  45. url: "ecl/" + filename,
  46. handleAs: "text",
  47. load: function (eclText) {
  48. context.onNewSelection(eclText);
  49. },
  50. error: function () {
  51. }
  52. });
  53. }
  54. }, this.id);
  55. try {
  56. this.selectControl.startup();
  57. } catch (e) {
  58. }
  59. }
  60. });
  61. });