Name: gateway-uvi/webconsole/console.js
| 1: | $(document).ready(function(){ |
| 2: | var history = 1; |
| 3: | var current_command = 1; |
| 4: | var dragging = 0; |
| 5: | var url = $('body').data('target'); |
| 6: | $('.jacen:last-child span').focus(); |
| 7: | $(document).on('click', '.jacen:last-child', function(e) { |
| 8: | $('.jacen:last-child .edit').focus(); |
| 9: | }); |
| 10: | $(document).on('keydown', 'body', function(e) { |
| 11: | if ((e.ctrlKey && e.keyCode == 86) || !e.ctrlKey) { |
| 12: | $('.jacen:last-child .edit').focus(); |
| 13: | } else { |
| 14: | return; |
| 15: | } |
| 16: | if (e.keyCode == 38) { |
| 17: | var anakin = $('.jacen:last-child .edit'); |
| 18: | if(current_command<history) { |
| 19: | current_command++; |
| 20: | } |
| 21: | anakin.text($(".jacen:nth-last-child("+current_command+") > .edit").text()); |
| 22: | anakin.focus(); |
| 23: | jQuery.event.trigger({type:'keyup',which:35,charCode:35,ctrlKey: false}); |
| 24: | return false; |
| 25: | } else if (e.keyCode == 40) { |
| 26: | var anakin = $('.jacen:last-child .edit'); |
| 27: | if(current_command>1) { |
| 28: | current_command--; |
| 29: | } |
| 30: | anakin.html($(".jacen:nth-last-child("+current_command+") > .edit").text()); |
| 31: | } else if (e.keyCode == 13) { |
| 32: | var anakin = $('.jacen:last-child .edit'); |
| 33: | var anakin_str = anakin.text().split(" "); |
| 34: | var command= ""; |
| 35: | var cc = 0; |
| 36: | history++; |
| 37: | current_command=1; |
| 38: | anakin_str.forEach(function(x){ |
| 39: | if(cc==0){ |
| 40: | command="command="+x; |
| 41: | cc++; |
| 42: | } |
| 43: | else{ |
| 44: | command+="¶meter="+x; |
| 45: | } |
| 46: | }); |
| 47: | if(anakin_str[0]=="clear"){ |
| 48: | window.location.reload(); |
| 49: | return false; |
| 50: | } |
| 51: | $.ajax({ |
| 52: | url: url, |
| 53: | type: 'put', |
| 54: | data: command, |
| 55: | success: function(data) { |
| 56: | if(jQuery.type(data[0])=="string"){ |
| 57: | var appendix = ''; |
| 58: | $.each(data,function(k,v){ |
| 59: | appendix += $.trim(v) + "\n"; |
| 60: | }); |
| 61: | |
| 62: | if(anakin_str[0]=="help") |
| 63: | appendix+="\033[1m\033[31mclear\033[0m\033[0m\n Clear screen."; |
| 64: | anakin.parent().append("<div><span>"+ansi_up.ansi_to_html(appendix.replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br/>").replace(/\s/g," "))+"</span></div>"); |
| 65: | } else{ |
| 66: | spalten = new Array(); |
| 67: | var tab = "<table border=\"1\"><tr>"; |
| 68: | var i = 0; |
| 69: | for( var key in data[0]){ |
| 70: | if(data[0].hasOwnProperty(key)){ |
| 71: | spalten[i] = key; |
| 72: | i++; |
| 73: | } |
| 74: | } |
| 75: | spalten.forEach(function(x){ |
| 76: | tab += "<th>"+x+"</th>"; |
| 77: | }); |
| 78: | tab += "</tr>"; |
| 79: | var j = 0; |
| 80: | zeilen = new Array(); |
| 81: | spalten.forEach(function(y){ |
| 82: | var i = 0; |
| 83: | data.forEach(function(x){ |
| 84: | if(j==0){ |
| 85: | zeilen[i]="<tr>"; |
| 86: | } |
| 87: | zeilen[i]+="<td>"; |
| 88: | for( var key in x){ |
| 89: | if(key==y){ |
| 90: | zeilen[i]+=x[key]; |
| 91: | } |
| 92: | } |
| 93: | zeilen[i]+="</td>"; |
| 94: | i++; |
| 95: | }); |
| 96: | j++; |
| 97: | }); |
| 98: | zeilen.forEach(function(x){ |
| 99: | tab+=x; |
| 100: | tab+="</tr>"; |
| 101: | }); |
| 102: | tab+="</table>"; |
| 103: | if (zeilen.length > 0) |
| 104: | anakin.parent().append("<div>"+tab+"</div>"); |
| 105: | } |
| 106: | }, |
| 107: | error: function(data) { |
| 108: | anakin.parent().append("<div>server made a boo boo</div>"); |
| 109: | }, |
| 110: | complete: function(data) { |
| 111: | var node = $("#jaina").clone().appendTo("body"); |
| 112: | node.show(); |
| 113: | node.removeAttr('id'); |
| 114: | $('.edit:last-child',node).focus(); |
| 115: | } |
| 116: | }); |
| 117: | anakin.attr('contenteditable',false); |
| 118: | return false; |
| 119: | } |
| 120: | }); |
| 121: | }); |
