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 displayHtmlStr= "";
816 //var xmlInfoStr = "<div id='xml-info-div'><p>" + "XML size:" + sizeStr + " <br>Number of Lines:" + numberOfLines + "</p></div>";
818 $( "#xmldialog" ).dialog({
819 title: "XML Generated",
824 dialogClass : "no-close",
825 closeOnEscape : false,
827 resize: function( event, ui ) {
829 $( this ).dialog( "option", "title",
830 ui.size.height + " x " + ui.size.width );
847 var size= $("#xmldialog").find('.textview').css("font-size");
848 console.log("size:" + size);
849 size=size.replace("px","");
850 var fsize=Number(size) +1;
857 $("#xmldialog").find('.textview').css("font-size",fsize);
860 var size= $("#xmldialog").find('.textview').css("font-size");
861 console.log("size:" + size);
862 size=size.replace(/px/,"");
863 var fsize=Number(size) -1;
867 $("#xmldialog").find('.textview').css("font-size",fsize);
870 "Validate XML" : function (event) {
871 $("#ace-editor-div").show();
872 if(!event) event = window.event;
873 var target = $(event.target);
874 target.text("Validating XML");
875 target.css({ "background-image": "url('images/page-loading.gif')" });
876 target.css({ "background-repeat": "no-repeat" });
877 target.css({ "background-size": "25px 25px" });
879 var resp= validateFinalXML(unformatted_xml_str);
880 console.log("errorList:" + errList);
884 target.text("Validate XML");
885 target.css({ "background-image": "none" });
887 "Email Flow" : function (event) {
888 if(!event) event = window.event;
889 var target = $(event.target);
890 target.text("Processing");
891 target.css({ "background-image": "url('images/page-loading.gif')" });
892 target.css({ "background-repeat": "no-repeat" });
893 target.css({ "background-size": "25px 25px" });
894 d3.xhr("style.css").get(function(err,resp){
895 console.log("resp:" + resp);
897 var styleSheetText = resp.responseText;
898 /*var htmlCode = "<style>" + styleSheetText + "</style></head>" +
899 '<body><div id="chart" class="ui-droppable">' +
901 //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">';
902 //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" >';
903 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" >';
904 var svgHtmlCode = $("svg").html();
905 //svgHtmlCode = svgHtmlCode.replace('<rect width="5000" height="5000"','<rect width="' + maxX + '" height="' + maxY +'"');
906 var find = 'href="icons/arrow-in.png"';
907 var re = new RegExp(find, 'g');
908 svgHtmlCode = svgHtmlCode.replace(re, 'href=""');
909 find = 'href="icons/inject.png"';
910 re = new RegExp(find, 'g');
911 svgHtmlCode = svgHtmlCode.replace(re, 'href=""');
912 htmlCode = "\n<style>\n" + styleSheetText + "</style></head>\n<body>" + svgTagInfo + svgHtmlCode + "\n</svg></div>";
913 //console.log($("svg").html());
914 //console.log(htmlCode);
915 //html,xml,json form id
917 //using form to submit
918 var form = $('<form id="hxjFormId" method="POST" action="/sendEmail"></form>');
919 form.append('<input id="flowHtmlId" type="hidden" name="flowHtml" value=""/>');
920 form.append('<input id="flowXmlId" type="hidden" name="flowXml" value=""/>');
921 form.append('<input id="flowJsonId" type="hidden" name="flowJson" value=""/>');
922 $("#screenInfoId").append(form);
923 //console.log($("#screenInfoId").html());
924 document.getElementById("flowHtmlId").value=htmlCode;
925 document.getElementById("flowXmlId").value=formatted_xml;
926 document.getElementById("flowJsonId").value=formatted_json;
927 //console.log($("#screenInfoId").html());
928 $("#hxjFormId").submit();
929 console.log("Submitted.");
932 "flowHtml" : htmlCode,
933 "flowXml" : formatted_xml,
934 "flowJson" : formatted_json,
935 "emailAddress" : RED.settings.emailAddress
938 $.post( "/sendEmail",reqData )
939 .done(function( data ) {
940 //console.log( "Data Loaded: " + data );
941 if(data != null && data.envelope != undefined && data.envelope != null){
942 var toAddress = data.envelope.to;
943 RED.notify("Email sent successfully to " + toAddress);
945 RED.notify("Email sent successfully.");
948 .fail(function(err) {
949 console.log( "error" + err );
950 RED.notify("Email send Failed.");
953 console.log( "finished" );
954 target.text("Email Flow");
955 target.css({ "background-image": "none" });
959 d3.xhr("/sendEmail").post(reqData,function(err,resp){
960 console.log("Error:" + JSON.stringify(err));
961 console.log("resp:" + JSON.stringify(resp));
968 Deploy : function () {
969 $("#btn-deploy").click();
972 "Upload XML" : function (event) {
973 if(!event) event = window.event;
974 //Save the flows.json
975 //RED.view.dirty(true);
976 //$('#btn-deploy').click();
977 console.log("Deployed..");
978 var target = $(event.target);
979 target.text("Processing");
980 target.css({ "background-image": "url('images/page-loading.gif')" });
981 target.css({ "background-repeat": "no-repeat" });
982 target.css({ "background-size": "25px 25px" });
983 var date = new Date();
985 var fileName = date.getTime() + ".xml";
987 "flowXml" : unformatted_xml_str,
988 "module" : origModuleName,
989 "rpc" : origMethodName
991 $.post("/uploadxml", reqData )
992 .done(function( data ) {
993 console.log("calling uploadxml. sending to server");
994 //var successHtmlStr = "<object width='600' height='450' type='text/html' data='" + data.url + "' />";
996 if( data != undefined && data != null && ((data.stdout != undefined && data.stdout != null && data.stdout.indexOf('Saving SvcLogicGraph') != -1) || (data.stderr != undefined && data.stderr != null && data.stderr.indexOf('Saving SvcLogicGraph') != -1))){
997 //RED.notify("<strong>Uploaded Successfully</strong>");
999 var _moduleName = data.module;
1000 var _rpc = data.rpc;
1004 msg_lines += data.stderr;
1005 msg_lines += data.stdout;
1007 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>";
1008 $("#upload-xml-status-dialog").dialog({
1010 title: "Upload XML ",
1018 class:"alertDialogButton",
1020 $(this).dialog("close");
1021 displayCurrentDGs(_moduleName,_rpc,function(htmlStr,dbHost){
1022 $("#svclogicPageDiv").dialog({
1024 title:"Service Logic Administration Module=" + _moduleName + " and RPC=" + _rpc,
1035 class:"alertDialogButton",
1037 $(this).dialog("close");
1041 }).html(msgHtmlStr);
1043 console.log("Could not upload.");
1044 var emsg =JSON.parse( data.responseText);
1048 if( emsg.stderr != "COMPILE_ERROR"){
1049 msg = JSON.stringify(emsg.stderr);
1051 msg = msg.replace('\\t',"");
1052 msg1 = msg.split('\\n');
1053 for(var k=0;k<=msg1.length && k<=10;k++){
1056 //msg_lines += "<span style='color:blue'>" + msg1[k] + "</span><br>";
1057 //msg_lines += msg1[k] +"\n";
1059 if(msg1[k].indexOf("Caused by:") != -1){
1060 //msg_lines += "<span style='color:red'> " + msg1[k] + "</span><br>";
1061 msg_lines += msg1[k] ;
1066 if(msg1[k] != null && msg1[k].indexOf("Caused by:") != -1){
1067 msg_lines += msg1[k] ;
1068 if((k+1)<=msg1.length){
1069 msg_lines += "\n" + msg1[k+1] ;
1071 if((k+2)<=msg1.length){
1072 msg_lines += "\n" + msg1[k+2] ;
1078 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>";
1079 $("#svclogicPageDiv").dialog({
1081 title: "Upload XML ",
1089 .fail(function(err) {
1090 //console.log( "error" + JSON.stringify(err) );
1091 //console.log( JSON.stringify(err.responseText));
1092 var emsg =JSON.parse( err.responseText);
1093 //console.log( emsg.stderr);
1097 if( emsg != null && emsg.stderr != 'COMPILE_ERROR'){
1098 msg = JSON.stringify(emsg.stderr);
1100 //msg = msg.replace("Caused by:","<span style='color:red'>Caused by:</span>");
1101 msg = msg.replace(/\\t/g,"");
1102 msg1 = msg.split('\\n');
1103 for(var k=0;k<=msg1.length && k<=msg1.length;k++){
1106 //msg_lines += "<span style='color:blue'>" + msg1[k] + "</span><br>";
1107 //msg_lines += msg1[k] + "\n" ;
1109 if(msg1[k].indexOf("Caused by:") != -1){
1110 //msg_lines += "<span style='color:red'> " + msg1[k] + "</span><br>";
1111 msg_lines += msg1[k] ;
1116 if(msg1[k] != null && msg1[k].indexOf("Caused by:") != -1){
1117 msg_lines += msg1[k] ;
1118 if((k+1)<=msg1.length){
1119 msg_lines += "\n" + msg1[k+1] ;
1121 if((k+2)<=msg1.length){
1122 msg_lines += "\n" + msg1[k+2] ;
1128 msg = JSON.stringify(emsg.stdout);
1130 msg = msg.replace('\\t',"");
1131 msg1 = msg.split('\\n');
1134 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>";
1135 $("#svclogicPageDiv").dialog({
1137 title: "Upload XML ",
1143 //RED.notify("<strong>ERROR:</strong>:" + err,"error");
1145 .always(function() {
1146 console.log( "finished" );
1147 target.text("Upload XML");
1148 target.css({ "background-image": "none" });
1151 d3.xhr("/uploadxml?fileName=" + fileName).post(function(err,resp) {
1152 if ( resp != null && resp.status == 200) {
1153 RED.notify("<strong>Uploaded Successfully</strong>");
1155 RED.notify("<strong>ERROR:</strong>:" + err,"error");
1157 //console.dir(resp);
1162 "View DG List": function () {
1164 displayCurrentDGs(origModuleName,origMethodName,function(htmlStr,dbHost){
1165 //console.log("htmlStr:" + htmlStr);
1166 $("#svclogicPageDiv").dialog({
1168 title: "Service Logic Administration for Module=" + origModuleName + " and RPC=" + origMethodName,
1176 "Download XML": function () {
1177 $(document).ready(function(){
1179 if(moduleName != undefined && moduleName != null && moduleName != ""){
1180 moduleName=moduleName.replace(/\s/g, "_");
1182 errList.push("Module name is required in the service-logic node.");
1185 if(dgVersion == undefined || dgVersion == null || dgVersion == ""){
1186 errList.push("Module version is required in the service-logic node.");
1189 if(methodName != undefined && methodName != null && methodName != ""){
1190 methodName=methodName.replace(/\s/g, "_");
1191 //formattedMethodName=methodName + "_" + dgVersion;
1192 formattedMethodName=methodName ;
1194 errList.push("rpc name is required in the method node.");
1196 console.log("Download Xml moduleName:" + moduleName);
1197 console.log("Download Xml methodName:" + formattedMethodName);
1199 if(errList != null && errList.length > 0 ){
1204 $("#dwnldXmlFormId").empty().remove();
1205 //using form to submit
1206 var form = $('<form id="dwnldXmlFormId" method="POST" action="/downloadXml"></form>');
1207 form.append('<input id="flowXmlId" type="hidden" name="flowXml"/>');
1208 form.append('<input type="hidden" name="moduleName" value="' + moduleName + '"/>');
1209 form.append('<input type="hidden" name="methodName" value="' + formattedMethodName + '"/>');
1210 form.appendTo('body');
1211 console.log("format_xml:" + format_xml);
1212 if(format_xml == "Y" || format_xml == undefined){
1213 $("#flowXmlId").val(formatted_xml);
1215 $("#flowXmlId").val(unformatted_xml_str);
1217 $("#dwnldXmlFormId").submit();
1218 //console.log("Form submitted.");
1221 "Download JSON": function () {
1222 $(document).ready(function(){
1224 if(moduleName != undefined && moduleName != null && moduleName != ""){
1225 moduleName=moduleName.replace(/\s/g, "_");
1227 errList.push("Module name is required in the service-logic node.");
1230 if(dgVersion == undefined || dgVersion == null || dgVersion == ""){
1231 errList.push("Module version is required in the service-logic node.");
1234 if(methodName != undefined && methodName != null && methodName != ""){
1235 methodName=methodName.replace(/\s/g, "_");
1236 //formattedMethodName=methodName + "_" + dgVersion;
1237 formattedMethodName=methodName ;
1239 errList.push("rpc name is required in the method node.");
1241 console.log("Download Xml moduleName:" + moduleName);
1242 console.log("Download Xml methodName:" + formattedMethodName);
1244 if(errList != null && errList.length > 0 ){
1248 //console.log("formatted_json:" + formatted_json);
1249 $("#dwnldJsonFormId").empty().remove();
1250 //using form to submit
1251 var form = $('<form id="dwnldJsonFormId" method="POST" action="/downloadJson"></form>');
1252 form.append('<input id="flowJsonId" type="hidden" name="flowJson" value=""/>');
1253 form.append('<input type="hidden" name="moduleName" value="' + moduleName + '"/>');
1254 form.append('<input type="hidden" name="methodName" value="' + formattedMethodName + '"/>');
1255 form.appendTo('body');
1256 console.log("format_json:" + format_json);
1257 if(format_json == "Y" || format_json == undefined){
1258 $("#flowJsonId").val(formatted_json);
1260 $("#flowJsonId").val(unformatted_json_str);
1262 $("#dwnldJsonFormId").submit();
1263 //console.log("Form submitted.");
1266 Close: function () {
1268 console.log("clearing the variables.");
1273 unformatted_xml_str="";
1274 unformatted_json_str="";
1276 ace.edit('xmldialog').destroy();
1277 $('.ui-dialog:has(#xmldialog)').empty().remove();
1280 //console.log($("#xmldialog").attr('id'));
1281 //$('.ui-dialog:has(# + $("#xmldialog").attr('id') + ')').empty().remove();
1282 //$("#xmldialog").hide();
1283 //$("#xmldialog").dialog("destroy").remove();
1289 var aceEditor = ace.edit("xmldialog");
1290 aceEditor.setTheme("ace/theme/eclipse");
1291 aceEditor.session.setMode("ace/mode/xml");
1292 aceEditor.setValue(formatted_xml);
1293 document.getElementById('xmldialog').style.fontSize='18px';
1294 aceEditor.setReadOnly(true);
1295 var numberOfLines = aceEditor.session.getLength();
1296 var xmlInfoStr = "<div id='xml-info-div'><p>" + "XML size:" + sizeStr + " <br>Number of Lines:" + numberOfLines + "</p></div>";
1299 $("#xmldialog").dialog("widget").find(".ui-dialog-buttonpane").append(xmlInfoStr);
1300 console.log("opened.");
1303 }).html(displayHtmlStr).dialog("open");
1305 //}).html(displayHtmlStr).dialog("widget").find(".ui-dialog-buttonpane").append(xmlInfoStr);
1307 //display size and number of lines in XML
1308 //$("#xmldialog").dialog("widget").find(".ui-dialog-buttonpane").append(xmlInfoStr);
1310 //$("#processingStatusId").html("");
1311 //This logic is commented as formatting and displaying orion is taking time
1314 var msecs1= Date.now();
1316 require(["orion/editor/edit"], function(edit) {
1317 that.editor = edit({
1318 parent:document.getElementById('xmldialog'),
1321 //showLinesRuler: false,
1322 contents: formatted_xml
1324 RED.library.create({
1325 url:"functions", // where to get the data from
1326 type:"function", // the type of object the library is for
1327 editor:that.editor, // the field name the main text body goes to
1328 fields:['name','outputs']
1331 var msecs2= Date.now();
1332 //console.log("Time taken for displaying XML:" + (msecs2 - msecs1));
1335 //var success = customValidation(currentNodeSet);
1336 var success = customValidation(nodeSetWithUpdatedDgNumbers);
1338 showFlowDesignErrorBox();
1340 $('#processingStatusId').html("");