SampleSelectControl.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. if (args) {
  30. declare.safeMixin(this, args);
  31. }
  32. var sampleStore = new dojo.data.ItemFileReadStore({
  33. url: this.samplesURL
  34. });
  35. var context = this;
  36. this.selectControl = new dijit.form.Select({
  37. name: this.id,
  38. store: sampleStore,
  39. value: "default.ecl",
  40. maxHeight: 480,
  41. style: {
  42. padding: 0
  43. },
  44. onChange: function () {
  45. var filename = dijit.byId(this.id).get("value");
  46. xhr.get({
  47. url: "ecl/" + filename,
  48. handleAs: "text",
  49. load: function (eclText) {
  50. context.onNewSelection(eclText);
  51. },
  52. error: function () {
  53. }
  54. });
  55. }
  56. }, this.id);
  57. try {
  58. this.selectControl.startup();
  59. } catch (e) {
  60. }
  61. }
  62. });
  63. });