pari: trunk r841 - /trunk/config/setup/4.html

asterisk-gui-commits at lists.digium.com asterisk-gui-commits at lists.digium.com
Wed May 2 10:20:23 MST 2007


Author: pari
Date: Wed May  2 12:20:22 2007
New Revision: 841

URL: http://svn.digium.com/view/asterisk-gui?view=rev&rev=841
Log:
The Service Providers page in the setup wizard is replaced with the
same code of the page from GUI.


Modified:
    trunk/config/setup/4.html

Modified: trunk/config/setup/4.html
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/setup/4.html?view=diff&rev=841&r1=840&r2=841
==============================================================================
--- trunk/config/setup/4.html (original)
+++ trunk/config/setup/4.html Wed May  2 12:20:22 2007
@@ -26,19 +26,19 @@
 </HEAD>
 <script src="../scripts/prototype.js"></script>
 <script src="../scripts/astman.js"></script>
-<SCRIPT>
-
-var rawman_url;
+<script>
 var origwidth;
-var widgets = {} ;
-var provwidgets = {} ;
+var widgets = {};
+var provwidgets = {};
 var callbacks = new Object;
 var phonecallbacks = new Object;
 var providercallbacks = new Object;
 var globalvars = new Object;
-var fieldnames = ['callerid', 'cancel', 'context', 'delete', 'dialformat', 'fromdomain', 'fromuser', 'group', 'hasexten', 'hasiax', 'hassip', 'host', 'host', 'insecure', 'name', 'new', 'provider', 'registeriax', 'registersip', 'save', 'secret', 'trunkname', 'trunkstyleanalog', 'trunkstylecustomvoip', 'trunkstylevoip', 'username', 'zapchan'];
-
-var provfieldnames = new Array('providerdesc', 'providerlogo');
+var fieldnames = ['disallow','allow','callerid','cancel','contact','context','delete','dialformat','fromdomain','fromuser','group','hasexten','hasiax','hassip',
+'host','insecure','name','new','port','provider','registeriax','registersip','save','secret','trunkname','trunkstyleanalog','trunkstylecustomvoip','trunkstylevoip',
+'username','zapchan'];
+
+var provfieldnames = ['providerdesc', 'providerlogo'];
 var isnewtrunk;
 var dids_array = [];
 var old_trunkname;
@@ -52,12 +52,11 @@
 		asynchronous: true,
 		onSuccess: function(t) { },
 		onFailure: function(t) {
-			alert("Config Error: " + t.status + ": " + t.statusText);
-			alert("Failed to create a DID context for " + trunk);
+			gui_alert("Config Error: " + t.status + ": " + t.statusText + "<BR><BR>"+ "Failed to create a DID context for " + trunk );
 		}
 	};
 	opt.parameters= "action=updateconfig&srcfilename=" + encodeURIComponent("extensions.conf") + "&dstfilename=" + encodeURIComponent("extensions.conf") + uri;
-	var tmp = new Ajax.Request(rawman_url, opt);
+	var tmp = new Ajax.Request(asterisk_rawmanPath, opt);
 }
 
 function update_didcontext(old_trunk, new_trunk){
@@ -67,15 +66,16 @@
 	var opt = {
 		method: 'get',
 		asynchronous: true,
-		onSuccess: function(t) { },
+		onSuccess: function(t) { callbacks_savechanges_step2(); },
 		onFailure: function(t) {
-			alert("Config Error: " + t.status + ": " + t.statusText);
-			alert("Failed to Rename the DID context for " + old_didcontext );
+			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("extensions.conf") + "&dstfilename=" + encodeURIComponent("extensions.conf") + uri;
-	var tmp = new Ajax.Request(rawman_url, opt);
-}
+	var tmp = new Ajax.Request(asterisk_rawmanPath, opt);
+}
+
 
 function delete_didcontext(trunk){
 	var didcontext = asterisk_guiTDPrefix + trunk ;
@@ -85,44 +85,23 @@
 		asynchronous: true,
 		onSuccess: function(t) { },
 		onFailure: function(t) {
-			alert("Config Error: " + t.status + ": " + t.statusText);
-			alert("Failed to delete DID context for " + trunk);
+			gui_alert("Config Error: " + t.status + ": " + t.statusText + "<BR> Failed to delete DID context for " + trunk);
 		}
 	};
 	opt.parameters= "action=updateconfig&srcfilename=" + encodeURIComponent("extensions.conf") + "&dstfilename=" + encodeURIComponent("extensions.conf") + uri;
-	var tmp = new Ajax.Request(rawman_url, opt);
-}
-
-function localinit(){
-	var focus_fields = [ 'username','secret','provider','customvoip_name','customvoip_protocol','customvoip_host','customvoip_username','customvoip_secret' ];
-	for( var  r =0; r < focus_fields.length ; r++ ){
-		var d = _$(focus_fields[r]);
-		d.onfocus = function(){ this.className = 'input9_hilight'; }
-		d.onblur = function(){ this.className = 'input9'; }
-	}
-
-	parent._$('back').onclick  = function(){ window.location.href="3.html"; };
-	parent._$('next').onclick = function(){ window.location.href="5.html"; };
-	//parent.$('next').disabled = true;
-	parent._$('back').disabled = false;
-	rawman_url = parent.rawman_url ;
-	parent.astmanEngine.setURL(rawman_url);
-	ping();
-}
-
-function ping(){
-	var opt = {method: 'get',asynchronous: true,onComplete: isloggedin };
-	opt.parameters="action=ping" ;
-	var tmp = new Ajax.Request(rawman_url , opt);
-}
-
-function isloggedin(originalRequest){
-	if ( originalRequest.responseText.match("Error") ) {
-		parent.window.location.href = parent.window.location.href ;
-		return;
-	}
-	if (originalRequest.responseText.match("Pong") ) {
-		localajaxinit();
+	var tmp = new Ajax.Request(asterisk_rawmanPath, opt);
+}
+
+providercallbacks.postselect = function() {
+	var _pl = _$('providerlink') ;
+	try{
+		var f = _$('provider');
+		var g = f.stored_config.catbyname[f.value].fieldbyname['regurl'] ;
+		_pl.href= ( g ) ? g :'#' ;
+		_pl.target = ( g ) ? '_blank' : '';
+	}catch(e){
+		_pl.href= "#";
+		_pl.target = "";
 	}
 }
 
@@ -134,8 +113,7 @@
 	if ( t.name.substring(0,asterisk_guiTDPrefix.length) == asterisk_guiTDPrefix ){
 		dids_array.push( t.name.substring( asterisk_guiTDPrefix.length ) );
 	}
-	if (t.name == "globals")
-		return t.name
+	if (t.name == "globals"){ return t.name ; }
 	return null;
 }
 
