pari: trunk r1274 - in /trunk/config: scripts/astman.js setup/5.html

SVN commits to the Asterisk-GUI project asterisk-gui-commits at lists.digium.com
Mon Jul 30 10:24:16 CDT 2007


Author: pari
Date: Mon Jul 30 10:24:15 2007
New Revision: 1274

URL: http://svn.digium.com/view/asterisk-gui?view=rev&rev=1274
Log:
Fix: the Outbound calling rules page in the setup wizard is different from the one in the gui

Modified:
    trunk/config/scripts/astman.js
    trunk/config/setup/5.html

Modified: trunk/config/scripts/astman.js
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/scripts/astman.js?view=diff&rev=1274&r1=1273&r2=1274
==============================================================================
--- trunk/config/scripts/astman.js (original)
+++ trunk/config/scripts/astman.js Mon Jul 30 10:24:15 2007
@@ -410,7 +410,7 @@
 	_hs.borderColor= "#7E5538";
 	_hs.borderStyle= "solid";
 	h.innerHTML = '<BR><BR><TABLE border=0 cellpadding=0 cellspacing=3 align=center>' +
-			'<TR><TD><img src="/static/config/images/loading.gif"></TD>' +
+			'<TR><TD><img src="/asterisk/static/config/images/loading.gif"></TD>' +
 			'<TD valign=middle align=center>&nbsp;&nbsp;<div id=message_text></div></TD></TR></TABLE>';
 	document.body.appendChild(h);
 }

Modified: trunk/config/setup/5.html
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/setup/5.html?view=diff&rev=1274&r1=1273&r2=1274
==============================================================================
--- trunk/config/setup/5.html (original)
+++ trunk/config/setup/5.html Mon Jul 30 10:24:15 2007
@@ -26,19 +26,18 @@
 <script src="../scripts/prototype.js"></script>
 <script src="../scripts/astman.js"></script>
 <SCRIPT>
-var rawman_url;
-var trunks_desc = new Object;
-var trunkcallbacks = new Object;
-var numplan_callbacks = new Object;
-var default_numberplan = 0;
-var default_np_rules = new Array;
-var default_np_comments = new Array;
-var default_np_data = new Object;
+var widgets = { } ;
+var trunkcallbacks = { };
+var trunks_desc = { };
+var numplan_callbacks = { };
+var numberplansdata = { };
+//var default_numberplan = 0;
 var isnewrule ;
 var iscustom ;
 var pattern_beingedited ;
 var pattern_beingedited_priority ;
-var oldselect;
+var np_oldselect;
+
 
 function localinit(){
 	showdiv_statusmessage();
@@ -47,9 +46,11 @@
 	parent._$('back').disabled = false;
 	parent._$('back').onclick  = function(){ window.location.href="4.html"; };
 	rawman_url = parent.rawman_url ;
+	asterisk_rawmanPath = parent.rawman_url ;
 	parent.astmanEngine.setURL(rawman_url);
 	ping();
 }
