Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui_form.html 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <script type="text/javascript">
  2. RED.nodes.registerType('ui_form',{
  3. category: RED._("node-red-dashboard/ui_base:ui_base.label.category"),
  4. color: 'rgb(176, 223, 227)',
  5. defaults: {
  6. name: {value: ''},
  7. label: {value: ''},
  8. group: {type: 'ui_group', required: true},
  9. order: {value: 0},
  10. width: {value: 0, validate: function(v) {
  11. var width = v||0;
  12. var currentGroup = $('#node-input-group').val()||this.group;
  13. var groupNode = RED.nodes.node(currentGroup);
  14. var valid = !groupNode || +width <= +groupNode.width;
  15. $("#node-input-size").toggleClass("input-error",!valid);
  16. return valid;
  17. }
  18. },
  19. height: {value: 0},
  20. options: {value:[{value:'', label :'', type:'', required:true}], validate:function(value) {
  21. if (value.length ) {
  22. for (var i = 0; i < value.length; i++) {
  23. if (!value[i].value) {
  24. return false;
  25. }
  26. }
  27. }
  28. else {
  29. return false;
  30. }
  31. return true;
  32. }, required:true},
  33. formValue:{value:{}},
  34. payload: {value: ''},
  35. submit: {value: "submit"},
  36. cancel: {value: "cancel"},
  37. topic: {value: 'topic', validate: (RED.validators.hasOwnProperty('typedInput')?RED.validators.typedInput('topicType'):function(v) { return true})},
  38. topicType: {value: 'msg'},
  39. splitLayout: {value:''},
  40. className: {value: ''}
  41. },
  42. inputs:1,
  43. outputs:1,
  44. icon: "ui_form.png",
  45. paletteLabel: 'form',
  46. label: function() { return this.name || this.label || 'form'; },
  47. labelStyle: function() { return this.name?"node_label_italic":""; },
  48. oneditprepare: function() {
  49. if ($("#node-input-submit").val() === null) { $("#node-input-submit").val("submit"); }
  50. if ($("#node-input-cancel").val() === null) { $("#node-input-cancel").val("cancel"); }
  51. $("#node-input-size").elementSizer({
  52. width: "#node-input-width",
  53. height: "#node-input-height",
  54. group: "#node-input-group"
  55. });
  56. this.resizeRule = function(option,newWidth) {
  57. //option.find(".node-input-option-type").width(newWidth);
  58. // option.find(".node-input-option-label").width(newWidth);
  59. // option.find(".node-input-option-value").width(newWidth);
  60. }
  61. function generateOption(i, option) {
  62. var container = $('<li/>',{style:"margin:0; padding:8px 0px 0px; border-bottom:1px solid #ccc;"});
  63. var row = $('<div/>').appendTo(container);
  64. var row2 = $('<div/>',{style:"padding-top:5px; padding-left:175px;"}).appendTo(container);
  65. var row3 = $('<div/>',{style:"padding-top:5px; padding-left:120px;"}).appendTo(container);
  66. $('<i style="cursor:move; margin-left:3px;" class="node-input-option-handle fa fa-bars"></i>').appendTo(row);
  67. var labelField = $('<input/>',{class:"node-input-option-label", type:"text", style:"margin-left:7px; width:20%;", placeholder: RED._("node-red-dashboard/ui_form:ui_form.label.egName"), value:option.label}).appendTo(row);//.typedInput({default:'str',types:['str', 'num']});
  68. var valueClass ="node-input-option-value"
  69. if (!option.value) { valueClass ="node-input-option-value input-error"; }
  70. var valueField = $('<input/>',{class:valueClass, type:"text", style:"margin-left:7px; width:20%;", placeholder: RED._("node-red-dashboard/ui_form:ui_form.label.egName2"), value:option.value}).appendTo(row);//.typedInput({default:'str',types:['str','num','bool']});
  71. valueField.keyup(function() {
  72. if ($(this).val() && $(this).hasClass('input-error')) {
  73. $(this).removeClass('input-error')
  74. }
  75. else {
  76. if (!$(this).val()) {
  77. $(this).addClass('input-error')
  78. }
  79. }
  80. });
  81. // var typeField = $('<input/>',{class:"node-input-option-type",type:"text",style:"margin-left: 7px; width: 135px;", placeholder: 'Type', value:option.type}).appendTo(row).typedInput({default:'str',types:['str', 'num']});
  82. var typeField = $('<select/>',{class:"node-input-option-type",type:"text",style:"margin-left:7px; width:16%"}).appendTo(row);//.typedInput({default:'str',types:['str', 'num']});
  83. var arr = [
  84. {val : "text", text: RED._("node-red-dashboard/ui_form:ui_form.label.text")},
  85. {val : "multiline", text: RED._("node-red-dashboard/ui_form:ui_form.label.multiline")},
  86. {val : "number", text: RED._("node-red-dashboard/ui_form:ui_form.label.number")},
  87. {val : "email", text: RED._("node-red-dashboard/ui_form:ui_form.label.email")},
  88. {val : "password", text: RED._("node-red-dashboard/ui_form:ui_form.label.password")},
  89. {val : "checkbox", text: RED._("node-red-dashboard/ui_form:ui_form.label.checkbox")},
  90. {val : "switch", text: RED._("node-red-dashboard/ui_form:ui_form.label.switch")},
  91. {val : "date", text: RED._("node-red-dashboard/ui_form:ui_form.label.date")},
  92. {val : "time", text: RED._("node-red-dashboard/ui_form:ui_form.label.time")}
  93. ];
  94. //var sel = $('<select>').appendTo('body');
  95. $(arr).each(function() {
  96. var isSelected= false;
  97. if (option.type == this.val) {
  98. isSelected = true;
  99. }
  100. typeField.append($("<option>").attr('value',this.val).text(this.text).prop('selected',isSelected));
  101. });
  102. //var labelForRequried = $('<span/>',{style:"margin: 10px;"}).text('Required').appendTo(row);
  103. var requiredContainer= $('<div/>',{style:"display:inline-block; height:34px; width:13%; vertical-align: middle"}).appendTo(row);
  104. var requiredInnerContainer= $('<div/>',{style:"left:35%; position:relative; width:30px"}).appendTo(requiredContainer);
  105. var reqRow=$("<label />",{class:"switch",style:"top:10px; width:30px;"}).appendTo(requiredInnerContainer);
  106. //var required = $('<input/>',{class:"node-input-option-required",style:"margin: 5px;width:19%",type:"checkbox", checked:option.required}).appendTo(row);//labelForRequried);//.typedInput({default:'str',types:['str', 'num']});
  107. var required = $('<input/>',{class:"node-input-option-required", type:"checkbox", checked:option.required, style:"vertical-align:top;"}).appendTo(reqRow);//labelForRequried);//.typedInput({default:'str',types:['str', 'num']});
  108. var reqDiv=$("<div />",{class:"slider round"}).appendTo(reqRow);
  109. var vis = option.rows ? 'visible' : 'hidden';
  110. var rowsField = $('<input/>',{class:"node-input-option-rows", type:"number", style:"width:10%;", placeholder:'Rows', value:option.rows }).css('visibility',vis).appendTo(row);
  111. var finalspan = $('<div/>',{style:"display:inline-block; width:5%;"}).appendTo(row);
  112. var deleteButton = $('<a/>',{href:"#",class:"editor-button", style:"font-size:1.3em; left:45%; position:relative;"}).appendTo(finalspan);
  113. $('<i/>',{class:"fa fa-trash-o"}).appendTo(deleteButton);
  114. typeField.change(function(e){
  115. if (e.target.value != 'multiline') {
  116. rowsField.val(undefined)
  117. option.rows = null;
  118. rowsField.css('visibility','hidden')
  119. } else {
  120. rowsField.css('visibility','visible')
  121. if (!rowsField[0].value) rowsField[0].value = 3;
  122. }
  123. })
  124. deleteButton.click(function() {
  125. container.find(".node-input-option-value").removeAttr('required')
  126. container.css({"background":"#fee"});
  127. container.fadeOut(300, function() {
  128. $(this).remove();
  129. });
  130. });
  131. $("#node-input-option-container").append(container);
  132. }
  133. $("#node-input-add-option").click(function() {
  134. generateOption($("#node-input-option-container").children().length+1, {});
  135. $("#node-input-option-container-div").scrollTop($("#node-input-option-container-div").get(0).scrollHeight);
  136. });
  137. for (var i=0; i<this.options.length; i++) {
  138. var option = this.options[i];
  139. generateOption(i+1,option);
  140. }
  141. $('#node-input-topic').typedInput({
  142. default: 'str',
  143. typeField: $("#node-input-topicType"),
  144. types: ['str','msg','flow','global']
  145. });
  146. $( "#node-input-option-container" ).sortable({
  147. axis: "y",
  148. handle:".node-input-option-handle",
  149. cursor: "move"
  150. });
  151. },
  152. oneditsave: function() {
  153. var options = $("#node-input-option-container").children();
  154. var node = this;
  155. node.options = [];
  156. node.formValue = {};
  157. options.each(function(i) {
  158. var option = $(this);
  159. var o = {
  160. label: option.find(".node-input-option-label").val(),//typedInput('value'),
  161. value: option.find(".node-input-option-value").val(),//typedInput('value'),
  162. type: option.find(".node-input-option-type").val(),//typedInput('value')
  163. required: option.find(".node-input-option-required").is(':checked'),
  164. rows: parseInt(option.find(".node-input-option-rows").val())
  165. };
  166. // o.value= o.value||o.label||(o.type+"_"+i);
  167. node.formValue[o.value]= o.type == "checkbox" || o.type == "switch" ? false : "";
  168. node.options.push(o);
  169. });
  170. },
  171. oneditresize: function() {
  172. var options = $("#node-input-option-container").children();
  173. var newWidth = ($("#node-input-option-container").width() - 175)/2;
  174. var node = this;
  175. options.each(function(i) {
  176. node.resizeRule($(this),newWidth);
  177. });
  178. }
  179. });
  180. </script>
  181. <script type="text/html" data-template-name="ui_form">
  182. <style>
  183. .switch {
  184. position: relative;
  185. display: inline-block;
  186. width: 30px;
  187. height: 18px;
  188. }
  189. .switch input {display:none;}
  190. .slider {
  191. position: absolute;
  192. cursor: pointer;
  193. top: 0;
  194. left: 0;
  195. right: 0;
  196. bottom: 0;
  197. background-color: #ccc;
  198. -webkit-transition: .4s;
  199. transition: .4s;
  200. }
  201. .slider:before {
  202. position: absolute;
  203. content: "";
  204. height: 15px;
  205. width: 15px;
  206. left: 2px;
  207. bottom: 2px;
  208. background-color: white;
  209. -webkit-transition: .4s;
  210. transition: .4s;
  211. }
  212. input:checked + .slider {
  213. background-color: #910000;
  214. }
  215. input:focus + .slider {
  216. box-shadow: 0 0 1px #2196F3;
  217. }
  218. input:checked + .slider:before {
  219. -webkit-transform: translateX(11px);
  220. -ms-transform: translateX(11px);
  221. transform: translateX(11px);
  222. }
  223. /* Rounded sliders */
  224. .slider.round {
  225. border-radius: 34px;
  226. }
  227. .slider.round:before {
  228. border-radius: 50%;
  229. }
  230. </style>
  231. <div class="form-row">
  232. <label for="node-input-group"><i class="fa fa-table"></i> <span data-i18n="ui_form.label.group"></label>
  233. <input type="text" id="node-input-group">
  234. </div>
  235. <div class="form-row">
  236. <label><i class="fa fa-object-group"></i> <span data-i18n="ui_form.label.size"></label>
  237. <input type="hidden" id="node-input-width">
  238. <input type="hidden" id="node-input-height">
  239. <button class="editor-button" id="node-input-size"></button>
  240. </div>
  241. <div class="form-row">
  242. <label for="node-input-label"><i class="fa fa-tag"></i> <span data-i18n="ui_form.label.label"></label>
  243. <input type="text" id="node-input-label" data-i18n="[placeholder]ui_form.label.optionalLabel">
  244. </div>
  245. <div class="form-row node-input-option-container-row" style="margin-bottom:0px; width:100%; min-width:520px">
  246. <label style="vertical-align:top;"><i class="fa fa-list-alt"></i> <span data-i18n="ui_form.label.formElements"></label>
  247. <div style="display:inline-block; width:78%; border:1px solid #ccc; border-radius:5px; box-sizing:border-box;">
  248. <div class="red-ui-tray-header" style="width:100%; display: inline-block; padding-top:10px; padding-buttom:10px; border-top:0px solid; border-radius:5px 5px 0 0; border-bottom:1px solid #ccc;">
  249. <div style="width:94%; display:inline-block; margin-left:27px">
  250. <div style="width:20%; text-align:center; float:left;" data-i18n="ui_form.label.label"></span></div>
  251. <div style="width:20%; text-align:center; float:left; margin-left:9px" data-i18n="node-red:common.label.name"></div>
  252. <div style="margin-left:7px; width:16%; text-align:center; float:left; margin-left:9px" data-i18n="ui_form.label.type"></div>
  253. <div style="width:16%; text-align:center; float:left;" data-i18n="ui_form.label.required"></div>
  254. <div style="width:10%; text-align:center; float:left;" data-i18n="ui_form.label.rows"></div>
  255. <div style="width:12%; text-align:center; float:left;" data-i18n="ui_form.label.remove"></div>
  256. </div>
  257. </div>
  258. <div id="node-input-option-container-div" style=" height: 257px; padding: 5px; overflow-y:scroll;">
  259. <ol id="node-input-option-container" style=" list-style-type:none; margin: 0;"></ol>
  260. </div>
  261. </div>
  262. </div>
  263. <div class="form-row">
  264. <a href="#" class="editor-button editor-button-small" id="node-input-add-option" style="margin-top: 4px; margin-left: 103px;"><i class="fa fa-plus"></i> <span data-i18n="ui_form.label.element"></span></a>
  265. </div>
  266. <div class="form-row">
  267. <label for="node-input-submit"><i class="fa fa-square"></i> <span data-i18n="ui_form.label.buttons"></label>
  268. <i class="fa fa-thumbs-o-up"></i> <input type="text" id="node-input-submit" data-i18n="[placeholder]ui_form.label.submitButtonText" style="width:35%;">
  269. <span style="margin-left:16px"><i class="fa fa-thumbs-o-down"></i></span>
  270. <input type="text" id="node-input-cancel" data-i18n="[placeholder]ui_form.label.cancelButtonText" style="width:35%;">
  271. </div>
  272. <div class="form-row">
  273. <label for="node-input-splitLayout"></label>
  274. <input type="checkbox" id="node-input-splitLayout" style="display:inline-block; width:auto; vertical-align:top;">
  275. <span data-i18n="ui_form.label.splitLayout">
  276. </div>
  277. <div class="form-row">
  278. <label for="node-input-topic"><i class="fa fa-tasks"></i> <span data-i18n="ui_form.label.topic"></label>
  279. <input type="text" id="node-input-topic" data-i18n="[placeholder]ui_form.label.optionalMsgTopic">
  280. <input type="hidden" id="node-input-topicType">
  281. </div>
  282. <div class="form-row">
  283. <label for="node-input-className"><i class="fa fa-code"></i> <span data-i18n="ui_form.label.className"></label>
  284. <input type="text" id="node-input-className" data-i18n="[placeholder]ui_form.label.classNamePlaceholder"/>
  285. </div>
  286. <div class="form-row">
  287. <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></label>
  288. <input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
  289. </div>
  290. </script>