ECLSourceWidget.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. "dijit/layout/_LayoutWidget",
  19. "dijit/_TemplatedMixin",
  20. "dijit/_WidgetsInTemplateMixin",
  21. "dijit/layout/BorderContainer",
  22. "dijit/layout/ContentPane",
  23. "dijit/registry",
  24. "hpcc/ESPWorkunit",
  25. "dojo/text!../templates/ECLSourceWidget.html",
  26. "dijit/Toolbar", "dijit/ToolbarSeparator", "dijit/form/Button"
  27. ],
  28. function (declare,
  29. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, BorderContainer, ContentPane, registry,
  30. ESPWorkunit,
  31. template) {
  32. return declare("ECLSourceWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  33. templateString: template,
  34. baseClass: "ECLSourceWidget",
  35. borderContainer: null,
  36. eclSourceContentPane: null,
  37. wu: null,
  38. editor: null,
  39. markers: [],
  40. highlightLines: [],
  41. readOnly: false,
  42. buildRendering: function (args) {
  43. this.inherited(arguments);
  44. },
  45. postCreate: function (args) {
  46. this.inherited(arguments);
  47. this.borderContainer = registry.byId(this.id + "BorderContainer");
  48. },
  49. startup: function (args) {
  50. this.inherited(arguments);
  51. },
  52. resize: function (args) {
  53. this.inherited(arguments);
  54. this.borderContainer.resize();
  55. },
  56. layout: function (args) {
  57. this.inherited(arguments);
  58. },
  59. // Plugin wrapper ---
  60. init: function (params) {
  61. this.editor = CodeMirror.fromTextArea(document.getElementById(this.id + "EclCode"), {
  62. tabMode: "indent",
  63. matchBrackets: true,
  64. gutter: true,
  65. lineNumbers: true,
  66. mode: this.WUXml ? "xml" : "ecl",
  67. readOnly: this.readOnly
  68. });
  69. var context = this;
  70. if (params.Wuid) {
  71. this.wu = new ESPWorkunit({
  72. Wuid: params.Wuid
  73. });
  74. if (this.WUXml) {
  75. this.wu.fetchXML(function (xml) {
  76. context.editor.setValue(xml);
  77. });
  78. }
  79. else {
  80. this.wu.fetchText(function (text) {
  81. context.editor.setValue(text);
  82. });
  83. }
  84. } else if (params.ECL) {
  85. context.editor.setValue(params.ECL);
  86. }
  87. },
  88. clearErrors: function (errWarnings) {
  89. for (var i = 0; i < this.markers.length; ++i) {
  90. this.editor.clearMarker(this.markers[i]);
  91. }
  92. this.markers = [];
  93. },
  94. setErrors: function (errWarnings) {
  95. for (var i = 0; i < errWarnings.length; ++i) {
  96. this.markers.push(this.editor.setMarker(parseInt(
  97. errWarnings[i].LineNo, 10) - 1, "",
  98. errWarnings[i].Severity + "Line"));
  99. }
  100. },
  101. setCursor: function (line, col) {
  102. this.editor.setCursor(line - 1, col - 1);
  103. this.editor.focus();
  104. },
  105. clearHighlightLines: function () {
  106. for (var i = 0; i < this.highlightLines.length; ++i) {
  107. this.editor.setLineClass(this.highlightLines[i], null, null);
  108. }
  109. },
  110. highlightLine: function (line) {
  111. this.highlightLines.push(this.editor.setLineClass(line - 1, "highlightline"));
  112. },
  113. setText: function (ecl) {
  114. this.editor.setValue(ecl);
  115. },
  116. setReadOnly: function (readonly) {
  117. this.editor.readOnly(readonly);
  118. },
  119. getText: function () {
  120. return this.editor.getValue();
  121. }
  122. });
  123. });