@@ -144,35 +122,19 @@
 }
 
 providercallbacks.loaded = function() {
-	_$('provider').altonchange = _$('provider').onchange;
-	_$('provider').onchange = null;
+	var p = _$('provider');
 	parent.astmanEngine.config2list("extensions.conf", _$('hiddenglobals'), new Array, globalvars);
 }
 
-providercallbacks.postselect = function(){
-	if (_$('provider').selectIndex == -1 || _$('provider').selectIndex == ""){ 
-		return true;
-	}else{
-		var element = document.getElementById("providerlogo_image");
-		while (element.firstChild) {
-			element.removeChild(element.firstChild);
-		}
-		var sp1 = document.createElement("img");
-		sp1.src = "../images/" + _$('providerlogo').value ;
-		//sp1.width="214";
-		//sp1.height="46";
-		_$('providerlogo_image').appendChild(sp1);
-	}
-}
-
 callbacks.format = function(t) {
-	if( InArray(dids_array, t.name) ){
-		return t.fieldbyname['trunkname'];
-	}
+	if( InArray(dids_array, t.name) ){ return t.fieldbyname['trunkname']; }
 	return null;
 }
 
 callbacks.cancelnewcategory = function(){
+	remove_event( _$('trunkstyleanalog') , 'click' , activateanalogvoip );
+	remove_event( _$('trunkstylevoip') , 'click' , activateanalogvoip );
+	remove_event( _$('trunkstylecustomvoip') , 'click' , activateanalogvoip );
 	hideSPdetails();
 }
 
