ECLSourceWidget.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. if (this.initalized)
  62. return;
  63. this.initalized = true;
  64. this.editor = CodeMirror.fromTextArea(document.getElementById(this.id + "EclCode"), {
  65. tabMode: "indent",
  66. matchBrackets: true,
  67. gutter: true,
  68. lineNumbers: true,
  69. mode: this.WUXml ? "xml" : "ecl",
  70. readOnly: this.readOnly,
  71. gutter: this.WUXml ? true : false,
  72. onGutterClick: CodeMirror.newFoldFunction(CodeMirror.tagRangeFinder)
  73. });
  74. var context = this;
  75. if (params.Wuid) {
  76. this.wu = new ESPWorkunit({
  77. Wuid: params.Wuid
  78. });
  79. if (this.WUXml) {
  80. this.wu.fetchXML(function (xml) {
  81. context.editor.setValue(xml);
  82. });
  83. }
  84. else {
  85. this.wu.fetchText(function (text) {
  86. context.editor.setValue(text);
  87. });
  88. }
  89. } else if (params.ECL) {
  90. context.editor.setValue(params.ECL);
  91. }
  92. },
  93. clearErrors: function (errWarnings) {
  94. for (var i = 0; i < this.markers.length; ++i) {
  95. this.editor.clearMarker(this.markers[i]);
  96. }
  97. this.markers = [];
  98. },
  99. setErrors: function (errWarnings) {
  100. for (var i = 0; i < errWarnings.length; ++i) {
  101. this.markers.push(this.editor.setMarker(parseInt(
  102. errWarnings[i].LineNo, 10) - 1, "",
  103. errWarnings[i].Severity + "Line"));
  104. }
  105. },
  106. setCursor: function (line, col) {
  107. this.editor.setCursor(line - 1, col - 1);
  108. this.editor.focus();
  109. },
  110. clearHighlightLines: function () {
  111. for (var i = 0; i < this.highlightLines.length; ++i) {
  112. this.editor.setLineClass(this.highlightLines[i], null, null);
  113. }
  114. },
  115. highlightLine: function (line) {
  116. this.highlightLines.push(this.editor.setLineClass(line - 1, "highlightline"));
  117. },
  118. setText: function (ecl) {
  119. this.editor.setValue(ecl);
  120. },
  121. setReadOnly: function (readonly) {
  122. this.editor.readOnly(readonly);
  123. },
  124. getText: function () {
  125. return this.editor.getValue();
  126. }
  127. });
  128. });