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 <div id="svclogicPageDiv" ></div>
17 <!-- dgbuilder javascript files START -->
18 <script src="util/js/validateNodeXml.js"/>
19 <script src="util/js/sliValues.js"/>
20 <script src="util/js/dgeToXml.js"/>
21 <script src="util/js/vkbeautify.0.99.00.beta.js"/>
22 <!-- dgbuilder javascript files END -->
24 <script type="text/x-red" data-template-name="dgstart">
25 <div class="form-tips">See the Info tab for help using this node.</div>
28 .no-close .ui-dialog-titlebar-close {display: none }
30 border-top: 1px solid #96d1f8;
32 background: -webkit-gradient(linear, left top, left bottom, from(#3e779d), to(#65a9d7));
33 background: -webkit-linear-gradient(top, #3e779d, #65a9d7);
34 background: -moz-linear-gradient(top, #3e779d, #65a9d7);
35 background: -ms-linear-gradient(top, #3e779d, #65a9d7);
36 background: -o-linear-gradient(top, #3e779d, #65a9d7);
38 -webkit-border-radius: 8px;
39 -moz-border-radius: 8px;
41 -webkit-box-shadow: rgba(0,0,0,1) 0 1px 0;
42 -moz-box-shadow: rgba(0,0,0,1) 0 1px 0;
43 box-shadow: rgba(0,0,0,1) 0 1px 0;
44 text-shadow: rgba(0,0,0,.4) 0 1px 0;
47 font-family: Georgia, serif;
48 text-decoration: none;
49 vertical-align: middle;
51 .alertDialogButton:hover {
52 border-top-color: #28597a;
57 .alertDialogButton:active {
58 border-top-color: #1b435e;
62 border-top: 1px solid #96d1f8;
63 background: lightgrey;
64 background: -webkit-gradient(linear, left top, left bottom, from(grey), to(lightgrey));
65 background: -webkit-linear-gradient(top, grey, grey);
66 background: -moz-linear-gradient(top, grey, grey);
67 background: -ms-linear-gradient(top, grey, grey);
68 background: -o-linear-gradient(top, grey, grey);
70 -webkit-border-radius: 8px;
71 -moz-border-radius: 8px;
73 -webkit-box-shadow: rgba(0,0,0,1) 0 1px 0;
74 -moz-box-shadow: rgba(0,0,0,1) 0 1px 0;
75 box-shadow: rgba(0,0,0,1) 0 1px 0;
76 text-shadow: rgba(0,0,0,.4) 0 1px 0;
79 font-family: Georgia, serif;
80 text-decoration: none;
81 vertical-align: middle;
84 <script type="text/javascript">
86 function activateDG(module,rpc,version,mode,displayOnlyCurrent){
87 var paramsObj = {'module': module , 'rpc' : rpc , 'version' : version , 'mode' : mode,'displayOnlyCurrent' : false};
88 if(displayOnlyCurrent){
89 paramsObj = {'module': module , 'rpc' : rpc , 'version' : version , 'mode' : mode,'displayOnlyCurrent' : true};
91 var dgInfo = "<div><table width='100%' border='1'><tr style='background-color:#65a9d7;color:white;' ><th>Module</th><th>RPC</th><th>Version</th></tr><tr style='background-color:white'><td>" + module +"</td><td>" + rpc + "</td><td>" +version + "</td></tr></table></div><br>";
92 var alertMsg = dgInfo + "<p>Are you sure you want to Activate this DG ?</p>";
93 $( "#alertdialog" ).dialog({
94 dialogClass: "no-close",
98 /*dialogClass: "alert",*/
99 title: "Confirm Activate",
104 class:"alertDialogButton",
106 $.get("/activateDG" , paramsObj)
107 .done(function( data ) {
108 //RED.notify("<strong>Activated Successfully</strong>");
111 if(displayOnlyCurrent){
112 htmlStr=getHtmlStr(data,true);
113 title="Service Logic Administration Module=" + module + " and RPC=" + rpc;
115 htmlStr=getHtmlStr(data);
116 title= "Service Logic Administration - " + data.dbHost;
118 $("#svclogicPageDiv").dialog({
127 .fail(function( err ) {
128 RED.notify("<strong>Could not Activate</strong>");
129 var htmlStr = "<p>" + "could not activate" + module + " " + rpc + " " + version +"</p> <a onclick='javascript:showSLA()'></a>";
130 if(displayOnlyCurrent == true){
131 htmlStr = "<p>" + "could not activate" + module + " " + rpc + " " + version +"</p> <a onclick='javascript:showCurrentDGs(\"" + module + "\",\"" + rpc + "\")'>Back to DG List</a>";
133 $("#svclogicPageDiv").dialog({
135 title: "Service Logic Administration - " + err.dbHost,
143 // $('.ui-dialog:has(#alertdialog)').empty().remove();
144 $("#alertdialog" ).dialog('close');
151 class:"alertDialogButton",
153 //$('.ui-dialog:has(#alertdialog)').empty().remove();
154 $( this ).dialog( "close" );
158 }).html(alertMsg).dialog('open');
159 //var dialogClass = $("#alertdialog").dialog( "option", "dialogClass" );
160 //$( "#alertdialog" ).dialog( "option", "dialogClass", "alert" );
161 //$("#alertdialog").dialog("widget").find(".ui-dialog-buttonpane").css("background-color", "#ECECFF");
163 $('#alertdialog').css("background-color", "#ECECEC");
164 $("#alertdialog").dialog("widget").find(".ui-dialog-buttonpane").css("background-color", "#ECECEC");
167 $("#alertdialog").dialog("widget").find(".ui-dialog-buttonpane").css({"padding":".1em .1em .1em 0","margin":"0 0 0 0"} )
170 $("#alertdialog").dialog("widget").find("button").css({"padding":"0 .2em 0 .2em","margin":"0 .5em 0 0"} )
171 $("#alertdialog").dialog("widget").find("button").addClass("alertDialogButton");
173 //console.dir($("#alertdialog"));
177 function deActivateDG(module,rpc,version,mode,displayOnlyCurrent){
178 var paramsObj = {'module': module , 'rpc' : rpc , 'version' : version , 'mode' : mode,'displayOnlyCurrent' : false};
179 if(displayOnlyCurrent){
180 paramsObj = {'module': module , 'rpc' : rpc , 'version' : version , 'mode' : mode,'displayOnlyCurrent' : true};
182 var dgInfo = "<div ><table width='100%' border='1'><tr style='background-color:#65a9d7;color:white;'><th>Module</th><th>RPC</th><th>Version</th></tr><tr style='background-color:white'><td>" + module +"</td><td>" + rpc + "</td><td>" +version + "</td></tr></table></div><br>";
183 var alertMsg = dgInfo + "<p>Are you sure you want to De-Activate this DG ?</p>";
184 $( "#alertdialog" ).dialog({
185 dialogClass: "no-close",
189 title: "Confirm De-Activate",
194 class:"alertDialogButton",
196 $.get("/deActivateDG" , paramsObj)
197 .done(function( data ) {
198 //RED.notify("<strong>deActivated Successfully</strong>");
201 if(displayOnlyCurrent){
202 htmlStr=getHtmlStr(data,true);
203 title="Service Logic Administration Module=" + module + " and RPC=" + rpc;
205 htmlStr=getHtmlStr(data);
206 title= "Service Logic Administration - " + data.dbHost;
208 $("#svclogicPageDiv").dialog({
217 .fail(function( err ) {
218 RED.notify("<strong>Could not De-Activate</strong>");
219 var htmlStr = "<p>" + "could not deactivate" + module + " " + rpc + " " + version +"</p> <a onclick='javascript:showSLA()'></a>";
220 if(displayOnlyCurrent == true){
221 htmlStr = "<p>" + "could not deactivate" + module + " " + rpc + " " + version +"</p> <a onclick='javascript:showCurrentDGs(\"" + module + "\",\"" + rpc + "\")'>Back to DG List</a>";
223 $("#svclogicPageDiv").dialog({
225 title: "Service Logic Administration - " + err.dbHost,
233 //$('.ui-dialog:has(#alertdialog)').empty().remove();
234 $( "#alertdialog" ).dialog( "close" );
235 //$("#alertdialog" ).dialog('destroy').remove();
241 class:"alertDialogButton",
243 //$('.ui-dialog:has(#alertdialog)').empty().remove();
244 //$(this).dialog('destroy').remove()
245 //$( this ).dialog( "close" );
246 /*if ($("#alertdialog").hasClass('ui-dialog-content')) {
247 $("#alertdialog" ).dialog('close');
249 $( this ).dialog( "close" );
252 $( this ).dialog( "close" );
256 }).html(alertMsg).dialog("open");
259 function deleteDG(module,rpc,version,mode,displayOnlyCurrent){
260 var paramsObj = {'module': module , 'rpc' : rpc , 'version' : version , 'mode' : mode,'displayOnlyCurrent' : false};
261 if(displayOnlyCurrent){
262 paramsObj = {'module': module , 'rpc' : rpc , 'version' : version , 'mode' : mode,'displayOnlyCurrent' : true};
264 var dgInfo = "<div ><table width='100%' border='1'><tr style='background-color:#65a9d7;color:white;'><th>Module</th><th>RPC</th><th>Version</th></tr><tr style='background-color:white'><td>" + module +"</td><td>" + rpc + "</td><td>" +version + "</td></tr></table></div><br>";
265 var alertMsg = dgInfo + "<p>Are you sure you want to Delete this DG ?</p>";
266 $( "#alertdialog" ).dialog({
267 dialogClass: "no-close",
271 title: "Confirm Delete",
276 class:"alertDialogButton",
278 $.get("/deleteDG" , paramsObj)
279 .done(function( data ) {
280 RED.notify("<strong>Deleted " + module + " " + rpc + " " + version + " Successfully</strong>");
283 if(displayOnlyCurrent){
284 htmlStr=getHtmlStr(data,true);
285 title="Service Logic Administration Module=" + module + " and RPC=" + rpc;
287 htmlStr=getHtmlStr(data);
288 title= "Service Logic Administration - " + data.dbHost;
290 $("#svclogicPageDiv").dialog({
299 .fail(function( err ) {
300 //RED.notify("<strong>Could not Delete" + module + " " + rpc + " " + version + "</strong>");
301 var htmlStr = "<p>" + "could not delete" + module + " " + rpc + " " + version +"</p> <a onclick='javascript:showSLA()'></a>";
302 if(displayOnlyCurrent == true){
303 htmlStr = "<p>" + "could not delete" + module + " " + rpc + " " + version +"</p> <a onclick='javascript:showCurrentDGs(\"" + module + "\",\"" + rpc + "\")'>Back to DG List</a>";
305 $("#svclogicPageDiv").dialog({
307 title: "Service Logic Administration - " + err.dbHost,
315 $( "#alertdialog" ).dialog( "close" );
316 //$('.ui-dialog:has(#alertdialog)').empty().remove();
317 //$("#alertdialog" ).dialog('destroy').remove();
323 class:"alertDialogButton",
326 if ($("#alertdialog").hasClass('ui-dialog-content')) {
327 $("#alertdialog" ).dialog('close');
329 $( this ).dialog( "close" );
332 //$( "#alertdialog" ).dialog( "close" );
333 //$('.ui-dialog:has(#alertdialog)').empty().remove();
334 //$( this ).dialog( "close" );
335 $( this ).dialog( "close" );
339 }).html(alertMsg).dialog("open");
342 function downloadDGXml(_module,rpc,version,mode){
343 var paramsObj = {'_module': _module , 'rpc' : rpc , 'version' : version , 'mode' : mode};
344 var form = $('<form id="dwnldDbXmlFormId" method="POST" action="/downloadDGXml"></form>');
345 form.append('<input type="hidden" name="_module" value="' + _module + '"/>');
346 form.append('<input type="hidden" name="rpc" value="' + rpc + '"/>');
347 form.append('<input type="hidden" name="version" value="' + version + '"/>');
348 form.append('<input type="hidden" name="mode" value="' + mode + '"/>');
349 form.appendTo('body');
350 $("#dwnldDbXmlFormId").submit();
354 function displayXml(module,rpc,version,mode,displayOnlyCurrent){
355 var paramsObj = {'_module': module , 'rpc' : rpc , 'version' : version , 'mode' : mode,'displayOnlyCurrent' : false};
356 var title="Service Logic Administration";
357 if(displayOnlyCurrent){
358 paramsObj = {'_module': module , 'rpc' : rpc , 'version' : version , 'mode' : mode,'displayOnlyCurrent' : true};
359 title="Service Logic Administration Module=" + module + " and RPC=" + rpc;
361 title="Service Logic Administration";
363 //var headingStr = "<a style='color: #337ab7;' onclick='javascript:showSLA()'><<Back to DG List</a><br><div style='background-color:#337ab7;clear:both;'><table style='width:100%;' border='0'>" +
364 var headingStr = "<a style='color: #337ab7;cursor:pointer;' onclick='javascript:showSLA()'><<Back to DG List</a><br><div style='clear:both;'><table style='width:25%' border='0'>" ;
365 if(displayOnlyCurrent == true){
366 headingStr = "<a style='color: #337ab7;cursor:pointer;' onclick='javascript:showCurrentDGs(\"" + module + "\",\"" + rpc + "\")'><<Back to DG List</a><br><div style='clear:both;'><table style='width:25%' border='0'>" ;
368 headingStr += "<tr><td><b>Module</b></td><td>" + module + "</td></tr>" +
369 "<tr><td><b>RPC</b></td><td>" + rpc + "</td></tr>" +
370 "<tr><td><b>Version</b></td><td>" + version + "</td></tr>" +
371 "<tr><td><b>Mode</b></td><td>" + mode + "</td></tr>" +
374 //var urlStr = "/displayXml?_module=" + module + "&rpc=" + rpc + "&version=" + version + "&mode=" + mode;
375 $.get("/displayXml",paramsObj)
376 .done(function( data ) {
377 //var htmlStr= headingStr + '<div style="clear:both;"></div><div style="background-color:lightgrey;border-style: solid;border-color:#337ab7;clear:both;">' + data.xmldata + "</div>";
378 var htmlStr= headingStr + '<hr style="clear:both;height:5px;background-color:#337ab7;"><div>' + data.xmldata + "</div>";
379 $("#svclogicPageDiv").dialog({
388 .fail(function( err ) {
389 //RED.notify("<strong>Could not display XML</strong>");
390 var htmlStr = "<p>" + "Could not display xml for" + module + " " + rpc + " " + version + "</p><a style='color: #337ab7;cursor:pointer;' onclick='javascript:showSLA()'>Back to DG List</a><br>";
391 if(displayOnlyCurrent == true){
392 htmlStr = "<p>" + "could not display XML" + module + " " + rpc + " " + version +"</p> <a onclick='javascript:showCurrentDGs(\"" + module + "\",\"" + rpc + "\")'>Back to DG List</a>";
394 $("#svclogicPageDiv").dialog({
396 title: "Service Logic Administration",
407 function displayDG(module,rpc,version,mode,displayOnlyCurrent){
408 var paramsObj = {'_module': module , 'rpc' : rpc , 'version' : version , 'mode' : mode,'displayOnlyCurrent' : false};
409 var title="Service Logic Administration";
410 if(displayOnlyCurrent){
411 paramsObj = {'_module': module , 'rpc' : rpc , 'version' : version , 'mode' : mode,'displayOnlyCurrent' : true};
413 //var headingStr = "<a style='color: #337ab7;cursor:pointer' onclick='javascript:showSLA()'><<Back to DG List</a><br><div><table id='msgTable' style='width:25%;background-color:lightgrey' border='0'>" +
414 var headingStr = "<a style='color: #337ab7;cursor:pointer;' onclick='javascript:showSLA()'><<Back to DG List</a><br><div><table id='msgTable' style='width:25%;' border='0'>" ;
415 if(displayOnlyCurrent == true){
416 headingStr = "<a style='color: #337ab7;cursor:pointer;' onclick='javascript:showCurrentDGs(\"" + module + "\",\"" + rpc + "\")'><<Back to DG List</a><br><div style='clear:both;'><table style='width:25%' border='0'>" ;
417 title="Service Logic Administration Module=" + module + " and RPC=" + rpc;
419 headingStr +="<tr><td><b>Module</b></td><td>" + module + "</td></tr>" +
420 "<tr><td><b>RPC</b></td><td>" + rpc + "</td></tr>" +
421 "<tr><td><b>Version</b></td><td>" + version + "</td></tr>" +
422 "<tr><td><b>Mode</b></td><td>" + mode + "</td></tr>" +
425 //var urlStr = "/displayAsGv?_module=" + module + "&rpc=" + rpc + "&version=" + version + "&mode=" + mode;
426 $.get("/displayAsGv",paramsObj)
427 .done(function( data ) {
428 var htmlStr= headingStr + '<div style="background-color:white;">' + data.svg_html + "</div>";
429 $("#svclogicPageDiv").dialog({
431 title: "Service Logic Administration",
438 .fail(function( err ) {
439 //RED.notify("<strong>Could not display XML</strong>");
440 var htmlStr = "<p>" + "Could not display DG for" + module + " " + rpc + " " + version + "</p><a style='color: #337ab7;cursor:pointer;' onclick='javascript:showSLA()'>Back to DG List</a><br>";
441 if(displayOnlyCurrent == true){
442 htmlStr = "<p>" + "could not display DG for" + module + " " + rpc + " " + version +"</p> <a onclick='javascript:showCurrentDGs(\"" + module + "\",\"" + rpc + "\")'>Back to DG List</a>";
444 $("#svclogicPageDiv").dialog({
446 title: "Service Logic Administration",
457 function getHtmlStr(data,displayOnlyCurrent,module,rpc){
458 var styleStr = "<style> " +
459 "table#t01 { width:100%; } \n" +
460 "table#t01 th,table#t01 td { border: 1px solid black; border-collapse: collapse; } \n" +
461 /*"table, th, td { border: 1px solid #65a9d7; border-collapse: collapse; } \n" +*/
462 "table#t01 th,table#t01 td { padding: 5px; text-align: left; } \n" +
463 "table#t01 tr:nth-child(even) { background-color: #eee; }\n" +
464 "table#t01 tr:nth-child(odd) { background-color:#fff; }\n" +
465 "table#t01 th { background-color: #65a9d7; color: white; }\n" +
466 "table#t01 a { color: #337ab7; }\n" +
467 "table#t01 a:link { color: #65a9d7; }\n" +
468 "table#t01 a:visited { color: #636; }\n" +
469 "table#t01 a:hover { color: #3366CC; cursor: pointer }\n" +
470 "table#t01 a:active { color: #65a9d7 }\n" +
472 if(data != null && data.rows != undefined && data.error == undefined){
473 var alertDialog = '<div id="alertdialog"></div>';
474 htmlStr= alertDialog + "<div style='width:1050;height:650'>" + styleStr;
475 htmlStr += "<table id='t01' >";
477 htmlStr += "<th>Module</th>" ;
478 htmlStr += "<th>RPC</th>" ;
479 htmlStr += "<th>Version</th>" ;
480 htmlStr += "<th>Mode</th>" ;
481 htmlStr += "<th>Active</th>" ;
482 htmlStr += "<th>Activate/Deactivate</th>";
483 htmlStr += "<th>Display DG</th>";
484 htmlStr += "<th>XML</th>";
485 htmlStr += "<th>Delete</th>";
487 var rows = data.rows;
488 if(rows != null && rows.length == 0){
490 htmlStr += "<td><b>No rows found</b></td>";
491 htmlStr += "</tr></table></div>";
494 for(var i=0;i<rows.length;i++){
496 var _module = row.module;
498 var version = row.version;
500 var active = row.active;
502 htmlStr += "<td>" + _module + "</td>";
503 htmlStr += "<td>" + rpc + "</td>";
504 htmlStr += "<td>" + version + "</td>";
505 htmlStr += "<td>" + mode + "</td>";
506 htmlStr += "<td>" + active + "</td>";
508 var methodParams = "'" + _module + "','" + rpc + "','" + version + "','" + mode + "'";
509 if(displayOnlyCurrent){
510 methodParams+= ",true";
513 htmlStr += "<td><a onclick=\"javascript:deActivateDG(" + methodParams + ")\">DeActivate</a></td>";
515 htmlStr += "<td><a onclick=\"javascript:activateDG(" + methodParams + ")\">Activate</a></td>";
517 htmlStr += "<td><a onclick=\"javascript:displayDG(" + methodParams + ")\">Display</a></td>";
519 htmlStr += "<td><a onclick=\"javascript:displayXml(" + methodParams + ")\">XML</a></td>";
521 htmlStr += "<td><a onclick=\"javascript:deleteDG(" + methodParams + ")\">Delete</a></td>";
524 htmlStr += "</table>";
534 .done(function( data ) {
535 var htmlStr=getHtmlStr(data);
536 $("#svclogicPageDiv").dialog({
538 title: "Service Logic Administration - " + data.dbHost,
545 .fail(function(err) {
546 htmlStr= "<div>Error occured displaying the DG list</div>";
547 $("#svclogicPageDiv").dialog({
549 title: "Service Logic Administration - " + data.dbHost,
562 function showCurrentDGs(module,rpc){
565 var params="?module=" + module + "&rpc=" + rpc;
566 var url="/listCurrentDGs" + params;
567 //console.log("url:" + url);
569 .done(function( data ) {
570 var htmlStr=getHtmlStr(data,true);
571 $("#svclogicPageDiv").dialog({
573 title:"Service Logic Administration Module=" + module + " and RPC=" + rpc,
580 .fail(function(err) {
581 htmlStr= "<div>Error occured displaying the DG list</div>";
582 $("#svclogicPageDiv").dialog({
584 title:"Service Logic Administration Module=" + module + " and RPC=" + rpc,
598 function displaySLA(callback){
602 .done(function( data ) {
603 var htmlStr=getHtmlStr(data);
604 callback(htmlStr,data.dbHost);
606 .fail(function(err) {
607 htmlStr= "<div>Error occured displaying the DG list</div>";
608 callback(htmlStr,err.dbHost);
613 callback(htmlStr,"");
617 function displayCurrentDGs(module,rpc,callback){
620 var params="?module=" + module + "&rpc=" + rpc;
621 var url="/listCurrentDGs" + params;
622 //console.log("url:" + url);
624 .done(function( data ) {
625 var htmlStr=getHtmlStr(data,true);
626 callback(htmlStr,data.dbHost);
628 .fail(function(err) {
629 htmlStr= "<div>Error occured displaying the Current DG list</div>";
630 callback(htmlStr,err.dbHost);
635 callback(htmlStr,"");
640 window.onbeforeunload = function (event) {
641 var dis = $('#btn-deploy').attr('class')
642 if ( dis.indexOf('disabled') == -1 ) {
643 var message = 'Important: You have changes that were not \'deployed\'.';
644 if (typeof event == 'undefined') {
645 event = window.event;
648 event.returnValue = message;
654 <script type="text/x-red" data-help-name="dgstart">
655 <p>This node starts a flow. This node is required on every flow.</p>
656 <p>This node has a button to its left, when clicked generates the XML for the flow</p>
657 <img src="images/dgstart.png"></img>
665 <div id="screenInfoId"></div>
666 <script type="text/javascript">
667 function getAttributeValue(xmlStr,attribute){
670 var myRe = new RegExp(attribute + "[\s+]?=[\s+]?['\"]([^'\"]+)['\"]","m");
671 var myArray = myRe.exec(xmlStr);
672 if(myArray != null && myArray[1] != null){
683 function showDgStartGenerateXmlStatus(){
684 var htmlStr="<div id='dgstart-generate-xml-div' style='width:375;height:225'><p>Generating XML. Please wait... </p><img src='images/page-loading.gif'></div>"
685 $("#dgstart-generate-xml-dialog").dialog({
687 title: "DGBuilder XML Generation Status",
695 RED.nodes.registerType('dgstart',{
699 name: {value:"DGSTART"},
708 onpaletteadd: function() {
709 //console.log("DGSTART Added to the palette.");
712 onclick: function() {
713 //$('#processingStatusId').text('working...');
714 //$('#processingStatusId').html("<span><p> Processing Please Wait...</span><img src='images/page-loading.gif'>");
715 $('#processingStatusId').html("<span style='font-size:0.2em;color:green'> Processing...</span>");
716 var timerObj = window.setTimeout(function() {
717 //document.getElementById("processingStatusId").innerHTML ="<img src='images/page-loading.gif'>";
720 var target = $(event.target);
721 //target.text("Validating XML");
722 target.css({ "background-image": "url('images/page-loading.gif')" });
723 target.css({ "background-repeat": "no-repeat" });
724 target.css({ "background-size": "25px 25px" });
729 var loopDetectionEnabled = true;
730 console.log("loopDetectionEnabled:" +loopDetectionEnabled);
731 if(loopDetectionEnabled){
732 var msecs1= Date.now();
733 var isLoopDetected = detectLoop();
734 var msecs2= Date.now();
735 console.log("Time taken for loop detection:" + (msecs2 - msecs1));
737 //RED.notify("<strong>Error</strong>: Loop Detected","error");
738 //target.css({ "background-image": "none" });
742 var nodeSetWithUpdatedDgNumbers = updateDgNumbers();
743 validateEachNodeXml();
744 //var nodeToXmlStr = getNodeToXml();
745 var unformatted_xml_str = getNodeToXml();
746 //console.log("Size of unformatted_xml_str" + unformatted_xml_str.length);
747 //console.log("output:" + nodeToXmlStr);
748 var formatted_xml = vkbeautify.xml(unformatted_xml_str);
750 var minified_xml = vkbeautify.xmlmin(unformatted_xml_str,true);
751 var lengthOfMinifiedXml = minified_xml.length;
752 if(lengthOfMinifiedXml >0){
753 var val = lengthOfMinifiedXml/(1024*1024)
754 var minSizeStr = val.toFixed(4) + " MB";
755 console.log("minified XML size:" + minSizeStr);
758 var lengthOfXml = formatted_xml.length;
761 var val = lengthOfXml/(1024*1024)
762 sizeStr = val.toFixed(4) + " MB";
763 console.log("length:" + val);
765 var xmlLines = formatted_xml.split("\n");
766 console.log("Number of lines " + xmlLines.length);
767 var numberOfLines = xmlLines.length;
768 //var display_formatted_xml = formatted_xml.replace("<","<");
769 var currentNodeSet = getCurrentFlowNodeSet();
770 //get max x and y coordinates
778 var formattedMethodName = "";
779 var origModuleName = "";
780 var origMethodName = "";
781 for(var i=0;currentNodeSet != null && i<currentNodeSet.length;i++){
782 if(currentNodeSet[i].type == "service-logic"){
783 //moduleName = currentNodeSet[i].name;
784 moduleName = currentNodeSet[i].module;
785 dgVersion = currentNodeSet[i].version;
786 origModuleName = getAttributeValue(currentNodeSet[i].xml,"module");
788 if(currentNodeSet[i].type == "method"){
789 //methodName = currentNodeSet[i].name;
790 origMethodName = getAttributeValue(currentNodeSet[i].xml,"rpc");;
791 methodName = origMethodName;
792 if(methodName == ""){
793 methodName = "rpc_not_set";
796 x = currentNodeSet[i].x;
797 y = currentNodeSet[i].y;
805 //add 5 more pixels to that
806 maxX= Math.ceil(maxX) + 5;
807 maxY= Math.ceil(maxY) + 5;
808 //console.log("maxX:" + maxX);
809 //console.log("maxY:" + maxY);
810 var unformatted_json_str=JSON.stringify(currentNodeSet);
811 var formatted_json = vkbeautify.json(unformatted_json_str);
812 //var displayHtmlStr="<div><textarea readonly='1' style='width:1100px;height:700px;border:none'>" + formatted_xml + "</textarea></div>";
813 var displayHtmlStr="<div style='font-size:20px;'><xmp>" + formatted_xml + "</xmp></div>";
814 var xmlInfoStr = "<div id='xml-info-div'><p>" + "XML size:" + sizeStr + " <br>Number of Lines:" + numberOfLines + "</p></div>";
816 $( "#xmldialog" ).dialog({
817 title: "XML Generated",
822 dialogClass : "no-close",
823 closeOnEscape : false,
825 resize: function( event, ui ) {
827 $( this ).dialog( "option", "title",
828 ui.size.height + " x " + ui.size.width );
845 var size= $("#xmldialog").find('.textview').css("font-size");
846 console.log("size:" + size);
847 size=size.replace("px","");
848 var fsize=Number(size) +1;
855 $("#xmldialog").find('.textview').css("font-size",fsize);
858 var size= $("#xmldialog").find('.textview').css("font-size");
859 console.log("size:" + size);
860 size=size.replace(/px/,"");
861 var fsize=Number(size) -1;
865 $("#xmldialog").find('.textview').css("font-size",fsize);
868 "Validate XML" : function (event) {
869 if(!event) event = window.event;
870 var target = $(event.target);
871 target.text("Validating XML");
872 target.css({ "background-image": "url('images/page-loading.gif')" });
873 target.css({ "background-repeat": "no-repeat" });
874 target.css({ "background-size": "25px 25px" });
876 var resp= validateFinalXML(unformatted_xml_str);
877 console.log("errorList:" + errList);
881 target.text("Validate XML");
882 target.css({ "background-image": "none" });
884 "Email Flow" : function (event) {
885 if(!event) event = window.event;
886 var target = $(event.target);
887 target.text("Processing");
888 target.css({ "background-image": "url('images/page-loading.gif')" });
889 target.css({ "background-repeat": "no-repeat" });
890 target.css({ "background-size": "25px 25px" });
891 d3.xhr("style.css").get(function(err,resp){
892 console.log("resp:" + resp);
894 var styleSheetText = resp.responseText;
895 /*var htmlCode = "<style>" + styleSheetText + "</style></head>" +
896 '<body><div id="chart" class="ui-droppable">' +
898 //var svgTagInfo = '<div style="overflow:auto;border:1px solid #D76D2D;height:600px;"><svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1024 768" preserveAspectRatio="xMidYMid meet">';
899 //var svgTagInfo = '<div style="overflow-x:auto;overflow-y:auto;border:1px solid #D76D2D;width:1200px;height:750px;"> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="3500px" height="3200px" viewBox="0 0 5500 5000" >';
900 var svgTagInfo = '<div style="overflow-x:auto;overflow-y:auto;border:1px solid #D76D2D;width:1200px;height:750px;"> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="3500px" height="3200px" viewBox="0 0 8000 7500" >';
901 var svgHtmlCode = $("svg").html();
902 //svgHtmlCode = svgHtmlCode.replace('<rect width="5000" height="5000"','<rect width="' + maxX + '" height="' + maxY +'"');
903 var find = 'href="icons/arrow-in.png"';
904 var re = new RegExp(find, 'g');
905 svgHtmlCode = svgHtmlCode.replace(re, 'href=""');
906 find = 'href="icons/inject.png"';
907 re = new RegExp(find, 'g');
908 svgHtmlCode = svgHtmlCode.replace(re, 'href=""');
909 htmlCode = "\n<style>\n" + styleSheetText + "</style></head>\n<body>" + svgTagInfo + svgHtmlCode + "\n</svg></div>";
910 //console.log($("svg").html());
911 //console.log(htmlCode);
912 //html,xml,json form id
914 //using form to submit
915 var form = $('<form id="hxjFormId" method="POST" action="/sendEmail"></form>');
916 form.append('<input id="flowHtmlId" type="hidden" name="flowHtml" value=""/>');
917 form.append('<input id="flowXmlId" type="hidden" name="flowXml" value=""/>');
918 form.append('<input id="flowJsonId" type="hidden" name="flowJson" value=""/>');
919 $("#screenInfoId").append(form);
920 //console.log($("#screenInfoId").html());
921 document.getElementById("flowHtmlId").value=htmlCode;
922 document.getElementById("flowXmlId").value=formatted_xml;
923 document.getElementById("flowJsonId").value=formatted_json;
924 //console.log($("#screenInfoId").html());
925 $("#hxjFormId").submit();
926 console.log("Submitted.");
929 "flowHtml" : htmlCode,
930 "flowXml" : formatted_xml,
931 "flowJson" : formatted_json
934 $.post( "/sendEmail",reqData )
935 .done(function( data ) {
936 //console.log( "Data Loaded: " + data );
937 if(data != null && data.envelope != undefined && data.envelope != null){
938 var toAddress = data.envelope.to;
939 RED.notify("Email sent successfully to " + toAddress);
941 RED.notify("Email sent successfully.");
944 .fail(function(err) {
945 console.log( "error" + err );
946 RED.notify("Email send Failed.");
949 console.log( "finished" );
950 target.text("Email Flow");
951 target.css({ "background-image": "none" });
955 d3.xhr("/sendEmail").post(reqData,function(err,resp){
956 console.log("Error:" + JSON.stringify(err));
957 console.log("resp:" + JSON.stringify(resp));
964 Deploy : function () {
965 $("#btn-deploy").click();
968 "Upload XML" : function (event) {
969 if(!event) event = window.event;
970 //Save the flows.json
971 //RED.view.dirty(true);
972 //$('#btn-deploy').click();
973 console.log("Deployed..");
974 var target = $(event.target);
975 target.text("Processing");
976 target.css({ "background-image": "url('images/page-loading.gif')" });
977 target.css({ "background-repeat": "no-repeat" });
978 target.css({ "background-size": "25px 25px" });
979 var date = new Date();
981 var fileName = date.getTime() + ".xml";
983 "flowXml" : unformatted_xml_str,
984 "module" : origModuleName,
985 "rpc" : origMethodName
987 $.post("/uploadxml", reqData )
988 .done(function( data ) {
989 console.log("calling uploadxml. sending to server");
990 //var successHtmlStr = "<object width='600' height='450' type='text/html' data='" + data.url + "' />";
992 if( data != undefined && data != null && (data.stdout.indexOf('Saving SvcLogicGraph') != -1 || data.stderr.indexOf('Saving SvcLogicGraph') != -1)){
993 //RED.notify("<strong>Uploaded Successfully</strong>");
995 var _moduleName = data.module;
1000 msg_lines += data.stderr;
1001 msg_lines += data.stdout;
1003 msgHtmlStr="<div><p><b>Uploaded the XML.<br>Additional Details<br><textarea style='width:90%;height:100%' readonly='1' rows='10' cols='90' >" + msg_lines + "</textarea></div>";
1004 $("#upload-xml-status-dialog").dialog({
1006 title: "Upload XML ",
1014 class:"alertDialogButton",
1016 $(this).dialog("close");
1017 displayCurrentDGs(_moduleName,_rpc,function(htmlStr,dbHost){
1018 $("#svclogicPageDiv").dialog({
1020 title:"Service Logic Administration Module=" + _moduleName + " and RPC=" + _rpc,
1031 class:"alertDialogButton",
1033 $(this).dialog("close");
1037 }).html(msgHtmlStr);
1039 console.log("Could not upload.");
1040 var emsg =JSON.parse( data.responseText);
1044 if( emsg.stderr != "COMPILE_ERROR"){
1045 msg = JSON.stringify(emsg.stderr);
1047 msg = msg.replace('\\t',"");
1048 msg1 = msg.split('\\n');
1049 for(var k=0;k<=msg1.length && k<=10;k++){
1052 //msg_lines += "<span style='color:blue'>" + msg1[k] + "</span><br>";
1053 //msg_lines += msg1[k] +"\n";
1055 if(msg1[k].indexOf("Caused by:") != -1){
1056 //msg_lines += "<span style='color:red'> " + msg1[k] + "</span><br>";
1057 msg_lines += msg1[k] ;
1062 if(msg1[k] != null && msg1[k].indexOf("Caused by:") != -1){
1063 msg_lines += msg1[k] ;
1064 if((k+1)<=msg1.length){
1065 msg_lines += "\n" + msg1[k+1] ;
1067 if((k+2)<=msg1.length){
1068 msg_lines += "\n" + msg1[k+2] ;
1074 htmlStr="<div><p><b>Could not upload the XML. Status:" + data.status + " Message:" + data.statusText + "</b><br></p><br>Additional Details<br><textarea style='width:90%;height:100%' readonly='1' rows='10' cols='90' >" + msg_lines + "</textarea></div>";
1075 $("#svclogicPageDiv").dialog({
1077 title: "Upload XML ",
1085 .fail(function(err) {
1086 //console.log( "error" + JSON.stringify(err) );
1087 //console.log( JSON.stringify(err.responseText));
1088 var emsg =JSON.parse( err.responseText);
1089 //console.log( emsg.stderr);
1093 if( emsg != null && emsg.stderr != 'COMPILE_ERROR'){
1094 msg = JSON.stringify(emsg.stderr);
1096 //msg = msg.replace("Caused by:","<span style='color:red'>Caused by:</span>");
1097 msg = msg.replace(/\\t/g,"");
1098 msg1 = msg.split('\\n');
1099 for(var k=0;k<=msg1.length && k<=msg1.length;k++){
1102 //msg_lines += "<span style='color:blue'>" + msg1[k] + "</span><br>";
1103 //msg_lines += msg1[k] + "\n" ;
1105 if(msg1[k].indexOf("Caused by:") != -1){
1106 //msg_lines += "<span style='color:red'> " + msg1[k] + "</span><br>";
1107 msg_lines += msg1[k] ;
1112 if(msg1[k] != null && msg1[k].indexOf("Caused by:") != -1){
1113 msg_lines += msg1[k] ;
1114 if((k+1)<=msg1.length){
1115 msg_lines += "\n" + msg1[k+1] ;
1117 if((k+2)<=msg1.length){
1118 msg_lines += "\n" + msg1[k+2] ;
1124 msg = JSON.stringify(emsg.stdout);
1126 msg = msg.replace('\\t',"");
1127 msg1 = msg.split('\\n');
1130 var htmlStr="<div><p><b>Could not upload the XML. Status:" + err.status + " Message:" + err.statusText + "</b><br></p><br><b>Additional Details</b><br><textarea style='width:90%;height:100%' readonly='1' rows='15' cols='90'>" + msg_lines + "</textarea></div>";
1131 $("#svclogicPageDiv").dialog({
1133 title: "Upload XML ",
1139 //RED.notify("<strong>ERROR:</strong>:" + err,"error");
1141 .always(function() {
1142 console.log( "finished" );
1143 target.text("Upload XML");
1144 target.css({ "background-image": "none" });
1147 d3.xhr("/uploadxml?fileName=" + fileName).post(function(err,resp) {
1148 if ( resp != null && resp.status == 200) {
1149 RED.notify("<strong>Uploaded Successfully</strong>");
1151 RED.notify("<strong>ERROR:</strong>:" + err,"error");
1153 //console.dir(resp);
1158 "View DG List": function () {
1160 displayCurrentDGs(origModuleName,origMethodName,function(htmlStr,dbHost){
1161 //console.log("htmlStr:" + htmlStr);
1162 $("#svclogicPageDiv").dialog({
1164 title: "Service Logic Administration for Module=" + origModuleName + " and RPC=" + origMethodName,
1172 "Download XML": function () {
1173 $(document).ready(function(){
1175 if(moduleName != undefined && moduleName != null && moduleName != ""){
1176 moduleName=moduleName.replace(/\s/g, "_");
1178 errList.push("Module name is required in the service-logic node.");
1181 if(dgVersion == undefined || dgVersion == null || dgVersion == ""){
1182 errList.push("Module version is required in the service-logic node.");
1185 if(methodName != undefined && methodName != null && methodName != ""){
1186 methodName=methodName.replace(/\s/g, "_");
1187 //formattedMethodName=methodName + "_" + dgVersion;
1188 formattedMethodName=methodName ;
1190 errList.push("rpc name is required in the method node.");
1192 console.log("Download Xml moduleName:" + moduleName);
1193 console.log("Download Xml methodName:" + formattedMethodName);
1195 if(errList != null && errList.length > 0 ){
1200 $("#dwnldXmlFormId").empty().remove();
1201 //using form to submit
1202 var form = $('<form id="dwnldXmlFormId" method="POST" action="/downloadXml"></form>');
1203 form.append('<input id="flowXmlId" type="hidden" name="flowXml"/>');
1204 form.append('<input type="hidden" name="moduleName" value="' + moduleName + '"/>');
1205 form.append('<input type="hidden" name="methodName" value="' + formattedMethodName + '"/>');
1206 form.appendTo('body');
1207 //$("#flowXmlId").val(formatted_xml);
1208 $("#flowXmlId").val(unformatted_xml_str);
1209 $("#dwnldXmlFormId").submit();
1210 //console.log("Form submitted.");
1213 "Download JSON": function () {
1214 $(document).ready(function(){
1216 if(moduleName != undefined && moduleName != null && moduleName != ""){
1217 moduleName=moduleName.replace(/\s/g, "_");
1219 errList.push("Module name is required in the service-logic node.");
1222 if(dgVersion == undefined || dgVersion == null || dgVersion == ""){
1223 errList.push("Module version is required in the service-logic node.");
1226 if(methodName != undefined && methodName != null && methodName != ""){
1227 methodName=methodName.replace(/\s/g, "_");
1228 //formattedMethodName=methodName + "_" + dgVersion;
1229 formattedMethodName=methodName ;
1231 errList.push("rpc name is required in the method node.");
1233 console.log("Download Xml moduleName:" + moduleName);
1234 console.log("Download Xml methodName:" + formattedMethodName);
1236 if(errList != null && errList.length > 0 ){
1240 //console.log("formatted_json:" + formatted_json);
1241 $("#dwnldJsonFormId").empty().remove();
1242 //using form to submit
1243 var form = $('<form id="dwnldJsonFormId" method="POST" action="/downloadJson"></form>');
1244 form.append('<input id="flowJsonId" type="hidden" name="flowJson" value=""/>');
1245 form.append('<input type="hidden" name="moduleName" value="' + moduleName + '"/>');
1246 form.append('<input type="hidden" name="methodName" value="' + formattedMethodName + '"/>');
1247 form.appendTo('body');
1248 //$("#flowJsonId").val(formatted_json);
1249 $("#flowJsonId").val(unformatted_json_str);
1250 $("#dwnldJsonFormId").submit();
1251 //console.log("Form submitted.");
1254 Close: function () {
1256 console.log("clearing the variables.");
1261 unformatted_xml_str="";
1262 unformatted_json_str="";
1264 $('.ui-dialog:has(#xmldialog)').empty().remove();
1267 //console.log($("#xmldialog").attr('id'));
1268 //$('.ui-dialog:has(# + $("#xmldialog").attr('id') + ')').empty().remove();
1269 //$("#xmldialog").hide();
1270 //$("#xmldialog").dialog("destroy").remove();
1275 $("#xmldialog").dialog("widget").find(".ui-dialog-buttonpane").append(xmlInfoStr);
1276 console.log("opened.");
1279 }).html(displayHtmlStr).dialog("open");
1281 //}).html(displayHtmlStr).dialog("widget").find(".ui-dialog-buttonpane").append(xmlInfoStr);
1283 //display size and number of lines in XML
1284 //$("#xmldialog").dialog("widget").find(".ui-dialog-buttonpane").append(xmlInfoStr);
1286 //$("#processingStatusId").html("");
1287 //This logic is commented as formatting and displaying orion is taking time
1290 var msecs1= Date.now();
1292 require(["orion/editor/edit"], function(edit) {
1293 that.editor = edit({
1294 parent:document.getElementById('xmldialog'),
1297 //showLinesRuler: false,
1298 contents: formatted_xml
1300 RED.library.create({
1301 url:"functions", // where to get the data from
1302 type:"function", // the type of object the library is for
1303 editor:that.editor, // the field name the main text body goes to
1304 fields:['name','outputs']
1307 var msecs2= Date.now();
1308 //console.log("Time taken for displaying XML:" + (msecs2 - msecs1));
1311 //var success = customValidation(currentNodeSet);
1312 var success = customValidation(nodeSetWithUpdatedDgNumbers);
1314 showFlowDesignErrorBox();
1316 $('#processingStatusId').html("");