ECLSourceWidget.js 5.2 KB

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