📄 feditor.html
字号:
<!--
* Asterisk-GUI - an Asterisk configuration interface
*
* File Editor - Edit asterisk config files from the GUI
*
* Copyright (C) 2006-2007, Digium, Inc.
*
* Pari Nannapaneni <pari@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*
-->
<script src="scripts/prototype.js"></script>
<script src="scripts/rico.js"></script>
<script src="scripts/astman.js"></script>
<link href="stylesheets/rico.css" media="all" rel="Stylesheet" type="text/css" />
<link href="stylesheets/schwing.css" media="all" rel="Stylesheet" type="text/css" />
<script>
var global_contextBeingEdited = "";
var global_fileBeingEdited = "";
function delete_context(){
if(!confirm("Are you sure you want to delete the selected context ?")){ return true; }
var uri = build_action('delcat', 0, global_contextBeingEdited ,"", "");
var opt = {
method: 'get',
asynchronous: true,
onSuccess: function() {
_$('AddContext').style.display = "none";
_$('div_editcontext').style.display = "none";
global_contextBeingEdited = "";
gui_feedback('Context Deleted','blue');
config2json( global_fileBeingEdited, 0, fileparsed );
},
onFailure: function(t) {
gui_alert("Config Error: " + t.status + ": " + t.statusText);
gui_alert("Failed to Rename the DID context for " + old_didcontext );
}
};
opt.parameters= "action=updateconfig&srcfilename=" + encodeURIComponent(global_fileBeingEdited) + "&dstfilename=" + encodeURIComponent(global_fileBeingEdited) + uri;
var tmp = new Ajax.Request(asterisk_rawmanPath, opt);
}
function cancel_context(){
global_contextBeingEdited = "";
_$('div_editcontext').style.display = "none";
}
function update_context(){ // rename from global_contextBeingEdited to $('context_edited').value
var uri = build_action('renamecat', 0, global_contextBeingEdited ,"", _$('context_edited').value );
var opt = {
method: 'get',
asynchronous: true,
onSuccess: function() {
_$('AddContext').style.display = "none";
_$('div_editcontext').style.display = "none";
global_contextBeingEdited = "";
gui_feedback('Context Updated','blue');
config2json( global_fileBeingEdited, 0, fileparsed );
},
onFailure: function(t) {
gui_alert("Config Error: " + t.status + ": " + t.statusText);
gui_alert("Failed to Rename the DID context for " + old_didcontext );
}
};
opt.parameters= "action=updateconfig&srcfilename=" + encodeURIComponent(global_fileBeingEdited) + "&dstfilename=" + encodeURIComponent(global_fileBeingEdited) + uri;
var tmp = new Ajax.Request(asterisk_rawmanPath, opt);
}
function resetmainscreen(){
top._$('mainscreen').width= 540;
}
function localajaxinit() {
top._$('mainscreen').width= 798;
setWindowTitle("File Editor");
load_recordedfiles();
add_event( _$('filenames') , 'change' , loadfile ) ;
parent.loadscreen(this);
}
function load_recordedfiles(){
parent.astmanEngine.run_tool(asterisk_guiListFiles + " " + asterisk_configfolder, callback = function() {
var opt = { method: 'get', asynchronous: true,
onComplete: function(originalRequest){
// Add config files to the list of files
_$('sysinfohtml').innerHTML = originalRequest.responseText;
var k = _$('list_files').innerHTML ;
var recfiles = k.split("\n") ;
New_OPTION = document.createElement('option');
New_OPTION.text = "Config Files" ;
New_OPTION.value = "" ;
New_OPTION.style.fontWeight = "bold";
try {
_$('filenames').add(New_OPTION, null); // W3C way
}catch(ex) {
_$('filenames').add(New_OPTION); // IE way
}
var file_name;
for( var i =0 ; i < recfiles.length ; i++){
if( typeof recfiles[i] == "undefined" || recfiles[i] == "" ){
continue;
}
recfiles[i] = recfiles[i].replace(/^\s*|\s*$/g,'') ;
if( recfiles[i] == "" ){ continue; }
if( recfiles[i].substr( (recfiles[i].length - 5), recfiles[i].length) != ".conf") { continue; }
file_name = recfiles[i].stripTags() ;
New_OPTION = document.createElement('option');
New_OPTION.text = file_name ;
New_OPTION.value = file_name ;
try {
_$('filenames').add(New_OPTION, null); // W3C way
}catch(ex) {
_$('filenames').add(New_OPTION); // IE way
}
}
},
onFailure: function(t) { alert("Config Error: " + t.status + ": " + t.statusText); }
};
opt.parameters="";
var tmp = new Ajax.Request(asterisk_guiSysInfo_output , opt);
});
}
function loadfile(){
if( !_$('filenames').value ) return;
global_fileBeingEdited = _$('filenames').value ;
_$('AddContext').style.display = "none";
_$('div_filename').style.display = "";
_$('CurrentFileName').innerHTML = global_fileBeingEdited;
config2json( global_fileBeingEdited, 0, fileparsed ) ;
}
function showeditcontext(){
_$('AddContext').style.display = "none";
_$('div_editcontextContent').style.display = "none";
//move div_editcontext ontop of h_id and display it
var h_id = this.getAttribute('id') ;
global_contextBeingEdited = this.getAttribute('context');
_$(h_id).insertBefore(_$('div_editcontext'), null );
_$('div_editcontext').style.display = "";
var f = this.getAttribute('context')
_$('context_edited').value = f ;
_$('context_edited').size = f.length;
}
function showeditcontextContent(){
_$('AddContext').style.display = "none";
_$('div_editcontext').style.display = "none";
var i_id = this.getAttribute('id') ;
global_contextBeingEdited = this.getAttribute('context');
_$(i_id).insertBefore(_$('div_editcontextContent'), null );
_$('div_editcontextContent').style.display = "";
_$('context_Content').value = this.CONTEXTCONTENT ;
_$('context_Content').rows = this.CONTEXTCONTENT_ROWS ;
//_$('context_edited').size = f.length;
}
function cancel_contextContent(){
global_contextBeingEdited = "";
_$('div_editcontextContent').style.display = "none";
}
function update_contextContent(){
var c = 0;
var uri = build_action('delcat', c , global_contextBeingEdited ,"", ""); c++;
uri += build_action('newcat', c , global_contextBeingEdited, "", ""); c++;
var r = 0;
var u = _$('context_Content').value.split("\n") ;
var posofeq ;
var firstpart ;
var secondpart ;
for( var f=0; f < u.length ; f++ ){
// in u[f] find 'first occurance of =' and split it there
posofeq = u[f].indexOf("=");
if( posofeq == -1){ continue; }
firstpart = u[f].substring(0, posofeq );
secondpart = u[f].substring( posofeq+1 );
uri += build_action('update', c, global_contextBeingEdited, firstpart, secondpart ); c++;
}
var opt = {
method: 'get',
asynchronous: true,
onSuccess: function() {
_$('div_editcontextContent').style.display = "none";
global_contextBeingEdited = "";
gui_feedback('Context Content Updated','blue');
config2json( global_fileBeingEdited, 0, fileparsed );
},
onFailure: function(t) {
gui_alert("Config Error: " + t.status + ": " + t.statusText);
gui_alert("Failed to Rename the DID context for " + old_didcontext );
}
};
opt.parameters= "action=updateconfig&srcfilename=" + encodeURIComponent(global_fileBeingEdited) + "&dstfilename=" + encodeURIComponent(global_fileBeingEdited) + uri;
var tmp = new Ajax.Request(asterisk_rawmanPath, opt);
}
function fileparsed(b){
_$('temp_holding').insertBefore(_$('div_editcontext'), null );
_$('temp_holding').insertBefore(_$('div_editcontextContent'), null );
_$('div_editcontext').style.display = "none";
_$('div_editcontextContent').style.display = "none";
//alert(b);
var zz = _$('file_output');
var c = eval('(' + b + ')');
var p = "";
var rows ;
while(zz.firstChild){
zz.removeChild(zz.firstChild);
}
for( var d in c ){
if ( c.hasOwnProperty(d) ) {
var h = document.createElement("div");
var h_id = "context_" + d;
h.setAttribute("id",h_id);
h.setAttribute("context",d);
h.align="left";
h.style.backgroundColor = '#4D5423';
h.style.color = '#FFFFFF';
h.style.marginTop = '15px' ;
h.style.width = '95%';
h.style.fontFamily = "'trebuchet ms',helvetica,sans-serif";
h.style.fontSize = '10pt' ;
var s_id = "span_" + d;
h.innerHTML = " [" + d + "]";
zz.appendChild(h);
Rico.Corner.round(h_id, {compact:true});
add_event( _$(h_id) , 'click', showeditcontext );
var i = document.createElement("div");
var i_id = "contextContent_" + d;
i.setAttribute("id", i_id );
i.setAttribute("context",d);
i.align= "left";
i.style.backgroundColor = '#E0E6C4';
i.style.marginTop = '5px' ;
i.style.width = '95%';
i.style.fontSize = '9pt' ;
i.style.fontFamily = 'courier' ;
var temp_contextContent = "" ;
rows = 0;
for(var r=0; r < c[d].length ; r++ ){
p = unescape( c[d][r] );
i.innerHTML += " " + p + "<BR>" ;
temp_contextContent += p + "\n";
rows++;
}
i.CONTEXTCONTENT = temp_contextContent ;
i.CONTEXTCONTENT_ROWS = rows ;
zz.appendChild(i);
Rico.Corner.round("contextContent_" + d, {compact:true});
add_event( _$(i_id) , 'click', showeditcontextContent );
}
}
var space = document.createElement("div");
space.style.height = '50px';
zz.appendChild(space);
}
function stopBubble(b) {
if (!b) { b = window.event; }
b.cancelBubble = true;
}
function show_addcontext(){
_$('New_ContextName').value = "";
var acb = _$('AddContextButton');
var tmp_left = acb.offsetLeft -1;
var tmp_top = acb.offsetTop -1 ;
var tmp_parent = acb;
while(tmp_parent.offsetParent != document.body){
tmp_parent = tmp_parent.offsetParent;
tmp_left += tmp_parent.offsetLeft;
tmp_top += tmp_parent.offsetTop;
}
_$('AddContext').style.left = tmp_left;
_$('AddContext').style.top = tmp_top ;
_$('AddContext').style.display = "" ;
_$('New_ContextName').focus();
}
function cancel_addcontext(){
_$('AddContext').style.display = "none";
_$('New_ContextName').value = "";
}
function add_context(){
var uri = build_action('newcat', 0, _$('New_ContextName').value ,"", "");
var opt = {
method: 'get',
asynchronous: true,
onSuccess: function() {
cancel_addcontext();
global_contextBeingEdited = "";
gui_feedback('New Context Added','blue');
config2json( global_fileBeingEdited, 0, fileparsed );
},
onFailure: function(t) {
gui_alert("Config Error: " + t.status + ": " + t.statusText);
gui_alert("Failed to Add New context ");
}
};
opt.parameters= "action=updateconfig&srcfilename=" + encodeURIComponent(global_fileBeingEdited) + "&dstfilename=" + encodeURIComponent(global_fileBeingEdited) + uri;
var tmp = new Ajax.Request(asterisk_rawmanPath, opt);
}
</script>
<body id="foo" onload="localajaxinit()" bgcolor="FFFFFF" onunload="resetmainscreen();">
<div style="font-size : 12px; padding : 4px 6px 4px 6px; border-style : solid none solid none; border-top-color : #BDC7E7; border-bottom-color : #182052; border-width : 1px 0px 1px 0px; background-color : #ef8700; color : #ffffff;">
<span style="margin-left: 4px;font-weight:bold;">File Editor</span>
<span style="cursor: pointer; cursor: hand;" onclick="window.location.href=window.location.href;" > <img src="images/refresh.png" title=" Refresh " border=0 > </span>
<span><select id="filenames" class="input9"></select></span>
</div>
<div style="display:none; font-size:14px; font-weight:bold; font-family:helvetica,sans-serif,'trebuchet ms'; padding : 6px 0px 6px 10px;" id="div_filename">
<span id="CurrentFileName"></span>
<a href=# class="splbutton" onclick="show_addcontext();" id="AddContextButton">Add Context</a>
</div>
<div id="file_output" style="height:475px;width= 770px; overflow :auto;" align="center"></div>
<span id="temp_holding"></span>
<span id="div_editcontext" style="display:none; z-index:1000; background-color : #4D5423" onclick="stopBubble(event)">
<input id="context_edited" size=15 class="input8">
<input id="save_context" type=button value="Save" class="input8" onclick="update_context();">
<input id="cancel_context" type=button value="Cancel" class="input8" onclick="cancel_context();">
<input id="delete_context" type=button value="Delete" class="input8" onclick="delete_context();">
</span>
<div id="div_editcontextContent" style="display:none; z-index:1001; background-color : #E0E6C4" onclick="stopBubble(event)">
<table>
<tr>
<td> <textarea id="context_Content" rows=1 cols=50 class="input8"></textarea> </td>
<td valign="top" align="center">
<input id="save_contextContent" type=button value="Save" class="input8" onclick="update_contextContent();">
<input id="cancel_contextContent" type=button value="Cancel" class="input8" onclick="cancel_contextContent();">
</td>
</tr>
</table>
</div>
<div id="AddContext" style="display:none; position:absolute; z-index:1004; background-color : #C1D7EC; padding : 6px 6px 6px 10px;">
Add New Context : <input id="New_ContextName" size=20 class="input9">
<input type="button" value="Add" style="font-size: 8pt; border:1px solid; padding : 0px 0px 0px 0px;" onclick="add_context();">
<input type="button" value="Cancel" style="font-size: 8pt; border:1px solid; padding : 0px 0px 0px 0px;" onclick="cancel_addcontext();">
</div>
<div id="sysinfohtml" style="display:none"></div>
</body>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -