📄 numberplan.html
字号:
<!--
* Asterisk-GUI - an Asterisk configuration interface
*
* Create Manage 'Dial Plans'
*
* Copyright (C) 2006-2007, Digium, Inc.
*
* Mark Spencer <markster@digium.com>
* 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>
<script src="scripts/tooltip.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 widgets = { } ;
var trunkcallbacks = { };
var trunks_desc = { };
var numplan_callbacks = { };
var numberplansdata = { };
var fieldnames = ['cancel', 'delete', 'include', 'name', 'new', 'plancomment', 'save'];
//var default_numberplan = 0;
var isnewrule ;
var iscustom ;
var pattern_beingedited ;
var pattern_beingedited_priority ;
var np_oldselect;
function basicpattern(){
iscustom = false;
_$('define_advanced').style.display="none";
_$('define_usual').style.display="";
}
function ownpattern(){
iscustom = true;
_$('define_advanced').style.display="";
_$('define_usual').style.display="none";
}
function enablesave(){
_$('save_a').disabled = 0;
return true;
}
function add_callingrule(){
isnewrule = true;
iscustom = false;
_$('rulename').value = "";
_$('trunks').selectedIndex = -1 ;
_$('pattern').value = "";
_$('prepend').value = "";
_$('strip').value = "0" ;
_$('save_a').disabled = 1;
_$('define_advanced').style.display="none";
_$('define_usual').style.display="";
_$('userscontent').style.display="";
_$('bg_transparent').style.display ='';
_$('addrule').disabled =1;
_$('beginswith').value = "";
_$('followedby').value ="";
_$('ormore').checked = false;
}
function checkfields(){
if( _$('rulename').value.length == 0 ){
gui_alert("Please enter a Rule Name");
_$('rulename').focus();
return false;
}
if( _$('trunks').selectedIndex == -1){
gui_alert("Please select a service provider to place this call through");
return false;
}
if( _$('define_advanced').style.display=="none" && _$('beginswith').value.length==0 ){
gui_alert("Please Enter the beginning pattern of the number");
_$('beginswith').focus();
return false;
}
if( _$('define_usual').style.display=="none" && _$('pattern').value.length == 0 ){
gui_alert("Please Enter a custom pattern");
_$('pattern').focus();
return false;
}
return true;
}
function buildpatternstring(){
var pattern = $('beginswith').value;
// Add an underscore
pattern = "_" + pattern;
// append 'followedby' number of X's
var s = _$('followedby').value ;
// append a '.' if 'ormore' is checked
if( _$('ormore').checked ){
for (var r=0; r < s-1 ; r++){
pattern = pattern + "X" ;
}
pattern = pattern + "." ;
}else{
for (var r=0; r < s ; r++){
pattern = pattern + "X" ;
}
}
// assign this to the field 'pattern'
_$('pattern').value = pattern;
}
function add_rule_fromeditform( this_priority, oncomplete ){
var commentstring = (iscustom )? "custom" :"standard" ;
var _ptv = _$('pattern').value ;
var _extv = _$('extensions').value ;
var _rnv = _$('rulename').value ;
var _tv = _$('trunks').value ;
var _sv = _$('strip').value ;
var _pv = _$('prepend').value ;
var rule_string = _ptv + ',' + this_priority + ',Macro(trunkdial,${' + _tv + '}/'+ _pv +'${EXTEN:' + _sv + '})' ;
var uri = build_action('append', 0 , _extv ,"exten", rule_string );
commentstring = _ptv + ',' + this_priority + ',' + _rnv + "," + commentstring ;
uri += build_action('append', 1 , _extv ,"comment", commentstring );
var opt = {
method: 'get',
asynchronous: true,
onSuccess: function(t) {
_$('status_message').style.display="none";
var m = numberplansdata[_extv]['npdata'];
if ( typeof m[_ptv] == 'undefined' ) { m[_ptv] = { }; }
m[_ptv][this_priority] = new ruleinanpdata(_tv, _sv , _pv );
m[_ptv][this_priority].rulename = _rnv ;
m[_ptv][this_priority].ruledesc = (iscustom) ? "custom" : parsepattern(_ptv,0) ;
oncomplete();
},
onFailure: function(t) {
gui_alert("Config Error: " + t.status + ": " + t.statusText);
}
};
opt.parameters= "action=updateconfig&srcfilename=" + encodeURIComponent("extensions.conf") + "&dstfilename=" + encodeURIComponent("extensions.conf") + uri;
_$('userscontent').style.display = "none";
_$('bg_transparent').style.display = "none";
_$('status_message').style.display = "";
var tmp = new Ajax.Request(asterisk_rawmanPath, opt);
}
function saverule(){
if ( !checkfields() ) return false;
if( !iscustom){ buildpatternstring();}
var _extv = _$('extensions').value ;
var _pv = _$('pattern').value ;
if(isnewrule){
var newpriority=1;
var m = numberplansdata[_extv]['npdata'];
if( m.hasOwnProperty(_pv) && m[_pv].hasOwnProperty(''+newpriority) ) {
gui_alert("A rule for this pattern is already defined !") ;
return ;
}
//if( typeof m[$('pattern').value] !="undefined" ){
// for ( var y in m[$('pattern').value] ){
// if ( m[$('pattern').value].hasOwnProperty( y ) ){break;}
// newpriority++;
// }
//}
add_rule_fromeditform( newpriority, oncomplete = function(){ show_npdata_table(_extv); } );
}else{ // update exiting rule
// delete existing rule
// add rule with new values
delete_callingrule(pattern_beingedited,pattern_beingedited_priority, oncomplete = function(){
add_rule_fromeditform( pattern_beingedited_priority, oncomplete = function(){ show_npdata_table(_extv); } );
}
);
//$('userscontent').style.display='none';
//$('addrule').disabled =0;
//return true;
}
}
function parse_nprulesAndnpcomments(){
// for each element in numberplansdata[t.name] {
// create an object numberplansdata[t.name]['npdata']
// parse "numberplansdata[t.name]['nprules']" and add to "numberplansdata[t.name]['npdata']"
// parse "numberplansdata[t.name]['npcomments']" and add to "numberplansdata[t.name]['npdata']"
// }
for(x in numberplansdata){ if (numberplansdata.hasOwnProperty(x)) {
var z = numberplansdata[x];
var y = z['npdata'];
for ( k =0 ; k < z['nprules'].length ; k++ ){
var temp = z['nprules'][k].split(","); // temp[0] is the pattern, temp[1] is the priority,temp[2] is 'Macro(trunkdial', temp[3] is ${trunkname}/${EXTEN:1})
var temp1 = temp[3].split("{");
var temp1b = temp1[1].split("/");
var temp1c = temp1b[1].split("$") ;
var temp2 = temp1[1].split("}");
var temp3 = temp1[2].split("}");
var temp4 = temp3[0].split(":");
temp[4] = temp2[0] ; // temp[4] is trunkname
temp[5] = temp4[1] ; // temp[5] is the #digits to strip in the front
if ( typeof y[temp[0]] == 'undefined' ) {
y[temp[0]] = { };
}
y[temp[0]][temp[1]] = new ruleinanpdata(temp[4], temp[5],temp1c[0]);
}
for ( k =0 ; k < z['npcomments'].length ; k++ ){
var temp = z['npcomments'][k].split(",");
if( typeof y[temp[0]] == "undefined"){ continue ; }
if ( typeof y[temp[0]][temp[1]] == "undefined" ){ continue ; }
y[temp[0]][temp[1]].rulename = temp[2] ;
y[temp[0]][temp[1]].ruledesc = ( temp[3] !="custom" ) ? parsepattern(temp[0],0) : "custom" ;
}
}}
}
function show_npdata_table(a){
// now show m in a table - where m is the npdata of the selected numberplan
clear_table();
_$('table_one').style.display="";
var rules_nosp = new Array ;
var m = numberplansdata[a]['npdata'];
var _trunks = _$('trunks') ;
for( var x in m ){ if (m.hasOwnProperty(x)) {
var sorted_priorities = [ ];
for ( var y in m[x] ){
if (m[x].hasOwnProperty(y)) { sorted_priorities.push(y); }
}
sorted_priorities.sort();
for( var z=0; z < sorted_priorities.length ; z++ ){
var trunk_exists = 0;
for(var i=0; i < _trunks.length ; i++ ){
if( _trunks.options[i].value == m[x][sorted_priorities[z]].trunk ){
trunk_exists = 1;
break;
}
}
if ( m[x][sorted_priorities[z]].trunk == "" ){
rules_nosp.push(m[x][sorted_priorities[z]].rulename) ;
addrowtotable( x , sorted_priorities[z] , "undefined" , m[x][sorted_priorities[z]].digits2strip );
}else if(trunk_exists == 0){
rules_nosp.push(m[x][sorted_priorities[z]].rulename) ;
//$('trunks').selectedIndex = -1;
addrowtotable( x , sorted_priorities[z] , "invalid" , m[x][sorted_priorities[z]].digits2strip );
}else{
addrowtotable( x , sorted_priorities[z] , m[x][sorted_priorities[z]].trunk , m[x][sorted_priorities[z]].digits2strip );
}
}
}}
if(rules_nosp.length > 0 ){
gui_feedback("A Service Provider is not defined for the Rule(s)<BR>" + rules_nosp,'default');
_trunks.selectedIndex = -1;
}
if( _$('callingRulesTable').rows.length == 0 ){
_$('table_one').style.display="none";
var newRow = _$('callingRulesTable').insertRow(-1);
var newCell0 = newRow.insertCell(0);
newCell0 .align = "center";
newCell0 .innerHTML = "<BR>A <I>Calling Rule</I> is not defined<BR><BR> Please click on the 'Add a Calling Rule' button<BR> to add a Calling Rule<BR><BR>" ;
return true;
}
_$('addrule').disabled = false;
}
function clear_table(){
var _crt = _$('callingRulesTable') ;
for( var i=0; i < _crt.rows.length; ){ _crt.deleteRow(i); }
}
function parsepattern(a,e){
returnstring="";
// Parsing into fields
// if first character is underscore (always) - remove it
var temp = a.substr(1);
// if there is a dot at the end
// check ormore and remove the trailing dot
if( temp.substr(-1,1) == "." ){
temp = temp.slice(0, -1);
returnstring = "or more";
if(e == 1){ _$('ormore').checked = true; }
}
var posofx = temp.indexOf('X');
// if X does not occur anywhere followedby is = 0
// if X happens somewhere then beginswith = string till somewhere
// and followedby = length of string from somewhere till end
if(posofx == -1){
if(returnstring == "or more"){
returnstring = "Begins with " + temp + " and followed by 1 or more digits" ;
}else{
returnstring = "Exactly macthes " + temp ;
}
if(e == 1){
_$('beginswith').value = temp;
_$('followedby').value = 0;
}
}else{
if(returnstring == "or more"){
if(e == 1){
_$('beginswith').value = temp.substr(0,posofx);
_$('followedby').value = (temp.length - posofx + 1);
}
returnstring = "Begins with " + temp.substr(0,posofx) + " and followed by "+(temp.length - posofx + 1)+" or more digits" ;
}else{
if(e == 1){
_$('beginswith').value = temp.substr(0,posofx);
_$('followedby').value = (temp.length - posofx );
}
returnstring = "Begins with " + temp.substr(0,posofx) + " and followed by "+(temp.length - posofx) + " digits";
}
}
disable_ormore();
return returnstring;
}
function addrowtotable(a,b,c,d){ // a is pattern, b is priority, c is trunk, d is digits2strip
var m = numberplansdata[_$('extensions').value]['npdata'];
var _crt = _$('callingRulesTable') ;
var sno = _crt.rows.length + 1;
var newRow = _crt.insertRow(-1);
newRow.id = "row" + sno;
var newCell0 = newRow.insertCell(0);
newCell0.innerHTML = sno ;
newCell0.width=35;
newCell0.align="center";
var newCell1 = newRow.insertCell(1);
newCell1.innerHTML = (m[a][b].rulename) ? m[a][b].rulename : "Not Defined" ;
newCell1.width=90;
var newCell2 = newRow.insertCell(2);
newCell2.innerHTML = (m[a][b].ruledesc) ? m[a][b].ruledesc : a ;
if(newCell2.innerHTML == "custom"){ newCell2.innerHTML = "custom ("+ a + ")"; }
if(c == "invalid" || c== "undefined" ){
var newCell3 = newRow.insertCell(3);
newCell3.innerHTML = "<B><font color=red>invalid trunk</font></B>" ;
newCell3.width=85;
}else{
var newCell3 = newRow.insertCell(3);
newCell3.innerHTML = trunks_desc[c].comment ;
newCell3.width=85;
}
var newCell4 = newRow.insertCell(4);
newCell4.innerHTML = "<A href=\"#\" onclick=\"editcallingrule('"+ a +"', '"+ b +"')\" onmouseover=\"show_tooltip('en', 'callingrules', 2);\">Edit</A> <A href=\"#\" onclick=\"deletecallingrule('"+ a +"', '"+ b +"')\" onmouseover=\"show_tooltip('en', 'callingrules', 3);\">Delete</A>";
newCell4.width=75;
newCell4.align="center";
return true;
}
function deletecallingrule(a,b){ // a is pattern, b is priority
if(!confirm("Are you sure ?")) { return true; }
delete_callingrule(a,b, oncomplete = function(){ show_npdata_table( _$('extensions').value ); } ) ;
}
function delete_callingrule(a,b,oncomplete){ // a is pattern, b is priority
var _extv = $('extensions').value ;
var m = numberplansdata[_extv]['npdata'];
var commentstring = (m[a][b].ruledesc == 'custom') ? "custom" : "standard" ;
var rule_string = a + ',' + b + ',Macro(trunkdial,${' + m[a][b].trunk + '}/'+ m[a][b].prepend + '${EXTEN:' + m[a][b].digits2strip + '})' ;
var uri = build_action('delete', 0, _extv ,"exten", "", rule_string );
commentstring = a + ',' + b + ',' + m[a][b].rulename + ',' + commentstring ;
uri += build_action('delete', 1 , _extv ,"comment","", commentstring );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -