removed dependency on built-editor.min.js
[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 displayHtmlStr=  "";
815               
816                 //var xmlInfoStr = "<div id='xml-info-div'><p>" + "XML size:" + sizeStr +  " <br>Number of Lines:" + numberOfLines +  "</p></div>";
817                 var htmlCode ="";
818                 $( "#xmldialog" ).dialog({
819                         title: "XML Generated",
820                         width: 1200,
821                         height: 750,
822                         minWidth : 800, 
823                         minHeight :450, 
824                         dialogClass : "no-close",
825                         closeOnEscape : false,  
826                         autoOpen : false,
827                         resize: function( event, ui ) {
828                                 /*
829                                         $( this ).dialog( "option", "title",
830                                         ui.size.height + " x " + ui.size.width );
831                                 */
832                         },
833                         modal: true,
834                         /*show: {
835                                 effect: "slide",
836                                 duration: 1000
837                         },
838                         */
839                         /*hide: {
840                                 effect: "slide",
841                                 duration: 500
842                         },
843                         */
844                         buttons: {
845                         /*      
846                            "+" : function () {
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;
851                                         if(fsize<19){
852                                                 fsize+=4;
853                                         }
854                                         if(fsize >= 26){
855                                                 return;
856                                         }
857                                         $("#xmldialog").find('.textview').css("font-size",fsize);
858                                 },
859                            "-" : function () {
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;
864                                         if(fsize <= 14){
865                                                 return;
866                                         }
867                                         $("#xmldialog").find('.textview').css("font-size",fsize);
868                                 },
869                         */
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" });
878
879                                 var resp= validateFinalXML(unformatted_xml_str);
880                                 console.log("errorList:" + errList);
881                                 if(!resp){
882                                         showErrors();   
883                                 }
884                                 target.text("Validate XML");
885                                 target.css({ "background-image": "none" });
886                            },
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);
896                                         //console.dir(resp);
897                                         var styleSheetText = resp.responseText;
898                                         /*var htmlCode = "<style>"  + styleSheetText + "</style></head>" + 
899                                                  '<body><div id="chart" class="ui-droppable">' +
900                                         */
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
916                                 /*
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.");
930                                         */
931                                         var reqData = {
932                                                 "flowHtml" : htmlCode,
933                                                 "flowXml" : formatted_xml,
934                                                 "flowJson" : formatted_json,
935                                                 "emailAddress" : RED.settings.emailAddress
936                                         };
937
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);
944                                                 }else{
945                                                         RED.notify("Email sent successfully.");
946                                                 }
947                                         })
948                                         .fail(function(err) {
949                                                  console.log( "error" + err ); 
950                                                 RED.notify("Email send Failed.");
951                                         }) 
952                                         .always(function() { 
953                                                 console.log( "finished" ); 
954                                                 target.text("Email Flow");
955                                                 target.css({ "background-image": "none" });
956                                         });
957
958                                         /*
959                                         d3.xhr("/sendEmail").post(reqData,function(err,resp){
960                                                 console.log("Error:" + JSON.stringify(err));
961                                                 console.log("resp:" + JSON.stringify(resp));
962                                                 console.dir(resp);
963                                         });
964                                         */
965                                 });
966                            },
967                                 /*
968                            Deploy : function () {
969                                 $("#btn-deploy").click();       
970                            },
971                                 */
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();  
984                                 
985                                 var fileName = date.getTime() + ".xml"; 
986                                 var reqData = {
987                                         "flowXml" : unformatted_xml_str,
988                                         "module" : origModuleName,
989                                         "rpc" : origMethodName
990                                         };
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 + "' />";
995                                                 //console.dir(data);    
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>");
998                                                         //console.dir(data);
999                                                         var _moduleName = data.module;
1000                                                         var _rpc = data.rpc;
1001                                                         var msg = "";
1002                                                         var actualMsg = "";
1003                                                         var msg_lines = "";
1004                                                         msg_lines += data.stderr;
1005                                                         msg_lines += data.stdout;
1006                                                                 
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({
1009                                                                         modal:true,     
1010                                                                         title: "Upload XML ",
1011                                                                         width: 900,
1012                                                                         height: 750,
1013                                                                         minWidth : 600, 
1014                                                                         minHeight :450, 
1015                                                                         buttons: [
1016                                                                                 {
1017                                                                                 text: "ViewDGList",
1018                                                                                 class:"alertDialogButton",
1019                                                                                 click: function() {
1020                                                                                         $(this).dialog("close");
1021                                                                                         displayCurrentDGs(_moduleName,_rpc,function(htmlStr,dbHost){
1022                                                                                                 $("#svclogicPageDiv").dialog({
1023                                                                                                 modal:true,     
1024                                                                                                 title:"Service Logic Administration  Module=" + _moduleName + " and RPC=" + _rpc,
1025                                                                                                 width: 1200,
1026                                                                                                 height: 750,
1027                                                                                                 minWidth : 600, 
1028                                                                                                 minHeight :450, 
1029                                                                                                 }).html(htmlStr);
1030                                                                                         });     
1031                                                                                         }
1032                                                                                 },
1033                                                                                 {
1034                                                                                 text: "Close",
1035                                                                                 class:"alertDialogButton",
1036                                                                                 click: function() {
1037                                                                                         $(this).dialog("close");
1038                                                                                 }
1039                                                                                 }
1040                                                                                 ]
1041                                                                 }).html(msgHtmlStr);
1042                                                 }else{
1043                                                         console.log("Could not upload.");
1044                                                         var emsg =JSON.parse( data.responseText);
1045                                                         var msg = "";
1046                                                         var actualMsg = "";
1047                                                         var msg_lines = "";
1048                                                         if( emsg.stderr != "COMPILE_ERROR"){
1049                                                                 msg = JSON.stringify(emsg.stderr);
1050                                                                 actualMsg = msg;
1051                                                                 msg = msg.replace('\\t',"");
1052                                                                 msg1 = msg.split('\\n');
1053                                                                 for(var k=0;k<=msg1.length && k<=10;k++){
1054                                                                         /*
1055                                                                         if(k == 0){
1056                                                                                 //msg_lines += "<span style='color:blue'>" + msg1[k] + "</span><br>";   
1057                                                                                 //msg_lines +=  msg1[k]  +"\n";
1058                                                                         }else{
1059                                                                                 if(msg1[k].indexOf("Caused by:") != -1){
1060                                                                                         //msg_lines += "<span style='color:red'> " + msg1[k] + "</span><br>";   
1061                                                                                         msg_lines += msg1[k] ;
1062                                                                                         break;
1063                                                                                 }
1064                                                                         }
1065                                                                         */
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] ;
1070                                                                                 }       
1071                                                                                 if((k+2)<=msg1.length){
1072                                                                                         msg_lines +=   "\n" + msg1[k+2] ;
1073                                                                                 }       
1074                                                                                 break;
1075                                                                         }
1076                                                                 }
1077                                                         }
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({
1080                                                         modal:true,     
1081                                                         title: "Upload XML ",
1082                                                         width: 900,
1083                                                         height: 750,
1084                                                         minWidth : 600, 
1085                                                         minHeight :450, 
1086                                                 }).html(htmlStr);
1087                                                 }
1088                                         })
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); 
1094                                                 var msg = "";
1095                                                 var actualMsg = "";
1096                                                 var msg_lines = "";
1097                                                 if( emsg != null &&  emsg.stderr != 'COMPILE_ERROR'){
1098                                                         msg = JSON.stringify(emsg.stderr);
1099                                                         actualMsg = msg;
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++){
1104                                                                 /*
1105                                                                 if(k == 0){
1106                                                                         //msg_lines += "<span style='color:blue'>" + msg1[k] + "</span><br>";   
1107                                                                         //msg_lines +=  msg1[k] + "\n" ;
1108                                                                 }else{
1109                                                                         if(msg1[k].indexOf("Caused by:") != -1){
1110                                                                                 //msg_lines += "<span style='color:red'> " + msg1[k] + "</span><br>";   
1111                                                                                 msg_lines +=  msg1[k] ;
1112                                                                                 break;
1113                                                                         }
1114                                                                 }
1115                                                                 */
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] ;
1120                                                                         }       
1121                                                                         if((k+2)<=msg1.length){
1122                                                                                 msg_lines +=   "\n" + msg1[k+2] ;
1123                                                                         }       
1124                                                                         break;
1125                                                                 }
1126                                                         }
1127                                                 }else{
1128                                                                 msg = JSON.stringify(emsg.stdout);
1129                                                                 actualMsg = msg;
1130                                                                 msg = msg.replace('\\t',"");
1131                                                                 msg1 = msg.split('\\n');
1132                                                                 msg_lines=msg1;
1133                                                 }
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({
1136                                                         modal:true,     
1137                                                         title: "Upload XML ",
1138                                                         width: 900,
1139                                                         height: 750,
1140                                                         minWidth : 600, 
1141                                                         minHeight :450, 
1142                                                 }).html(htmlStr);
1143                                                 //RED.notify("<strong>ERROR:</strong>:" + err,"error");
1144                                         }) 
1145                                         .always(function() { 
1146                                                 console.log( "finished" ); 
1147                                                 target.text("Upload XML");
1148                                                 target.css({ "background-image": "none" });
1149                                         });
1150                                 /*
1151                                 d3.xhr("/uploadxml?fileName=" + fileName).post(function(err,resp) {
1152                                         if ( resp != null && resp.status == 200) {
1153                                                 RED.notify("<strong>Uploaded Successfully</strong>");
1154                                         }else{
1155                                                 RED.notify("<strong>ERROR:</strong>:" + err,"error");
1156                                                 console.log(err);
1157                                                 //console.dir(resp);
1158                                         }
1159                                 });
1160                                 */
1161                            },
1162                            "View DG List": function () {
1163
1164                                         displayCurrentDGs(origModuleName,origMethodName,function(htmlStr,dbHost){
1165                                                 //console.log("htmlStr:" + htmlStr);
1166                                                 $("#svclogicPageDiv").dialog({
1167                                                         modal:true,     
1168                                                         title: "Service Logic Administration for Module=" + origModuleName + "  and RPC=" + origMethodName, 
1169                                                         width: 1200,
1170                                                         height: 750,
1171                                                         minWidth : 600, 
1172                                                         minHeight :450, 
1173                                                 }).html(htmlStr);
1174                                         });     
1175                            },
1176                            "Download XML": function () {
1177                                 $(document).ready(function(){
1178                                         errList=[];
1179                                         if(moduleName != undefined && moduleName != null && moduleName != ""){
1180                                                 moduleName=moduleName.replace(/\s/g, "_");
1181                                         }else{
1182                                                 errList.push("Module name is required in the service-logic node.");
1183                                         }
1184
1185                                         if(dgVersion == undefined || dgVersion == null || dgVersion == ""){
1186                                                 errList.push("Module version is required in the service-logic node.");
1187                                         }
1188
1189                                         if(methodName != undefined && methodName != null && methodName != ""){
1190                                                 methodName=methodName.replace(/\s/g, "_");
1191                                                 //formattedMethodName=methodName + "_" + dgVersion;
1192                                                 formattedMethodName=methodName ;
1193                                         }else{
1194                                                 errList.push("rpc name is required in the method node.");
1195                                         }
1196                                         console.log("Download Xml moduleName:" + moduleName);   
1197                                         console.log("Download Xml methodName:" + formattedMethodName);  
1198
1199                                         if(errList != null && errList.length > 0 ){
1200                                                 showErrors();
1201                                                 return;
1202                                         }
1203
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);
1214                                         }else{
1215                                                 $("#flowXmlId").val(unformatted_xml_str);
1216                                         }
1217                                         $("#dwnldXmlFormId").submit();
1218                                         //console.log("Form submitted.");
1219                                 });
1220                            },
1221                            "Download JSON": function () {
1222                                 $(document).ready(function(){
1223                                         errList=[];
1224                                         if(moduleName != undefined && moduleName != null && moduleName != ""){
1225                                                 moduleName=moduleName.replace(/\s/g, "_");
1226                                         }else{
1227                                                 errList.push("Module name is required in the service-logic node.");
1228                                         }
1229
1230                                         if(dgVersion == undefined || dgVersion == null || dgVersion == ""){
1231                                                 errList.push("Module version is required in the service-logic node.");
1232                                         }
1233
1234                                         if(methodName != undefined && methodName != null && methodName != ""){
1235                                                 methodName=methodName.replace(/\s/g, "_");
1236                                                 //formattedMethodName=methodName + "_" + dgVersion;
1237                                                 formattedMethodName=methodName ;
1238                                         }else{
1239                                                 errList.push("rpc name is required in the method node.");
1240                                         }
1241                                         console.log("Download Xml moduleName:" + moduleName);   
1242                                         console.log("Download Xml methodName:" + formattedMethodName);  
1243
1244                                         if(errList != null && errList.length > 0 ){
1245                                                 showErrors();
1246                                                 return;
1247                                         }
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);
1259                                         }else{
1260                                                 $("#flowJsonId").val(unformatted_json_str);
1261                                         }
1262                                         $("#dwnldJsonFormId").submit();
1263                                         //console.log("Form submitted.");
1264                                 });
1265                            },
1266                            Close: function ()   {
1267                                 /*
1268                                 console.log("clearing the variables.");
1269                                 htmlCode ="";
1270                                 formatted_json ="";
1271                                 formatted_xml ="";
1272                                 xmlLines =[];
1273                                 unformatted_xml_str="";
1274                                 unformatted_json_str="";
1275                                 */
1276                                 ace.edit('xmldialog').destroy();
1277                                $('.ui-dialog:has(#xmldialog)').empty().remove();
1278                                 RED.view.redraw();
1279
1280                                 //console.log($("#xmldialog").attr('id'));
1281                                 //$('.ui-dialog:has(# + $("#xmldialog").attr('id') + ')').empty().remove();
1282                                 //$("#xmldialog").hide();
1283                                 //$("#xmldialog").dialog("destroy").remove();
1284                         }
1285                        },
1286                         open:function (){
1287                                 $(function(){
1288                                         try{
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>";
1297                                         }catch(err){
1298                                         }
1299                                 $("#xmldialog").dialog("widget").find(".ui-dialog-buttonpane").append(xmlInfoStr);
1300                                         console.log("opened.");
1301                                 });
1302                         }       
1303                 }).html(displayHtmlStr).dialog("open");
1304                 
1305                 //}).html(displayHtmlStr).dialog("widget").find(".ui-dialog-buttonpane").append(xmlInfoStr);
1306
1307                 //display size and number of lines in XML
1308                 //$("#xmldialog").dialog("widget").find(".ui-dialog-buttonpane").append(xmlInfoStr);
1309
1310                 //$("#processingStatusId").html("");
1311                  //This logic is commented as formatting and displaying orion is taking time
1312                 //START
1313                 /*
1314                 var msecs1= Date.now();
1315                 var that = this;
1316                 require(["orion/editor/edit"], function(edit) {
1317                 that.editor = edit({
1318                     parent:document.getElementById('xmldialog'),
1319                     lang:"html",
1320                     readonly:true,
1321                     //showLinesRuler: false,
1322                     contents: formatted_xml
1323                 });
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']
1329                 });
1330                 });
1331                 var msecs2= Date.now();
1332                 //console.log("Time taken for displaying XML:" + (msecs2 - msecs1));
1333                 */
1334                 //END
1335                 //var success = customValidation(currentNodeSet);
1336                 var success = customValidation(nodeSetWithUpdatedDgNumbers);
1337                 if(!success){
1338                         showFlowDesignErrorBox();
1339                 }
1340                 $('#processingStatusId').html("");
1341                 }, 0);
1342             }
1343         }
1344
1345     });
1346 </script>