removed dependency on built-editor.min.js
[ccsdk/distribution.git] / dgbuilder / public / red / main.js
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
17 var RED = (function() {
18
19     function hideDropTarget() {
20         $("#dropTarget").hide();
21         RED.keyboard.remove(/* ESCAPE */ 27);
22     }
23
24     $('#chart').on("dragenter",function(event) {
25         if ($.inArray("text/plain",event.originalEvent.dataTransfer.types) != -1) {
26             $("#dropTarget").css({display:'table'});
27             RED.keyboard.add(/* ESCAPE */ 27,hideDropTarget);
28         }
29     });
30
31     $('#dropTarget').on("dragover",function(event) {
32         if ($.inArray("text/plain",event.originalEvent.dataTransfer.types) != -1) {
33             event.preventDefault();
34         }
35     })
36     .on("dragleave",function(event) {
37         hideDropTarget();
38     })
39     .on("drop",function(event) {
40         var data = event.originalEvent.dataTransfer.getData("text/plain");
41         hideDropTarget();
42         RED.view.importNodes(data);
43         event.preventDefault();
44     });
45
46
47     function save(force) {
48         if (RED.view.dirty()) {
49             //$("#debug-tab-clear").click();  // uncomment this to auto clear debug on deploy
50
51             if (!force) {
52                 var invalid = false;
53                 var unknownNodes = [];
54                 RED.nodes.eachNode(function(node) {
55                     invalid = invalid || !node.valid;
56                     if (node.type === "unknown") {
57                         if (unknownNodes.indexOf(node.name) == -1) {
58                             unknownNodes.push(node.name);
59                         }
60                         invalid = true;
61                     }
62                 });
63                 if (invalid) {
64                     if (unknownNodes.length > 0) {
65                         $( "#node-dialog-confirm-deploy-config" ).hide();
66                         $( "#node-dialog-confirm-deploy-unknown" ).show();
67                         var list = "<li>"+unknownNodes.join("</li><li>")+"</li>";
68                         $( "#node-dialog-confirm-deploy-unknown-list" ).html(list);
69                     } else {
70                         $( "#node-dialog-confirm-deploy-config" ).show();
71                         $( "#node-dialog-confirm-deploy-unknown" ).hide();
72                     }
73                     $( "#node-dialog-confirm-deploy" ).dialog( "open" );
74                     return;
75                 }
76             }
77             var nns = RED.nodes.createCompleteNodeSet();
78             /****************************************/
79             /*added new code to save the Tabs order */
80             /****************************************/ 
81             //console.log("nns before changes.");
82             //console.dir(nns);
83             var allTabsObj={};
84             var allTabsList=[];
85             var nnsTabIdsArr = [];
86             var guiTabIdsArr = [];
87             nns.forEach(function(n) {
88                         if(n.type == 'tab'){
89                                 allTabsObj[n.id] = n;
90                                 allTabsList.push(n);
91                                 nnsTabIdsArr.push(n.id);
92                         }
93             });
94             var idx =0; 
95             $("#workspace-tabs li a").each(function(){
96                 var href = $(this).prop("href");
97                 var indexOfHash = href.indexOf("#");
98                 var idVal = href.slice(indexOfHash+1);
99                 guiTabIdsArr.push(idVal);
100                 nns.splice(idx,1,allTabsObj[idVal]);;
101                 idx++;
102             }); 
103             //console.log(nnsTabIdsArr.join(","));      
104             //console.log(guiTabIdsArr.join(","));      
105             //console.log("nns after changes.");
106             //console.dir(nns);
107             /****************************/ 
108             $("#btn-icn-deploy").removeClass('fa-download');
109             $("#btn-icn-deploy").addClass('spinner');
110             RED.view.dirty(false);
111
112             $.ajax({
113                 url:"flows",
114                 type: "POST",
115                 data: JSON.stringify(nns),
116                 contentType: "application/json; charset=utf-8"
117             }).done(function(data,textStatus,xhr) {
118                 RED.notify("Successfully saved","success");
119                 RED.nodes.eachNode(function(node) {
120                     if (node.changed) {
121                         node.dirty = true;
122                         node.changed = false;
123                     }
124                     if(node.credentials) {
125                         delete node.credentials;
126                     }
127                 });
128                 RED.nodes.eachConfig(function (confNode) {
129                     if (confNode.credentials) {
130                         delete confNode.credentials;
131                     }
132                 });
133                 // Once deployed, cannot undo back to a clean state
134                 RED.history.markAllDirty();
135                 RED.view.redraw();
136             }).fail(function(xhr,textStatus,err) {
137                 RED.view.dirty(true);
138                 if (xhr.responseText) {
139                     RED.notify("<strong>Error</strong>: "+xhr.responseText,"error");
140                 } else {
141                     RED.notify("<strong>Error</strong>: no response from server","error");
142                 }
143             }).always(function() {
144                 $("#btn-icn-deploy").removeClass('spinner');
145                 $("#btn-icn-deploy").addClass('fa-download');
146             });
147         }
148     }
149
150     $('#btn-deploy').click(function() { save(); });
151
152     $( "#node-dialog-confirm-deploy" ).dialog({
153             title: "Confirm deploy",
154             modal: true,
155             autoOpen: false,
156             width: 530,
157             height: 230,
158             buttons: [
159                 {
160                     text: "Confirm deploy",
161                     click: function() {
162                         save(true);
163                         $( this ).dialog( "close" );
164                     }
165                 },
166                 {
167                     text: "Cancel",
168                     click: function() {
169                         $( this ).dialog( "close" );
170                     }
171                 }
172             ]
173     });
174
175     function loadSettings() {
176         $.get('settings', function(data) {
177             RED.settings = data;
178             console.log("Node-RED: "+data.version);
179             loadNodeList();
180         });
181     }
182
183     function loadNodeList() {
184         $.ajax({
185             headers: {
186                 "Accept":"application/json"
187             },
188             cache: false,
189             url: 'nodes',
190             success: function(data) {
191                 RED.nodes.setNodeList(data);
192                 loadNodes();
193             }
194         });
195     }
196
197     function loadNodes() {
198         $.ajax({
199             headers: {
200                 "Accept":"text/html"
201             },
202             cache: false,
203             url: 'nodes',
204             success: function(data) {
205                 $("body").append(data);
206                 $(".palette-spinner").hide();
207                 $(".palette-scroll").show();
208                 $("#palette-search").show();
209                 loadFlows();
210             }
211         });
212     }
213
214     function loadFlows() {
215         $.ajax({
216             headers: {
217                 "Accept":"application/json"
218             },
219             cache: false,
220             url: 'flows',
221             success: function(nodes) {
222                 RED.nodes.import(nodes);
223                 RED.view.dirty(false);
224                 RED.view.redraw();
225                 RED.comms.subscribe("status/#",function(topic,msg) {
226                     var parts = topic.split("/");
227                     var node = RED.nodes.node(parts[1]);
228                     if (node) {
229                         node.status = msg;
230                         if (statusEnabled) {
231                             node.dirty = true;
232                             RED.view.redraw();
233                         }
234                     }
235                 });
236                 RED.comms.subscribe("node/#",function(topic,msg) {
237                     var i,m;
238                     var typeList;
239                     var info;
240                     
241                     if (topic == "node/added") {
242                         var addedTypes = [];
243                         for (i=0;i<msg.length;i++) {
244                             m = msg[i];
245                             var id = m.id;
246                             RED.nodes.addNodeSet(m);
247                             if (m.loaded) {
248                                 addedTypes = addedTypes.concat(m.types);
249                                 $.get('nodes/'+id, function(data) {
250                                     $("body").append(data);
251                                 });
252                             }
253                         }
254                         if (addedTypes.length) {
255                             typeList = "<ul><li>"+addedTypes.join("</li><li>")+"</li></ul>";
256                             RED.notify("Node"+(addedTypes.length!=1 ? "s":"")+" added to palette:"+typeList,"success");
257                         }
258                     } else if (topic == "node/removed") {
259                         for (i=0;i<msg.length;i++) {
260                             m = msg[i];
261                             info = RED.nodes.removeNodeSet(m.id);
262                             if (info.added) {
263                                 typeList = "<ul><li>"+m.types.join("</li><li>")+"</li></ul>";
264                                 RED.notify("Node"+(m.types.length!=1 ? "s":"")+" removed from palette:"+typeList,"success");
265                             }
266                         }
267                     } else if (topic == "node/enabled") {
268                         if (msg.types) {
269                             info = RED.nodes.getNodeSet(msg.id);
270                             if (info.added) {
271                                 RED.nodes.enableNodeSet(msg.id);
272                                 typeList = "<ul><li>"+msg.types.join("</li><li>")+"</li></ul>";
273                                 RED.notify("Node"+(msg.types.length!=1 ? "s":"")+" enabled:"+typeList,"success");
274                             } else {
275                                 $.get('nodes/'+msg.id, function(data) {
276                                     $("body").append(data);
277                                     typeList = "<ul><li>"+msg.types.join("</li><li>")+"</li></ul>";
278                                     RED.notify("Node"+(msg.types.length!=1 ? "s":"")+" added to palette:"+typeList,"success");
279                                 });
280                             } 
281                         }
282                     } else if (topic == "node/disabled") {
283                         if (msg.types) {
284                             RED.nodes.disableNodeSet(msg.id);
285                             typeList = "<ul><li>"+msg.types.join("</li><li>")+"</li></ul>";
286                             RED.notify("Node"+(msg.types.length!=1 ? "s":"")+" disabled:"+typeList,"success");
287                         }
288                     }
289                 });
290             }
291         });
292     }
293
294     var statusEnabled = false;
295     function toggleStatus(state) {
296         statusEnabled = state;
297         RED.view.status(statusEnabled);
298     }
299
300     function performLoopDetection(state) {
301         loopDetectionEnabled = state;
302         console.log("loopDetectionEnabled:" + loopDetectionEnabled);
303     }
304
305     var dgNumberEnabled = false;
306     function toggleDgNumberDisplay(state) {
307         dgNumberEnabled = state;
308         RED.view.showNumbers(dgNumberEnabled);
309     }
310
311     var nodePaletteDisplay = false;
312     function toggleNodePaletteDisplay(state) {
313         nodePaletteDisplay = state;
314         RED.view.showNodePalette(nodePaletteDisplay);
315     }
316     function displayAllDGs(state) {
317                 //defined showSLa() in dgstart.html 
318                 showSLA();
319     }
320
321
322     function showHelp() {
323
324         var dialog = $('#node-help');
325
326         //$("#node-help").draggable({
327         //        handle: ".modal-header"
328         //});
329
330         dialog.on('show',function() {
331             RED.keyboard.disable();
332         });
333         dialog.on('hidden',function() {
334             RED.keyboard.enable();
335         });
336
337         dialog.modal();
338     }
339
340
341 //Custom Functions Added here
342         function  showCodeCloudFlows(){
343                 codeCloudFlowFiles=[];
344                 var divStyle="<style>#codecloud-data-container a { color: #067ab4; font-size: 0.75em;} #codecloud-data-container a:hover { text-decoration: underline; padding: -15px -15px -15px 15px; } .header { height: 40px; border-bottom: 1px solid #EEE; background-color: #ffffff; height: 40px; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; } .footer { height: 40px; background-color: whiteSmoke; border-top: 1px solid #DDD; -webkit-border-bottom-left-radius: 5px; -webkit-border-bottom-right-radius: 5px; -moz-border-radius-bottomleft: 5px; -moz-border-radius-bottomright: 5px; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; }</style>";
345                 $.get( "/getCodeCloudFlows")
346                                .done(function( data ) {
347                                         
348                                         var header="<div class='header'>List of DG Flows in Code Cloud</div><div><input id='flowFilterBoxId' type='text' onkeyup='filterFlows(this.value)'></div>";
349                                         var html=  divStyle + header +  "<div id='codecloud-data-container'>";
350                                         html+="<ul>";
351                                         if(data != null){
352                                                 var files=data.files;
353                                                 codeCloudFlowFiles=files;
354                                                 //console.dir(files);
355                                                 files.sort(function (a,b){
356                                                         if(a > b){
357                                                                 return 1;
358                                                         }else if(a <  b){
359                                                                 return -1;
360                                                         }else{  
361                                                                 return 0;
362                                                         }
363                                                 });
364                                                 for(var i=0;files != null && i<files.length;i++){
365                                                         html+="<li><a href=\"#\" onclick=\"getCommits('" + files[i] + "')\">" + files[i] + "</a></li>";
366                                                 }
367                                         }
368                                         html+="</ul>";
369                                         html+="</div>";
370                                         $( "#codecloud-browser-dialog" ).dialog({
371                                         title: "Code Cloud DG Flow Browser",
372                                         modal: true,
373                                         autoOpen: true,
374                                         width: 830,
375                                         height: 630,
376                                         buttons: [
377                                                 {
378                                                         text: "Close",
379                                                         click: function() {
380                                                                 $( this ).dialog( "close" );
381                                                         }
382                                                 }
383                                                 ],
384                                         close: function(ev,ui){
385                                                 $(this).dialog("destroy");
386                                         }
387                                         }).html(html);
388                                         $("#codecloud-browser-dialog").show();
389                                })
390                                 .fail(function(err) {
391                                          RED.notify("Failed to get users.");
392                                 })
393                                  .always(function() {
394                                 });
395         }
396                 
397         /*
398         function  listYangFiles(){
399                 yangFilesList=[];
400                 var divStyle="<style>#list-yang-data-container a { color: #067ab4; font-size: 0.75em;} #list-yang-data-container a:hover { text-decoration: underline; padding: -15px -15px -15px 15px; } .header { height: 40px; border-bottom: 1px solid #EEE; background-color: #ffffff; height: 40px; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; } .footer { height: 40px; background-color: whiteSmoke; border-top: 1px solid #DDD; -webkit-border-bottom-left-radius: 5px; -webkit-border-bottom-right-radius: 5px; -moz-border-radius-bottomleft: 5px; -moz-border-radius-bottomright: 5px; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; }</style>";
401                 $.get( "/getYangFiles")
402                                .done(function( data ) {
403                                         
404                                         var header="<div class='header'>List of Yang Files </div><div><input id='flowFilterBoxId' type='text' onkeyup='filterYangFiles(this.value)'></div>";
405                                         var html=  divStyle + header +  "<div id='list-yang-data-container'>";
406                                         html+="<ul>";
407                                         if(data != null){
408                                                 var files=data.files;
409                                                 yangFilesList=files;
410                                                 //console.dir(files);
411                                                 files.sort(function (a,b){
412                                                         if(a > b){
413                                                                 return 1;
414                                                         }else if(a <  b){
415                                                                 return -1;
416                                                         }else{  
417                                                                 return 0;
418                                                         }
419                                                 });
420                                                 for(var i=0;files != null && i<files.length;i++){
421                                                         html+="<li><a href=\"#\" onclick=\"getYangFile('" + files[i] + "')\">" + files[i] + "</a></li>";
422                                                 }
423                                         }
424                                         html+="</ul>";
425                                         html+="</div>";
426                                         $( "#list-yang-browser-dialog" ).dialog({
427                                         title: "List Yang Files",
428                                         modal: true,
429                                         autoOpen: true,
430                                         width: 830,
431                                         height: 630,
432                                         buttons: [
433                                                 {
434                                                         text: "Close",
435                                                         click: function() {
436                                                                 $( this ).dialog( "close" );
437                                                         }
438                                                 }
439                                                 ],
440                                         close: function(ev,ui){
441                                                 $(this).dialog("destroy");
442                                         }
443                                         }).html(html);
444                                         $("#list-yang-browser-dialog").show();
445                                })
446                                 .fail(function(err) {
447                                          RED.notify("Failed to get yang files.");
448                                 })
449                                  .always(function() {
450                                 });
451         }
452         */
453
454         function  listYangFiles(){
455                 yangFilesList=[];
456         
457                 var divStyle="<style>#yang-files-data-container a { color: #067ab4; font-size: 0.75em;} #yang-files-data-container a:hover { text-decoration: underline; padding: -15px -15px -15px 15px; } .header { height: 40px; border-bottom: 1px solid #EEE; background-color: #ffffff; height: 40px; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; } .footer { height: 40px; background-color: whiteSmoke; border-top: 1px solid #DDD; -webkit-border-bottom-left-radius: 5px; -webkit-border-bottom-right-radius: 5px; -moz-border-radius-bottomleft: 5px; -moz-border-radius-bottomright: 5px; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; } table#yang-file-list-table { width:100%; } table#yang-file-list-table th,table#yang-file-list-table td { border: 1px solid black; border-collapse: collapse; } table#yang-file-list-table th,table#yang-file-list-table td { padding: 5px; text-align: left; } table#yang-file-list-table tr:nth-child(even) { background-color: #eee; } table#yang-file-list-table tr:nth-child(odd) { background-color:#fff; } table#yang-file-list-table th    { background-color: #65a9d7; color: white; } table#yang-file-list-table a { color: #337ab7; } table#yang-file-list-table a:link { color: #65a9d7; } table#yang-file-list-table a:visited { color: #636; } table#yang-file-list-table a:hover { color: #3366CC; cursor: pointer } table#yang-file-list-table a:active { color: #65a9d7 }</style>";
458                 $.get( "/getYangFiles")
459                                .done(function( data ) {
460                                         
461                                         var header="<div class='header'>List of Yang Files </div><div><input id='flowFilterBoxId' type='text' onkeyup='filterYangFiles(this.value)'></div>";
462                                         var html=  divStyle + header +  "<div id='yang-files-data-container'>";
463                                         html+="<table id='yang-file-list-table'  border=1>";
464                                         html+="<tr>";
465                                         html+="<th>File</th>";
466                                         html+="<th>Delete</th>";
467                                         html+="</tr>";
468                                         if(data != null){
469                                                 var files=data.files;
470                                                 yangFilesList=files;
471                                                 //console.dir(files);
472                                                 files.sort(function (a,b){
473                                                         if(a > b){
474                                                                 return 1;
475                                                         }else if(a <  b){
476                                                                 return -1;
477                                                         }else{  
478                                                                 return 0;
479                                                         }
480                                                 });
481                                                 for(var i=0;files != null && i<files.length;i++){
482                                                         html+="<tr><td><a href=\"#\" onclick=\"getYangFile('" + files[i] + "')\">" + files[i] + "</a></td><td>" + "<input type='button'  onclick='deleteYangFile(\"" + files[i]  + "\")' value='Delete'></td></td></td></tr>";
483                                                 }
484                                         }
485                                         html+="</table>";
486                                         html+="</div>";
487                                         $( "#list-yang-browser-dialog" ).dialog({
488                                         title: "List Yang Files",
489                                         modal: true,
490                                         autoOpen: true,
491                                         width: 830,
492                                         height: 630,
493                                         buttons: [
494                                                 {
495                                                         text: "Close",
496                                                         click: function() {
497                                                                 $( this ).dialog( "close" );
498                                                         }
499                                                 }
500                                                 ],
501                                         close: function(ev,ui){
502                                                 $(this).dialog("destroy");
503                                         }
504                                         }).html(html);
505                                         $("#list-yang-browser-dialog").show();
506                                })
507                                 .fail(function(err) {
508                                          RED.notify("Failed to get yang files.");
509                                 })
510                                  .always(function() {
511                                 });
512         }
513                 
514
515         function showGitPullDialog(){
516                 $.get( "/getCurrentGitBranch")
517                                .done(function( data ) {
518                                         if(data != null){ 
519                                                 if(data.output == "GIT_LOCAL_REPOSITORY_NOT_SET" ){
520                                                         RED.notify("Git Local Repository path is not set. Please set it by choosing Configuration from the menu.");
521                                                         return;
522                                                 }       
523
524                                                 var html= "<div id='gitcheckout-container'>";
525                                                 html+="<table>";
526                                                 html+="<tr>";
527                                                 html+="<td>Branch</td>";
528                                                 html+="<td>" +  data.output + "</td>";
529                                                 html+="</tr>";
530                                                 html+="<tr>";
531                                                 html+="<td><input id='gitPullBtnId' type='button' value='Pull' onclick='performGitPull()'></td>";
532                                                 html+="<td>&nbsp;&nbsp;</td>"
533                                                 html+="</tr>";
534                                                 html+="<tr>";
535                                                 //html+="<td colspan=3><textarea readonly='1' rows='5' cols='200'  id='responseId'></textarea></td>";
536                                                 html+="</tr>";
537                                                 html+="</table>";
538                                                 html+="<br><div id='responseId'></div>";
539                                                 html+="</div>";
540                                                 $( "#gitcommands-dialog" ).dialog({
541                                                         title: "Git Pull",
542                                                         modal: true,
543                                                         autoOpen: true,
544                                                         width: 630,
545                                                         height: 500,
546                                                         buttons: [
547                                                         {
548                                                                 text: "Close",
549                                                                 click: function() {
550                                                                         $( this ).dialog( "close" );
551                                                                 }
552                                                         }
553                                                         ],
554                                                         close: function(ev,ui){
555                                                                 $(this).dialog("destroy");
556                                                         }
557                                                 }).html(html);
558                                           $("#responseId").css({width:'550',height:'275px', border: '2px solid lightgrey',overflow:'scroll', padding: '20px' });
559                                           $("#responseId").hide();
560                                         $("#gitcommands-dialog").show();
561                                 }
562                                })
563                                 .fail(function(err) {
564                                          RED.notify("Failed to get gitBranch.");
565                                 })
566                                  .always(function() {
567                                 });
568         }
569
570         function showGitStatusDialog(){
571                 $.get( "/getCurrentGitBranch")
572                                .done(function( data ) {
573                                         if(data != null){ 
574                                                 if(data.output == "GIT_LOCAL_REPOSITORY_NOT_SET" ){
575                                                         RED.notify("Git Local Repository path is not set. Please set it by choosing Configuration from the menu.");
576                                                         return;
577                                                 }       
578
579                                                 var html= "<div id='gitcheckout-container'>";
580                                                 html+="<table>";
581                                                 html+="<tr>";
582                                                 html+="<td>Branch</td>";
583                                                 html+="<td>" + data.output + "</td>";
584                                                 html+="</tr>";
585                                                 html+="<tr>";
586                                                 html+="<td><input id='gitStatusBtnId' type='button' value='Status' onclick='performGitStatus()'></td>";
587                                                 html+="<td>&nbsp;&nbsp;</td>"
588                                                 html+="</tr>";
589                                                 html+="<tr>";
590                                                 //html+="<td colspan=3><textarea readonly='1' rows='5' cols='200'  id='responseId'></textarea></td>";
591                                                 html+="</tr>";
592                                                 html+="</table>";
593                                                 html+="<br><div id='responseId'></div>";
594                                                 html+="</div>";
595                                                 $( "#gitcommands-dialog" ).dialog({
596                                                         title: "Git Status",
597                                                         modal: true,
598                                                         autoOpen: true,
599                                                         width: 630,
600                                                         height: 500,
601                                                         buttons: [
602                                                         {
603                                                                 text: "Close",
604                                                                 click: function() {
605                                                                         $( this ).dialog( "close" );
606                                                                 }
607                                                         }
608                                                         ],
609                                                         close: function(ev,ui){
610                                                                 $(this).dialog("destroy");
611                                                         }
612                                                 }).html(html);
613                                           //$("#responseId").css({width:'600px',height:'100px','border-radius' : '25px', border: '2px solid lightgrey', padding: '20px' });
614                                           $("#responseId").css({width:'550px',height:'100px', border: '2px solid lightgrey',overflow:'scroll', padding: '20px' });
615                                           $("#responseId").hide();
616                                         $("#gitcommands-dialog").show();
617                                 }
618                                })
619                                 .fail(function(err) {
620                                          RED.notify("Failed to get gitBranch.");
621                                 })
622                                  .always(function() {
623                                 });
624         }
625
626         function showGitCheckoutDialog(){
627                 $.get( "/getCurrentGitBranch")
628                                .done(function( data ) {
629                                         if(data != null){ 
630                                                 if(data.output == "GIT_LOCAL_REPOSITORY_NOT_SET" ){
631                                                         RED.notify("Git Local Repository path is not set. Please set it by choosing Configuration from the menu.");
632                                                         return;
633                                                 }       
634
635                                                 var html= "<div id='gitcheckout-container'>";
636                                                 html+="<table>";
637                                                 html+="<tr>";
638                                                 html+="<td>Branch</td>";
639                                                 html+="<td><input id='branchId' type='text' value='" + data.output + "'></td>";
640                                                 html+="</tr>";
641                                                 html+="<tr>";
642                                                 html+="<td><input id='checkoutBtnId' type='button' value='Checkout' onclick='performGitCheckout()'></td>";
643                                                 html+="<td>&nbsp;&nbsp;</td>"
644                                                 html+="</tr>";
645                                                 html+="<tr>";
646                                                 //html+="<td colspan=3><textarea readonly='1' rows='5' cols='200'  id='responseId'></textarea></td>";
647                                                 html+="</tr>";
648                                                 html+="</table>";
649                                                 html+="<br><div id='responseId'></div>";
650                                                 html+="</div>";
651                                                 $( "#gitcommands-dialog" ).dialog({
652                                                         title: "Git Checkout",
653                                                         modal: true,
654                                                         autoOpen: true,
655                                                         width: 430,
656                                                         height: 350,
657                                                         buttons: [
658                                                         {
659                                                                 text: "Close",
660                                                                 click: function() {
661                                                                         $( this ).dialog( "close" );
662                                                                 }
663                                                         }
664                                                         ],
665                                                         close: function(ev,ui){
666                                                                 $(this).dialog("destroy");
667                                                         }
668                                                 }).html(html);
669                                           $("#responseId").css({width:'300',height:'100px', border: '2px solid lightgrey',overflow:'scroll', padding: '20px' });
670                                           $("#responseId").hide();
671                                         $("#gitcommands-dialog").show();
672                                 }
673                                })
674                                 .fail(function(err) {
675                                          RED.notify("Failed to get gitBranch.");
676                                 })
677                                  .always(function() {
678                                 });
679         }
680
681         function  showGitLocalFlows(){
682                 giLocalFlowFiles=[];
683                 var divStyle="<style>#gitlocal-data-container a { color: #067ab4; font-size: 0.75em;} #gitlocal-data-container a:hover { text-decoration: underline; padding: -15px -15px -15px 15px; } .header { height: 40px; border-bottom: 1px solid #EEE; background-color: #ffffff; height: 40px; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; } .footer { height: 40px; background-color: whiteSmoke; border-top: 1px solid #DDD; -webkit-border-bottom-left-radius: 5px; -webkit-border-bottom-right-radius: 5px; -moz-border-radius-bottomleft: 5px; -moz-border-radius-bottomright: 5px; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; }</style>";
684                 $.get( "/getGitLocalFlows")
685                                .done(function( data ) {
686                                         if(data != null && data.files != null && data.files.length == 1){
687                                                 if(data.files[0] == "GIT_LOCAL_REPOSITORY_NOT_SET" ){
688                                                         RED.notify("Git Local Repository path is not set. Please set it by choosing Configuration from the menu.");
689                                                         return;
690                                                 }       
691                                         }
692                                         //console.log("got response from server.");
693                                         
694                                         var header="<div class='header'>List of DG Flows  from  Git Local Repository </div><div><input id='flowFilterBoxId' type='text' onkeyup='filterGitLocalFlows(this.value)'></div>";
695                                         var html=  divStyle + header +  "<div id='gitlocal-data-container'>";
696                                         html+="<ul>";
697                                         if(data != null){
698                                                 var files=data.files;
699                                                 gitLocalFlowFiles=files;
700                                                 //console.dir(files);
701                                                 files.sort(function (a,b){
702                                                         if(a > b){
703                                                                 return 1;
704                                                         }else if(a <  b){
705                                                                 return -1;
706                                                         }else{  
707                                                                 return 0;
708                                                         }
709                                                 });
710                                                 for(var i=0;files != null && i<files.length;i++){
711                                                         html+="<li><a href=\"#\" onclick=\"importGitLocalFlow('" + files[i] + "')\">" + files[i] + "</a></li>";
712                                                 }
713                                         }
714                                         html+="</ul>";
715                                         html+="</div>";
716                                         $( "#gitlocal-browser-dialog" ).dialog({
717                                         title: "Git Local Repository DG Flow Browser",
718                                         modal: true,
719                                         autoOpen: true,
720                                         width: 830,
721                                         height: 630,
722                                         buttons: [
723                                                 {
724                                                         text: "Close",
725                                                         click: function() {
726                                                                 $(this).dialog("close");
727                                                         }
728                                                 }
729                                                 ]
730                                         }).html(html);
731                                         $("#gitlocal-browser-dialog").show();
732                                         /*
733                                         if ($("#gitlocal-browser-dialog").dialog( "isOpen" )===true) {
734                                                 console.log("gitlocal dialog box is open");     
735                                                 //true
736                                         } else {
737                                                 console.log("gitlocal dialog box is not open"); 
738                                         //      $( "#gitlocal-browser-dialog" ).dialog("destroy").remove();
739                                                 console.log($("#gitlocal-browser-dialog").dialog( "widget" ));
740                                                 $("#gitlocal-browser-dialog").dialog( "open" );
741                                                 if ($("#gitlocal-browser-dialog").dialog( "isOpen" )===true) {
742                                                         console.log("gitlocal dialog box is now open"); 
743                                                 }
744                                                 $("#gitlocal-browser-dialog").show();
745                                                 //false
746                                         }
747                                         */
748                                })
749                                 .fail(function(err) {
750                                          RED.notify("Failed to get flows.");
751                                 })
752                                  .always(function() {
753                                         console.log("Done displaying");
754                                 });
755         }
756
757         function  showFlowShareUsers(){
758                 var divStyle="<style>#data-container a { color: #067ab4; font-size: 0.75em;} #data-container a:hover { text-decoration: underline; padding: -15px -15px -15px 15px; } .header { height: 40px; border-bottom: 1px solid #EEE; background-color: #ffffff; height: 40px; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; } .footer { height: 40px; background-color: whiteSmoke; border-top: 1px solid #DDD; -webkit-border-bottom-left-radius: 5px; -webkit-border-bottom-right-radius: 5px; -moz-border-radius-bottomleft: 5px; -moz-border-radius-bottomright: 5px; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; }</style>";
759                 $.get("/flowShareUsers")
760                         .done(function (data){
761                                         
762                                         var header="<div class='header'>List of Downloaded DG Flows</div>";
763                                         var html=  divStyle + header +  "<div id='data-container'>";
764                                         html+="<ul>";
765                                         if(data != null){
766                                                 var users=data.flowShareUsers;
767                                                 users.sort(function (a,b){
768                                                         if(a.name > b.name){
769                                                                 return 1;
770                                                         }else if(a.name <  b.name){
771                                                                 return -1;
772                                                         }else{  
773                                                                 return 0;
774                                                         }
775                                                 });
776                                                 for(var i=0;users != null && i<users.length;i++){
777                                                         html+="<li><a href=\"#\" onclick=\"showFlowFiles('" + users[i].rootDir + "')\">" + users[i].name + "</a></li>";
778                                                 }
779                                         }
780                                         html+="</ul>";
781                                         html+="</div>";
782                                         $( "#dgflow-browser-dialog" ).dialog({
783                                         title: "Downloaded DG Flows Browser",
784                                         modal: true,
785                                         autoOpen: true,
786                                         width: 530,
787                                         height: 530,
788                                         buttons: [
789                                                 {
790                                                         text: "Close",
791                                                         click: function() {
792                                                                 $( this ).dialog( "close" );
793                                                                 //$(this).dialog('destroy').remove();
794                                                         }
795                                                 }
796                                                 ]
797                                         }).html(html);
798                                         $("#dgflow-browser-dialog").show();
799                                         /*
800                                         if ($("#dgflow-browser-dialog").dialog( "isOpen" )===true) {
801                                                 console.log("dgflow dialog box is open");       
802                                                 //true
803                                         } else {
804                                                 console.log("dgflow dialog box is not open");   
805                                                 $("#dgflow-browser-dialog").dialog( "open" );
806                                                 $("#dgflow-browser-dialog").show();
807                                                 //false
808                                         }
809                                         */
810                                })
811                                 .fail(function(err) {
812                                          RED.notify("Failed to get users.");
813                                 })
814                                  .always(function() {
815                                 });
816         }
817
818 /*      function  showFlowShareUsers(){
819                 var divStyle="<style>#data-container a { color: #067ab4; font-size: 0.75em;} #data-container a:hover { text-decoration: underline; padding: -15px -15px -15px 15px; } .header { height: 40px; border-bottom: 1px solid #EEE; background-color: #ffffff; height: 40px; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; } .footer { height: 40px; background-color: whiteSmoke; border-top: 1px solid #DDD; -webkit-border-bottom-left-radius: 5px; -webkit-border-bottom-right-radius: 5px; -moz-border-radius-bottomleft: 5px; -moz-border-radius-bottomright: 5px; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; }</style>";
820                 $.get( "/flowShareUsers")
821                                .done(function( data ) {
822                                         
823                                         var header="<div class='header'>List of Downloaded DG Flows</div>";
824                                         var html=  divStyle + header +  "<div id='data-container'>";
825                                         html+="<ul>";
826                                         if(data != null){
827                                                 var users=data.flowShareUsers;
828                                                 users.sort(function (a,b){
829                                                         if(a.name > b.name){
830                                                                 return 1;
831                                                         }else if(a.name <  b.name){
832                                                                 return -1;
833                                                         }else{  
834                                                                 return 0;
835                                                         }
836                                                 });
837                                                 for(var i=0;users != null && i<users.length;i++){
838                                                         html+="<li><a href=\"#\" onclick=\"showFlowFiles('" + users[i].rootDir + "')\">" + users[i].name + "</a></li>";
839                                                 }
840                                         }
841                                         html+="</ul>";
842                                         html+="</div>";
843                                         $( "#dgflow-browser-dialog" ).dialog({
844                                         title: "Downloaded DG Flows Browser",
845                                         modal: true,
846                                         autoOpen: true,
847                                         width: 530,
848                                         height: 530,
849                                         buttons: [
850                                                 {
851                                                         text: "Close",
852                                                         click: function() {
853                                                                 //$( this ).dialog( "close" );
854                                                                 $(this).dialog('destroy').remove();
855                                                         }
856                                                 }
857                                                 ]
858                                         }).html(html);
859                                         //$("#dgflow-browser-dialog").show();
860                                         $( "#dgflow-browser-dialog" ).dialog( "open" );
861                                })
862                                 .fail(function(err) {
863                                          RED.notify("Failed to get users.");
864                                 })
865                                  .always(function() {
866                                 });
867         }
868         */
869
870
871 function detectLoopInFlow(){
872                 var errList = [];
873                 var activeWorkspace=RED.view.getWorkspace();
874                 var nSet=[];
875                 
876                 RED.nodes.eachNode(function(n) {
877                         if (n.z == activeWorkspace) {
878                                 nSet.push({n:n});
879                         }
880                 });
881
882                 var nodeSet = RED.nodes.createExportableNodeSet(nSet);
883
884                 var isLoopDetected = false;     
885                 var dgStartNode = getDgStartNode(nodeSet);
886                 if(dgStartNode == null || dgStartNode == undefined) {
887                         console.log("dgstart node not linked.");
888                         return null;
889                 }
890
891                 var wires = dgStartNode.wires;
892                 var nodesInPath = {};
893                 var dgStartNodeId = dgStartNode.id;
894                 if(wires != null && wires != undefined && wires[0] != undefined){
895                         for(var k=0;k<wires[0].length;k++){
896                                 var val = wires[0][k];
897                                 nodesInPath[dgStartNodeId + "->" + val] = "";
898                         }
899                 }else{
900                                 nodesInPath[dgStartNodeId + "->" + ""] = "";
901                 }
902                         
903                 var loopDetectedObj = {};
904                 /* the nodes will not be in order so will need to loop thru again */
905         for(var m=0;nodeSet != null && m<nodeSet.length;m++){
906                 for(var i=0;nodeSet != null && i<nodeSet.length;i++){
907                         var link=nodeSet[i].id;
908                         //console.log("NAME:" + nodeSet[i].name + ":" + link);
909                         if(link == dgStartNodeId) continue;
910                         var wires = nodeSet[i].wires;
911                         //console.log("link:" + link);
912                         var delKeys = [];
913                         if(wires != null && wires != undefined && wires[0] != undefined){
914                                 for(var k=0;k<wires[0].length;k++){
915                                         var val = (wires[0])[k];
916                                         var keys = Object.keys(nodesInPath);
917                                         //console.log("keys:" + keys);
918                                         for (var j=0;j<keys.length;j++){
919                                                 //console.log("key:" + keys[j]);
920                                                 //console.log("val:" + val);
921                                                 var index = keys[j].indexOf("->" + link);
922                                                 var lastIndex = keys[j].lastIndexOf("->");
923                                                 if(index != -1 && index == lastIndex){
924                                                         //delete nodesInPath[key];
925                                                         var previousNodeId = keys[j].substr(lastIndex +2);
926                                                         var indexOfArrow = -1;
927                                                         if(previousNodeId != ""){
928                                                                 indexOfArrow = previousNodeId.indexOf("->");
929                                                         }
930                                                         if(previousNodeId != null && indexOfArrow != -1){
931                                                                 previousNodeId = previousNodeId.substr(0,indexOfArrow);
932                                                         }       
933                                                         nodesInPath[keys[j] + "->" + val] = "";
934                                                         //console.log("keys[j]:" + keys[j]);
935                                                         delKeys.push(keys[j]);
936                                                         var prevNodeIdIndex = keys[j].indexOf("->" + previousNodeId);
937                                                         var priorOccurence = keys[j].indexOf(val + "->");
938                                                         if(priorOccurence != -1 && priorOccurence<prevNodeIdIndex){
939                                                                 //console.log("previousNodeId:" + previousNodeId);
940                                                                 //console.log("val:" + val);
941                                                                 var n1 = getNode(nodeSet,previousNodeId);
942                                                                 var n2 = getNode(nodeSet,val);
943                                                                 //console.log("loop detected for node " + n1.name + " and " + n2.name); 
944                                                                 loopDetectedObj[n1.name + "->" + n2.name] ="looped";
945                                                                 console.dir(loopDetectedObj);
946                                                                 errList.push("Loop detected between " + n1.name + " and " + n2.name);
947                                                                 isLoopDetected = true;
948                                                         }               
949                                                 } 
950                                         }
951                                 }
952                         }
953                         for(var l=0;delKeys != null && l<delKeys.length;l++){
954                                 delete nodesInPath[delKeys[l]];
955                         }
956                 }
957
958
959         }       
960         /*
961         if(loopDetectedObj != null ){ 
962                 var msg = "";
963                 for(var key in loopDetectedObj){
964                         if(loopDetectedObj.hasOwnProperty(key)) {
965                                 console.log("Loop detected  " + key);
966                                 msg += "<strong>Loop detected for:" + key + "</strong><br>";
967                         }
968                 }
969                 if(msg != ""){
970                         isLoopDetected = true;
971                         //RED.notify(msg);
972                 }
973         }       
974         */
975         //images/page-loading.gif
976                 return errList;
977 }
978
979 function showLoopDetectionBox(){
980         $(function() {
981         var htmlStr="<div id='loop-box-div' style='width:375;height:225'><p>Loop detection in Progress ...</p><img src='images/page-loading.gif'></div>"
982         $("#loop-detection-dialog").dialog({
983                 modal:true,     
984                 autoOpen :true,
985                 title: "DG Flow Loop Detection",
986                 width: 400,
987                 height: 250,
988                 minWidth : 400, 
989                 minHeight :200, 
990                 }).html(htmlStr);
991                 if($("#loop-detection-dialog").dialog("isOpen") == true){
992                         var errList = detectLoopInFlow();
993                         var errList=[];
994                         if(errList == null){
995                                 $("#loop-detection-dialog").dialog("close");
996                         }
997                         var msgHtml = "";
998                         for(var i=0;errList != null && i<errList.length;i++){
999                                 msgHtml += "<p>" + errList[i] + "</p>";
1000                         }
1001                         if(msgHtml == ""){
1002                                 $("loop-box-div").html("<p>SUCCESS. No Loop detected.</p>");
1003                         }else{
1004                                 $("loop-box-div").html(msgHtml);
1005                         }
1006                 }
1007         });
1008         
1009 }
1010
1011 function showSelectedTabs(){
1012         var tabSheets = [];
1013         var beforeTabsOrder=[];
1014         $(".red-ui-tabs li a").each(function(i){
1015                 var id=$(this).attr("href").replace('#','');
1016                 var title=$(this).attr("title");
1017                 var isVisible = $(this).parent().is(":visible"); 
1018                 if(title != 'info'){
1019                         tabSheets.push({"id" : id ,"title":title,"module":"NOT_SET","version" : "NOT_SET","rpc":"NOT_SET","isVisible":isVisible});
1020                         beforeTabsOrder.push(id);
1021                 }
1022         });
1023
1024         RED.nodes.eachNode(function(n) {
1025                 if(n.type == 'service-logic'){
1026                         var id = n.z;
1027                         var module = n.module;
1028                         tabSheets.forEach(function(tab){
1029                                 if(tab.id == id){
1030                                         tab.module=module;
1031                                         tab.version=n.version;
1032                                 }       
1033                         });
1034                 }else if(n.type == 'method'){
1035                         var id = n.z;
1036                         tabSheets.forEach(function(tab){
1037                                 if(tab.id == id){
1038                                         var rpc=getAttributeValue(n.xml,"rpc");
1039                                         tab.rpc=rpc;
1040                                 }       
1041                         });
1042                 }
1043         });
1044         //console.dir(tabSheets);
1045         var htmlStr = getHtmlStr(tabSheets);
1046         $("#filter-tabs-dialog").dialog({
1047                 modal:true,     
1048                 title: "DG Builder Tabs",
1049                 width: 1200,
1050                 height: 750,
1051                 minWidth : 600, 
1052                 minHeight :450, 
1053                 }).html(htmlStr);
1054 /* This code allows for the drag-drop of the rows in the table */
1055         var fixHelperModified = function(e, tr) {
1056                 var $originals = tr.children();
1057                 var $helper = tr.clone();
1058                 $helper.children().each(function(index) {
1059                 $(this).width($originals.eq(index).width())
1060         });
1061         return $helper;
1062         },
1063         updateIndex = function(e, ui) {
1064                 var afterTabsOrder=[];
1065                 $('td.index', ui.item.parent()).each(function (i) {
1066                         $(this).html(i + 1);
1067                 });
1068                 //RE-ARRANGE the tabs
1069                 var ul = $("#workspace-tabs");
1070                 $("#ftab02 tr td:nth-child(1)").each(function(i){
1071                         var idStr = $(this).prop("id").replace("tab-td_","");
1072                         afterTabsOrder.push(idStr);
1073                         link = ul.find("a[href='#"+ idStr+"']");
1074                         li = link.parent();
1075                         //li.remove();
1076                         firstTab = $("#workspace-tabs li:first-child");
1077                         lastTab = $("#workspace-tabs li:last-child");
1078                         li.insertAfter(lastTab);
1079                         //console.log( idStr);
1080                 });
1081                 var beforeTabsStr = beforeTabsOrder.join(",");
1082                 var afterTabsStr = afterTabsOrder.join(",");
1083                 //console.log("beforeTabsStr:" +beforeTabsStr);
1084                 //console.log("afterTabsStr:" +afterTabsStr);
1085                 if(beforeTabsStr !== afterTabsStr){
1086                         //activate only when order has changed
1087                         //activate the deploy button
1088                         RED.view.dirty(true);
1089                         $("#btn-deploy").removeClass("disabled");
1090                 }
1091         };
1092
1093         $("#ftab02 tbody").sortable({
1094         helper: fixHelperModified,
1095         stop: updateIndex
1096         }).disableSelection();
1097
1098 }
1099
1100 function getHtmlStr(rows){
1101         var styleStr = "<style> " + 
1102                         "table#ftab02 { width:100%; } \n" +
1103                                 "table#ftab02 th,table#ftab02 td { border: 1px solid black; border-collapse: collapse; } \n" +
1104                                 /*"table, th, td { border: 1px solid #65a9d7; border-collapse: collapse; } \n" +*/
1105                                 "table#ftab02 th,table#ftab02 td { padding: 5px; text-align: left; } \n" +
1106                                 "table#ftab02 tr:nth-child(even) { background-color: #eee; }\n" +
1107                                 "table#ftab02 tr:nth-child(odd) { background-color:#fff; }\n" +
1108                                 "table#ftab02 th        { background-color: #65a9d7; color: white; }\n" +
1109                                 "table#ftab02 a { color: #337ab7; }\n" +
1110                                 "table#ftab02 a:link { color: #65a9d7; }\n" +
1111                                 "table#ftab02 a:visited { color: #636; }\n" + 
1112                                 "table#ftab02 a:hover { color: #3366CC; cursor: pointer }\n" + 
1113                                 "table#ftab02 a:active { color: #65a9d7 }\n" +
1114                                 "</style>";
1115                         if(rows != null && rows != undefined){
1116                                 //var alertDialog = '<div id="confdialog"></div>';
1117                                 //htmlStr= alertDialog +  "<div style='width:1050;height:650'>" + styleStr;
1118                                 var alertDialog = '<div id="tabAlertDialog"></div>';
1119                                 htmlStr= alertDialog +  "<div id='tabs-div' style='width:1050;height:650'>" + styleStr;
1120                                 htmlStr += "<table id='ftab02' >";
1121                                 htmlStr += "<tr>";
1122                                 htmlStr += "<th class='index'>No.</th>" ;
1123                                 htmlStr += "<th>Tab Title</th>" ;
1124                                 htmlStr += "<th>Module</th>" ;
1125                                 htmlStr += "<th>RPC</th>" ;
1126                                 htmlStr += "<th>Version</th>" ;
1127                                 htmlStr += "<th>Rename</th>" ;
1128                                 htmlStr += "<th>Delete</th>" ;
1129                                 htmlStr += "</tr>";
1130                                 htmlStr += "<tbody>";
1131                                 if(rows != null && rows.length == 0){
1132                                         htmlStr += "<tr>";
1133                                         htmlStr += "<td><b>No rows found</b></td>";
1134                                         htmlStr += "</tr></table></div>";
1135                                         return htmlStr;
1136                                 }
1137                                 for(var i=0;i<rows.length;i++){
1138                                         var row = rows[i];
1139                                         var title = row.title;
1140                                         var _module = row.module;
1141                                         var version = row.version;
1142                                         var rpc = row.rpc;
1143                                         var idVal = row.id;
1144                                         var isVisible = row.isVisible;
1145                                         htmlStr += "<tr id='tab-tr_" + idVal + "'>";
1146                                         //htmlStr += "<td id=" + "'tab-td_" + idVal  + "' ><a href='javascript:activateClickedTab(\"" + idVal + "\")'>" + (i+1) + "</a></td>";
1147                                         htmlStr += "<td class='index' id=" + "'tab-td_" + idVal  + "' >" + (i+1) + "</td>";
1148                                         htmlStr += "<td><a href='javascript:activateClickedTab(\"" + idVal + "\")'>" + title + "</a></td>";
1149                                         htmlStr += "<td>" + _module + "</td>";
1150                                         htmlStr += "<td>" + rpc + "</td>";
1151                                         htmlStr += "<td>" + version + "</td>";
1152                                         //htmlStr += "<td><a href='javascript:deleteOrRenameTab(\"" + idVal + "\")'>Delete/Rename</a></td>";
1153                                         htmlStr += "<td><input type='button' onclick='renameSelectedTab(\"" + idVal + "\",\"" + title + "\",\"" +  _module + "\",\"" + rpc + "\",\"" + version + "\")' value='Rename'></td>";
1154                                         if(rows.length == 1){
1155                                                 htmlStr += "<td><input type='button' disabled='1' onclick='deleteSelectedTab(\"" + idVal + "\",\"" + title + "\",\"" +  _module + "\",\"" + rpc + "\",\"" + version + "\")' value='Delete'></td>";
1156                                         }else{
1157                                                 htmlStr += "<td><input type='button'  onclick='deleteSelectedTab(\"" + idVal + "\",\"" + title + "\",\"" +  _module + "\",\"" + rpc + "\",\"" + version + "\")' value='Delete'></td>";
1158                                         }
1159                                         /*
1160                                         if(isVisible){
1161                                                 htmlStr += "<td><input type='checkbox' onclick=\"showOrHideTab(this,'" + idVal + "')\" checked='true'></td>";
1162                                         }else{
1163                                                 htmlStr += "<td><input type='checkbox' onclick=\"showOrHideTab(this,'" + idVal + "')\"></td>";
1164                                         }
1165                                         */
1166                                         htmlStr += "</tr>";
1167                                 }
1168                                 htmlStr += "</tbody>";
1169                                 htmlStr += "</table>";
1170                                 htmlStr += "</div>";
1171                         }
1172         return htmlStr;
1173 }
1174 /*
1175 Added this logic because , when the configuration item is choosen in the menu the other dialog boxes were not poping up
1176 */
1177 (function(){
1178         //var msecs1= Date.now();
1179                 $( "#gitlocal-browser-dialog" ).dialog();
1180                 $( "#gitlocal-browser-dialog" ).dialog("close");
1181                 $( "#dgflow-browser-dialog" ).dialog();
1182                 $( "#dgflow-browser-dialog" ).dialog("close");
1183                 $( "#update-password-dialog" ).dialog();
1184                 $( "#update-password-dialog" ).dialog("close");
1185                 $( "#codecloud-browser-dialog" ).dialog();
1186                 $( "#codecloud-browser-dialog" ).dialog("close");
1187                 $( "#update-configuration-dialog" ).dialog();
1188                 $( "#update-configuration-dialog" ).dialog("close");
1189                 $( "#gitcommands-dialog" ).dialog();
1190                 $( "#gitcommands-dialog" ).dialog("close");
1191                 $("#filter-tabs-dialog").dialog();
1192                 $("#filter-tabs-dialog").dialog("close");
1193                 $("#loop-detection-dialog").dialog();
1194                 $("#loop-detection-dialog").dialog("close");
1195                 $("#dgstart-generate-xml-dialog").dialog();
1196                 $("#dgstart-generate-xml-dialog").dialog("close");
1197                 $("#xmldialog").dialog();
1198                 $("#xmldialog").dialog("close");
1199                 $("#upload-xml-status-dialog").dialog();
1200                 $("#upload-xml-status-dialog").dialog("close");
1201                 $("#flow-design-err-dialog").dialog();
1202                 $("#flow-design-err-dialog").dialog("close");
1203                 $("#sli-values-dialog").dialog();
1204                 $("#sli-values-dialog").dialog("close");
1205                 $("#comments-dialog").dialog();
1206                 $("#comments-dialog").dialog("close");
1207                 $("#show-errors-dialog").dialog();
1208                 $("#show-errors-dialog").dialog("close");
1209                 $("#dgnumber-find-dialog").dialog();
1210                 $("#dgnumber-find-dialog").dialog("close");
1211                 $("#search-text-dialog").dialog();
1212                 $("#search-text-dialog").dialog("close");
1213                 $("#yang-upload-dialog").dialog();
1214                 $("#yang-upload-dialog").dialog("close");
1215                 $("#yang-modules-browser-dialog").dialog();
1216                 $("#yang-modules-browser-dialog").dialog("close");
1217                 $("#list-yang-browser-dialog").dialog();
1218                 $("#list-yang-browser-dialog").dialog("close");
1219                 $("#request-input-dialog").dialog();
1220                 $("#request-input-dialog").dialog("close");
1221                 $("#test-dg-dialog").dialog();
1222                 $("#test-dg-dialog").dialog("close");
1223                 $("#ctx-values-dialog").dialog();
1224                 $("#ctx-values-dialog").dialog("close");
1225                 $("#list-input-browser-dialog").dialog();
1226                 $("#list-input-browser-dialog").dialog("close");
1227                 $("#diff-browser-dialog").dialog();
1228                 $("#diff-browser-dialog").dialog("close");
1229                 //var msecs2= Date.now();
1230                 //console.log("Time taken for dialog boxes:" + (msecs2 - msecs1));
1231 })();
1232
1233
1234         //start functions to support Test DG
1235         function testDG(){
1236                 getSliParametersFromDG();
1237                 /*
1238                 for (var property in callNodes) {
1239                         if (callNodes.hasOwnProperty(property)) {
1240                                 console.log(property);
1241                                 var moduleRpc = property.split("_");
1242                                 var mName = moduleRpc[0];
1243                                 var rName = moduleRpc[1];
1244                         }
1245                 }
1246                 */
1247                 showTestDGDialog();
1248         }
1249         
1250
1251         function  showInputFiles(files){
1252                 var divStyle="<style>#input-files-data-container a { color: #067ab4; font-size: 0.75em;} #input-files-data-container a:hover { text-decoration: underline; padding: -15px -15px -15px 15px; } .header { height: 40px; border-bottom: 1px solid #EEE; background-color: #ffffff; height: 40px; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; } .footer { height: 40px; background-color: whiteSmoke; border-top: 1px solid #DDD; -webkit-border-bottom-left-radius: 5px; -webkit-border-bottom-right-radius: 5px; -moz-border-radius-bottomleft: 5px; -moz-border-radius-bottomright: 5px; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; } table#input-file-list-table { width:100%; } table#input-file-list-table th,table#input-file-list-table td { border: 1px solid black; border-collapse: collapse; } table#input-file-list-table th,table#input-file-list-table td { padding: 5px; text-align: left; } table#input-file-list-table tr:nth-child(even) { background-color: #eee; } table#input-file-list-table tr:nth-child(odd) { background-color:#fff; } table#input-file-list-table th  { background-color: #65a9d7; color: white; } table#input-file-list-table a { color: #337ab7; } table#input-file-list-table a:link { color: #65a9d7; } table#input-file-list-table a:visited { color: #636; } table#input-file-list-table a:hover { color: #3366CC; cursor: pointer } table#input-file-list-table a:active { color: #65a9d7 }</style>";
1253                                         
1254                 var header="<div class='header'>List of Input Files </div>";
1255                         var html=  divStyle + header +  "<div id='input-files-data-container'>";
1256                         html+="<table id='input-file-list-table'  border=1>";
1257                                         html+="<tr>";
1258                                         html+="<th>File</th>";
1259                                         html+="<th>Delete</th>";
1260                                         html+="</tr>";
1261                                         files.sort(function (a,b){
1262                                                         if(a > b){
1263                                                                 return -1;
1264                                                         }else if(a <  b){
1265                                                                 return 1;
1266                                                         }else{  
1267                                                                 return 0;
1268                                                         }
1269                                         });
1270                                         for(var i=0;files != null && i<files.length;i++){
1271                                                         html+="<tr><td><a href=\"#\" onclick=\"loadInputFile('" + files[i] + "')\">" + files[i] + "</a></td><td>" + "<input type='button'  onclick='deleteInputFile(\"" + files[i]  + "\")' value='Delete'></td></td></td></tr>";
1272                                         }
1273                         html+="</table>";
1274                         html+="</div>";
1275                         $( "#list-input-browser-dialog" ).dialog({
1276                                         title: "List Input Files",
1277                                         modal: true,
1278                                         autoOpen: true,
1279                                         width: 830,
1280                                         height: 630,
1281                                         buttons: [
1282                                                 {
1283                                                         text: "Close",
1284                                                         click: function() {
1285                                                                 $( this ).dialog( "close" );
1286                                                         }
1287                                                 }
1288                                                 ],
1289                                         close: function(ev,ui){
1290                                                 $(this).dialog("destroy");
1291                                         }
1292                                 }).html(html);
1293                         $("#list-input-browser-dialog").show();
1294         }
1295                 
1296
1297         function showTestDGDialog(){
1298            $.get("/getCurrentSettings",function (data){
1299                 var activeWorkspace=RED.view.getWorkspace();
1300                 var currNodes =  RED.nodes.nodes.filter(function(d) { return d.z == activeWorkspace })
1301                 var moduleName = "";
1302                 var rpcName = "";
1303                 if(currNodes != null && currNodes.length > 1){
1304                         currNodes.forEach(function(n){
1305                                 if(n.type == 'service-logic'){
1306                                         moduleName = getAttributeValue(n.xml,"module");
1307                                 }else if(n.type == 'method'){
1308                                         rpcName = getAttributeValue(n.xml,"rpc");
1309                                 }
1310                         });
1311                 }
1312
1313                 var sliApiInputObj = { "input" : { "module-name" : moduleName, "rpc-name" : rpcName, "mode" : "sync", "sli-parameter" : []}};
1314                 var intParameterObj = { "parameter-name" : "", "int-value": 0};
1315                 var booleanParameterObj = { "parameter-name" : "", "boolean-value": true};
1316                 /*
1317                 //Use this logic to add all the Ctx variables that have -input.
1318                 Object.keys(dgParsedParameters).forEach(function(key,index) {
1319                         //console.log("key:" + key + " index" +index );
1320                         if(key.indexOf("-input.") != -1){
1321                                 key = key.replace(/\$/g,"");
1322                                 var strParameterObj = { "parameter-name" : key, "string-value": ""};
1323                                 sliApiInputObj["input"]["sli-parameter"].push(strParameterObj); 
1324                         }
1325                 });
1326                 */
1327
1328                 var sliApiInputStr = JSON.stringify(sliApiInputObj,null,4);
1329                 
1330                 //var htmlStr="<div id='request-template-div' style='width:875px;height:575px'><textarea style='width:875px;height:575px'>" + inputValStr + "</textarea></div>"
1331                 //var htmlStr="<div id='request-template-div' style='width:750px;height:550px;font-weight:bold;font-size:1em'><pre>" + inputValStr + "</pre></div>"
1332                 //var htmlStr = "<div id='test-dg-div' style='width:750px;height:50px'>"; 
1333                 var htmlStr = "<label style='font-weight:bold;font-size:1em'>URL</label><input id='test-dg-url' type='textbox' style='width:743px;height:30px;font-weight:bold;font-size:1em' value='" + data.restConfUrl + "'><br><br><label style='font-weight:bold;font-size:1em'>Method</label><input type='radio' name='methodType' value='GET'> GET <input type='radio' name='methodType' value='POST' checked> POST  <input type='radio' name='methodType' value='PUT' > PUT  <input type='radio' name='methodType' value='DELETE' > DELETE <br><br><label style='font-weight:bold;font-size:1em'>Input</label>"; 
1334                 htmlStr +="<textarea  id='test-dg-request' style='width:750px;height:350px;font-size:1em' >" + sliApiInputStr + "</textarea><br><br><label style='font-weight:bold;font-size:1em'>Response</label><textarea  id='test-dg-response' style='width:750px;height:150px;font-weight:bold;font-size:1em'></textarea>"
1335                         //background: "#c3e8d1",
1336                 $("#test-dg-dialog").dialog({
1337                         dialogClass :"no-close",
1338                         modal:true,     
1339                         autoOpen :false,
1340                         title: "Test DG Module:" + moduleName + "    RPC:" + rpcName,
1341                         width: 800,
1342                         height: "auto",
1343                         buttons :[
1344                         {
1345                                 text: "$Variables",
1346                                 click: function() {
1347                                         $("#test-dg-response").val("");
1348                                         showCtxVariables(moduleName,rpcName);
1349                                         //console.dir(dgParsedParameters);
1350                                 }
1351                         },
1352                         {
1353                                 text: "Load",
1354                                 click: function() {
1355                                         var inputData = {
1356                                                         "moduleName" : moduleName,
1357                                                         "rpcName" : rpcName
1358                                         };
1359
1360                                          $.post( "/getInputFiles",inputData )
1361                                                 .done(function( data ) { 
1362                                                         //console.dir(data);
1363                                                         if(data != undefined && data != null){
1364                                                                 showInputFiles(data.files);
1365                                                         }
1366                                                 })
1367                                                 .fail(function(err) {
1368                                                         console.log( "failed to save input. " + err );
1369                                                 })
1370                                                 .always(function() {
1371                                                 });
1372                                 }
1373                         },
1374                         {
1375                                 text: "Send",
1376                                 click: function() {
1377                                         $("#test-dg-response").val("");
1378                                         var methodType =$("input[name=methodType]:checked").val();
1379                                         var urlValue = $("#test-dg-url").val();
1380                                         var reqData = {};
1381                                         try{
1382                                                  reqData = JSON.parse($("#test-dg-request").val());
1383                                         }catch(er){
1384                                                         $("#test-dg-response").val(er);         
1385                                                         return false;
1386                                         }
1387                                         //console.log("urlValue:" + urlValue);
1388                                         //console.dir(reqData);
1389                                         var inputStr = $("#test-dg-request").val();
1390                                         //headers: { 'Authorization': 'Basic ' + btoa(data.restConfUser + ":" + data.restConfPassword)},
1391                                                 var inputData = {
1392                                                                 "moduleName" : moduleName,
1393                                                                 "rpcName" : rpcName,
1394                                                                 "inputStr" : inputStr
1395                                                 };
1396
1397                                                  $.post( "/saveTestDGInput",inputData )
1398                                                         .done(function( data ) {
1399                                                                 
1400                                                         })
1401                                                         .fail(function(err) {
1402                                                                 console.log( "failed to save input. " + err );
1403                                                         })
1404                                                         .always(function() {
1405                                                                 $.ajax({
1406                                                                         xhrFields: { withCredentials: true },
1407                                                                         type: methodType,
1408                                                                         url: urlValue,
1409                                                                         data: JSON.stringify(reqData),
1410                                                                         contentType: "application/json; charset=utf-8",
1411                                                                         username : data.restConfUser,
1412                                                                         password : data.restConfPassword,
1413                                                                         success: function(data) {
1414                                                                         if(data != null){
1415                                                                                 $("#test-dg-response").val(JSON.stringify(data,null,4));
1416                                                                         }else{
1417                                                                                 $("#test-dg-response").val("No Content returned");
1418                                                                         }
1419                                                                 },
1420                                                                 error: function(err) {
1421                                                                         if(err != null){
1422                                                                                 $("#test-dg-response").val(JSON.stringify(err,null,4));         
1423                                                                         }else{
1424                                                                                 $("#test-dg-response").val("error Occured");
1425                                                                         }
1426                                                                 }
1427                                                                 });
1428                                                         }); 
1429                                 }
1430                         },
1431                         {
1432                                 text: "Reset",
1433                                 click: function() {
1434                                         $("#test-dg-request").val(sliApiInputStr);
1435                                         $("#test-dg-response").val("");
1436                                 }
1437                         },
1438                         {
1439                                 text: "Close",
1440                                 click: function() {
1441                                         $("#test-dg-dialog").dialog("close");
1442                                 }
1443                         }
1444                         ],
1445                         open:function(){
1446                                  $('#test-dg-dialog').css('overflow', 'hidden'); 
1447                         }
1448                 }).dialog("open").html(htmlStr).css("background","aliceblue");
1449         });
1450         }
1451         //end functions to support Test DG
1452         
1453
1454         function updateConfiguration(){
1455                 //console.log("in updateConfiguration");
1456                 $.get("/getCurrentSettings",function (data){
1457                 var dbHost = data.dbHost;
1458                 var dbPort = data.dbPort;
1459                 var dbName = data.dbName;
1460                 var dbUser = data.dbUser;
1461                 var dbPassword = data.dbPassword;
1462                 var formatXML = data.formatXML;
1463                 var formatJSON = data.formatJSON;
1464                 var gitLocalRepository = data.gitLocalRepository;
1465                 var performGitPull = data.performGitPull;
1466
1467                 var restConfUrl = data.restConfUrl;
1468                 var restConfUser = data.restConfUser;
1469                 var restConfPassword = data.restConfPassword;
1470                 var emailAddress = data.emailAddress;
1471
1472                 if(dbHost == undefined) dbHost="";
1473                 if(dbPort == undefined) dbPort="";
1474                 if(dbName == undefined) dbName="";
1475                 if(dbUser == undefined) dbUser="";
1476                 if(dbPassword == undefined) dbPassword="";
1477                 if(gitLocalRepository == undefined) gitLocalRepository="";
1478                 if(performGitPull  == undefined || performGitPull == null) performGitPull="N";
1479                 if(restConfUrl == undefined) restConfUrl="";
1480                 if(restConfUser == undefined) restConfUser="";
1481                 if(restConfPassword == undefined) restConfPassword="";
1482                 if(emailAddress == undefined) emailAddress="";
1483                 if(formatXML == undefined) formatXML="Y";
1484                 if(formatJSON == undefined) formatJSON="Y";
1485
1486                 var divStyle="border: 1px solid #a1a1a1; padding: 10px 40px; background: #dddddd; width: 600px; border-radius: 25px;";
1487                 //var divStyle="border: 2px solid #a1a1a1; padding: 10px 40px; background: #99CCFF; width: 400px; border-radius: 25px;";
1488         
1489
1490                    var  html = "<div>";
1491                         html += "<script>function changeType(obj,targetId){if( obj.checked== true){$('#' + targetId).prop('type','password');}else{$('#'+ targetId).prop('type','text');}} function changeTitle(){ document.getElementById(\"gitLocalRepository\").title=document.getElementById(\"gitLocalRepository\").value;} function changeTitle1(){ document.getElementById(\"restconfurl\").title=document.getElementById(\"restconfurl\").value;}</script>";
1492                         html += "<div style='" + divStyle + "' >";
1493                         html += "<table border='0' cellpadding='5' >";
1494                         html += "<tr>";
1495                         html += "<td style='font-size:12px;align:center'><b>DB Host IP</b></td>";
1496                         html += "<td><input  style='align:center;font-size:11px;font-weight:bold' id='dbhost' name='dbhost' type='text' value='" + dbHost + "'></td>";
1497                         html += "</tr>";
1498                         html += "<tr>";
1499                         html += "<td style='font-size:12px;align:center'><b>DB Port</b></td>";
1500                         html += "<td><input style='align:center;font-size:11px;font-weight:bold' id='dbport' name='dbport' type='text' value='" + dbPort + "'></td>";
1501                         html += "</tr>";
1502                         html += "<tr>";
1503                         html += "<td style='font-size:12px;align:center'><b>DB Name</b></td>";
1504                         html += "<td><input style='align:center;font-size:11px;font-weight:bold' id='dbname' name='dbname' type='text' value='" + dbName + "'></td>";
1505                         html += "</tr>";
1506                         html += "<tr>";
1507                         html += "<td style='font-size:12px;align:center'><b>DB UserName</b></td>";
1508                         html += "<td><input style='align:center;font-size:11px;font-weight:bold' id='dbuser' name='dbuser' type='password' value='" + dbUser + "'></td>";
1509                         html += "<td><input style='background:background:white;width:20px;height:20px' type='checkbox' checked value='1' onclick=\"changeType(this,'dbuser')\">Hide</td>";
1510                         html += "</tr>";
1511                         html += "<tr>";
1512                         html += "<td style='font-size:12px;align:center'><b>DB Password</b></td>";
1513                         html += "<td><input style='align:center;font-size:11px;font-weight:bold' id='dbpassword' name='dbpassword' type='password' value='" + dbPassword + "'></td>";
1514                         html += "<td><input style='background:background:white;width:20px;height:20px' type='checkbox' checked value='1' onclick=\"changeType(this,'dbpassword')\">Hide</td>";
1515                         html += "</tr>";
1516                         html += "</table>";
1517                         html += "</div>";
1518                         html += "<div style='fill:both;clear:both'></div><br>";
1519                         html += "<div style='" + divStyle + "' >";
1520                         html += "<table border='0' cellpadding='5' >";
1521                         html += "<tr>";
1522                         html += "<td style='font-size:12px;align:center'><b>RestConf URL</b></td>";
1523                         html += "<td><textarea style='align:center;font-size:14px;width:100%' cols='100' rows='4' id='restconfurl' name='restconfurl' onkeyup='changeTitle1()' title='" + restConfUrl + "'>" + restConfUrl + "</textarea></td>";
1524                         html += "</tr>";
1525                         html += "<tr>";
1526                         html += "<td style='font-size:12px;align:center'><b>RestConf UserName</b></td>";
1527                         html += "<td><input style='align:center;font-size:11px;font-weight:bold' id='restconfuser' name='restconfuser' type='password' value='" + restConfUser + "'>";
1528                         html += "&nbsp;&nbsp;<input style='background:background:white;width:20px;height:20px' type='checkbox' checked value='1' onclick=\"changeType(this,'restconfuser')\">Hide</td>";
1529                         html += "</tr>";
1530                         html += "<tr>";
1531                         html += "<td style='font-size:12px;align:center'><b>RestConf Password</b></td>";
1532                         html += "<td><input style='align:center;font-size:11px;font-weight:bold' id='restconfpassword' name='restconfpassword' type='password' value='" + restConfPassword + "'>";
1533                         html += "&nbsp;&nbsp;<input style='background:background:white;width:20px;height:20px' type='checkbox' checked value='1' onclick=\"changeType(this,'restconfpassword')\">Hide</td>";
1534                         html += "</tr>";
1535                         html += "</table>";
1536                         html += "</div>";
1537                         html += "<div style='fill:both;clear:both'></div><br>";
1538         
1539                         html += "<div style='" + divStyle + "' >";
1540                         html += "<table border='0' cellpadding='5' width='100%' >";
1541                         html += "<tr>";
1542                         html += "<td style='font-size:12px;align:center'><b>Git Local Repository Path</b></td>";
1543                         html += "<td><textarea style='align:center;font-size:14px;width:100%' cols='100' rows='4' id='gitLocalRepository' name='gitLocalRepository' onkeyup='changeTitle()' title='" + gitLocalRepository + "'>" + gitLocalRepository + "</textarea></td>";
1544                         html += "</tr>";
1545                         html += "</table>";
1546                         html += "<table border='0' cellpadding='5' >";
1547                         html += "<tr>";
1548                         if(performGitPull == "N"){
1549                                 html += "<td style='align:center;'><input style='color:blue;width:20px;height:20px;' id='performGitPull' type='checkbox' value='Y'>Perform Git Pull in Local Git Repository prior to import</td>";
1550                         }else{
1551                                 html += "<td style='align:center;'><input style='color:blue;width:20px;height:20px;' id='performGitPull' type='checkbox' value='Y' checked>Perform Git Pull in Local Git Repository prior to import</td>";
1552                         }
1553                         html += "</tr>";
1554                         html += "</table>";
1555                         html += "</div>";
1556                         html += "<div style='fill:both;clear:both'></div><br>";
1557         
1558                         html += "<div style='" + divStyle + "' >";
1559                         html += "<table border='0' cellpadding='5' width='100%' >";
1560                         html += "<tr>";
1561                         html += "<td style='font-size:12px;align:center'><b>Email</b></td>";
1562                         html += "<td><input style='align:center;font-size:11px;font-weight:bold' id='emailaddress' name='emailaddress' type='text' value='" + emailAddress + "'></td>";
1563                         html += "</tr>";
1564                         html += "<tr>";
1565                         if(formatXML == "Y"){
1566                                 html += "<td style='align:center;'><input style='color:blue;width:20px;height:20px;' id='formatXML' type='checkbox' value='Y' checked><b>Format XML</b></td>";
1567                         }else{
1568                                 html += "<td style='align:center;'><input style='color:blue;width:20px;height:20px;' id='formatXML' type='checkbox' value='Y'><b>Format XML</b></td>";
1569                         }
1570                         if(formatJSON == "Y"){
1571                                 html += "<td style='align:center;'><input style='color:blue;width:20px;height:20px;' id='formatJSON' type='checkbox' value='Y' checked><b>Format JSON</b></td>";
1572                         }else{
1573                                 html += "<td style='align:center;'><input style='color:blue;width:20px;height:20px;' id='formatJSON' type='checkbox' value='Y'><b>Format JSON</b></td>";
1574                         }
1575                         html += "</tr>";
1576                         html += "</table>";
1577                         html += "</div>";
1578                         html += "</div>";
1579                         //console.log("html:" + html);
1580                 $( "#update-configuration-dialog" ).dialog({
1581                         title: "Configuration",
1582                         modal: true,
1583                         autoOpen: true,
1584                         width: 730,
1585                         height: 930,
1586                         buttons: [
1587                                 {
1588                                 text: "Save",
1589                                 click: function() {
1590                                         var newDBHost = $("#dbhost").val().trim();
1591                                         var newDBPort = $("#dbport").val().trim();
1592                                         var newDBName = $("#dbname").val().trim();
1593                                         var newDBUser = $("#dbuser").val().trim();
1594                                         var newDBPassword = $("#dbpassword").val().trim();
1595                                         var newGitLocalRepository = $("#gitLocalRepository").val().trim();
1596
1597                                         var isFormatXML = $('#formatXML').is(':checked');
1598                                         var isFormatJSON = $('#formatJSON').is(':checked');
1599                                         var isPerformGitPullChecked = $('#performGitPull').is(':checked');
1600                                         var newRestConfUrl = $("#restconfurl").val().trim();
1601                                         var newRestConfUser = $("#restconfuser").val().trim();
1602                                         var newRestConfPassword = $("#restconfpassword").val().trim();
1603                                         var newPerformGitPull = "N";
1604                                         var newEmailAddress = $("#emailaddress").val().trim();
1605                                         //console.log("newEmailAddress:" + newEmailAddress);
1606                                         if(isPerformGitPullChecked){
1607                                                 newPerformGitPull = "Y";
1608                                         }
1609                                         if(isFormatXML){
1610                                                 newFormatXML = "Y";
1611                                         }else{
1612                                                 newFormatXML = "N";
1613                                         }
1614                                         if(isFormatJSON){
1615                                                 newFormatJSON = "Y";
1616                                         }else{
1617                                                 newFormatJSON = "N";
1618                                         }
1619                                         if(newDBHost == ""){
1620                                                 RED.notify("Error: DB Host is required.");              
1621                                                 $("#dbhost").focus();
1622                                                 return;
1623                                         }else if(newDBPort == ""){
1624                                                 RED.notify("Error: DB Port is required.");              
1625                                                 $("#dbport").focus();
1626                                                 return;
1627                                         }else if(newDBName == ""){
1628                                                 RED.notify("Error: DB Name is required.");              
1629                                                 $("#dbname").focus();
1630                                                 return;
1631                                         }else if(newDBUser == ""){
1632                                                 RED.notify("Error: DB User is required.");              
1633                                                 $("#dbuser").focus();
1634                                                 return;
1635                                         }else if(newDBPassword == ""){
1636                                                 RED.notify("Error: DB Password is required.");          
1637                                                 $("#dbpassword").focus();
1638                                                 return;
1639                                         }else if(newEmailAddress == ""){
1640                                                 RED.notify("Error: Email Address is required.");                
1641                                                 $("#emailaddress").focus();
1642                                                 return;
1643                                         }else{ 
1644                                                 //console.log("newGitLocalRepository:" + newGitLocalRepository);
1645                                                 var reqData= {"dbHost":newDBHost,
1646                                                                 "dbPort" : newDBPort,
1647                                                                 "dbName" : newDBName,
1648                                                                 "dbUser" : newDBUser,
1649                                                                 "dbPassword" : newDBPassword,
1650                                                                 "gitLocalRepository" : newGitLocalRepository, 
1651                                                                 "performGitPull" : newPerformGitPull ,
1652                                                                 "formatXML": newFormatXML,
1653                                                                 "formatJSON": newFormatJSON,
1654                                                                 "restConfUrl" : newRestConfUrl,
1655                                                                 "restConfUser" : newRestConfUser,
1656                                                                 "restConfPassword" : newRestConfPassword,
1657                                                                 "emailAddress" : newEmailAddress
1658                                                              };
1659                                                  $.post( "/updateConfiguration",reqData )
1660                                                 .done(function( data ) {
1661                                                         RED.settings.emailAddress = newEmailAddress;
1662                                                         format_xml = newFormatXML;
1663                                                         format_json = newFormatJSON;
1664                                                         RED.notify("Configuration updated successfully"); 
1665                                                         //loadSettings();
1666                                                         //RED.comms.connect();
1667                                                         //$( "#update-configuration-dialog" ).dialog('close');
1668                                                         $("#update-configuration-dialog").dialog("close");
1669                                                         //location.reload();
1670                                                                 
1671                                                 })
1672                                                 .fail(function(err) {
1673                                                         console.log( "error" + err );
1674                                                         RED.notify("Failed to update the Configuration.");
1675                                                 })
1676                                                 .always(function() {
1677                                                 });
1678                                         }
1679                                    }
1680                                 },
1681                                 {
1682                                         text: "Cancel",
1683                                         click: function() {
1684                                                 $( this ).dialog( "close" );
1685                                         }
1686                                 }
1687                         ]
1688                 }).html(html);
1689                 //$("#update-configuration-dialog").show();
1690                 $("#gitLocalRepository").css({"width" : 300});
1691
1692                 });
1693         }
1694
1695         function updatePassword(){
1696                 var html="<div>";
1697                         html += "<div><span><b>New Password</b></span><br>";
1698                         html += "<input id='passwd1' name='passwd1' type='password' value=''>";
1699                         html += "</div>";
1700                         html += "<div><span><b>Confirm Password</b></span><br>";
1701                         html += "<input id='passwd2' name='passwd2' type='password' value=''>";
1702                         html += "</div>";
1703                 $( "#update-password-dialog" ).dialog({
1704                         title: "Update Password",
1705                         modal: true,
1706                         autoOpen: true,
1707                         width: 530,
1708                         height: 230,
1709                         buttons: [
1710                                 {
1711                                 text: "Update Password",
1712                                 click: function() {
1713                                         var passwd1 = $("#passwd1").val().trim();
1714                                         var passwd2 = $("#passwd2").val().trim();
1715                                         if((passwd1 != passwd2) || (passwd1 == "" || passwd2 == "")){
1716                                                 RED.notify("Error:Passwords entered must be same and must be populated.");              
1717                                                 return;
1718                                         }else{ 
1719                                                 var reqData= {"password":passwd1};
1720                                                  $.post( "/updatePassword",reqData )
1721                                                 .done(function( data ) {
1722                                                         RED.notify("Password updated successfully"); 
1723                                                         //loadSettings();
1724                                                         $( "#update-password-dialog" ).dialog('close');
1725                                                 })
1726                                                 .fail(function(err) {
1727                                                         console.log( "error" + err );
1728                                                         RED.notify("Failed to update the password.");
1729                                                 })
1730                                                 .always(function() {
1731                                                 });
1732                                         }
1733                                    }
1734                                 },
1735                                 {
1736                                         text: "Cancel",
1737                                         click: function() {
1738                                                 $( this ).dialog( "close" );
1739                                         }
1740                                 }
1741                         ]
1742                 }).html(html);
1743                 $("#update-password-dialog").show();
1744
1745         }
1746
1747         function  showAvailableYangModules(){
1748                 availableYangModules=[];
1749                 var divStyle="<style>#yang-modules-data-container a { color: #067ab4; font-size: 0.75em;} #yang-modules-data-container a:hover { text-decoration: underline; padding: -15px -15px -15px 15px; } .header { height: 40px; border-bottom: 1px solid #EEE; background-color: #ffffff; height: 40px; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; } .footer { height: 40px; background-color: whiteSmoke; border-top: 1px solid #DDD; -webkit-border-bottom-left-radius: 5px; -webkit-border-bottom-right-radius: 5px; -moz-border-radius-bottomleft: 5px; -moz-border-radius-bottomright: 5px; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; } table#yang-list-table { width:100%; } table#yang-list-table th,table#yang-list-table td { border: 1px solid black; border-collapse: collapse; } table#yang-list-table th,table#yang-list-table td { padding: 5px; text-align: left; } table#yang-list-table tr:nth-child(even) { background-color: #eee; } table#yang-list-table tr:nth-child(odd) { background-color:#fff; } table#yang-list-table th        { background-color: #65a9d7; color: white; } table#yang-list-table a { color: #337ab7; } table#yang-list-table a:link { color: #65a9d7; } table#yang-list-table a:visited { color: #636; } table#yang-list-table a:hover { color: #3366CC; cursor: pointer } table#yang-list-table a:active { color: #65a9d7 }</style>";
1750                 $.get( "/listAvailableModules")
1751                                .done(function( data ) {
1752                                         var header="<div class='header'>List of Available Yang Modules</div>";
1753                                         header += "<div><p><i>Check the modules that you want to load and click on the Load button.</i></p></div>";     
1754                                         //header += "<div><input id='yangModuleFilterBoxId' type='text' onkeyup='filterYangModules(this.value)'></div>";
1755                                         var html=  divStyle + header +  "<div id='yang-modules-data-container'>";
1756                                         html+="<table id='yang-list-table'  border=1>";
1757                                         html+="<tr>";
1758                                         html+="<th>#</th>";
1759                                         html+="<th>Load</th>";
1760                                         html+="<th>Module</th>";
1761                                         html+="</tr>";
1762                                         if(data != null){
1763                                                 var files=data.files;
1764                                                 availableYangModules=files;
1765                                                 //console.dir(files);
1766                                                 files.sort(function (a,b){
1767                                                         if(a > b){
1768                                                                 return 1;
1769                                                         }else if(a <  b){
1770                                                                 return -1;
1771                                                         }else{  
1772                                                                 return 0;
1773                                                         }
1774                                                 });
1775                                                 var count=1;
1776                                                 for(var i=0;files != null && i<files.length;i++){
1777                                                         var val = files[i].replace(/:.*/,"");
1778                                                         if(files[i].indexOf(":checked") != -1){
1779                                                                 html+="<tr><td>" + count + "</td><td><input type='checkbox' checked value='" + val + "'></td><td>" + val + "</td></tr>";
1780                                                         }else{
1781                                                                 html+="<tr><td>" + count + "</td><td><input type='checkbox' value='" + val + "'></td><td>" + val + "</td></tr>";
1782                                                         }
1783                                                         count++;
1784                                                 }
1785                                         }
1786                                         html+="</table>";
1787                                         html+="</div>";
1788                                         $( "#yang-modules-browser-dialog" ).dialog({
1789                                         title: "Available Yang Modules",
1790                                         modal: true,
1791                                         autoOpen: true,
1792                                         width: 830,
1793                                         height: 630,
1794                                         buttons: [
1795                                                 {
1796                                                         text: "Load",
1797                                                         click: function() {
1798                                                                 var allVals = [];
1799                                                                 function getValuesForSelected() {         
1800                                                                         $('#yang-modules-data-container :checked').each(function() {
1801                                                                                 allVals.push($(this).val());
1802                                                                         });
1803                                                                         return allVals;
1804                                                                 }
1805                                                                 var selectedModules = getValuesForSelected().toString();
1806                                                                 console.log(selectedModules);
1807                                                                 $.ajax({
1808                                                                         type: 'GET',
1809                                                                         /*contentType: "application/x-www-form-urlencoded",*/
1810                                                                         url: '/loadSelectedModules?selectedModules=' + selectedModules,
1811                                                                         success: function(data) {
1812                                                                                 RED.notify("Modules Loaded successfully"); 
1813                                                                                 //emptying existing g;obal variables
1814                                                                                 sliValuesObj = {};
1815                                                                                 rpcValues = {};
1816                                                                                 reqInputValues = {};
1817
1818                                                                                 if(data != undefined && data != null){
1819                                                                                         for(var i=0;i<data.sliValuesObj.length;i++){
1820                                                                                                 var moduleName = data.sliValuesObj[i].moduleName;
1821                                                                                                 sliValuesObj[moduleName] = data.sliValuesObj[i][moduleName + '_PROPS'];
1822                                                                                                 rpcValues[moduleName] = data.sliValuesObj[i][ moduleName +'_RPCS'];
1823                                                                                                 for(var k=0;rpcValues[moduleName] != undefined && k<rpcValues[moduleName].length;k++){
1824                                                                                                         var rpcName = rpcValues[moduleName][k];
1825                                                                                                         reqInputValues[moduleName + "_" + rpcName] = data.sliValuesObj[i][rpcName +"-input"];
1826                                                                                                         //console.dir(reqInputValues);
1827                                                                                                 }
1828                                                                                         }
1829                                                                                 }
1830                                                                                 $( "#yang-modules-browser-dialog" ).dialog('close');
1831                                                                                 console.log('success');
1832                                                                                 //console.log(JSON.stringify(data));                               
1833                                                                         },
1834                                                                         error: function(error) {
1835                                                                                 RED.notify("Failed to load modules.");
1836                                                                                 console.log("some error in fetching the notifications");
1837                                                                         }
1838                                                                 });     
1839                                                         }
1840                                                 },
1841                                                 {
1842                                                         text: "Close",
1843                                                         click: function() {
1844                                                                 $(this).dialog("close");
1845                                                         }
1846                                                 }
1847                                                 ]
1848                                         }).html(html);
1849                                         $("#yang-modules-browser-dialog").show();
1850                                })
1851                                 .fail(function(err) {
1852                                          RED.notify("Failed to get yang modules.");
1853                                 })
1854                                  .always(function() {
1855                                         console.log("Done displaying");
1856                                 });
1857         }
1858
1859
1860     $(function() {
1861         RED.menu.init({id:"btn-sidemenu",
1862             options: [
1863                 {id:"btn-sidebar",icon:"fa fa-columns",label:"Sidebar   (Ctrl+Space)",toggle:true,onselect:RED.sidebar.toggleSidebar},
1864                 null,
1865                 {id:"btn-manage-yang-modules-menu",icon:"fa fa-sign-in",label:"Manage Yang Modules",options:[
1866                     {id:"btn-yang-upload",icon:"fa fa-clipboard",label:"Upload Yang File",onselect:RED.view.showYangUploadDialog},
1867                     {id:"btn-available-yang-modules",icon:"fa fa-clipboard",label:"Available Yang Modules",onselect:showAvailableYangModules},
1868                     {id:"btn-list-yang-files",icon:"fa fa-clipboard",label:"List Yang Files",onselect:listYangFiles},
1869                 ]},
1870                 null,
1871                /* {id:"btn-dg-diff-menu",icon:"fa fa-sign-in",label:"DG diff",options:[
1872                     {id:"btn-diff-json",icon:"fa fa-clipboard",label:"Json diff since import",onselect:RED.view.diffJsonSinceImportDialog},
1873                     {id:"btn-diff-xml",icon:"fa fa-clipboard",label:"XML diff since import",onselect:RED.view.diffXmlSinceImportDialog},
1874                 ]},
1875                 null,*/
1876                 {id:"btn-configure-upload",icon:"fa fa-book",label:"Configuration",toggle:false,onselect:updateConfiguration},
1877                 null,
1878                 {id:"btn-manage-tabs",icon:"fa fa-info",label:"Manage Tabs",toggle:false,onselect:showSelectedTabs},
1879                 null,
1880                 {id:"btn-test-dg",icon:"fa fa-book",label:"Test DG",toggle:false,onselect:testDG},
1881                 null,
1882                 {id:"btn-find-dgnumber",icon:"fa fa-info",label:"Search Text (Ctrl+[)",toggle:false,onselect:RED.view.showSearchTextDialog},
1883                 null,
1884                 {id:"btn-find-dgnumber",icon:"fa fa-info",label:"Find Node (Ctrl+B)",toggle:false,onselect:RED.view.showDgNumberDialog},
1885                 null,
1886                 {id:"btn-request-input",icon:"fa fa-info",label:"RPC Input (Ctrl+O)",toggle:false,onselect:RED.view.showRequestTemplateDialog},
1887                 null,
1888                 /*{id:"btn-loop-detection",icon:"fa fa-info",label:"Loop Detection",toggle:true,onselect:performLoopDetection},
1889                null ,*/
1890                 {id:"btn-node-status",icon:"fa fa-info",label:"Node Status",toggle:true,onselect:toggleStatus},
1891                 null,
1892                 {id:"btn-node-dgnumber",icon:"fa fa-info",label:"Show Node Numbers",toggle:true,onselect:toggleDgNumberDisplay},
1893                 null,
1894                 {id:"btn-node-panel",icon:"fa fa-columns",label:"Node Palette (Ctrl+M)",toggle:true,onselect:toggleNodePaletteDisplay},
1895                 null,
1896                 {id:"btn-node-viewdgs",icon:"fa fa-info",label:"View All DG List",toggle:false,onselect:displayAllDGs},
1897                 null,
1898                 /*
1899                 {id:"btn-node-gitmenu",icon:"fa fa-info",label:"Git Commands",options: [
1900                     {id:"btn-node-gitcheckout",icon:"fa fa-info",label:"Git Checkout",onselect:showGitCheckoutDialog},
1901                     {id:"btn-node-gitpull",icon:"fa fa-info",label:"Git Pull",onselect:showGitPullDialog},
1902                     {id:"btn-node-gitstatus",icon:"fa fa-info",label:"Git Status",onselect:showGitStatusDialog}
1903                 ]},
1904                 null,
1905                 */
1906                 {id:"btn-import-menu",icon:"fa fa-sign-in",label:"Import...",options:[
1907                     /*{id:"btn-import-codecloud",icon:"fa fa-clipboard",label:"Code Cloud",onselect:showCodeCloudFlows},
1908                         */
1909                     {id:"btn-import-codecloud",icon:"fa fa-clipboard",label:"Git Local Repository",onselect:showGitLocalFlows},
1910                     {id:"btn-import-userflows",icon:"fa fa-clipboard",label:"Downloaded DG Flows...",onselect:showFlowShareUsers},
1911                     {id:"btn-import-clipboard",icon:"fa fa-clipboard",label:"Clipboard...",onselect:RED.view.showImportNodesDialog},
1912                     {id:"btn-import-library",icon:"fa fa-book",label:"Library",options:[]}
1913                 ]},
1914                 {id:"btn-export-menu",icon:"fa fa-sign-out",label:"Export...",disabled:true,options:[
1915                     {id:"btn-export-clipboard",icon:"fa fa-clipboard",label:"Clipboard...",disabled:true,onselect:RED.view.showExportNodesDialog},
1916                     {id:"btn-export-library",icon:"fa fa-book",label:"Library...",disabled:true,onselect:RED.view.showExportNodesLibraryDialog}
1917                 ]},
1918                 null,
1919                 {id:"btn-change-password",icon:"fa fa-columns",label:"Change Password",toggle:false,onselect:updatePassword},
1920                 null,
1921                 /*{id:"btn-config-nodes",icon:"fa fa-th-list",label:"Configuration nodes...",onselect:RED.sidebar.config.show},
1922                 null,*/
1923                 {id:"btn-workspace-menu",icon:"fa fa-th-large",label:"Workspaces",options:[
1924                     {id:"btn-workspace-add",icon:"fa fa-plus",label:"Add"},
1925                     {id:"btn-workspace-edit",icon:"fa fa-pencil",label:"Rename"},
1926                     {id:"btn-workspace-delete",icon:"fa fa-minus",label:"Delete"},
1927                     null
1928                 ]},
1929                 null,
1930                 {id:"btn-keyboard-shortcuts",icon:"fa fa-keyboard-o",label:"Keyboard Shortcuts",onselect:showHelp}
1931                 /*{id:"btn-help",icon:"fa fa-question",label:"Help...", href:"http://nodered.org/docs"}*/
1932             ]
1933         });
1934
1935         //Making default loop detection on and display check mark in the menu
1936         //$("#btn-loop-detection").addClass("active");
1937
1938         RED.keyboard.add(/* ? */ 191,{shift:true,ctrl:true},function(){showHelp();d3.event.preventDefault();});
1939         loadSettings();
1940         RED.comms.connect();
1941     });
1942
1943     return {
1944     };
1945 })();