ECLSourceWidget.js 5.4 KB

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