Merge "Add Graph/Node to org.ops4j.pax.logging.cfg"
[ccsdk/distribution.git] / dgbuilder / nodes / dge / dgemain / dgstart.html
1 <!--
2   Copyright 2013 IBM Corp.
3
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
7
8   http://www.apache.org/licenses/LICENSE-2.0
9
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.
15 -->
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 -->
23
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>
26 </script>
27 <style>
28 .no-close .ui-dialog-titlebar-close {display: none }
29 .alertDialogButton {
30    border-top: 1px solid #96d1f8;
31    background: #65a9d7;
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);
37    padding: 5px 10px;
38    -webkit-border-radius: 8px;
39    -moz-border-radius: 8px;
40    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;
45    color: white;
46    font-size: 14px;
47    font-family: Georgia, serif;
48    text-decoration: none;
49    vertical-align: middle;
50    }
51 .alertDialogButton:hover {
52    border-top-color: #28597a;
53    background: #28597a;
54    color: #ccc;
55    }
56
57 .alertDialogButton:active {
58    border-top-color: #1b435e;
59    background: #1b435e;
60    }
61 .disabled-button {
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);
69    padding: 5px 10px;
70    -webkit-border-radius: 8px;
71    -moz-border-radius: 8px;
72    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;
77    color: lightgrey;
78    font-size: 14px;
79    font-family: Georgia, serif;
80    text-decoration: none;
81    vertical-align: middle;
82    }
83 </style>
84 <script type="text/javascript">
85
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};
90         }
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",
95   autoOpen :false,
96   modal:true,
97   draggable : true,
98   /*dialogClass: "alert",*/
99   title: "Confirm Activate",
100   width: 600,
101   buttons: [
102     {
103       text: "Activate",
104       class:"alertDialogButton",
105       click: function() {
106         $.get("/activateDG" , paramsObj)
107         .done(function( data ) {
108                   //RED.notify("<strong>Activated Successfully</strong>");
109                 var htmlStr = "";
110                 var title ="";
111                 if(displayOnlyCurrent){
112                          htmlStr=getHtmlStr(data,true);
113                          title="Service Logic Administration  Module=" + module + " and RPC=" + rpc;
114                 }else{
115                          htmlStr=getHtmlStr(data);
116                          title= "Service Logic Administration - " + data.dbHost; 
117                 }
118                 $("#svclogicPageDiv").dialog({
119                                 modal:true,     
120                                 title: title,
121                                 width: 1200,
122                                 height: 750,
123                                 minWidth : 600, 
124                                 minHeight :450, 
125                                 }).html(htmlStr);
126           })
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>";
132                 }
133                 $("#svclogicPageDiv").dialog({
134                                 modal:true,     
135                                 title: "Service Logic Administration - " + err.dbHost, 
136                                 width: 1200,
137                                 height: 750,
138                                 minWidth : 600, 
139                                 minHeight :450, 
140                                 }).html(htmlStr);
141           })
142         .always(function() { 
143                 // $('.ui-dialog:has(#alertdialog)').empty().remove();
144                 $("#alertdialog" ).dialog('close');
145                 
146         });
147         }
148     },
149     {
150       text: "Cancel",
151       class:"alertDialogButton",
152       click: function() {
153         //$('.ui-dialog:has(#alertdialog)').empty().remove();
154         $( this ).dialog( "close" );
155       }
156     }
157   ]
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");
162 /*
163 $('#alertdialog').css("background-color", "#ECECEC");
164 $("#alertdialog").dialog("widget").find(".ui-dialog-buttonpane").css("background-color", "#ECECEC");
165
166 // button pane style
167 $("#alertdialog").dialog("widget").find(".ui-dialog-buttonpane").css({"padding":".1em .1em .1em 0","margin":"0 0 0 0"} )
168
169 // button style
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");
172 */
173 //console.dir($("#alertdialog"));
174 }
175
176
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};
181         }
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",
186   autoOpen : false,     
187   modal:true,
188   draggable : true,
189   title: "Confirm De-Activate",
190   width: 600,
191   buttons: [
192     {
193       text: "De-Activate",
194       class:"alertDialogButton",
195       click: function() {
196         $.get("/deActivateDG" , paramsObj)
197         .done(function( data ) {
198                   //RED.notify("<strong>deActivated Successfully</strong>");
199                 var htmlStr = "";
200                 var title ="";
201                 if(displayOnlyCurrent){
202                          htmlStr=getHtmlStr(data,true);
203                          title="Service Logic Administration  Module=" + module + " and RPC=" + rpc;
204                 }else{
205                          htmlStr=getHtmlStr(data);
206                          title= "Service Logic Administration - " + data.dbHost; 
207                 }
208                 $("#svclogicPageDiv").dialog({
209                                 modal:true,     
210                                 title: title,
211                                 width: 1200,
212                                 height: 750,
213                                 minWidth : 600, 
214                                 minHeight :450, 
215                                 }).html(htmlStr);
216           })
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>";
222                 }
223                 $("#svclogicPageDiv").dialog({
224                                 modal:true,     
225                                 title: "Service Logic Administration - " + err.dbHost, 
226                                 width: 1200,
227                                 height: 750,
228                                 minWidth : 600, 
229                                 minHeight :450, 
230                                 }).html(htmlStr);
231           })
232         .always(function() { 
233                  //$('.ui-dialog:has(#alertdialog)').empty().remove();
234                 $( "#alertdialog" ).dialog( "close" );
235                 //$("#alertdialog" ).dialog('destroy').remove();
236         });
237       }
238     },
239     {
240       text: "Cancel",
241       class:"alertDialogButton",
242       click: function() {
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');
248         }else{
249                 $( this ).dialog( "close" );
250         }
251         */
252         $( this ).dialog( "close" );
253       }
254     }
255   ]
256 }).html(alertMsg).dialog("open");
257 }
258
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};
263         }
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",
268   autoOpen: false,
269   modal:true,
270   draggable : true,
271   title: "Confirm Delete",
272   width: 600,
273   buttons: [
274     {
275       text: "Delete",
276       class:"alertDialogButton",
277       click: function() {
278         $.get("/deleteDG" , paramsObj)
279         .done(function( data ) {
280                   RED.notify("<strong>Deleted " + module + " " + rpc + " " + version + " Successfully</strong>");
281                 var htmlStr = "";
282                 var title ="";
283                 if(displayOnlyCurrent){
284                          htmlStr=getHtmlStr(data,true);
285                          title="Service Logic Administration  Module=" + module + " and RPC=" + rpc;
286                 }else{
287                          htmlStr=getHtmlStr(data);
288                          title= "Service Logic Administration - " + data.dbHost; 
289                 }
290                 $("#svclogicPageDiv").dialog({
291                                 modal:true,     
292                                 title: title,
293                                 width: 1200,
294                                 height: 750,
295                                 minWidth : 600, 
296                                 minHeight :450, 
297                                 }).html(htmlStr);
298           })
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>";
304                 }
305                 $("#svclogicPageDiv").dialog({
306                                 modal:true,     
307                                 title: "Service Logic Administration - " + err.dbHost, 
308                                 width: 1200,
309                                 height: 750,
310                                 minWidth : 600, 
311                                 minHeight :450, 
312                                 }).html(htmlStr);
313           })
314         .always(function() { 
315                 $( "#alertdialog" ).dialog( "close" );
316                  //$('.ui-dialog:has(#alertdialog)').empty().remove();
317                 //$("#alertdialog" ).dialog('destroy').remove();
318         });
319       }
320     },
321     {
322       text: "Cancel",
323       class:"alertDialogButton",
324       click: function() {
325         /*
326         if ($("#alertdialog").hasClass('ui-dialog-content')) {
327                 $("#alertdialog" ).dialog('close');
328         }else{
329                 $( this ).dialog( "close" );
330         }
331         */
332         //$( "#alertdialog" ).dialog( "close" );
333         //$('.ui-dialog:has(#alertdialog)').empty().remove();
334         //$( this ).dialog( "close" );
335         $( this ).dialog( "close" );
336       }
337     }
338   ]
339 }).html(alertMsg).dialog("open");
340 }
341 /*
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();
351 }
352 */
353
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;
360         }else{
361                 title="Service Logic Administration";
362         }
363         //var headingStr = "<a style='color: #337ab7;' onclick='javascript:showSLA()'>&lt;&lt;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()'>&lt;&lt;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 + "\")'>&lt;&lt;Back to DG List</a><br><div style='clear:both;'><table style='width:25%' border='0'>" ;
367                 }
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>" +
372                         "</table></div>";
373
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({
380                                 modal:true,     
381                                 title: title,
382                                 width: 1200,
383                                 height: 750,
384                                 minWidth : 600, 
385                                 minHeight :450, 
386                                 }).html(htmlStr);
387           })
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>";
393                 }
394                 $("#svclogicPageDiv").dialog({
395                                 modal:true,     
396                                 title: "Service Logic Administration",
397                                 width: 1200,
398                                 height: 750,
399                                 minWidth : 600, 
400                                 minHeight :450, 
401                                 }).html(htmlStr);
402           })
403         .always(function() { 
404         });
405 }
406
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};
412         }
413         //var headingStr = "<a style='color: #337ab7;cursor:pointer' onclick='javascript:showSLA()'>&lt;&lt;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()'>&lt;&lt;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 + "\")'>&lt;&lt;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;
418                 }
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>" +
423                         "</table></div>";
424
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({
430                                 modal:true,     
431                                 title: "Service Logic Administration",
432                                 width: 1200,
433                                 height: 750,
434                                 minWidth : 600, 
435                                 minHeight :450, 
436                                 }).html(htmlStr);
437           })
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>";
443                 }
444                 $("#svclogicPageDiv").dialog({
445                                 modal:true,     
446                                 title: "Service Logic Administration",
447                                 width: 1200,
448                                 height: 750,
449                                 minWidth : 600, 
450                                 minHeight :450, 
451                                 }).html(htmlStr);
452           })
453         .always(function() { 
454         });
455 }
456
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" +
471                                 "</style>";
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' >";
476                                 htmlStr += "<tr>";
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>";
486                                 htmlStr += "</tr>";
487                                 var rows = data.rows;
488                                 if(rows != null && rows.length == 0){
489                                         htmlStr += "<tr>";
490                                         htmlStr += "<td><b>No rows found</b></td>";
491                                         htmlStr += "</tr></table></div>";
492                                         return htmlStr;
493                                 }
494                                 for(var i=0;i<rows.length;i++){
495                                         var row = rows[i];
496                                         var _module = row.module;
497                                         var rpc = row.rpc;
498                                         var version = row.version;
499                                         var mode = row.mode;
500                                         var active = row.active;
501                                         htmlStr += "<tr>";
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>";
507
508                                         var methodParams =  "'" + _module +  "','" + rpc + "','" + version + "','"  + mode + "'";
509                                         if(displayOnlyCurrent){
510                                                 methodParams+= ",true";
511                                         }
512                                         if(active == 'Y'){
513                                                         htmlStr += "<td><a onclick=\"javascript:deActivateDG(" +  methodParams + ")\">DeActivate</a></td>";
514                                         }else{
515                                                 htmlStr += "<td><a onclick=\"javascript:activateDG(" + methodParams +  ")\">Activate</a></td>";
516                                         }
517                                         htmlStr += "<td><a onclick=\"javascript:displayDG(" + methodParams + ")\">Display</a></td>";
518
519                                         htmlStr += "<td><a onclick=\"javascript:displayXml(" + methodParams + ")\">XML</a></td>";
520
521                                         htmlStr += "<td><a onclick=\"javascript:deleteDG(" + methodParams + ")\">Delete</a></td>";
522                                         htmlStr += "</tr>";
523                                 }
524                                 htmlStr += "</table>";
525                                 htmlStr += "</div>";
526                         }
527         return htmlStr;
528 }
529
530 function showSLA(){
531         var htmlStr = "";
532         try{
533                 $.get("/listSLA")
534                 .done(function( data ) {
535                         var htmlStr=getHtmlStr(data);
536                         $("#svclogicPageDiv").dialog({
537                                 modal:true,     
538                                 title: "Service Logic Administration - " + data.dbHost, 
539                                 width: 1200,
540                                 height: 750,
541                                 minWidth : 600, 
542                                 minHeight :450, 
543                                 }).html(htmlStr);
544                 })
545                 .fail(function(err) {
546                         htmlStr= "<div>Error occured displaying the DG list</div>";
547                         $("#svclogicPageDiv").dialog({
548                                 modal:true,     
549                                 title: "Service Logic Administration - " + data.dbHost, 
550                                 width: 1200,
551                                 height: 750,
552                                 minWidth : 600, 
553                                 minHeight :450, 
554                                 }).html(htmlStr);
555                 })
556                 .always(function() { 
557                 });
558         }catch(err){
559         }
560 }
561
562 function showCurrentDGs(module,rpc){
563         var htmlStr = "";
564         try{
565                 var params="?module=" + module + "&rpc=" + rpc;
566                 var url="/listCurrentDGs" + params;
567                 //console.log("url:" + url);
568                 $.get(url)
569                 .done(function( data ) {
570                         var htmlStr=getHtmlStr(data,true);
571                         $("#svclogicPageDiv").dialog({
572                                 modal:true,     
573                                 title:"Service Logic Administration  Module=" + module + " and RPC=" + rpc,
574                                 width: 1200,
575                                 height: 750,
576                                 minWidth : 600, 
577                                 minHeight :450, 
578                                 }).html(htmlStr);
579                 })
580                 .fail(function(err) {
581                         htmlStr= "<div>Error occured displaying the DG list</div>";
582                         $("#svclogicPageDiv").dialog({
583                                 modal:true,     
584                                 title:"Service Logic Administration  Module=" + module + " and RPC=" + rpc,
585                                 width: 1200,
586                                 height: 750,
587                                 minWidth : 600, 
588                                 minHeight :450, 
589                                 }).html(htmlStr);
590                 })
591                 .always(function() { 
592                 });
593         }catch(err){
594         }
595 }
596
597
598 function displaySLA(callback){
599         var htmlStr = "";
600         try{
601                 $.get("/listSLA")
602                 .done(function( data ) {
603                         var htmlStr=getHtmlStr(data);
604                         callback(htmlStr,data.dbHost);
605                 })
606                 .fail(function(err) {
607                         htmlStr= "<div>Error occured displaying the DG list</div>";
608                         callback(htmlStr,err.dbHost);
609                 })
610                 .always(function() { 
611                 });
612         }catch(err){
613                         callback(htmlStr,"");
614         }
615 }
616
617 function displayCurrentDGs(module,rpc,callback){
618         var htmlStr = "";
619         try{
620                 var params="?module=" + module + "&rpc=" + rpc;
621                 var url="/listCurrentDGs" + params;
622                 //console.log("url:" + url);
623                 $.get(url )
624                 .done(function( data ) {
625                         var htmlStr=getHtmlStr(data,true);
626                         callback(htmlStr,data.dbHost);
627                 })
628                 .fail(function(err) {
629                         htmlStr= "<div>Error occured displaying the Current DG list</div>";
630                         callback(htmlStr,err.dbHost);
631                 })
632                 .always(function() { 
633                 });
634         }catch(err){
635                         callback(htmlStr,"");
636         }
637 }
638
639
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;
646                 }
647                 if (event) {
648                         event.returnValue = message;
649                 }
650                 return message;
651         }
652 };
653 </script>
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>
658 </script>
659 <style>
660 .textview{
661         font-size:20px;
662 }
663 </style>
664
665 <div id="screenInfoId"></div>
666 <script type="text/javascript">
667 function getAttributeValue(xmlStr,attribute){
668         var attrVal=null;
669         try{
670                 var myRe = new RegExp(attribute + "[\s+]?=[\s+]?['\"]([^'\"]+)['\"]","m");
671                 var myArray = myRe.exec(xmlStr);
672                 if(myArray != null && myArray[1] != null){
673                         attrVal=myArray[1];
674                 }
675         }catch(err){
676                 console.log(err);
677         }
678         return attrVal;
679
680 }
681
682
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({
686                 modal:true,     
687                 title: "DGBuilder XML Generation Status",
688                 width: 400,
689                 height: 250,
690                 minWidth : 400, 
691                 minHeight :200, 
692                 }).html(htmlStr);
693 }
694
695     RED.nodes.registerType('dgstart',{
696         color:"#fdd0a2",
697         category: 'DGEmain',
698         defaults: {
699             name: {value:"DGSTART"},
700             outputs: {value:1}
701         },
702         inputs:0,
703         outputs:1,
704         icon: "inject.png",
705         label: function() {
706             return this.name;
707         },
708         onpaletteadd: function() {
709                 //console.log("DGSTART Added to the palette.");
710         },
711         button: {
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'>";
718
719                 /*
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" });
725                 */
726
727                 //deploy button 
728                 //$("#btn-deploy")
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));
736                         if(isLoopDetected){
737                                 //RED.notify("<strong>Error</strong>: Loop Detected","error");
738                                 //target.css({ "background-image": "none" });
739                                 return false;
740                         }
741                 }
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);        
749                 /*
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);
756                 }
757                 */
758                 var lengthOfXml = formatted_xml.length;
759                 var sizeStr = "";
760                 if(lengthOfXml >0){
761                         var val = lengthOfXml/(1024*1024)
762                         sizeStr = val.toFixed(4) + " MB";
763                         console.log("length:" + val);
764                 }
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("&lt;","<");
769                 var currentNodeSet = getCurrentFlowNodeSet();
770                 //get max x and y coordinates
771                 var x=0;
772                 var y=0;
773                 var maxX=0;
774                 var maxY=0;
775                 var moduleName = "";
776                 var dgVersion = "";
777                 var methodName = "";
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");
787                         }
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";
794                                 }
795                         }
796                         x = currentNodeSet[i].x;        
797                         y = currentNodeSet[i].y;        
798                         if(x>maxX){
799                                 maxX=x;
800                         }
801                         if(y>maxY){
802                                 maxY=y;
803                         }
804                 }
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>";
815                 var htmlCode ="";
816                 $( "#xmldialog" ).dialog({
817                         title: "XML Generated",
818                         width: 1200,
819                         height: 750,
820                         minWidth : 800, 
821                         minHeight :450, 
822                         dialogClass : "no-close",
823                         closeOnEscape : false,  
824                         autoOpen : false,
825                         resize: function( event, ui ) {
826                                 /*
827                                         $( this ).dialog( "option", "title",
828                                         ui.size.height + " x " + ui.size.width );
829                                 */
830                         },
831                         modal: true,
832                         /*show: {
833                                 effect: "slide",
834                                 duration: 1000
835                         },
836                         */
837                         /*hide: {
838                                 effect: "slide",
839                                 duration: 500
840                         },
841                         */
842                         buttons: {
843                         /*      
844                            "+" : function () {
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;
849                                         if(fsize<19){
850                                                 fsize+=4;
851                                         }
852                                         if(fsize >= 26){
853                                                 return;
854                                         }
855                                         $("#xmldialog").find('.textview').css("font-size",fsize);
856                                 },
857                            "-" : function () {
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;
862                                         if(fsize <= 14){
863                                                 return;
864                                         }
865                                         $("#xmldialog").find('.textview').css("font-size",fsize);
866                                 },
867                         */
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" });
875
876                                 var resp= validateFinalXML(unformatted_xml_str);
877                                 console.log("errorList:" + errList);
878                                 if(!resp){
879                                         showErrors();   
880                                 }
881                                 target.text("Validate XML");
882                                 target.css({ "background-image": "none" });
883                            },
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);
893                                         //console.dir(resp);
894                                         var styleSheetText = resp.responseText;
895                                         /*var htmlCode = "<style>"  + styleSheetText + "</style></head>" + 
896                                                  '<body><div id="chart" class="ui-droppable">' +
897                                         */
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
913                                 /*
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.");
927                                         */
928                                         var reqData = {
929                                                 "flowHtml" : htmlCode,
930                                                 "flowXml" : formatted_xml,
931                                                 "flowJson" : formatted_json
932                                         };
933
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);
940                                                 }else{
941                                                         RED.notify("Email sent successfully.");
942                                                 }
943                                         })
944                                         .fail(function(err) {
945                                                  console.log( "error" + err ); 
946                                                 RED.notify("Email send Failed.");
947                                         }) 
948                                         .always(function() { 
949                                                 console.log( "finished" ); 
950                                                 target.text("Email Flow");
951                                                 target.css({ "background-image": "none" });
952                                         });
953
954                                         /*
955                                         d3.xhr("/sendEmail").post(reqData,function(err,resp){
956                                                 console.log("Error:" + JSON.stringify(err));
957                                                 console.log("resp:" + JSON.stringify(resp));
958                                                 console.dir(resp);
959                                         });
960                                         */
961                                 });
962                            },
963                                 /*
964                            Deploy : function () {
965                                 $("#btn-deploy").click();       
966                            },
967                                 */
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();  
980                                 
981                                 var fileName = date.getTime() + ".xml"; 
982                                 var reqData = {
983                                         "flowXml" : unformatted_xml_str,
984                                         "module" : origModuleName,
985                                         "rpc" : origMethodName
986                                         };
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 + "' />";
991                                                 
992                                                 if( data != undefined  && data != null &&  (data.stdout.indexOf('Saving SvcLogicGraph to database') != -1 || data.stderr.indexOf('Saving SvcLogicGraph to database') != -1)){
993                                                         //RED.notify("<strong>Uploaded Successfully</strong>");
994                                                         //console.dir(data);
995                                                         var _moduleName = data.module;
996                                                         var _rpc = data.rpc;
997                                                         var msg = "";
998                                                         var actualMsg = "";
999                                                         var msg_lines = "";
1000                                                         msg_lines += data.stderr;
1001                                                         msg_lines += data.stdout;
1002                                                                 
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({
1005                                                                         modal:true,     
1006                                                                         title: "Upload XML ",
1007                                                                         width: 900,
1008                                                                         height: 750,
1009                                                                         minWidth : 600, 
1010                                                                         minHeight :450, 
1011                                                                         buttons: [
1012                                                                                 {
1013                                                                                 text: "ViewDGList",
1014                                                                                 class:"alertDialogButton",
1015                                                                                 click: function() {
1016                                                                                         $(this).dialog("close");
1017                                                                                         displayCurrentDGs(_moduleName,_rpc,function(htmlStr,dbHost){
1018                                                                                                 $("#svclogicPageDiv").dialog({
1019                                                                                                 modal:true,     
1020                                                                                                 title:"Service Logic Administration  Module=" + _moduleName + " and RPC=" + _rpc,
1021                                                                                                 width: 1200,
1022                                                                                                 height: 750,
1023                                                                                                 minWidth : 600, 
1024                                                                                                 minHeight :450, 
1025                                                                                                 }).html(htmlStr);
1026                                                                                         });     
1027                                                                                         }
1028                                                                                 },
1029                                                                                 {
1030                                                                                 text: "Close",
1031                                                                                 class:"alertDialogButton",
1032                                                                                 click: function() {
1033                                                                                         $(this).dialog("close");
1034                                                                                 }
1035                                                                                 }
1036                                                                                 ]
1037                                                                 }).html(msgHtmlStr);
1038                                                 }else{
1039                                                         console.log("Could not upload.");
1040                                                         var emsg =JSON.parse( data.responseText);
1041                                                         var msg = "";
1042                                                         var actualMsg = "";
1043                                                         var msg_lines = "";
1044                                                         if( emsg.stderr != "COMPILE_ERROR"){
1045                                                                 msg = JSON.stringify(emsg.stderr);
1046                                                                 actualMsg = msg;
1047                                                                 msg = msg.replace('\\t',"");
1048                                                                 msg1 = msg.split('\\n');
1049                                                                 for(var k=0;k<=msg1.length && k<=10;k++){
1050                                                                         /*
1051                                                                         if(k == 0){
1052                                                                                 //msg_lines += "<span style='color:blue'>" + msg1[k] + "</span><br>";   
1053                                                                                 //msg_lines +=  msg1[k]  +"\n";
1054                                                                         }else{
1055                                                                                 if(msg1[k].indexOf("Caused by:") != -1){
1056                                                                                         //msg_lines += "<span style='color:red'> " + msg1[k] + "</span><br>";   
1057                                                                                         msg_lines += msg1[k] ;
1058                                                                                         break;
1059                                                                                 }
1060                                                                         }
1061                                                                         */
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] ;
1066                                                                                 }       
1067                                                                                 if((k+2)<=msg1.length){
1068                                                                                         msg_lines +=   "\n" + msg1[k+2] ;
1069                                                                                 }       
1070                                                                                 break;
1071                                                                         }
1072                                                                 }
1073                                                         }
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({
1076                                                         modal:true,     
1077                                                         title: "Upload XML ",
1078                                                         width: 900,
1079                                                         height: 750,
1080                                                         minWidth : 600, 
1081                                                         minHeight :450, 
1082                                                 }).html(htmlStr);
1083                                                 }
1084                                         })
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); 
1090                                                 var msg = "";
1091                                                 var actualMsg = "";
1092                                                 var msg_lines = "";
1093                                                 if( emsg != null &&  emsg.stderr != 'COMPILE_ERROR'){
1094                                                         msg = JSON.stringify(emsg.stderr);
1095                                                         actualMsg = msg;
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++){
1100                                                                 /*
1101                                                                 if(k == 0){
1102                                                                         //msg_lines += "<span style='color:blue'>" + msg1[k] + "</span><br>";   
1103                                                                         //msg_lines +=  msg1[k] + "\n" ;
1104                                                                 }else{
1105                                                                         if(msg1[k].indexOf("Caused by:") != -1){
1106                                                                                 //msg_lines += "<span style='color:red'> " + msg1[k] + "</span><br>";   
1107                                                                                 msg_lines +=  msg1[k] ;
1108                                                                                 break;
1109                                                                         }
1110                                                                 }
1111                                                                 */
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] ;
1116                                                                         }       
1117                                                                         if((k+2)<=msg1.length){
1118                                                                                 msg_lines +=   "\n" + msg1[k+2] ;
1119                                                                         }       
1120                                                                         break;
1121                                                                 }
1122                                                         }
1123                                                 }else{
1124                                                                 msg = JSON.stringify(emsg.stdout);
1125                                                                 actualMsg = msg;
1126                                                                 msg = msg.replace('\\t',"");
1127                                                                 msg1 = msg.split('\\n');
1128                                                                 msg_lines=msg1;
1129                                                 }
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({
1132                                                         modal:true,     
1133                                                         title: "Upload XML ",
1134                                                         width: 900,
1135                                                         height: 750,
1136                                                         minWidth : 600, 
1137                                                         minHeight :450, 
1138                                                 }).html(htmlStr);
1139                                                 //RED.notify("<strong>ERROR:</strong>:" + err,"error");
1140                                         }) 
1141                                         .always(function() { 
1142                                                 console.log( "finished" ); 
1143                                                 target.text("Upload XML");
1144                                                 target.css({ "background-image": "none" });
1145                                         });
1146                                 /*
1147                                 d3.xhr("/uploadxml?fileName=" + fileName).post(function(err,resp) {
1148                                         if ( resp != null && resp.status == 200) {
1149                                                 RED.notify("<strong>Uploaded Successfully</strong>");
1150                                         }else{
1151                                                 RED.notify("<strong>ERROR:</strong>:" + err,"error");
1152                                                 console.log(err);
1153                                                 //console.dir(resp);
1154                                         }
1155                                 });
1156                                 */
1157                            },
1158                            "View DG List": function () {
1159
1160                                         displayCurrentDGs(origModuleName,origMethodName,function(htmlStr,dbHost){
1161                                                 //console.log("htmlStr:" + htmlStr);
1162                                                 $("#svclogicPageDiv").dialog({
1163                                                         modal:true,     
1164                                                         title: "Service Logic Administration for Module=" + origModuleName + "  and RPC=" + origMethodName, 
1165                                                         width: 1200,
1166                                                         height: 750,
1167                                                         minWidth : 600, 
1168                                                         minHeight :450, 
1169                                                 }).html(htmlStr);
1170                                         });     
1171                            },
1172                            "Download XML": function () {
1173                                 $(document).ready(function(){
1174                                         errList=[];
1175                                         if(moduleName != undefined && moduleName != null && moduleName != ""){
1176                                                 moduleName=moduleName.replace(/\s/g, "_");
1177                                         }else{
1178                                                 errList.push("Module name is required in the service-logic node.");
1179                                         }
1180
1181                                         if(dgVersion == undefined || dgVersion == null || dgVersion == ""){
1182                                                 errList.push("Module version is required in the service-logic node.");
1183                                         }
1184
1185                                         if(methodName != undefined && methodName != null && methodName != ""){
1186                                                 methodName=methodName.replace(/\s/g, "_");
1187                                                 //formattedMethodName=methodName + "_" + dgVersion;
1188                                                 formattedMethodName=methodName ;
1189                                         }else{
1190                                                 errList.push("rpc name is required in the method node.");
1191                                         }
1192                                         console.log("Download Xml moduleName:" + moduleName);   
1193                                         console.log("Download Xml methodName:" + formattedMethodName);  
1194
1195                                         if(errList != null && errList.length > 0 ){
1196                                                 showErrors();
1197                                                 return;
1198                                         }
1199
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.");
1211                                 });
1212                            },
1213                            "Download JSON": function () {
1214                                 $(document).ready(function(){
1215                                         errList=[];
1216                                         if(moduleName != undefined && moduleName != null && moduleName != ""){
1217                                                 moduleName=moduleName.replace(/\s/g, "_");
1218                                         }else{
1219                                                 errList.push("Module name is required in the service-logic node.");
1220                                         }
1221
1222                                         if(dgVersion == undefined || dgVersion == null || dgVersion == ""){
1223                                                 errList.push("Module version is required in the service-logic node.");
1224                                         }
1225
1226                                         if(methodName != undefined && methodName != null && methodName != ""){
1227                                                 methodName=methodName.replace(/\s/g, "_");
1228                                                 //formattedMethodName=methodName + "_" + dgVersion;
1229                                                 formattedMethodName=methodName ;
1230                                         }else{
1231                                                 errList.push("rpc name is required in the method node.");
1232                                         }
1233                                         console.log("Download Xml moduleName:" + moduleName);   
1234                                         console.log("Download Xml methodName:" + formattedMethodName);  
1235
1236                                         if(errList != null && errList.length > 0 ){
1237                                                 showErrors();
1238                                                 return;
1239                                         }
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.");
1252                                 });
1253                            },
1254                            Close: function ()   {
1255                                 /*
1256                                 console.log("clearing the variables.");
1257                                 htmlCode ="";
1258                                 formatted_json ="";
1259                                 formatted_xml ="";
1260                                 xmlLines =[];
1261                                 unformatted_xml_str="";
1262                                 unformatted_json_str="";
1263                                 */
1264                                $('.ui-dialog:has(#xmldialog)').empty().remove();
1265                                 RED.view.redraw();
1266
1267                                 //console.log($("#xmldialog").attr('id'));
1268                                 //$('.ui-dialog:has(# + $("#xmldialog").attr('id') + ')').empty().remove();
1269                                 //$("#xmldialog").hide();
1270                                 //$("#xmldialog").dialog("destroy").remove();
1271                         }
1272                        },
1273                         open:function (){
1274                                 $(function(){
1275                                 $("#xmldialog").dialog("widget").find(".ui-dialog-buttonpane").append(xmlInfoStr);
1276                                         console.log("opened.");
1277                                 });
1278                         }       
1279                 }).html(displayHtmlStr).dialog("open");
1280                 
1281                 //}).html(displayHtmlStr).dialog("widget").find(".ui-dialog-buttonpane").append(xmlInfoStr);
1282
1283                 //display size and number of lines in XML
1284                 //$("#xmldialog").dialog("widget").find(".ui-dialog-buttonpane").append(xmlInfoStr);
1285
1286                 //$("#processingStatusId").html("");
1287                  //This logic is commented as formatting and displaying orion is taking time
1288                 //START
1289                 /*
1290                 var msecs1= Date.now();
1291                 var that = this;
1292                 require(["orion/editor/edit"], function(edit) {
1293                 that.editor = edit({
1294                     parent:document.getElementById('xmldialog'),
1295                     lang:"html",
1296                     readonly:true,
1297                     //showLinesRuler: false,
1298                     contents: formatted_xml
1299                 });
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']
1305                 });
1306                 });
1307                 var msecs2= Date.now();
1308                 //console.log("Time taken for displaying XML:" + (msecs2 - msecs1));
1309                 */
1310                 //END
1311                 //var success = customValidation(currentNodeSet);
1312                 var success = customValidation(nodeSetWithUpdatedDgNumbers);
1313                 if(!success){
1314                         showFlowDesignErrorBox();
1315                 }
1316                 $('#processingStatusId').html("");
1317                 }, 0);
1318             }
1319         }
1320
1321     });
1322 </script>