ECLSourceWidget.js 5.4 KB

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