@@ -181,34 +143,26 @@
 }
 
 callbacks.loaded = function() {
+	var _devices = _$('devices');
+	_devices.contentEditable = 'true';
+	_devices.disabled = 0;
+	add_event( _$('new') , "click", showSPdetails ) ;
+	loadServiceProvidersintotable();
+	//preparemenus();
+	//parent.loadscreen(this);
 	parent.astmanEngine.pollEvents();
-	_$('devices').contentEditable = 'true';
-	_$('devices').disabled = 0;
-	//_$('new').addEventListener("click", showSPdetails, false);
-	add_event( _$('new') , "click", showSPdetails );
-	loadServiceProvidersintotable();
 }
 
 callbacks.postselect = function(){
-
 	if( _$('trunkstylecustomvoip').checked ){
 		// Custom VOIP
-		var tmp = _$('trunkname').value.split("Custom - ")  ;
+		var tmp = $('trunkname').value.split("Custom - ")  ;
 		_$('customvoip_name').value = tmp[1];
 		_$('customvoip_username').value = _$('username').value;
 		_$('customvoip_secret').value = _$('secret').value;
-		if ( _$('hassip').value  == "yes" ){
-			_$('customvoip_protocol').selectedIndex = 1;
-		}else {
-			_$('customvoip_protocol').selectedIndex = 0;
-		}
+		_$('customvoip_protocol').selectedIndex = ( _$('hassip').value  == "yes" ) ? 1 : 0;
 		_$('customvoip_host').value = _$('host').value;
-		if(_$('registeriax').value == "yes" || _$('registersip').value == "yes"){
-			_$('customvoip_register').checked = true;
-		}else{
-			_$('customvoip_register').checked = false;
-		}
-
+		_$('customvoip_register').checked = ( _$('registeriax').value == "yes" || _$('registersip').value == "yes") ? true : false ;
 	}else if ( _$('trunkstylevoip').checked ){
 		// VOIP
 		_$('customvoip_name').value = "";
@@ -217,191 +171,195 @@
 		_$('customvoip_protocol').selectedIndex = 0;
 		_$('customvoip_host').value ="";
 	}
-
 }
 
 
 callbacks.delchanges = function(box, value) {
 	deletesp_fromui(value);
 	delete_didcontext(value);
-	var oldvalue = _$('hiddenglobals').stored_config.catbyname['globals'].fieldbyname[value];
+	var _hglobals = _$('hiddenglobals');
+	var oldvalue = _hglobals.stored_config.catbyname['globals'].fieldbyname[value];
 	if (oldvalue) {
 		uri = build_action('delete', 0, 'globals', value, "");
-		apply_uri(_$('hiddenglobals'), uri);
-		_$('hiddenglobals').stored_config.catbyname['globals'].fieldbyname[value] = null;
+		apply_uri( _hglobals, uri);
+		_hglobals.stored_config.catbyname['globals'].fieldbyname[value] = null;
 		return true;
 	}
 }
 
 callbacks.beforeSaving = function(){
-	if (_$('trunkstylevoip').checked && !_$('provider').value) {
-		alert("Please select a service provider!");
-		return false;
-	}
-	if (_$('trunkstylevoip').checked && !_$('username').value.length ) {
-		alert("When using VoIP, the username must not be empty!");
-		return false;
-	}
-	if (_$('trunkstyleanalog').checked ) {
-		if( _$('zapchan').options.length == 0 ){
-		alert("No analog line hardware installed on the system");
-		return false;
-		}
-
-		if (!_$('zapchan').value) {
-		alert("When using Analog, at least one port must be selected.");
-		return false;
-		}
-	}
-	if ( _$('trunkstylecustomvoip').checked ) {
-		if( _$('customvoip_name').value.length == 0 ){
-			alert("Please enter a Comment for this Service Provider");
-			_$('customvoip_name').focus();
-			return false;
-		}
-
-		if ( !_$('customvoip_host').value ) {
-			alert("Please enter a host name");
-			_$('customvoip_host').focus();
-			return false;
-		}
-		if ( !_$('customvoip_username').value ) {
-			alert("Please enter a Username");
-			_$('customvoip_username').focus();
-			return false;
-		}
-	}
-	
-	if(!$('trunkstylevoip').checked && !$('trunkstyleanalog').checked && !$('trunkstylecustomvoip').checked ){
-		alert("A trunk must be Analog or VoIP or Custom VOIP");
-		return false;
-	}
+	var _tsv = _$('trunkstylevoip');
+	var _tsa = _$('trunkstyleanalog');
+	var _tscv = _$('trunkstylecustomvoip');
+	var _cv_un = _$('customvoip_username');
+	var _name = _$('name')  ;
+	var _dvcs_v = _$('devices').value ;
+
+	var _msg1 = "When using VoIP, the username must not be empty!" ;
+	var _msg2 = "No analog line hardware installed on the system";
+	var _msg3 = "When using Analog, at least one port must be selected.";
+	var _msg4 = "Please enter a Comment for this Service Provider";
+
+	if ( _tsv.checked && !_$('username').value.length ) { gui_alert(_msg1); return false; }
+
+	if ( _tsa.checked ) {
+		var _zapchan = _$('zapchan');
+		if( _zapchan.options.length == 0 ){ gui_alert(_msg2); return false; }
+		if (!_zapchan.value) { gui_alert( _msg3); return false; }
+	}
+	if ( _tscv.checked ) {
+		var _csv_n = _$('customvoip_name');
+		if( _csv_n.value.length == 0 ){ gui_alert( _msg4); _csv_n.focus(); return false; }
+		var _cv_h = _$('customvoip_host') ; 
+		if ( !_cv_h.value ) { gui_alert("Please enter a host name"); _cv_h.focus(); return false; }
+		if ( !_cv_un.value ) { gui_alert("Please enter a Username"); _cv_un.focus(); return false; }
+	}
+	if( !_tsv.checked && !_tsa.checked && !_tscv.checked ){ gui_alert("A trunk must be Analog or VoIP or Custom VOIP"); return false; }
+
+	if(_dvcs_v.length ==0 ){
+		ifnewtrunk();
+	}else{
+		ifedit_existing();
+	}
+
 	if(isnewtrunk ==1){
 		try{
-		provider = _$('provider').stored_config.catbyname[_$('provider').value];		
-		if( typeof provider.fieldbyname['trunk_username'] != "undefined"  && _$('trunkstylevoip').checked ){
-			_$('name').value = provider.fieldbyname['trunk_username'];
-		}
+			var _pvdr = _$('provider');
+			provider = _pvdr.stored_config.catbyname[_pvdr.value];		
+			if( typeof provider.fieldbyname['trunk_username'] != "undefined" && _tsv.checked ){
+				_name.value = provider.fieldbyname['trunk_username'];
+			}
 		}catch(e){
 
 		}
-		dids_array.push(_$('name').value );
+		dids_array.push( _name.value );
 	}else{
-		old_trunkname = _$('devices').value ;
-		if( _$('devices').value != _$('name').value){ // if the trunk name is changed , change the name in dids_array
-			for( var i=0 ; i < dids_array.length; i ++	){
-				if( dids_array[i] == _$('devices').value) { dids_array[i] = _$('name').value;}
+
+		if( _$('trunkstyleanalog').checked ){
+			_$('context').value =  asterisk_guiTDPrefix + _$('name').value  ;
+			var needcomma = 0 ;
+			var count = 0 ;
+			_$('trunkname').value = "" ;
+			for (var x=0;x< _$('zapchan').options.length;x++) {
+				if (_$('zapchan').options[x].selected) {
+					if(needcomma){ _$('trunkname').value += "," }
+					needcomma = 1 ;
+					_$('trunkname').value += _$('zapchan').options[x].value ;
+					count++ ;
+				}
 			}
+			_$('trunkname').value = ((count > 1) ? "Ports ":"Port ") + _$('trunkname').value ;
+		}
+
+		old_trunkname = _dvcs_v ;
+		if( _dvcs_v != _name.value ){ // if the trunk name is changed , change the name in dids_array
+			for( var i=0 ; i < dids_array.length; i ++){  if( dids_array[i] == _dvcs_v ) { dids_array[i] = _name.value ; break; } }
 		}	
 	}
 }
 
 callbacks.savechanges = function() {
 	if(isnewtrunk == 1){ //New Trunk created , add [DID_trunk_x] in extensions.conf
-		add_didcontext( _$('name').value );
+		add_didcontext(_$('name').value);
+		if (_$('trunkstylevoip').checked) {
+			_$('dialformat').value = (provider.fieldbyname['dialformat']) ? provider.fieldbyname['dialformat'] : '${EXTEN:1}';
+			_$('callerid').value = '';
+			_$('insecure').value = (provider.fieldbyname['insecure']) ? provider.fieldbyname['insecure'] : '' ;
+			_$('port').value = (provider.fieldbyname['port']) ? provider.fieldbyname['port'] : '' ;
+			_$('fromuser').value = (provider.fieldbyname['fromuser']) ? provider.fieldbyname['fromuser'] : '' ;
+			if (_$('fromuser').value == '<DID>') { _$('fromuser').value = _$('username').value; }
+			_$('fromdomain').value = (provider.fieldbyname['fromdomain']) ? provider.fieldbyname['fromdomain'] : '' ;
+		}
+		callbacks_savechanges_step2();
 	}else{
-		if(old_trunkname != _$('name').value ){	 // rename DID if needed
-			update_didcontext(old_trunkname, _$('name').value );
-		}
-	}
-	saveSPdetails();
+		if(old_trunkname != _$('name').value ){ update_didcontext(old_trunkname, _$('name').value); } // rename DID if needed
+	}
+
+	return true;
+}
+
+
+function callbacks_savechanges_step2(){
+	hideSPdetails();
+	loadServiceProvidersintotable();
+
 	var uri;
 	var newvalue;
-	var tmp = _$('devices').value.split('_');
-	var oldvalue = _$('hiddenglobals').stored_config.catbyname['globals'].fieldbyname[_$('devices').value];
+	var _devices = _$('devices') ; 
+	var tmp = _devices.value.split('_');
+	var _hiddenglobals = _$('hiddenglobals') ;
+
+	var oldvalue = _hiddenglobals.stored_config.catbyname['globals'].fieldbyname[_devices.value];
 	if (_$('trunkstylevoip').checked || _$('trunkstylecustomvoip').checked) {
-		if (_$('devices').stored_config.catbyname[_$('devices').value].fieldbyname['hasiax'] == 'yes')
-			newvalue = "IAX2/" + _$('devices').value;
+		if (_devices.stored_config.catbyname[_devices.value].fieldbyname['hasiax'] == 'yes')
+			newvalue = "IAX2/" + _devices.value;
 		else
-			newvalue = "SIP/" + _$('devices').value;
+			newvalue = "SIP/" + _devices.value;
 	} else {
 		newvalue = "Zap/g"+tmp[1];
 	}
+
 	if (newvalue != oldvalue) {
-		if(old_trunkname == _$('name').value ){	
-			uri = build_action('update', 0, 'globals', _$('devices').value, newvalue);
-			apply_uri(_$('hiddenglobals'), uri);
-			_$('hiddenglobals').stored_config.catbyname['globals'].fieldbyname[_$('devices').value] = newvalue;
+		var _name = _$('name') ;
+		if(old_trunkname == _name.value ){	
+			uri = build_action('update', 0, 'globals', _devices.value, newvalue);
+			apply_uri(_hiddenglobals, uri);
+			_hiddenglobals.stored_config.catbyname['globals'].fieldbyname[_devices.value] = newvalue;
 			return true;
 		}else{
-			uri = build_action('delete', 0, 'globals', old_trunkname, "","" );
-			uri += build_action('update', 1, 'globals', _$('name').value, newvalue);
-			apply_uri(_$('hiddenglobals'), uri);
-			_$('hiddenglobals').stored_config.catbyname['globals'].fieldbyname[_$('name').value] = newvalue;
+			uri = "";
+			var u =0; 
+			if(old_trunkname){ uri = build_action('delete', u, 'globals', old_trunkname, "","" ); u++; }
+			uri += build_action('update', u , 'globals', _name.value, newvalue); u++;
+			apply_uri(_hiddenglobals, uri);
+			_hiddenglobals.stored_config.catbyname['globals'].fieldbyname[ _name.value ] = newvalue;
 			return true;
 		}
 	}
-	return false;
-}
-
-callbacks.checkparams = function(box) {
+}
+
+function ifedit_existing(){
+	_$('context').value =  asterisk_guiTDPrefix + _$('custom_trunkname').value  ;
+}
+
+
+function ifnewtrunk(){
 	var needcomma = 0;
 	var provider;
 	var count = 0;
+	var _provider = _$('provider');
+	var _zapchan = _$('zapchan');
+	var _trunkname = _$('trunkname');
 	_$('hasexten').value = 'no';
 	_$('context').value =  asterisk_guiTDPrefix + _$('name').value  ;
+
 	if (_$('trunkstylevoip').checked) {
-		provider = _$('provider').stored_config.catbyname[_$('provider').value];
-		_$('trunkname').value = _$('provider').options[_$('provider').selectedIndex].innerHTML + " - " + _$('username').value;
+		provider = _provider.stored_config.catbyname[_provider.value];
+		_trunkname.value = _provider.options[_provider.selectedIndex].innerHTML + " - " + _$('username').value;
 		_$('hassip').value = provider.fieldbyname['hassip'];
 		_$('hasiax').value = provider.fieldbyname['hasiax'];
 		_$('registeriax').value = provider.fieldbyname['registeriax'];
 		_$('registersip').value = provider.fieldbyname['registersip'];
 		_$('host').value = provider.fieldbyname['host'];
-		if (provider.fieldbyname['dialformat'])
-			_$('dialformat').value = provider.fieldbyname['dialformat'];
-		else
-			_$('dialformat').value = '${EXTEN:1}';
-		_$('callerid').value = '';
-
-		if (provider.fieldbyname['insecure'])
-			_$('insecure').value = provider.fieldbyname['insecure'];
-		else
-			_$('insecure').value = '';
-		if (provider.fieldbyname['port'])
-			_$('port').value = provider.fieldbyname['port'];
-		else
-			_$('port').value = '';
-		//if (provider.fieldbyname['context'])
-		//	$('context').value = provider.fieldbyname['context'];
-		//else
-		//	$('context').value = 'default';
-		if (provider.fieldbyname['fromuser'])
-			_$('fromuser').value = provider.fieldbyname['fromuser'];
-		else
-			_$('fromuser').value = '';
-			
-		if (_$('fromuser').value == '<DID>') {
-			_$('fromuser').value = _$('username').value;
-		}
-
-		if (provider.fieldbyname['fromdomain'])
-			_$('fromdomain').value = provider.fieldbyname['fromdomain'];
-		else
-			_$('fromdomain').value = '';
-
-		for (var x=0;x<_$('zapchan').options.length;x++)
-			_$('zapchan').options[x].selected = false;
-		_$('zapchan').value = '';
+		for (var x=0;x<_zapchan.options.length;x++){  _zapchan.options[x].selected = false; }
+		_zapchan.value = '';
 		_$('group').value = '';
+		_$('disallow').value= "";
+		_$('allow').value = "all";
 	} else if (_$('trunkstyleanalog').checked) {
 		// Analog
-		_$('provider').selectedIndex  = -1;
+		_provider.selectedIndex  = -1;
 		count = 0;
-		_$('trunkname').value = "";
-		for (var x=0;x<_$('zapchan').options.length;x++) {
-			if (_$('zapchan').options[x].selected) {
-				if (needcomma)
-					_$('trunkname').value += ","
-				needcomma = 1;
-				_$('trunkname').value += _$('zapchan').options[x].value;
+		_trunkname.value = "";
+		for (var x=0;x<_zapchan.options.length;x++) {
+			if (_zapchan.options[x].selected) {
+				if (needcomma){ _trunkname.value += "," }
+				needcomma = 1 ;
+				_trunkname.value += _zapchan.options[x].value;
 				count++;
 			}
 		}
-		if (count > 1)
-			_$('trunkname').value = "Ports " + _$('trunkname').value;
-		else
-			_$('trunkname').value = "Port " + _$('trunkname').value;
+		_trunkname.value = ((count > 1) ? "Ports ":"Port ") + _trunkname.value;
 		_$('callerid').value = 'asreceived';
 		_$('hassip').value = 'no';
 		_$('hasiax').value = 'no';
@@ -409,58 +367,56 @@
 		_$('group').value = _$('name').value.split('_')[1];
 	} else if( _$('trunkstylecustomvoip').checked ){
 		// Custom VOIP Provider
-		_$('trunkname').value = "Custom - " + _$('customvoip_name').value;
+		_trunkname.value = "Custom - " + _$('customvoip_name').value;
 		provider = _$('customvoip_name').value;
-		_$('provider').selectedIndex  = -1;
+		_provider.selectedIndex  = -1;
 		_$('username').value = _$('customvoip_username').value;
 		_$('secret').value = _$('customvoip_secret').value;
-		if( _$('customvoip_protocol').value == "iax" ){
-			_$('hassip').value = "no";
-			_$('hasiax').value = "yes";
+		var _cv_p = $('customvoip_protocol').value ;
+		_$('hassip').value = ( _cv_p == "iax" ) ? "no" : "yes" ;
+		_$('hasiax').value = ( _cv_p == "iax" ) ? "yes" : "no";
+		var _cv_r = _$('customvoip_register') ;
+		var _registeriax = _$('registeriax') ;
+		var _registersip = _$('registersip');
+
+		if( !_cv_r.checked ){
+			_registeriax.value = 'no'; 
+			_registersip.value = 'no';
 		}else{
-			_$('hassip').value = "yes";
-			_$('hasiax').value = "no";				
-		}
-		if( _$('customvoip_register').checked && _$('customvoip_protocol').value == "iax"){
-			_$('registeriax').value = 'yes';
-			_$('registersip').value = 'no';
-		}
-		if( _$('customvoip_register').checked && _$('customvoip_protocol').value == "sip"){
-			_$('registeriax').value = 'no';
-			_$('registersip').value = 'yes';
-		}
-		if( !_$('customvoip_register').checked ){
-			_$('registeriax').value = 'no';
-			_$('registersip').value = 'no';
-		}
-		_$('host').value = $('customvoip_host').value ;
+			_registeriax.value = ( _cv_p == "iax") ?'yes' : 'no';
+			_registersip.value =  ( _cv_p == "sip") ?'yes' : 'no';
+		}
+
+		_$('host').value = _$('customvoip_host').value ;
 		_$('dialformat').value = '${EXTEN:1}';
 		_$('callerid').value = '';
 		_$('insecure').value = '';
-		_$('port').value = '';
+		_$('port').value = ( _cv_p == "iax" ) ? "4569" : "5060";
 		//$('context').value = 'default';
 		_$('fromuser').value = '';
 		_$('fromdomain').value = '';
-		for (var x=0;x<_$('zapchan').options.length;x++)
-			_$('zapchan').options[x].selected = false;
-		_$('zapchan').value = '';
+		for (var x=0;x<_zapchan.options.length;x++)
+			_zapchan.options[x].selected = false;
+		_zapchan.value = '';
 		_$('group').value = '';
-	}
-	return false;
+		_$('disallow').value= "";
+		_$('allow').value = "all";
+	}
 }
 
 callbacks.newcategory = function() {
 	var tmp = null;
 	var x;
-	if (_$('devices').stored_config.catbyname['general'])
-		tmp = objcopy(_$('devices').stored_config.catbyname['general']);
+	var _devices = _$('devices'); 
+	if ( _devices.stored_config.catbyname['general'])
+		tmp = objcopy( _devices.stored_config.catbyname['general']);
 	if (tmp) {
 		x = 1;
-		while(_$('devices').stored_config.catbyname['trunk_' + x]) x++;
+		while( _devices.stored_config.catbyname['trunk_' + x]) x++;
 		tmp.name = 'trunk_' + x;
 	}
 	tmp.fieldbyname['hasexten'] = 'no';
-	tmp.fieldbyname['context'] = asterisk_guiTDPrefix + tmp.name; 
+	tmp.fieldbyname['context'] = asterisk_guiTDPrefix + tmp.name;
 	_$('customvoip_name').value = "";
 	_$('customvoip_username').value = "";
 	_$('customvoip_secret').value = "";
@@ -477,8 +433,8 @@
 	add_event( _$('trunkstylecustomvoip') , 'click' , activateanalogvoip );
 
 	return tmp;
-
-}
+}
+
 callbacks.identifier = "extension";
 
 phonecallbacks.format = function(t) {
@@ -490,106 +446,114 @@
 phonecallbacks.loaded = function() {
 	parent.astmanEngine.config2list("providers.conf", _$('provider'), provwidgets, providercallbacks);
 }
-	
 
 function update_zapchan(){
 	_$('save').disabled = false;
 	_$('cancel').disabled = false;
-
-	for (k=0;k< _$('zapchan').length ;k++ ){
-		var selectedline = "selectedline" + k;
-		if( _$(selectedline).checked  ){
-			_$('zapchan').options[k].selected = true;
-		}else{
-			_$('zapchan').options[k].selected = false;
-		}
-	}
-}
-
-
+	var _zapchan = _$('zapchan');
+	for (k=0;k< _zapchan.length ;k++ ){
+		_zapchan.options[k].selected = ( _$("selectedline" + k).checked  ) ?true:false;
+	}
+}
 
 function activateanalogvoip() {
 	_$('analog').style.display = "none";
-	_$('zapchan').style.display = "none";
-	_$('zapchan_analoglines').style.display = "none";
-	_$('zapchan_analoglines').innerHTML ="";
+	var _zapchan = _$('zapchan'); 
+	_zapchan.style.display = "none";
+	var _zcal = _$('zapchan_analoglines');
+	_zcal.style.display = "none";
+	_zcal.innerHTML ="";
 	_$('customvoip').style.display = "none" ;
 	_$('voip').style.display= "none";
+
 	if (_$('trunkstyleanalog').checked) {
-		_$('analog').style.display = "";
-		_$('zapchan_analoglines').style.display = "";
-		if(_$('zapchan').options.length ==0){
-			_$('zapchan_analoglines').innerHTML = "No analog line hardware installed on the system";
+		_$('analog').style.display = "block";
+		_zcal.style.display = "";
+		if(_zapchan.options.length ==0){
+			_zcal.innerHTML = "No analog line hardware installed on the system";
 		}else{
-			for (k=0;k< _$('zapchan').length ;k++ ){
+			for (k=0;k< _zapchan.length ;k++ ){
 				var selectedline = "selectedline" + k;
-				if(_$('zapchan').options[k].selected){
-					_$('zapchan_analoglines').innerHTML += '<LABEL FOR="' + selectedline + '"><INPUT id="' + selectedline + '" TYPE="CHECKBOX" VALUE="'+ _$('zapchan').options[k].value+ '" checked onclick="update_zapchan()">' + _$('zapchan').options[k].text + '</LABEL><BR>';
+				if(_zapchan.options[k].selected){
+					_zcal.innerHTML += '<LABEL FOR="' + selectedline + '"><INPUT id="' + selectedline + '" TYPE="CHECKBOX" VALUE="'+ _zapchan.options[k].value+ '" checked onclick="update_zapchan()">' + _zapchan.options[k].text + '</LABEL><BR>';
 				}else{
-					_$('zapchan_analoglines').innerHTML += '<LABEL FOR="'+ selectedline+'"><INPUT id="' + selectedline + '" TYPE="CHECKBOX" VALUE="'+ _$('zapchan').options[k].value+ '" onclick="update_zapchan()">' + _$('zapchan').options[k].text + '</LABEL><BR>';
+					_zcal.innerHTML += '<LABEL FOR="'+ selectedline+'"><INPUT id="' + selectedline + '" TYPE="CHECKBOX" VALUE="'+ _zapchan.options[k].value+ '" onclick="update_zapchan()">' + _zapchan.options[k].text + '</LABEL><BR>';
 				}
 			}
 		}
 	}else if (_$('trunkstylevoip').checked) {
-		_$('voip').style.display = "block";
-		_$('voip').style.height =350;
+		_$('voip').style.display = "";
 	}else if (_$('trunkstylecustomvoip').checked) {
-		_$('customvoip').style.display = "block" ;
-	}
-}
-	
+		_$('customvoip').style.display = "" ;
+	}
+}
+
 function localajaxinit() {
+	setWindowTitle("Service Providers");
 	_$('devices').contentEditable = 'false';
 	_$('zapchan').splitchar=',';
-	_$('trunkstyleanalog').altonclick = _$('trunkstyleanalog').onclick;
-	_$('trunkstyleanalog').onclick = null;
-	_$('trunkstylevoip').altonclick = _$('trunkstylevoip').onclick;
-	_$('trunkstylevoip').onclick = null;
-	_$('trunkstylecustomvoip').altonclick = _$('trunkstylecustomvoip').onclick;
-	_$('trunkstylecustomvoip').onclick = null;
-	
+	var _trunkstyleanalog = _$('trunkstyleanalog') ;
+	_trunkstyleanalog.onclick = null;
+
+	parent._$('back').onclick  = function(){ window.location.href="3.html"; };
+	parent._$('next').onclick = function(){ window.location.href="5.html"; };
+	asterisk_rawmanPath = parent.rawman_url ;
+
+	var _trunkstylevoip = _$('trunkstylevoip');
+	_trunkstylevoip.onclick = null;
+
+	var _trunkstylecustomvoip = _$('trunkstylecustomvoip');
+	_trunkstylecustomvoip.onclick = null;
+
+	add_event( _$('custom_trunkname') , 'change' , function(){ 
+		_$('name').value = _$('custom_trunkname').value;
+			_$('save').disabled = false; 
+		}
+	) ;
+
 	for (var x =0; x< fieldnames.length; x++) {
-		widgets[fieldnames[x]] = $(fieldnames[x]);
+		widgets[fieldnames[x]] = _$(fieldnames[x]);
 		widgets[fieldnames[x]].disabled = true;
 	}
 	for (var x =0; x < provfieldnames.length ; x++) {
-		provwidgets[provfieldnames[x]] = $(provfieldnames[x]);
+		provwidgets[provfieldnames[x]] = _$(provfieldnames[x]);
 		provwidgets[provfieldnames[x]].disabled = true;
 	}
+
 	parent.astmanEngine.config2list("zapscan.conf", _$('zapchan'), new Array(), phonecallbacks);
 }
 
 
 function loadServiceProvidersintotable(){
-
-	for( var i=0; i < _$('serviceproviderstable').rows.length; ){
-		 _$('serviceproviderstable').deleteRow(i);
-	}
-
-	if(_$('devices').length == "0" ){
+	var _spt = _$('serviceproviderstable');
+	for( var i=0; i <  _spt.rows.length; ){
+		_spt.deleteRow(i);
+	}
+	var _devices = _$('devices');
+ 
+	if( _devices.length == "0" ){
 		_$('table_one').style.display="none";
-		var newRow = _$('serviceproviderstable').insertRow(-1);
+		var newRow = _spt.insertRow(-1);
 		var newCell0 = newRow.insertCell(0);
 		newCell0 .align = "center";
-		_$('new').style.display= "none";
-		newCell0 .innerHTML = "<BR>You do not have any <I>Service Providers</I> defined<BR><BR>  <Input type=button onclick=\"$('new').click()\" value=\"Add Service Provider\"><BR><BR>" ;
+		newCell0 .innerHTML = "<BR>A <I>Service Provider</I> is not defined<BR><BR> Please click on the 'Add Service Provider' button<BR> to add a service provider<BR><BR>" ;
 		return true;
-	}else{
-		_$('new').style.display= "";
 	}
 
 	_$('table_one').style.display="";	
-	for(i=0; i< _$('devices').length; i++){
-		if(_$('devices').options[i].text != "New Entry")
-		addrow_totable(_$('devices').options[i].text, _$('devices').options[i].value);
+	for(i=0; i< _devices.length; i++){
+		if( _devices.options[i].text != "New Entry")
+		addrow_totable(_devices.options[i].text, _devices.options[i].value);
 	}
 
 }
 
 function addrow_totable(sp_text, sp_value){
-	var sno = _$('serviceproviderstable').rows.length + 1;
-	var newRow = _$('serviceproviderstable').insertRow(-1);
-	newRow.id = "row" + sp_value; 
+	var _spt = _$('serviceproviderstable') ;
+	var sno = _spt.rows.length + 1;
+	var newRow = _spt.insertRow(-1);
+	newRow.id ="row" + sp_value ;
+	newRow["sp_value"] = sp_value ;
 
 	var newCell0 = newRow.insertCell(0);
 	newCell0 .innerHTML = sno ;
@@ -602,36 +566,302 @@
 	var newCell2 = newRow.insertCell(2);
 	switch ( _$('devices').stored_config.catbyname[sp_value].fieldbyname['trunkstyle'] ){
 	case "customvoip":
-		newCell2 .innerHTML =  "Custom Voip";
+		newCell2.innerHTML =  "Custom Voip";
 		break;
 	case "analog":
-		newCell2 .innerHTML =  "Analog";
+		newCell2.innerHTML =  "Analog";
 		break;
 	case "voip":
-		newCell2 .innerHTML =  "Voip";
+		newCell2.innerHTML =  "Voip";
 		break;
 	default : 
-		newCell2 .innerHTML =  "?";
+		newCell2.innerHTML =  "?";
 	}
 
 	var newCell3 = newRow.insertCell(3);
-	newCell3 .innerHTML = "<A href=\"#\" onclick=\"editSP('"+ sp_value +"');\" class=\"field_text9\">Edit</A>&nbsp;&nbsp;&nbsp;&nbsp;<A href=\"#\" onclick=\"deleteSP('"+ sp_value +"');\"  class=\"field_text9\">Delete</A>" ;
-	newCell3 .style.width = 120;
+	var _span_menu = "span" + sp_value;
+	//newCell3 .innerHTML = "<span class=\"downmenubutton\" id='" + "span_" + sp_value  + "' onclick=\"show_downmenu( '"+ sp_value + "');\">Options&nbsp;&nbsp;<img src=images/1.gif></span>" ;
+	newCell3 .innerHTML = " <A href='#' onclick=\"editSP('"+ sp_value + "')\">Edit</A>" + "&nbsp;&nbsp;"
+				+ "<A href='#' onclick=\"deleteSP('"+ sp_value + "')\">Delete</A> ";
+	newCell3 .style.width = 90;
 	newCell3 .align = "center";
-
+}
+
+
+function show_downmenu( a ) {
+	var menu = document.getElementById('mymenu');
+	menu.sp_value = "";
+	menu.sp_value = a ;
+	
+	var tmp_left = _$("span_"+a).offsetLeft;
+	var tmp_top = _$("span_"+a).offsetTop + _$("span_"+a).offsetHeight;
+	var tmp_parent = _$("span_"+a);
+	while(tmp_parent.offsetParent != document.body){
+		tmp_parent = tmp_parent.offsetParent;
+		tmp_left += tmp_parent.offsetLeft;
+		tmp_top += tmp_parent.offsetTop;
+	}
+
+	menu.style.top =tmp_top ;
+	menu.style.left = tmp_left ;
+	setTimeout( function(){ _$('mymenu').style.display=""; } , 100 );
+}
+
+function hide_mymenu( ) {
+	document.getElementById('mymenu').style.display="none"; 
+}
+
+function preparemenus(){
+	var menu_div = document.getElementById('mymenu') ;
+	menu_div.style.width="80";
+	menu_div.style.borderColor = "#eee #bbb #bbb #ddd";
+	add_event( document.body , "click", function(){ _$('mymenu').style.display="none"; } );
+
+	var menuitem1 = document.createElement('div');
+	menuitem1.innerHTML = "Edit" ;
+	menuitem1.onclick =  function(){ hide_mymenu( ); editSP( this.parentNode.sp_value) };
+	menuitem1.onmouseover= function(){  
+		document.getElementById('row'+this.parentNode.sp_value ).style.backgroundColor='#F6E7B6';   
+		this.style.backgroundColor='#EFEFEF';  
+	};
+	menuitem1.onmouseout=function(){  
+		document.getElementById('row'+this.parentNode.sp_value ).style.backgroundColor='#FFFFFF';  
+		this.style.backgroundColor='#FFFFFF';  
+	};
+	menu_div.appendChild(menuitem1);
+
+	var menuitem2 = document.createElement('div');
+	menuitem2.innerHTML = "Codecs" ;
+
+	menuitem2.onclick =  function(){
+		if( _$('devices').stored_config.catbyname[this.parentNode.sp_value].fieldbyname['trunkstyle'] == 'analog'){
+			hide_mymenu();
+			gui_feedback("You can not edit codecs for an analog trunk ");
+			return true;
+		}
+		var _devices = _$('devices');
+		for(var i=0; i< _devices.length; i++){
+			if( this.parentNode.sp_value == _devices.options[i].value ){
+				_devices.selectitem(i);
+				showCodec_details();
+				break;
+			}
+		}
+	};
+	menuitem2.onmouseover= function(){ 
+		document.getElementById('row'+this.parentNode.sp_value ).style.backgroundColor='#F6E7B6';   
+		this.style.backgroundColor='#EFEFEF'; 
+	};
+	menuitem2.onmouseout=function(){ 
+		document.getElementById('row'+this.parentNode.sp_value ).style.backgroundColor='#FFFFFF';  
+		this.style.backgroundColor='#FFFFFF'; 
+	};
+	menu_div.appendChild(menuitem2);
+
+	var menuitem4 = document.createElement('div');
+	menuitem4.innerHTML = "Advanced" ;
+	menuitem4.onclick =  function(){  
+		hide_mymenu( );
+		if( _$('devices').stored_config.catbyname[this.parentNode.sp_value].fieldbyname['trunkstyle'] == 'analog'){
+			gui_feedback("No Advanced settings for analog trunks ");
+			return true;
+		}
+		var _devices = _$('devices');
+ 		for(var i=0; i< _devices.length; i++){
+			if( this.parentNode.sp_value == _devices.options[i].value ){
+				_devices.selectitem(i);
+				_$('bg_transparent').style.display = "";
+				_$('custom_trunkname').value = _$('name').value ;
+				_$('advanced_content').style.display = "";  
+				break;
+			}
+		}
+	};
+	menuitem4.onmouseover= function(){ 
+		document.getElementById('row'+this.parentNode.sp_value ).style.backgroundColor='#F6E7B6';   
+		this.style.backgroundColor='#EFEFEF'; 
+	};
+	menuitem4.onmouseout=function(){ 
+		document.getElementById('row'+this.parentNode.sp_value ).style.backgroundColor='#FFFFFF';  
+		this.style.backgroundColor='#FFFFFF'; 
+	};
+	menu_div.appendChild(menuitem4);
+
+	var menuitem3 = document.createElement('div');
+	menuitem3.innerHTML = "Delete" ;
+	menuitem3.onclick =  function(){  hide_mymenu( );  deleteSP( this.parentNode.sp_value );  };
+	menuitem3.onmouseover= function(){ 
+		document.getElementById('row'+this.parentNode.sp_value ).style.backgroundColor='#F6E7B6';   
+		this.style.backgroundColor='#EFEFEF'; 
+	};
+	menuitem3.onmouseout=function(){ 
+		document.getElementById('row'+this.parentNode.sp_value ).style.backgroundColor='#FFFFFF';  
+		this.style.backgroundColor='#FFFFFF'; 
+	};
+	menu_div.appendChild(menuitem3);
+
+}
+
+function codecs_save(){
+	_$('save').click( );
+	_$('codecs_content').style.display = 'none';
+	_$('bg_transparent').style.display ='none';
+}
+
+function showCodec_details(){
+	update_div_setordercodecs();
+	_$('codecs_content').style.display = "";
+	_$('bg_transparent').style.display ='';
+}
+
+function hide_codecs(){
+	_$('cancel').click( );
+	_$('codecs_content').style.display = 'none';
+	_$('bg_transparent').style.display ='none';
 }
 
 function editSP(sp_value){
 	isnewtrunk = 0;
-	_$('userscontent_title').innerHTML = "Edit Service Provider";
-	for(var i=0; i< _$('devices').length; i++){
-		if(sp_value == _$('devices').options[i].value ){
-			_$('devices').selectitem(i);
+	$('userscontent_title').innerHTML = "Edit Service Provider";
+	var _devices = _$('devices');
+	for(var i=0; i< _devices.length; i++){
+		if(sp_value == _devices.options[i].value ){
+			_devices.selectitem(i);
 			showSPdetails();
+			activateanalogvoip();
 			break;
 		}
 	}
 }
+
+// Allowed/Disallowed codescs related functions
+function enable_selectedcodec(){
+	// add to allowed
+	selectbox_add("allowed" ,  _$('disallowed').value );
+	// remove selected from disallowed
+	selectbox_remove("disallowed", _$('disallowed').value );
+	update_ordercodecs();
+}
+function disable_selectedcodec(){
+	// add to disallowed
+	selectbox_add("disallowed" ,  _$('allowed').value );
+	// remove selected from allowed
+	selectbox_remove("allowed", _$('allowed').value );
+	update_ordercodecs();
+}
+
+function selectbox_add(selectbox_id, codec){
+	switch(codec) {
+		case 'ulaw': addtosel("u-law","ulaw",selectbox_id) ; break;
+		case 'alaw': addtosel("a-law","alaw",selectbox_id) ; break;
+		case 'gsm': addtosel("GSM","gsm",selectbox_id) ; break ;
+		case 'ilbc': addtosel("ILBC","ilbc",selectbox_id) ; break ;
+		case 'speex': addtosel("SPEEX","speex",selectbox_id) ; break ;
+		case 'g726':  addtosel("G.726","g726",selectbox_id) ; break ;
+		case 'adpcm': addtosel("ADPCM","adpcm",selectbox_id) ; break ;
+		case 'lpc10': addtosel("LPC10","lpc10",selectbox_id) ; break ;
+		case 'g729': addtosel("G.729","g729",selectbox_id) ; break ;
+		default: break
+	}
+
+	function addtosel(a,b,c){ // a is text, b is value, c is the select box id
+	  var newoption = document.createElement('option');
+	  newoption.text = a ;
+	  newoption.value = b ;
+	  var selectbox = document.getElementById( c );
+	  try {
+		selectbox.add(newoption, null); // standards compliant; doesn't work in IE
+	  }catch(ex) {
+		selectbox.add(newoption); // IE only
+	  }
+	}
+}
+
+function  selectbox_remove(selectbox_id,codec){
+	for (var x=0; x < $(selectbox_id).length; x++){
+		if( $(selectbox_id).options[x].value==codec ){	$(selectbox_id).remove(x); return true;}
+	}
+}
+function update_ordercodecs(){
+	var _allow = _$('allow') ;
+	var _allowed = _$('allowed') ;
+	var _disallow = _$('disallow');
+	var _disallowed = _$('disallowed');
+
+	_disallow.value = "";
+	_allow.value = "";
+	if(_$('disallow_all').checked){
+		_disallow.value = "all";
+	}else{
+		for (var x=0; x < _disallowed.length ; x++){
+			if(x==0){
+				_disallow.value = _disallowed.options[x].value ;
+			}else{
+				_disallow.value = _disallow.value + "," + _disallowed.options[x].value ;
+			}
+		}
+	}
+
+	for (var x=0; x < _allowed.length ; x++){
+		if(x==0){
+			_allow.value = _allowed.options[x].value ; 
+		}else{
+			_allow.value = _allow.value + "," +  _allowed.options[x].value ; 
+		}
+	}
+	_$('save').disabled = false;
+	_$('cancel').disabled = false;
+}
+
+function update_div_setordercodecs(){
+	_$('disallowed').innerHTML=""; 	_$('allowed').innerHTML="";
+	if( _$('disallow').value == "all" ){
+		_$('disallow_all').checked = true;
+		selectbox_add("disallowed", "ulaw");
+		selectbox_add("disallowed", "alaw");
+		selectbox_add("disallowed", "gsm");

[... 468 lines stripped ...]


More information about the asterisk-gui-commits mailing list