ECLSourceWidget.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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/lang",
  19. "dojo/dom",
  20. "dijit/layout/BorderContainer",
  21. "dijit/layout/ContentPane",
  22. "dijit/registry",
  23. "hpcc/_Widget",
  24. "hpcc/ESPWorkunit",
  25. "dojo/text!../templates/ECLSourceWidget.html",
  26. "dijit/Toolbar", "dijit/ToolbarSeparator", "dijit/form/Button"
  27. ],
  28. function (declare, lang, dom,
  29. BorderContainer, ContentPane, registry,
  30. _Widget, ESPWorkunit,
  31. template) {
  32. return declare("ECLSourceWidget", [_Widget], {
  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.inherited(arguments))
  62. return;
  63. var mode = "ecl";
  64. if (params.sourceMode !== undefined) {
  65. mode = params.sourceMode;
  66. } else if (this.WUXml) {
  67. mode = "xml";
  68. }
  69. this.editor = CodeMirror.fromTextArea(document.getElementById(this.id + "EclCode"), {
  70. tabMode: "indent",
  71. matchBrackets: true,
  72. gutter: true,
  73. lineNumbers: true,
  74. mode: mode,
  75. readOnly: this.readOnly,
  76. gutter: mode === "xml" ? true : false,
  77. onGutterClick: CodeMirror.newFoldFunction(CodeMirror.tagRangeFinder)
  78. });
  79. dom.byId(this.id + "EclContent").style.backgroundColor = this.readOnly ? 0xd0d0d0 : 0xffffff;
  80. var context = this;
  81. if (params.Wuid) {
  82. this.wu = ESPWorkunit.Get(params.Wuid);
  83. if (this.WUXml) {
  84. this.wu.fetchXML(function (xml) {
  85. context.editor.setValue(xml);
  86. });
  87. }
  88. else {
  89. this.wu.fetchText(function (text) {
  90. context.editor.setValue(text);
  91. });
  92. }
  93. } else if (lang.exists("ECL"), params) {
  94. context.editor.setValue(params.ECL ? params.ECL : "");
  95. }
  96. },
  97. clearErrors: function (errWarnings) {
  98. for (var i = 0; i < this.markers.length; ++i) {
  99. this.editor.clearMarker(this.markers[i]);
  100. }
  101. this.markers = [];
  102. },
  103. setErrors: function (errWarnings) {
  104. for (var i = 0; i < errWarnings.length; ++i) {
  105. this.markers.push(this.editor.setMarker(parseInt(
  106. errWarnings[i].LineNo, 10) - 1, "",
  107. errWarnings[i].Severity + "Line"));
  108. }
  109. },
  110. setCursor: function (line, col) {
  111. this.editor.setCursor(line - 1, col - 1);
  112. this.editor.focus();
  113. },
  114. clearHighlightLines: function () {
  115. for (var i = 0; i < this.highlightLines.length; ++i) {
  116. this.editor.setLineClass(this.highlightLines[i], null, null);
  117. }
  118. },
  119. highlightLine: function (line) {
  120. this.highlightLines.push(this.editor.setLineClass(line - 1, "highlightline"));
  121. },
  122. setText: function (ecl) {
  123. this.editor.setValue(ecl);
  124. },
  125. setReadOnly: function (readonly) {
  126. this.editor.readOnly(readonly);
  127. },
  128. getText: function () {
  129. return this.editor.getValue();
  130. }
  131. });
  132. });