ECLSourceWidget.js 4.7 KB

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