ECLSourceWidget.js 5.2 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. "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. this.editor = CodeMirror.fromTextArea(document.getElementById(this.id + "EclCode"), {
  66. tabMode: "indent",
  67. matchBrackets: true,
  68. gutter: true,
  69. lineNumbers: true,
  70. mode: this.WUXml ? "xml" : "ecl",
  71. readOnly: this.readOnly,
  72. gutter: this.WUXml ? true : false,
  73. onGutterClick: CodeMirror.newFoldFunction(CodeMirror.tagRangeFinder)
  74. });
  75. dom.byId(this.id + "EclContent").style.backgroundColor = this.readOnly ? 0xd0d0d0 : 0xffffff;
  76. var context = this;
  77. if (params.Wuid) {
  78. this.wu = ESPWorkunit.Get(params.Wuid);
  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. });