Node-Red configuration
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ui_template.html 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <script type="text/javascript">
  2. // convert to i18 text
  3. function c_(x) {
  4. return RED._("node-red-dashboard/ui_template:ui_template."+x);
  5. }
  6. RED.nodes.registerType('ui_template',{
  7. category: RED._("node-red-dashboard/ui_base:ui_base.label.category"),
  8. color: 'rgb( 63, 173, 181)',
  9. defaults: {
  10. group: {type: 'ui_group', required:false},
  11. name: {value: ''},
  12. order: {value: 0},
  13. width: {value: 0, validate: function(v) {
  14. var valid = true
  15. if (this.templateScope !== 'global') {
  16. var width = v||0;
  17. var currentGroup = $('#node-input-group').val()||this.group;
  18. var groupNode = RED.nodes.node(currentGroup);
  19. valid = !groupNode || +width <= +groupNode.width;
  20. $("#node-input-size").toggleClass("input-error",!valid);
  21. }
  22. return valid;
  23. }},
  24. height: {value: 0},
  25. format: {value: '<div ng-bind-html="msg.payload"></div>'},
  26. storeOutMessages: {value: true},
  27. fwdInMessages: {value: true},
  28. resendOnRefresh: {value: true},
  29. templateScope: {value: 'local'},
  30. className: {value: ''}
  31. },
  32. inputs:1,
  33. outputs:1,
  34. icon: "ui_template.png",
  35. paletteLabel: 'template',
  36. label: function() { return this.name || 'template'; },
  37. labelStyle: function() { return this.name?"node_label_italic":""; },
  38. oneditprepare: function() {
  39. if (RED.editor.hasOwnProperty("editText") && typeof RED.editor.editText === "function") {
  40. $("#node-template-expand-editor").show();
  41. }
  42. else {
  43. $("#node-template-expand-editor").hide();
  44. }
  45. var that = this;
  46. $("#node-input-size").elementSizer({
  47. width: "#node-input-width",
  48. height: "#node-input-height",
  49. group: "#node-input-group"
  50. });
  51. if (typeof this.storeOutMessages === 'undefined') {
  52. this.storeOutMessages = true;
  53. $('#node-input-storeOutMessages').prop('checked', true);
  54. }
  55. if (typeof this.fwdInMessages === 'undefined') {
  56. this.fwdInMessages = true;
  57. $('#node-input-fwdInMessages').prop('checked', true);
  58. }
  59. if (typeof this.templateScope === 'undefined') {
  60. this.templateScope = 'local';
  61. $('#node-input-templateScope').val(this.templateScope);
  62. }
  63. $('#node-input-templateScope').on('change', function() {
  64. if ($('#node-input-templateScope').val() === 'global') {
  65. $('#template-row-group, #template-row-size, #template-pass-store, #template-row-class').hide();
  66. that._def.defaults.group.required = false;
  67. }
  68. else {
  69. $('#template-row-group, #template-row-size, #template-pass-store, #template-row-class').show();
  70. that._def.defaults.group.required = true;
  71. }
  72. var rows = $("#dialog-form>div:not(.node-text-editor-row)");
  73. var height = $("#dialog-form").height();
  74. for (var i=0; i<rows.size(); i++) {
  75. height = height - $(rows[i]).outerHeight(true);
  76. }
  77. if ($('#node-input-templateScope').val() === "global") { height += 240; }
  78. var editorRow = $("#dialog-form>div.node-text-editor-row");
  79. height -= (parseInt(editorRow.css("marginTop")) + parseInt(editorRow.css("marginBottom")));
  80. $(".node-text-editor").css("height",height+"px");
  81. if (this.editor) { this.editor.resize(); }
  82. })
  83. this.editor = RED.editor.createEditor({
  84. id: 'node-input-format-editor',
  85. mode: 'ace/mode/html',
  86. value: $("#node-input-format").val()
  87. });
  88. RED.library.create({
  89. url:"uitemplates", // where to get the data from
  90. type:"ui_template", // the type of object the library is for
  91. editor:this.editor, // the field name the main text body goes to
  92. mode:"ace/mode/html",
  93. fields:['name']
  94. });
  95. this.editor.focus();
  96. RED.popover.tooltip($("#node-template-expand-editor"),c_("label.expand"));
  97. $("#node-template-expand-editor").on("click", function(e) {
  98. e.preventDefault();
  99. var value = that.editor.getValue();
  100. RED.editor.editText({
  101. mode: 'html',
  102. value: value,
  103. width: "Infinity",
  104. cursor: that.editor.getCursorPosition(),
  105. complete: function(v,cursor) {
  106. that.editor.setValue(v, -1);
  107. that.editor.gotoLine(cursor.row+1,cursor.column,false);
  108. setTimeout(function() { that.editor.focus(); },300);
  109. }
  110. })
  111. })
  112. },
  113. oneditsave: function() {
  114. var annot = this.editor.getSession().getAnnotations();
  115. this.noerr = 0;
  116. $("#node-input-noerr").val(0);
  117. for (var k=0; k < annot.length; k++) {
  118. if (annot[k].type === "error") {
  119. $("#node-input-noerr").val(annot.length);
  120. this.noerr = annot.length;
  121. }
  122. }
  123. $("#node-input-format").val(this.editor.getValue());
  124. this.editor.destroy();
  125. delete this.editor;
  126. },
  127. oneditcancel: function() {
  128. this.editor.destroy();
  129. delete this.editor;
  130. },
  131. oneditresize: function(size) {
  132. var rows = $("#dialog-form>div:not(.node-text-editor-row)");
  133. var height = $("#dialog-form").height();
  134. for (var i=0; i<rows.size(); i++) {
  135. height = height - $(rows[i]).outerHeight(true);
  136. }
  137. if ($('#node-input-templateScope').val() === "global") { height += 232; }
  138. var editorRow = $("#dialog-form>div.node-text-editor-row");
  139. height -= (parseInt(editorRow.css("marginTop")) + parseInt(editorRow.css("marginBottom")));
  140. $(".node-text-editor").css("height",height+"px");
  141. this.editor.resize();
  142. }
  143. });
  144. </script>
  145. <script type="text/html" data-template-name="ui_template">
  146. <div class="form-row">
  147. <label for="node-input-format"><span data-i18n="ui_template.label.type"></span></label>
  148. <select style="width:76%" id="node-input-templateScope">
  149. <option value="local" data-i18n="ui_template.label.local"></option>
  150. <option value="global" data-i18n="ui_template.label.global"></option>
  151. </select>
  152. </div>
  153. <div class="form-row" id="template-row-group">
  154. <label for="node-input-group"><i class="fa fa-table"></i> <span data-i18n="ui_template.label.group"></span></label>
  155. <input type="text" id="node-input-group">
  156. </div>
  157. <div class="form-row" id="template-row-size">
  158. <label><i class="fa fa-object-group"></i> <span data-i18n="ui_template.label.size"></span></label>
  159. <input type="hidden" id="node-input-width">
  160. <input type="hidden" id="node-input-height">
  161. <button class="editor-button" id="node-input-size"></button>
  162. </div>
  163. <div class="form-row" id="template-row-class">
  164. <label for="node-input-className"><i class="fa fa-code"></i> <span data-i18n="ui_template.label.className"></label>
  165. <input type="text" id="node-input-className" data-i18n="[placeholder]ui_template.label.classNamePlaceholder"/>
  166. </div>
  167. <div class="form-row">
  168. <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
  169. <div style="display:inline-block; width:calc(100% - 105px)">
  170. <input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
  171. </div>
  172. </div>
  173. <div class="form-row" style="margin-bottom:0px;">
  174. <label for="node-input-format"><i class="fa fa-copy"></i> <span data-i18n="ui_template.label.template"></span></label>
  175. <input type="hidden" id="node-input-format">
  176. <button id="node-template-expand-editor" class="red-ui-button red-ui-button-small" style="float:right"><i class="fa fa-expand"></i></button>
  177. </div>
  178. <div class="form-row node-text-editor-row">
  179. <div style="height:250px; min-height:100px" class="node-text-editor" id="node-input-format-editor" ></div>
  180. </div>
  181. <div id="template-pass-store">
  182. <div class="form-row" style="margin-bottom:0px;">
  183. <input type="checkbox" id="node-input-fwdInMessages" style="display:inline-block; margin-left:8px; width:auto; vertical-align:top;">
  184. <label for="node-input-fwdInMessages" style="width:70%;"> <span data-i18n="ui_template.label.pass-through"></span></label>
  185. </div>
  186. <div class="form-row" style="margin-bottom:0px;">
  187. <input type="checkbox" id="node-input-storeOutMessages" style="display:inline-block; margin-left:8px; width:auto; vertical-align:top;">
  188. <label for="node-input-storeOutMessages" style="width:70%;"> <span data-i18n="ui_template.label.store-state"></span></label>
  189. </div>
  190. <div class="form-row" style="margin-bottom:0px;">
  191. <input type="checkbox" id="node-input-resendOnRefresh" style="display:inline-block; margin-left:8px; width:auto; vertical-align:top;">
  192. <label for="node-input-resendOnRefresh" style="width:70%;"> <span data-i18n="ui_template.label.resend"></span></label>
  193. </div>
  194. </div>
  195. </script>