+
 
 function ping(){
 	var opt = {
@@ -69,262 +70,254 @@
 
 	if ( originalRequest.responseText.match("Pong") ) {
 		_$('message_text').innerHTML ="Saving Changes...";
-		parent.astmanEngine.config2list("users.conf", _$('trunks'), new Object(), trunkcallbacks);
-	}
-}
-
-function addthe_default_callingplan(){
-	gui_feedback("A default DialPlan is not found !! ", 5000 );
-	_$('table_one').style.display="none";
-	var newRow = _$('callingRulesTable').insertRow(-1);
-	var newCell0 = newRow.insertCell(0);
-	newCell0 .align = "center";
-	newCell0 .style.fontSize = "14px";
-	newCell0 .style.padding = "15px 0px 30px 0px";
-	newCell0 .innerHTML = "the default DialPlan <B>'DialPlan1'</B> is not found !! "
-	+ "<BR><BR><A href=\"#\" class=\"splbutton\" onclick=\"addthe_default_callingplan2()\">Click here</A> to create 'DialPlan1'" ;
-	_$('addrule').disabled = 1;
-	_$('heading2').style.display = "none";
-}
-
-
-function addthe_default_callingplan2(){
-	var default_planname = 'numberplan-custom-1' ;
-	var uri = build_action('newcat', 0, default_planname ,"", "");
-	uri += build_action('append', 1, default_planname,"plancomment", "DialPlan1"); 
-	uri += build_action('append', 2, default_planname,"include", "default"); 
-	uri += build_action('append', 3, default_planname,"include", "parkedcalls");
-	var opt = {
-		method: 'get',
-		asynchronous: true,
-		onSuccess: function(t) { location.reload(); },
-		onFailure: function(t) {
-			alert("Config Error: " + t.status + ": " + t.statusText);
-		}
-	};
-	opt.parameters= "action=updateconfig&srcfilename=" + encodeURIComponent("extensions.conf") + "&dstfilename=" + encodeURIComponent("extensions.conf") + uri;
-	var tmp = new Ajax.Request(rawman_url, opt);
-}
-
-
-trunkcallbacks.format = function(t) {
-	if ( t.fieldbyname['context'] != asterisk_guiTDPrefix + t.name ) {
-		return null;
-	}
-	if (t.fieldbyname['trunkname'] && t.fieldbyname['trunkname'].length) {
-		trunks_desc[t.name] = new Object();
-		trunks_desc[t.name].comment = t.fieldbyname['trunkname'] ;
-		return t.fieldbyname['trunkname'];
-	} else{
-		trunks_desc[t.name] = new Object();
-		trunks_desc[t.name].comment = t.name ;
-		return t.name;
-	}
-}
-
-trunkcallbacks.loaded = function(){
-	//_$('trunks').addEventListener('click',hackenablesave,false);
-	ASTGUI.events.add( _$('trunks') , "click", hackenablesave );
-	parent.astmanEngine.config2list("extensions.conf", _$('extensions'), new Object(), numplan_callbacks);
-}
-
-function hackenablesave(){
-	if( oldselect != _$('trunks').value ){
-		enablesave();
-	}
-}
-
-numplan_callbacks.format = function(t, x) {
-	var exten_fields;
-	if(t.name == "numberplan-custom-1" && x == undefined ){ 
-		default_numberplan = 1;
-	}else if(t.name == "numberplan-custom-1" && t.names[x]=='exten' ){ 
-		default_np_rules.push( t.fields[x] );
-	}else if(t.name == "numberplan-custom-1" && t.names[x]=='comment' ){ 
-		var tmp = t.fields[x].split(",");
-		if( tmp.length > 1 ){
-			default_np_comments.push( t.fields[x] );
-		}
-	}
-
-	return false;
-}
-
-numplan_callbacks.loaded = function() {
-	//parent.astmanEngine.pollEvents();
-	if(!default_numberplan){
-		// Redirect To creating a default Number Plan
-		addthe_default_callingplan();
-		return true;
-	}
-	for( var i=0; i < default_np_rules.length; i++){
-		var temp = default_np_rules[i].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 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 default_np_data[temp[0]] == 'undefined' ) {
-			default_np_data[temp[0]] = new Object();
-		}
-		default_np_data[temp[0]][temp[1]] = new Object();
-		default_np_data[temp[0]][temp[1]].trunk = temp[4] ;
-		default_np_data[temp[0]][temp[1]].digits2strip = temp[5] ;
-	}
-	for ( var i =0; i < default_np_comments.length ; i++){
-		var temp = default_np_comments[i].split(",");
-		default_np_data[temp[0]][temp[1]].rulename = temp[2] ;
-		if(temp[3] !="custom"){
-			default_np_data[temp[0]][temp[1]].ruledesc = parsepattern(temp[0],0) ;
-		}else{
-			default_np_data[temp[0]][temp[1]].ruledesc = "custom" ;
-		}
-	}
-	// now show this object in a table.
-	for( var x in default_np_data ){	// x is the pattern
-		// sort the priorities
-		if( !default_np_data.hasOwnProperty(x) ){ continue; }
-		var sorted_priorities = [];
-		for ( var y in default_np_data[x] ){
-			if( default_np_data[x].hasOwnProperty(y) ){
-				sorted_priorities.push(y);
+		config2json('users.conf', 1, trunks_loaded ) ;
+	}
+}
+
+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 ;
+       for (var r=0; r < s ; r++){
+               pattern = pattern + "X" ;
+       }
+	// append a '.' if 'ormore' is checked
+	if( _$('ormore').checked ){
+		pattern = pattern + "!" ;
+	}
+	// 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 provider_name;
+	config2json('users.conf', 1, function(b) { 
+        var c = b ;
+       	provider_name = (c[_tv]['provider']) ? unescape(c[_tv]['provider']) : _tv;
+	if(provider_name == 'bandwidth') {
+	/* Add a + sign on outgoing calls so that bandwidth.com will properly recognize and receive it. */
+	var rule_string = _ptv + ',' + this_priority + ',Macro(trunkdial,${' + _tv + '}/'+ _pv + "+" + '${EXTEN:' + _sv + '}@${'+_tv+'})' ;
+	} else {
+	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 );
+
+	_$('userscontent').style.display = "none";
+	_$('bg_transparent').style.display = "none";
+	_$('status_message').style.display = "";
+
+	makerequest('u', 'extensions.conf', uri,
+		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(); 
+		}
+	);
+	});
+}
+
+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++;
+		//	}
+		//}
+		var msg = "Calling Rule Added." ;
+		add_rule_fromeditform( newpriority, oncomplete = function(){ show_npdata_table(_extv);gui_feedback(msg,'blue'); } );
+	 }else{	// update exiting rule
+		// delete existing rule
+		// add rule with new values
+		delete_callingrule(pattern_beingedited,pattern_beingedited_priority, oncomplete = function(){
+				var msg = "Calling Rule Updated." ;
+				add_rule_fromeditform( pattern_beingedited_priority, oncomplete = function(){show_npdata_table(_extv); gui_feedback(msg,'blue');});
+			} 
+		);
+		//$('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();
-		// done sorting priorities
-		// show fields in a table in the order of sorted priorities
 		for( var z=0; z < sorted_priorities.length ; z++ ){
-			//check if the trunk defined is actually an existing trunk
 			var trunk_exists = 0;
-			for(var i=0; i < _$('trunks').length ; i++ ){
-				if( _$('trunks').options[i].value == default_np_data[x][sorted_priorities[z]].trunk ){
+			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 ( default_np_data[x][sorted_priorities[z]].trunk  == "" ){
-				_$('trunks').selectedIndex = -1;
-				addrowtotable( x , sorted_priorities[z] , "undefined" , default_np_data[x][sorted_priorities[z]].digits2strip );
-			}else if(trunk_exists == 0){
-				_$('trunks').selectedIndex = -1;
-				addrowtotable( x , sorted_priorities[z] , "invalid" , default_np_data[x][sorted_priorities[z]].digits2strip );
-			}else{
-				addrowtotable( x , sorted_priorities[z] , default_np_data[x][sorted_priorities[z]].trunk , default_np_data[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 .style.fontSize = "13px";
 		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;
 	}
-}
-
-numplan_callbacks.eachline = true;
-numplan_callbacks.includecats = true;
-
-function addrowtotable(a,b,c,d){	// a is pattern, b is priority, c is trunk, d is digits2strip
-
-	var sno = _$('callingRulesTable').rows.length + 1;
-	var newRow = _$('callingRulesTable').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 =  default_np_data[a][b].rulename ; 
-	newCell1.width=90;
-
-	var newCell2 = newRow.insertCell(2);
-	newCell2.innerHTML =  default_np_data[a][b].ruledesc ; 
-
-	var newCell3 = newRow.insertCell(3);
-	newCell3.align="center";
-	newCell3.width=85;
-	if(c == "invalid" || c== "undefined"  ){
-		newCell3.innerHTML = "<span style='cursor:pointer; color : #0000ff;'  onclick=\"editcallingrule('"+ a +"', '"+ b +"')\">Select a ServiceProvider</span>";
-	}else{
-		newCell3.innerHTML = trunks_desc[c].comment  ;
-	}
-
-	var newCell4 = newRow.insertCell(4);
-	newCell4.innerHTML = "<A href=\"#\" onclick=\"editcallingrule('"+ a +"', '"+ b +"')\">Edit</A>&nbsp;&nbsp;<A href=\"#\" onclick=\"deletecallingrule('"+ a +"', '"+ b +"')\">Delete</A>";
-	newCell4.width=75;
-	newCell4.align="center";
-	return true;
-}
-
-function deletecallingrule(a,b){
-	t=confirm("Are you sure ?")
-	if(t == false){ return true; }
-	delete_callingrule(a,b, oncomplete = function(){location.reload();} )  ;
-}
-
-function delete_callingrule(a,b,oncomplete){
-	var commentstring = (default_np_data[a][b].ruledesc == 'custom')?"custom":"standard" ;
-	var rule_string = a + ',' + b + ',Macro(trunkdial,${' + default_np_data[a][b].trunk + '}/${EXTEN:' + default_np_data[a][b].digits2strip + '})' ;
-	var uri = build_action('delete', 0, "numberplan-custom-1" ,"exten", "", rule_string ); 
-	commentstring = a + ',' + b + ',' + default_np_data[a][b].rulename + ',' + commentstring ;
-	uri += build_action('delete', 1 , "numberplan-custom-1" ,"comment","", commentstring );
-
-	var opt = {
-		method: 'get',
-		asynchronous: true,
-		onSuccess: function(t) { oncomplete(); },
-		onFailure: function(t) {
-			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(rawman_url, opt);
-}
-
-function editcallingrule(a,b){
-	pattern_beingedited = a ;
-	pattern_beingedited_priority = b ;
-	oldselect = _$('trunks').value;
-	isnewrule = false;
-	_$('rulename').value = default_np_data[a][b].rulename;
-	_$('trunks').selectedIndex = -1 ;
-	for(var i=0; i < _$('trunks').length ; i++ ){
-		if( _$('trunks').options[i].value == default_np_data[a][b].trunk ){
-		_$('trunks').selectedIndex = i ;
-		break;
-		}
-	}
-	_$('pattern').value = a;
-	_$('strip').value = default_np_data[a][b].digits2strip;
-	_$('save_a').disabled = 1;
-
-	if(default_np_data[a][b].ruledesc == 'custom' ){
-		// if this is a custom pattern then donot try to parse the pattern
-		iscustom = true;
-		_$('define_advanced').style.display="";
-		_$('define_usual').style.display="none";
-	}else{
-		// if this is standard pattern then parse the pattern into 'beginswith', 'followedby'
-		var temp = parsepattern(a,1);
-		iscustom = false;
-		_$('define_advanced').style.display="none";
-		_$('define_usual').style.display="";
-	}
-
-	_$('userscontent').style.display="";
-	_$('bg_transparent').style.display='';
-	_$('addrule').disabled =1;
+
+	_$('addrule').disabled = false;
+} 
+
+function clear_table(){
+	var _crt = _$('callingRulesTable') ;
+	for( var i=0; i <  _crt.rows.length; ){ _crt.deleteRow(i); }
 }
 
 function parsepattern(a,e){
@@ -337,11 +330,9 @@
 	if( temp.substr(-1,1) == "!" ){
 		temp = temp.slice(0, -1);
 		returnstring = "or more";
-		if(e == 1)
-		_$('ormore').checked = true;
+		if(e == 1){ _$('ormore').checked = true; }
 	}
 	var posofx = temp.indexOf('X');
-	//alert("position of X in " + temp + " is " + posofx );
 	// 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
@@ -370,126 +361,216 @@
 return returnstring;
 }
 
-function ownpattern(){
-	iscustom = true;
-	_$('define_advanced').style.display="";
-	_$('define_usual').style.display="none";
-}
-
-function enablesave(){
-	_$('save_a').disabled = 0;
+
+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 + ")"; }
+
+	var newCell3 = newRow.insertCell(3);
+	newCell3.align="center";
+	newCell3.width=85;
+	if(c == "invalid" || c== "undefined"  ){
+		newCell3.innerHTML = "<span style='cursor:pointer; color : #0000ff;'  onclick=\"editcallingrule('"+ a +"', '"+ b +"')\">Select a ServiceProvider</span>";
+	}else{
+		newCell3.innerHTML = trunks_desc[c].comment  ;
+	}
+
+	var newCell4 = newRow.insertCell(4);
+	newCell4.innerHTML = "<A href=\"#\" onclick=\"editcallingrule('"+ a +"', '"+ b +"')\" tip=\"en,callingrules,2\">Edit</A>&nbsp;&nbsp;<A href=\"#\" onclick=\"deletecallingrule('"+ a +"', '"+ b +"')\" tip=\"en,callingrules,3\">Delete</A>";
+	newCell4.width=75;
+	newCell4.align="center";
 	return true;
 }
 
-function add_callingrule(){
-	isnewrule = true;
-	_$('rulename').value = "";
-	_$('trunks').selectedIndex = -1 ;
-	_$('pattern').value = "";
-	_$('strip').value = "0" ;
+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 ); gui_feedback("Calling Rule Deleted",'default'); } ) ;
+}
+
+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 _prov = String(_$('trunks').innerHTML); 
+	if(!_prov.search("Bandwidth") || !_prov.search("bandwidth")) {
+	var rule_string = a + ',' + b + ',Macro(trunkdial,${' + m[a][b].trunk + '}/'+ m[a][b].prepend + '+${EXTEN:' + m[a][b].digits2strip + '}@'+_$('trunks').value+')' ;
+	} else {
+	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 );
+	_$('userscontent').style.display = "none";
+	_$('bg_transparent').style.display = "none";
+	_$('status_message').style.display = "";
+
+	makerequest('u','extensions.conf', uri,
+		function(t){
+			_$('status_message').style.display="none";
+			delete numberplansdata[ _extv ]['npdata'][a][b] ;
+			oncomplete(); 
+		}
+	);
+}
+
+
+function editcallingrule(a,b){	// a is pattern, b is priority
+	pattern_beingedited = a ;
+	pattern_beingedited_priority = b ;
+	//oldselect = $('trunks').value;
+	isnewrule = false ;
+	var _trunks = _$('trunks') ;
+
+	var m = numberplansdata[_$('extensions').value]['npdata'];
+	_$('rulename').value = m[a][b].rulename;
+	_trunks.selectedIndex = -1 ;
+	for(var i=0; i < _trunks.length ; i++ ){
+		if( _trunks.options[i].value == m[a][b].trunk ){
+			_trunks.selectedIndex = i ;
+			break;
+		}
+	}
+	_$('pattern').value = a;
+	_$('strip').value = m[a][b].digits2strip;
+	_$('prepend').value = m[a][b].prepend;
 	_$('save_a').disabled = 1;
-	_$('define_advanced').style.display="none";
-	_$('define_usual').style.display="";
+	if( m[a][b].ruledesc == 'custom' || !m[a][b].ruledesc ){
+		// if this is a custom pattern then donot try to parse the pattern
+		iscustom = true;
+		_$('rulename').value = (m[a][b].rulename) ? m[a][b].rulename : "";
+		m[a][b].ruledesc = 'custom' ;
+		_$('define_advanced').style.display="";
+		_$('define_usual').style.display="none";
+	}else{
+		// if this is standard pattern then parse the pattern into 'beginswith', 'followedby'
+		var temp = parsepattern(a,1);
+		iscustom = false;
+		_$('define_advanced').style.display="none";
+		_$('define_usual').style.display="";
+	}
 	_$('userscontent').style.display="";
-	_$('bg_transparent').style.display='';
+	_$('bg_transparent').style.display ='';
 	_$('addrule').disabled =1;
-	_$('beginswith').value = "";
-	_$('followedby').value ="";
-	_$('ormore').checked = false;
-}
-
-function add_rule_fromeditform( this_priority, oncomplete ){
-	if( iscustom ){ // custom - take pattern as is
-		var commentstring = "custom";
+}
+
+function ruleinanpdata(a,b,c){
+	this.trunk = a ;
+	this.digits2strip = b;
+	this.prepend = c;
+}
+
+function numberplan_context(){
+	this.plancomment = "";
+	this.nprules = [ ];
+	this.npcomments = [ ];
+	this.npdata = { }; 
+}
+
+numplan_callbacks.format = function(t, x) {
+	if ((t.name.substr(0,11) != 'numberplan-'))
+		return null;
+	if( x == undefined ){  // is a new number plan 
+		numberplansdata[t.name] = new numberplan_context ;
+		try{
+			return t.fieldbyname['plancomment'] ;
+		}catch(err){
+			return t.name;
+		}
+	}else if( t.names[x]=='plancomment' ){ 
+		numberplansdata[t.name]['plancomment'] =  t.fields[x] ; 
+	}else if( t.names[x]=='exten' ){ 
+		numberplansdata[t.name]['nprules'].push( t.fields[x] ) ; 
+	}else if( t.names[x]=='comment' ){ 
+		var tmp = t.fields[x].split(",");
+		if( tmp.length > 1 ){
+			numberplansdata[t.name]['npcomments'].push( t.fields[x] ) ; 
+		}
+	}
+	
+	return null;
+}
+
+numplan_callbacks.loaded = function() {
+	var _extns = _$('extensions') ;
+	if( _extns.options.length ==0 ){
+		addthe_default_callingplan();
 	}else{
-		var commentstring = "standard";
-		//build a pattern into $('pattern').value
-		buildpatternstring();
-	}
-		
-	var rule_string = _$('pattern').value + ',' + this_priority + ',Macro(trunkdial,${' + $('trunks').value + '}/${EXTEN:' + $('strip').value + '})' ;
-	var uri = build_action('append', 0 , "numberplan-custom-1" ,"exten", rule_string );
-	commentstring = _$('pattern').value + ',' + this_priority + ',' + _$('rulename').value + "," + commentstring ;
-	uri += build_action('append', 1 , "numberplan-custom-1" ,"comment", commentstring );
-
-	var opt = {
-		method: 'get',
-		asynchronous: true,
-		onSuccess: function(t) { oncomplete(); },
-		onFailure: function(t) {
-			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(rawman_url, opt);
-}
-
-
-function saverule(){
-	if ( !checkfields() ) return false;
-	 if(isnewrule){ // add this rule to the default plan and reload the page
-		var newpriority=1;
-		if( typeof default_np_data[$('pattern').value] !="undefined" ){
-			var  t = _$('pattern').value;
-			for ( var y in default_np_data[t] ){
-				if(default_np_data[t].hasOwnProperty(y) ){ newpriority++; }
+		_extns.selectedIndex = 0;
+		_extns.selectitem(0);
+		parse_nprulesAndnpcomments();
+		show_npdata_table(_extns.options[0].value);
+	}
+}
+numplan_callbacks.eachline = true;
+numplan_callbacks.includecats = true;
+
+function trunks_loaded(b){
+	var c = b ;
+	for( var d in c ){
+		if ( c.hasOwnProperty(d) && c[d]['context'] && (c[d]['context'] == asterisk_guiTDPrefix + d ) ) {
+			trunks_desc[d] = new Object();
+			trunks_desc[d].comment = (c[d]['trunkname']) ? unescape(c[d]['trunkname']) : d ;
+			var New_OPTION = document.createElement('option');
+			New_OPTION.text =  unescape(trunks_desc[d].comment) ;
+			New_OPTION.value =d ;
+			try {
+				_$('trunks').add(New_OPTION, null); // W3C way
+			}catch(ex) {
+				_$('trunks').add(New_OPTION); // IE way
 			}
 		}
-		add_rule_fromeditform( newpriority, oncomplete = function(){location.reload();}  );
-	 }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(){location.reload();} );
-		});
-		//$('userscontent').style.display='none';
-		//$('addrule').disabled =0;
-		//return true;
-	 }
-}
-
-function	buildpatternstring(){
-	var pattern = _$('beginswith').value;
-	// Add an underscore
-	pattern = "_" + pattern;
-	// append 'followedby' number of X's 
-	for (var r=0; r < _$('followedby').value ; r++){
-		pattern = pattern + "X" ;
-	}
-	// append a '.' if 'ormore' is checked
-	if( _$('ormore').checked ){
-		pattern = pattern + "!" ;
-	}
-	// assign this to the field 'pattern'
-	_$('pattern').value = pattern;
-}
-
-function checkfields(){
-	if( _$('rulename').value.length == 0 ){
-		alert("Please enter a Rule Name");
-		_$('rulename').focus();
-		return false;
-	}
-	if(_$('trunks').selectedIndex == -1){
-		alert("Please select a service provider to place this call through");
-		return false;
-	}
-	if(_$('define_advanced').style.display=="none" && _$('beginswith').value.length==0 ){
-		alert("Please Enter the beginning pattern of the number");
-		_$('beginswith').focus();
-		return false;
-	}
-	if(_$('define_usual').style.display=="none" && _$('pattern').value.length == 0 ){
-		alert("Please Enter a custom pattern");
-		_$('pattern').focus();
-		return false;
-	}
-return true;
-}
-
+	}
+	parent.astmanEngine.config2list("extensions.conf", _$('extensions'), new Array, numplan_callbacks);
+}
+
+function newnumberplan(){
+	_$('bg_transparent').style.display ='';
+	_$('new').click();
+}
+
+function delete_numberplan(){	_$('delete').click();	}
+
+function addthe_default_callingplan(a){
+	if(!a){
+		_$('message_text').innerHTML = "A default DialPlan is not found !!"
+		+ "<BR><BR> <A href=\"#\" class=\"splbutton\" onclick=\"addthe_default_callingplan(1)\">click here</A> to create a default DialPlan";
+		var _bg_s = _$('bg_transparent').style ;
+		var _sm_s = _$('status_message').style ;
+		_sm_s.left = 220 ;
+		_sm_s.top = 60 ;
+		_sm_s.height = 155 ;
+		_sm_s.width = 375 ;
+		_sm_s.zIndex = _bg_s.zIndex + 1;
+		_bg_s.display = '' ;
+		_sm_s.display = '' ;
+		return true;
+	}
+	var default_planname = 'numberplan-custom-1' ;
+	var uri = build_action('newcat', 0, default_planname ,"", "");
+	uri += build_action('append', 1, default_planname,"plancomment", "DialPlan1");
+	uri += build_action('append', 2, default_planname,"include", "default");
+	uri += build_action('append', 3, default_planname,"include", "parkedcalls"); 
+	makerequest('u','extensions.conf', uri, function(t){gui_feedback("Created Default DialPlan",'green'); location.reload();});
+}
+
+function free_mem(){ }
 </SCRIPT>
 <BODY bgcolor="#FFFFFF" onload="localinit()" topmargin=0 leftmargin=0>
 <table width="100%" height="100%" border=0 cellpadding=0 cellspacing=0>
@@ -499,7 +580,7 @@
 	<table cellpadding=3 cellspacing=2 border=0 id="sidelist">
 		<tr><td width=3></td><td>Start</td></tr>
 		<tr><td></td><td>Verify Analog Ports</td></tr>
-		<!-- <tr><td></td><td>Date & Time</td></tr> -->
+		<tr><td></td><td>Date & Time</td></tr>
 		<tr><td></td><td>Local Extension Settings</td></tr>
 		<tr><td></td><td>Service Providers</td></tr>
 		<tr><td></td><td class="slselected">Calling Rules</td></tr>
@@ -513,56 +594,57 @@
 </td>
 <td valign=top align=center>
 <!--  this page -->
-	<select id="extensions" style="display:none"></select>
-	<div class="heading">Step 4 of <script>document.write(parent.numberofsteps);</script>&nbsp;&nbsp;-  Outbound Calling Rules</div>
+<center>
+	<select id="extensions" style="display:none" style="z-index:2"></select>
+	<div class="heading">Step 5 of <script>document.write(parent.numberofsteps);</script>&nbsp;&nbsp;-  Outbound Calling Rules</div>
 	<div id="heading2" style="font-size:13px; padding : 0px 0px 10px 0px;">List of Calling Rules in default dialplan - <B>DialPlan1</B> </div>
-	<table class="table_blacksm" cellpadding=2 cellspacing=2 border=0 align=center width=500 id="table_one">
+
+	<center>
+		<table class="table_blacksm" cellpadding=2 cellspacing=2 border=0 align=center width=500 id="table_one">
 		<tr>	<td width=35>S.No</td>
 			<td width=90>RuleName</td>
 			<td>Dial Pattern</td>
 			<td width=85 align=center>Call Using</td>
 			<td width=75 align=center>Options</td>
 		</tr>
-	</table>
-	
-	<div id="callingRulesTable_div" style="height:250px;width=100%; overflow :auto; padding : 0px 0px 0px 0px;">
-		<table id="callingRulesTable" cellpadding=2 cellspacing=1 border=0 align=center width=500></table>
-	</div>
-
-	<div style="display:none;" id='status'></div>
-	<center><input type="button" id="addrule" value="Add a Calling Rule" onclick="add_callingrule();"></center>
-	
-	<div id="userscontent" STYLE="display:none; position: absolute; left: 225; top: 40; width:500; height:290;  background-color:#F4EFE5;   border-width: 1px; border-color: #7E5538; border-style: solid; z-index:5">
-	<table width="100%" cellpadding=0 cellspacing=0 onmousedown="ASTGUI.startDrag(event , 'userscontent');">
-	<TR bgcolor="#7E5538" >
+		</table>
+		<div id="callingRulesTable_div" style="height:210px;width=100%; overflow :auto; padding : 0px 0px 0px 0px;">
+			<table id="callingRulesTable" cellpadding=2 cellspacing=1 border=0 align=center width=500></table>
+		</div>
+		<BR>
+		<div align=center>
+			<input type="button" id="addrule" value="Add a Calling Rule" onclick="add_callingrule();"  tip="en,callingrules,4">
+		</div>
+	</center>
+
+	<div id="userscontent" STYLE="display:none; position: absolute; left: 230; top: 30; width:500; height:290;  background-color:#F4EFE5;   border-width: 1px; border-color: #7E5538; border-style: solid; z-index:5">
+	<table width="100%" cellpadding=0 cellspacing=0  onmousedown="ASTGUI.startDrag(event , 'userscontent');">
+	<TR bgcolor="#7E5538"  style="background-image:url('images/title_gradient.gif');">
 		<TD Height="20" align="right" style="cursor: move">
 			<A href="#" onclick="$('cancel_a').click();"><font style="color:#FFFFFF; font-size: 12px; font-weight:bold;">X</font></A>
 		</TD>
 		<TD width=4></TD>
 	</TR>
 	</table>
-
 	<TABLE	align=center cellpadding=2 cellspacing=2 border=0 width="480">
-	<TR>	<TD align="right" width=175  class="field_text">Rule Name:</TD>
-		<TD><input type="text" id="rulename" size="" onChange="enablesave();" onkeyup="enablesave();"></TD>
+	<TR>	<TD align="right" width=175 tip="en,callingrules,5" class="field_text">Rule Name:</TD>
+		<TD><input type="text" id="rulename" size="" onChange="enablesave();" onkeyup="enablesave();" class="input9"></TD>
 	</TR>
-	<TR>	<TD  align="right" height=40  class="field_text"> Place this call through :</TD>
-		<TD><select id="trunks"></select></TD>
+	<TR>	<TD  align="right" height=40 tip="en,callingrules,6" class="field_text"> Place this call through :</TD>
+		<TD><select id="trunks"  class="input9" onChange="enablesave();"></select></TD>
 	</TR>
 	<TR id="define_usual" height=100>
-		<TD valign="top" align=right  class="field_text">Dialing Rules :</TD>
-		<TD valign="top"  class="field_text">
-		If the number begins with <input id="beginswith" type='text' size=6 onChange="enablesave();" onkeyup="enablesave();"> 
-		and followed by <input id="followedby" type='text' size=1  onChange="enablesave();" onkeyup="enablesave();"> 
-		digits <input type="checkbox" id="ormore" onChange="enablesave();"> or more 
-		<BR> <A href="#" onclick="ownpattern();">(define a custom pattern)</A>
+		<TD valign="top" align=right tip="en,callingrules,7" class="field_text">Dialing Rules :</TD>
+		<TD valign="top" class="field_text"> If the number begins with <input id="beginswith"  class="input9" type='text' size=6 onChange="enablesave();" onkeyup="enablesave();"> and followed by <input id="followedby" type='text'  class="input9" size=1 onChange="enablesave();" onkeyup="enablesave();"> digits <input type="checkbox" id="ormore" onChange="enablesave();"> or more <BR>
+			<A href="#" onclick="ownpattern();">(define a custom pattern)</A>
 		</TD>
 	</TR>
 	
 	<TR id="define_advanced"  height=100>
-		<TD valign="top" align=right  class="field_text"> Custom Pattern: </TD>
-		<TD valign=top>
-			<input type="text" id="pattern" size="" onChange="enablesave();" onkeyup="enablesave();"><BR>
+		<TD valign="top" align=right tip="en,callingrules,8" class="field_text"> Custom Pattern: </TD>
+		<TD valign=top  class="field_text">
+			<input type="text" id="pattern" size="" onChange="enablesave();" onkeyup="enablesave();"  class="input9"><BR>
+			<A href="#" onclick="basicpattern();">(define a Basic Pattern)</A><BR>
 			<table align='left' cellpadding=0 cellspacing=0>
 			<tr>	<td class="field_text"><b>N&nbsp;&nbsp;</b></td>
 				<td class="field_text">Any digit from 2 to 9</td>
@@ -576,15 +658,14 @@
 			</table>
 		</TD>
 	</TR>
-
-	<TR>	<TD colspan=2 align=center  class="field_text">
-		Strip <input type="text" id="strip" size="1"  onChange="enablesave();" onkeyup="enablesave();"> 
-		digits from the front before dialing:
+	<TR>	<TD colspan=2 align=center tip="en,callingrules,9" class="field_text">
+			Strip <input type="text" id="strip"  class="input9" size="1"  onChange="enablesave();" onkeyup="enablesave();"> 
+			digits from the front and prepend <input type="text" id="prepend"  class="input9" size="3"  onChange="enablesave();" onkeyup="enablesave();"> before dialing
 		</TD>
 	</TR>
 	<TR>	<TD colspan=2 align=center height=50 valign=middle>  
 			<input type="button" id="save_a" value="Save" onclick="saverule();">&nbsp;&nbsp;
-			<input type="button" id="cancel_a" value="Cancel" onclick="$('userscontent').style.display='none'; $('bg_transparent').style.display='none'; $('addrule').disabled =0; " >
+			<input type="button" id="cancel_a" value="Cancel" onclick="$('userscontent').style.display='none'; $('bg_transparent').style.display ='none'; $('addrule').disabled =0;">
 		</TD>
 	</TR>
 	</TABLE>
@@ -596,4 +677,4 @@
 <div id="bg_transparent" STYLE="display:none; position: absolute; left: 0; top: 0; width:100%; height:100%;  background-color:#FFFFFF; filter:alpha(opacity=50); -moz-opacity:.50;opacity:.50; border-width: 0px; z-index:4">
 </div>
 </BODY>
-</HTML>
+</HTML>




More information about the asterisk-gui-commits mailing list