2 Copyright 2013 IBM Corp.
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
16 <script type="text/x-red" data-template-name="block">
17 <div class="form-row">
18 <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
19 <input type="text" id="node-input-name" placeholder="Name">
21 <div class="form-row">
23 <table border='0' width='100%' style='cellspacing:5px;'>
26 <input type="checkbox" id="node-input-atomic-chkBox" onclick=updateXml()>
27 <input type="hidden" id="node-input-atomic" value="">
30 <span style="font-size:.8em;">Atomic</span>
35 <label for="node-input-xml"><i class="fa fa-wrench"></i> Node XML</label>
36 <input type="hidden" id="node-input-xml" autofocus="autofocus">
37 <div style="height: 450px;" class="node-text-editor" id="node-input-xml-editor" onkeyup="resetStatus()" ></div>
39 <div class="form-row">
40 <a href="#" class="btn btn-mini" id="node-input-validate" style="margin-top: 4px;"><b>Validate XML</b></a>
41 <a href="#" class="btn btn-mini" id="node-input-show-sli-values" style="margin-top: 4px;"><b>Show Values</b></a>
42 <input type="hidden" id="node-input-comments">
43 <a href="#" class="btn btn-mini" id="node-input-btnComments" style="margin-top: 4px;"><b>Add Comments</b></a>
44 <div id="node-validate-result" class="form-tips" style="float:right;font-size:10px"></div>
46 <div class="form-tips">See the Info tab for help using this node.</div>
49 <script type="text/x-red" data-help-name="block">
51 <p>Name can be anything.</p>
52 <p>Do not include closing tag - it will be automatically generated.</p>
55 <h3><a name="Flow_Control"></a>Flow Control</h3>
57 <h4><a name="Block_node"></a>Block node</h4>
59 <h5><a name="Description"></a>Description</h5>
60 <p>A <b>block</b> node is used to executes a set of nodes. </p></div>
62 <h5><a name="Attributes"></a>Attributes</h5>
63 <table border="1" class="table table-striped">
65 <td align="center"><b>atomic</b></td>
66 <td align="left">if <i>true</i>, then if a node returns failure, subsequent nodes will not be executed and nodes already executed will be backed out.</td></tr></table></div>
68 <h5><a name="Parameters"></a>Parameters</h5>
71 <h5><a name="Outcomes"></a>Outcomes</h5>
74 <h5><a name="Example"></a>Example</h5>
77 <record plugin="org.onap.ccsdk.sli.core.sli.recording.FileRecorder">
78 <parameter name="file" value="/tmp/sample_r1.log" />
79 <parameter name="field1" value="__TIMESTAMP__"/>
80 <parameter name="field2" value="RESERVED"/>
81 <parameter name="field3" value="$asePort.uni_circuit_id"/>
83 <return status="success">
84 <parameter name="uni-circuit-id" value="$asePort.uni_circuit_id" />
86 </block></pre></div></div></div>
91 <script type="text/javascript">
93 RED.nodes.registerType('block',{
97 name: {value:"block"},
98 xml: {value:"<block>\n"},
99 atomic: {value:"false"},
105 icon: "arrow-in.png",
109 oneditprepare: function() {
111 $( "#node-input-outputs" ).spinner({
114 var comments = $( "#node-input-comments").val();
115 if(comments != null){
116 comments = comments.trim();
118 $("#node-input-btnComments").html("<span style='color:blue;'><b>View Comments</b></span>");
122 var atomic = $( "#node-input-atomic").val();
123 if(atomic == "true"){
124 $('#node-input-atomic-chkBox').prop('checked', true);
126 $('#node-input-atomic-chkBox').prop('checked', false);
129 function functionDialogResize() {
130 var rows = $("#dialog-form>div:not(.node-text-editor-row)");
131 var height = $("#dialog-form").height();
132 for (var i=0;i<rows.size();i++) {
133 height -= $(rows[i]).outerHeight(true);
135 var editorRow = $("#dialog-form>div.node-text-editor-row");
136 height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
137 $(".node-text-editor").css("height",height+"px");
138 that.editor.resize();
140 $( "#dialog" ).on("dialogresize", functionDialogResize);
141 $( "#dialog" ).one("dialogopen", function(ev) {
142 var size = $( "#dialog" ).dialog('option','sizeCache-function');
144 $("#dialog").dialog('option','width',size.width);
145 $("#dialog").dialog('option','height',size.height);
146 functionDialogResize();
149 $( "#dialog" ).one("dialogclose", function(ev,ui) {
150 var height = $( "#dialog" ).dialog('option','height');
151 $( "#dialog" ).off("dialogresize",functionDialogResize);
154 this.editor = RED.editor.createEditor({
155 id: 'node-input-xml-editor',
156 mode: 'ace/mode/html'
158 this.editor.setValue($("#node-input-xml").val(),-1);
159 blockXmlEditor=that.editor;
162 url:"functions", // where to get the data from
163 type:"function", // the type of object the library is for
164 editor:this.editor, // the field name the main text body goes to
165 mode:"ace/mode/html",
166 fields:['name','outputs']
170 /* close dialog when ESC is pressed and released */
171 $( "#node-input-xml-editor" ).keyup(function(event){
172 if(event.which == 27 ) {
173 $("#node-dialog-cancel").click();
176 $("#node-input-validate").click(function(){
177 console.log("validate clicked.");
178 //console.dir(that.editor);
179 //console.log("getText:" + that.editor.getText());
180 var val = that.editor.getValue();
183 $("#node-input-show-sli-values").click(function(){
184 //console.log("show Values clicked.");
185 showValuesBox(that.editor,sliValuesObj);
187 //for click of add comments button
188 $("#node-input-btnComments").click(function(e){
192 oneditsave: function() {
193 $("#node-input-xml").val(this.editor.getValue());
194 var resp=validateXML(this.editor.getValue());
196 this.status = {fill:"green",shape:"dot",text:"OK"};
198 this.status = {fill:"red",shape:"dot",text:"ERROR"};
201 delete blockXmlEditor;
204 function updateXml(){
205 if($("#node-input-atomic-chkBox").is(':checked')){
206 $("#node-input-name").val("block : atomic");
207 $("#node-input-atomic").val("true");
208 //alert($("#node-input-xml-editor div.textview div.textviewContent").text());
209 var xmlStr = blockXmlEditor.getValue();
210 var re = new RegExp("<block[^<]+");
211 xmlStr=xmlStr.replace(re,"<block atomic='true'>");
212 //$("#node-input-xml-editor div.textview div.textviewContent").text(xmlStr);
213 blockXmlEditor.setValue(xmlStr);
214 //console.log("block xmlStr:" + xmlStr);
216 $("#node-input-name").val("block");
217 $("#node-input-atomic").val("false");
218 var xmlStr = blockXmlEditor.getValue();
219 var re = new RegExp("<block[^<]+");
220 xmlStr=xmlStr.replace(re,"<block>");
221 blockXmlEditor.setValue(xmlStr);
222 //$("#node-input-xml-editor div.textview div.textviewContent").text(xmlStr);
223 //console.log("block xmlStr:" + xmlStr);