pari: trunk r168 - in /trunk/config: ./ bkps/ scripts/ setup/ stylesheets/

asterisk-gui-commits at lists.digium.com asterisk-gui-commits at lists.digium.com
Fri Dec 15 19:09:45 MST 2006


Author: pari
Date: Fri Dec 15 20:09:44 2006
New Revision: 168

URL: http://svn.digium.com/view/asterisk-gui?view=rev&rev=168
Log:
Lots of major changes in this commit - most noticeably Calling Rules ,  and Setup Wizard. There is no field validations on Calling Rules page yet so this might cause some problems, also Calling Rules page assumes a default numberplan 'numberplan-custom-1'. An advanced version of the same page(numberplan_advanced.html) is being developed for use with cfgadvanced.html. I did not have enough time to check whether everything is in proper place and is working correctly, so please expect a few number of follow-up commits within the next few hours.  Cheers :) , -Pari 

Added:
    trunk/config/bkps/
    trunk/config/incoming.html
    trunk/config/numberplan_advanced.html
    trunk/config/setup/
    trunk/config/setup/1.html
    trunk/config/setup/10.html
    trunk/config/setup/2.html
    trunk/config/setup/3.html
    trunk/config/setup/4.html
    trunk/config/setup/5.html
    trunk/config/setup/6.html
    trunk/config/setup/7.html
    trunk/config/setup/digiumlogo.gif   (with props)
    trunk/config/setup/install.html
    trunk/config/setup/setup.css
    trunk/config/setup/template.html
Removed:
    trunk/config/setup.html
Modified:
    trunk/config/backup.html
    trunk/config/cfgbasic.html
    trunk/config/home.html
    trunk/config/homeapp.html
    trunk/config/localexts.html
    trunk/config/networking.html
    trunk/config/numberplan.html
    trunk/config/options.html
    trunk/config/scripts/astman.js
    trunk/config/stylesheets/schwing.css
    trunk/config/sysinfo.html
    trunk/config/users.html

Modified: trunk/config/backup.html
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/backup.html?view=diff&rev=168&r1=167&r2=168
==============================================================================
--- trunk/config/backup.html (original)
+++ trunk/config/backup.html Fri Dec 15 20:09:44 2006
@@ -44,20 +44,7 @@
 	$('message_text').innerHTML = "Please wait while the system <BR> Generates a Backup ... ";
 	$('status_message').style.display="block";
 	//remove bkpfile on server 
-			var opt = {
-				method: 'get',
-				asynchronous: true,
-				onSuccess: function(t) { 
-					// file deleted on server
-					download_bkp();
-				},
-				onFailure: function(t) {
-					// file not deleted on server
-				}
-			};
-			opt.parameters="action=originate&channel=" + encodeURIComponent("Local/removefile@" + asterisk_guitools) + "&Variable=var1%3d"+ encodeURIComponent( bkp_path+ "conf_* -f")+"&application=noop&timeout=60000";
-			var tmp = new Ajax.Request("../../rawman", opt);	
-			return true;
+	parent.astmanEngine.run_tool("/bin/rm " + bkp_path+ "conf_* -f", download_bkp );
 }
 
 
@@ -78,20 +65,10 @@
 		var minute =addzero(today.getMinutes());
 		var seconds =addzero(today.getSeconds());
 		bkpfile =  "conf_" + year + month + day + hour  + minute +seconds  +".tar";
-		var opt = {
-				method: 'get',
-				asynchronous: true,
-				onSuccess: function(t) { 
+		parent.astmanEngine.run_tool("/bin/tar -cf "+ bkp_path + bkpfile +" /etc/asterisk/", callback=function(){
 							$('status').innerHTML = " <I> Finished generating Backup ! </I>";
 							$('message_text').innerHTML = "<A href=\"./bkps/"+ bkpfile  +"\" onclick=\"showremovebkpfile()\">Click Here to Download</A>";
-				},
-				onFailure: function(t) {
-					$('status_message').style.display='none';
-					alert("Config Error: " + t.status + ": " + t.statusText);
-				}
-		};
-		opt.parameters="action=originate&channel=" + encodeURIComponent("Local/takebackup@"+asterisk_guitools) + "&Variable=var1%3d"+ encodeURIComponent( bkp_path + bkpfile)+"&application=noop&timeout=60000";
-		var tmp = new Ajax.Request("../../rawman", opt);
+		} );
 }
 
 </script>

Modified: trunk/config/cfgbasic.html
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/cfgbasic.html?view=diff&rev=168&r1=167&r2=168
==============================================================================
--- trunk/config/cfgbasic.html (original)
+++ trunk/config/cfgbasic.html Fri Dec 15 20:09:44 2006
@@ -41,6 +41,7 @@
 	var accordion;
 	var copyright = "Copyright &copy;2006 Digium, Inc.  All Rights Reserved. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
 	var tooltip_default = "Move the mouse over to a field to see tooltips";
+	var asterisk_guitools_inextconf = 0;
 
 	eventeater.eventcb = function(msgs) {
 		if (loggedon == 1){
@@ -74,6 +75,9 @@
 
 		new PanelDef("numberplan", "Calling Rules", "accordion-icon.gif",
 			"The Calling Rules define dialing permissions and least cost routing rules."),
+
+		new PanelDef("incoming", "Incoming Calls", "accordion-icon.gif",
+			"Define how your incoming calls should be handled & configure DID (Direct inward Dialing)"),
 
 //		new PanelDef("musiconhold", "Music On Hold", "accordion-icon.gif",
 //			"Music on hold sometimes keeps people less angry while they wait for an answer."),
@@ -183,8 +187,6 @@
 		opt2.parameters ="action=logoff";
 		var tmp2 = new Ajax.Request("../../rawman", opt2);
 	}
-
-
 
 </script>
 <head>

Modified: trunk/config/home.html
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/home.html?view=diff&rev=168&r1=167&r2=168
==============================================================================
--- trunk/config/home.html (original)
+++ trunk/config/home.html Fri Dec 15 20:09:44 2006
@@ -22,10 +22,11 @@
 <script src="scripts/prototype.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 demo = new Object;
 	var localloggedon = -1;
+	var asterisk_guitools = parent.asterisk_guitools;
+
 	function updateButtons()
 	{
 		if (parent.loggedon) {
@@ -55,10 +56,14 @@
 			window.location.href="options.html";
 			return;
 		}
-		// parse extensions.conf 
+
 		//if(!asterisk_guitools  || !correct version || !hasSetup ){
 				// redirect to setup
 		//}
+	
+		if( parent.asterisk_guitools_inextconf == 0){
+			checkessentials();
+		}
 
 		parent.setLoggedOn(1);
 		parent.loggedon = 1;
@@ -153,6 +158,42 @@
 			return false;
 		}
 }
+
+
+
+
+
+function checkessentials(){
+	// see if asterisk_guitools exists in extensions.conf
+	//if everything ok set  asterisk_guitools_inextconf = 1;
+		var opt = {
+			method: 'get',
+			asynchronous: true,
+			onComplete: checkExtconfig
+		};
+		opt.parameters="action=getconfig&filename=extensions.conf" ;
+		var tmp = new Ajax.Request("../../rawman", opt);
+}
+
+
+function checkExtconfig(originalRequest){
+	var lines = originalRequest.responseText.split("\n");
+	for( var i=0 ; i < lines.length ; i++){
+			if ( lines[i].substr(0,9) == "Category-"  ){
+				var tmp = lines[i].split(": ");
+				if( tmp[1].match(asterisk_guitools) ){
+						parent.asterisk_guitools_inextconf = 1;
+				}
+			}
+	}
+	
+	if(parent.asterisk_guitools_inextconf == 0 ){
+		// not found
+		parent.window.location.href = "./setup/install.html";
+	}
+
+}
+
 </script>
 <body id="foo" onload="localinit()" topmargin=0  bgcolor="EFEFEF">
 <div class="mainscreenTitleBar">

Modified: trunk/config/homeapp.html
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/homeapp.html?view=diff&rev=168&r1=167&r2=168
==============================================================================
--- trunk/config/homeapp.html (original)
+++ trunk/config/homeapp.html Fri Dec 15 20:09:44 2006
@@ -71,20 +71,20 @@
 	}
 	
 	function doSaveConfig() {
-		parent.astmanEngine.run_tool("save_config");
+		parent.astmanEngine.run_tool("/bin/save_config");
 		alert("Configuration Saved");
 	}
 	
 	function doReboot() {
 		if (confirm("Are you sure you want to reboot the appliance?")) {
-			parent.astmanEngine.run_tool("reboot");
+			parent.astmanEngine.run_tool("/bin/reboot");
 			alert("Rebooting!");
 		}
 	}
 	
 	function doFactoryDefault() {
 		if (confirm("Are you sure you want to reset to factory defaults?")) {
-			parent.astmanEngine.run_tool("factory_default");
+			parent.astmanEngine.run_tool("/bin/reset_config");
 			alert("Resetting to defaults.  Please reboot!");
 		}
 	}

Added: trunk/config/incoming.html
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/incoming.html?view=auto&rev=168
==============================================================================
--- trunk/config/incoming.html (added)
+++ trunk/config/incoming.html Fri Dec 15 20:09:44 2006
@@ -1,0 +1,54 @@
+<!--
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Configuration for "Users" generally
+ *
+ * Copyright (C) 1999 - 2006, Digium, Inc.
+ *
+ * Mark Spencer <markster at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ *
+-->
+<script src="scripts/prototype.js"></script>
+<script src="scripts/rico.js"></script>
+<script src="scripts/astman.js"></script>
+<link href="stylesheets/rico.css" media="all" rel="Stylesheet" type="text/css" />
+<link href="stylesheets/schwing.css" media="all" rel="Stylesheet" type="text/css" />
+<script>
+
+// ok 
+// Get list of user extensions to pick for mapping DIDs
+// 
+
+
+
+
+
+function localajaxinit() {
+	parent.loadscreen(this);
+}
+
+</script>
+<body id="foo" onload="localajaxinit()"  bgcolor="EFEFEF">
+<div class="mainscreenTitleBar">
+	<span style="margin-left: 4px;font-weight:bold;">Incoming Calls</span>
+	<span style="cursor: pointer; cursor: hand;" onclick="window.location.href=window.location.href;" >&nbsp;<img src="images/refresh.png" title=" Refresh " border=0 >&nbsp;</span>
+</div>
+<div class="mainscreenContentBox" id="userscontent">
+<table class="mainscreenTable" align="center">
+	
+</table>
+<div id="status"></div>
+</div>
+<SCRIPT LANGUAGE="JavaScript">
+</SCRIPT>
+</body>

Modified: trunk/config/localexts.html
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/localexts.html?view=diff&rev=168&r1=167&r2=168
==============================================================================
--- trunk/config/localexts.html (original)
+++ trunk/config/localexts.html Fri Dec 15 20:09:44 2006
@@ -93,14 +93,14 @@
 <TR>
 	<TD valign="bottom" align="center"><font style="border-bottom: 2px solid #000; padding-bottom: 2px;">Local Extension settings</font></TD>
 	<TD><A href="options.html" class="field_text">Change Password</A></TD>
-	<!-- <TD valign="bottom" align="left"><A href="#" onclick="tosetup();" class="field_text">Run Setup Wizard</A></TD> -->
+	<TD valign="bottom" align="left"><A href="#" onclick="tosetup();" class="field_text">Run Setup Wizard</A></TD> 
 </TR>
 </TABLE>
 <BR><BR>
 <table class="mainscreenTable" align="center">
 	<tr>	<td align="center" valign="top">
 					<select id="devices" style="display:none"></select> 
-					<p class="field_text">	Local Extensions are <select id="localextenlength"><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select>digits long&nbsp;</p>
+					<p class="field_text">	Local Extensions are <select id="localextenlength"><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select> digits long&nbsp;</p>
 					<p class="field_text">	Starting point of Allocation of extensions : <input type=text id="userbase" size=5>	</p>
 					<center>
 							<div style="height:15px" id='status'></div><BR>
@@ -111,4 +111,4 @@
 	<tr valign="top" height="18">	<td></td></tr>
 </table>
 </div>
-</body>
+</body>

Modified: trunk/config/networking.html
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/networking.html?view=diff&rev=168&r1=167&r2=168
==============================================================================
--- trunk/config/networking.html (original)
+++ trunk/config/networking.html Fri Dec 15 20:09:44 2006
@@ -79,7 +79,7 @@
 		$('hiddennetworking').selectedIndex = 0;
 		if ($('hiddennetworking').onchange)
 			$('hiddennetworking').onchange($('hiddenvoicemail'));
-		parent.loadscreen(this);
+		//parent.loadscreen(this);
 	}
 	
 	networkingcallbacks.format = function(t) {
@@ -89,6 +89,10 @@
 	}
 	
 	function localajaxinit() {
+	parent.loadscreen(this);
+	return;
+
+
 		$('advancedw').style.overflow = "hidden";
 		$('advancedw').style.height = 1;
 		$('advancedw').style.width = $('split').width;
@@ -114,13 +118,51 @@
 </div>
 <div class="mainscreenContentBox" id="mailboxcontent">
 <table class="mainscreenTable" align="center">
-	<tr valign="top"><td height=20></td>	</tr>
-	<tr valign="top">
-		<td height=395 align=center>
-		<div id='adjustments'>
-		<table cellspacing='0' cellpadding='0'>
-			<tr valign="top"><td>
-				<table>
+		<TR>
+			<TD valign="top" align="right">WAN Settings:</TD>
+			<TD>
+			<!--  wan settings -->
+					<TABLE>
+						<TR>
+							<TD><input type=radio id="wan_type" name="want_itype" value="dhcp">DHCP</TD>
+							<TD><input type=radio id="wan_type" name="want_itype" value="static">Static</TD>
+						</TR>
+						<TR>
+							<TD>IP</TD>
+							<TD><input size=14 id="wan_staticip"></TD>
+						</TR>
+						<TR>
+							<TD>SubNet</TD>
+							<TD><input size=14 id="wan_staticsubnet"></TD>
+						</TR>
+						<TR>
+							<TD>Gateway</TD>
+							<TD><input size=14 id="wan_staticgateway"></TD>
+						</TR>
+					</TABLE>
+			<!--  wan settings -->
+			</TD>
+		</TR>
+		<TR>
+			<TD  valign="top" align="right">LAN Settings:</TD>
+			<TD>
+			<!--  Lan settings -->
+				<table align='center'>
+				<tr><td>Local Subnet</td><td><input type='text' size='16' id='LAN_SUBBLOCK'></td></tr>
+				<tr><td>Alternate Local Subnet</td><td><input size='16' type='text' id='LAN_ALTSUBBLOCK'></td></tr>
+				<tr><td>Netmask</td><td><input type='text' size='16' id='LAN_NETMASK'></td></tr>
+				<tr><td>DHCP Start unit</td><td><input type='text' size='5' id='LAN_DHCPSTARTUNIT'></td></tr>
+				<tr><td>DHCP Count</td><td><input type='text' size='5' id='LAN_DHCPCOUNT'></td></tr>
+				</table>
+			<!--  Lan settings -->
+			</TD>
+		</TR>
+		<TR>
+			<TD valign="top" align="right">WIRELESS Settings:</TD>
+			<TD>
+			<!--  wireless settings -->
+
+<table>
 				<tr><td>Operating Mode:</td><td><select id='OPERMODE'>
 					<option value='FCC'>FCC (US, Canada)</option>
 					<option value='TBR21'>TBR21 (Most of Europe)</option>
@@ -197,43 +239,29 @@
 					<option value="YEMEN">Yemen</option>
 				</select></td></tr>
 				<tr><td>Hostname:</td><td><input type='text' id='HOSTNAME'></td></tr>
-				<tr><td>ESSID:</td><td><input type='text' id='ESSID'></td></tr>
-				<tr><td>WEP Key:</td><td><input type='text' id='WEPKEY'></td></tr>
-				<tr><td>SSH Access:</td><td><select id='SSHACCESS'><option value=''>Disabled</option><option value='yes'>Enabled</option></select></td></tr>
-				<tr><td colspan='2' align='center'><div style="height:15px" id='status'></div></td></tr>
+				<tr><td>ESSID:</td><td><input type='text' id='WL_ESSID'></td></tr>
+				<tr><td>WEP Key:</td><td><input type='text' id='WL_WEPKEY'></td></tr>
+						<TR>
+							<TD><input type=radio id="WL_type" name="wl_itype" value="dhcp">DHCP</TD>
+							<TD><input type=radio id="WL_type" name="wl_itype" value="static">Static</TD>
+						</TR>
+						<TR>
+							<TD>IP</TD>
+							<TD><input size=14 id="wl_staticip"></TD>
+						</TR>
+						<TR>
+							<TD>SubNet</TD>
+							<TD><input size=14 id="wl_staticsubnet"></TD>
+						</TR>
+						<TR>
+							<TD>Gateway</TD>
+							<TD><input size=14 id="wl_staticgateway"></TD>
+						</TR>
 				</table>
-			</td>
-			</tr>
-			<tr><td><img id="split" onClick="togglefeatures()" src="images/split-v.gif"></td></tr>
-			<tr><td>
-				<div style="background-image:url(images/slice-v.gif)" id='advancedw'>
-				<table id='advancedi' align='center'>
-				<tr><td></td><td width='50' height=5></td><td></td></tr>
-				<tr><td>Local Subnet</td><td><input type='text' size='16' id='SUBBLOCK'></td></tr>
-				<tr><td>Alternate Local Subnet</td><td><input size='16' type='text' id='ALTSUBBLOCK'></td></tr>
-				<tr><td>Netmask</td><td><input type='text' size='16' id='NETMASK'></td></tr>
-				<tr><td>DHCP Start unit</td><td><input type='text' size='5' id='DHCPSTARTUNIT'></td></tr>
-				<tr><td>DHCP Count</td><td><input type='text' size='5' id='DHCPCOUNT'></td></tr>
-				</table>
-				</div>
-			</td></tr>
-			<tr><td>
-				<img onClick="togglefeatures()" src="images/adv-v.gif">
-			</td>
-			</tr>
-		</table>
-		</div>
-		</td>
-	</tr>
-	<tr><td align='center' colspan='2'>
-						<input type='hidden' id='name'>
-						<input style='width:80' type='button' id='save' value='Save'>&nbsp;&nbsp;<input style='width:80' type='button' id='cancel' value='Cancel'>
-						<div style='visibility:hidden;overflow:hidden;width:0px;height:0px'>
-								<select id='hiddenusers'>	</select>
-								<select id='hiddennetworking'></select>
-						</div>
-			</td>				
-	</tr>
+			<!--  wireless settings -->
+			</TD>
+		</TR>
+
 </table>
 </div>
 </body>

Modified: trunk/config/numberplan.html
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/numberplan.html?view=diff&rev=168&r1=167&r2=168
==============================================================================
--- trunk/config/numberplan.html (original)
+++ trunk/config/numberplan.html Fri Dec 15 20:09:44 2006
@@ -18,7 +18,6 @@
  * 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>
@@ -26,537 +25,479 @@
 <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 origwidth;
-	var widgets = new Array;
-	var adstatus;
-	var meetmes;
-	var callbacks = new Object;
-	var usercallbacks = new Object;
-	var fieldnames = new Array(
-				'name', 'delete', 'status', 'new', 'newitem', 'priority', 'realpriority',
-				'save', 'cancel', 'comment', 'planident', 'trunk', 'include');
-
-	function changed_extension() {
-		var app;
-		var tmp = $('extensions').value.split(']');
-		var app = findapp($('extensions').stored_config.catbyname[tmp[0]].subfields[tmp[1]]['app']);
-		$('name').value = $('extensions').stored_config.catbyname[tmp[0]].subfields[tmp[1]]['name'];
-		$('features').value = app.name.toLowerCase();
+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 isnewrule ;
+var iscustom ;
+var pattern_beingedited ;
+var pattern_beingedited_priority ;
+
+
+function addthe_default_callingplan(){
+	t=confirm("A default Dial Plan is not found. \n" + " Do you want to create a default Dial Plan ");
+	if(t == false){ 
+		$('status').innerHTML = "A default DialPlan is not found !! "
+		+ "<BR> <A href=\"#\" onclick=\"addthe_default_callingplan()\">click here</A> to create a default Dial plan";
+		$('addrule').disabled = 1;
+		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"); 
+	var opt = {
+		method: 'get',
+		asynchronous: true,
+		onSuccess: function(t) { location.reload(); },
+		onFailure: function(t) {
+			alert("Config Error: " + t.status + ": " + t.statusText);
+		}
 	};
-
-	callbacks.fields2val = function(box, subfields) {
-		// Called when (new/existing) Pattern is Saved - Onclik of "Save" of Pattern
-		var flags = "d";
-		var xargs="";
-		var room;
-		var newpriority = 0 ;
-		// Calculate New Priority
-		if( $('priority').value != ''){
-				newpriority = Number($('priority').value);
+	opt.parameters= "action=updateconfig&reload=yes&srcfilename=" + encodeURIComponent("extensions.conf") + "&dstfilename=" + encodeURIComponent("extensions.conf") + uri;
+	var tmp = new Ajax.Request("../../rawman", opt);
+}
+
+
+
+
+trunkcallbacks.format = function(t) {
+	if (t.name.substr(0,6) != 'trunk_')
+		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('change',enablesave,false);
+	parent.astmanEngine.config2list("extensions.conf", $('extensions'), new Array(), numplan_callbacks);
+}
+
+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.loadscreen(this);
+	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 ( x == "extend"){ break;}
+			var sorted_priorities = [];
+			for ( var y in default_np_data[x] ){
+				if ( y == "extend"){break;}
+				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 ){
+							trunk_exists = 1;
+							break;
+						}
+				}				
+				if ( default_np_data[x][sorted_priorities[z]].trunk  == "" || trunk_exists == 0 ){
+						if(default_np_data[x][sorted_priorities[z]].trunk  == "" ){
+							alert("A Service Provider is not defined for this Rule ("+default_np_data[x][sorted_priorities[z]].rulename+")\n"
+						+" You will now be asked to choose a Service Provider ");
+						}else if( trunk_exists == 0 ){
+							alert("Calling Rule ("+default_np_data[x][sorted_priorities[z]].rulename+") has an invalid Service Provider\n"
+						+" You will now be asked to choose from a list of existing Service Providers ");
+						}
+						editcallingrule(x , sorted_priorities[z]);
+						return true;
+				}
+				addrowtotable( x , sorted_priorities[z] , default_np_data[x][sorted_priorities[z]].trunk , default_np_data[x][sorted_priorities[z]].digits2strip );
+			}
+	} 
+}
+
+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.innerHTML = trunks_desc[c].comment  ;
+		newCell3.width=85;
+
+		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){
+		if(default_np_data[a][b].ruledesc == 'custom'){
+			var commentstring = "custom";
 		}else{
-				name_parts = $('extensions').value.split(']');
-				
-				for (v=0; v < $('extensions').length; v++){
-					tname = $('extensions').options[v].value.split(']');
-					if(tname[1]>0 && $('extensions').options[v].text !='New Entry' ){
-						if( name_parts[0] == tname[0] && $('name').value == box.stored_config.catbyname[tname[0]].subfields[tname[1]]['name'] &&  box.stored_config.catbyname[tname[0]].subfields[tname[1]]['priority'] > newpriority ){
-							newpriority=box.stored_config.catbyname[tname[0]].subfields[tname[1]]['priority'];
+			var commentstring = "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&reload=yes&srcfilename=" + encodeURIComponent("extensions.conf") + "&dstfilename=" + encodeURIComponent("extensions.conf") + uri;
+		$('userscontent').style.display="none";
+		$('status_message').style.display="block";
+		var tmp = new Ajax.Request("../../rawman", opt);
+}
+
+
+
+
+function editcallingrule(a,b){
+	pattern_beingedited = a ;
+	pattern_beingedited_priority = b ;
+
+	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="";
+	$('addrule').disabled =1;
+}
+
+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');
+	//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
+	if(posofx == -1){ 	
+			if(returnstring == "or more"){
+				returnstring = "Begins with " + temp + " and followed by 0 or more digits" ;
+			}else{
+				returnstring = "Exactly macthes " + temp  ;
+			}
+			if(e == 1){
+				$('beginswith').value = temp;
+				$('followedby').value = 0;
+			}
+	}else{
+			if(returnstring == "or more"){
+				returnstring = "Begins with " + temp.substr(0,posofx) + " and followed by "+(temp.length - posofx)+" or more digits" ;
+			}else{
+				returnstring = "Begins with " + temp.substr(0,posofx) + " and followed by "+(temp.length - posofx) + " digits";
+			}
+			if(e == 1){
+				$('beginswith').value = temp.substr(0,posofx);
+				$('followedby').value = (temp.length - posofx);
+			}
+	}
+
+return returnstring;
+}
+
+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;
+	$('rulename').value = "";
+	$('trunks').selectedIndex = -1 ;
+	$('pattern').value = "";
+	$('strip').value = "0" ;
+	$('save_a').disabled = 1;
+	$('define_advanced').style.display="none";
+	$('define_usual').style.display="";
+	$('userscontent').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";
+					}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&reload=yes&srcfilename=" + encodeURIComponent("extensions.conf") + "&dstfilename=" + encodeURIComponent("extensions.conf") + uri;
+					$('userscontent').style.display="none";
+					$('status_message').style.display="block";
+					var tmp = new Ajax.Request("../../rawman", opt);
+}
+
+
+function saverule(){
+	 if(isnewrule){ // add this rule to the default plan and reload the page
+					var newpriority=1;
+					if( typeof default_np_data[$('pattern').value] !="undefined" ){
+						for ( var y in default_np_data[$('pattern').value] ){
+							if ( y == "extend"){break;}
+							newpriority++;
 						}
 					}
-				}
-				
-				newpriority = Number(newpriority) + 1;
-		}
-		room = $('trunk').stored_config.catbyname[$('trunk').value].fieldbyname['dialformat'];
-		if (!room || (room == ''))
- 			room = '${EXTEN:1}';
- 		return $('name').value + "," + newpriority + ",Macro(trunkdial,${" + $('trunk').value + "}/" + room + ")";
-	}
-
-
-	callbacks.compare = function(w, a, b) {
-		var tmpa = a.value.split(']');
-		var tmpb = b.value.split(']');
-		if (tmpa.length > 1) {
-			if (tmpb.length > 1) {
-				/* Both are entries */
-				if (tmpa[0] != tmpb[0])
-					return tmpa[0] < tmpb[0];
-				else {
-					if (w.stored_config.catbyname[tmpa[0]].subfields[tmpa[1]]['name'] == 
-					    w.stored_config.catbyname[tmpb[0]].subfields[tmpb[1]]['name']) {
-						if (w.stored_config.catbyname[tmpa[0]].subfields[tmpa[1]]['realpriority'] <
-						       w.stored_config.catbyname[tmpb[0]].subfields[tmpb[1]]['realpriority'])
-							return true;
-						else
-							return false;
-					} else {
-						if (w.stored_config.catbyname[tmpa[0]].subfields[tmpa[1]]['name'] <
-						    w.stored_config.catbyname[tmpb[0]].subfields[tmpb[1]]['name'])
-								return true;
-						else
-							return false;
-					}
-				}
-			} else {
-				/* A is an entry, B is a context */
-				return tmpa[0] < b.value;
-			}
-		} else {
-			if (tmpb.length > 1) {
-				/* A is an context, B is an entry */
-				return a.value <= tmpb[0];
-			} else {
-				/* Both A and B are contexts */
-				return a.value < b.value;
-			}
-		}
-		return a.innerHTML < b.innerHTML;
-	}
-
-
-
-
-	callbacks.format = function(t, x) {
-		var ret;
-		var tmp;
-		var options = new Array;
-		var tmp2, y;
-		var context;
-		var v;
-			
-		if ((t.name.substr(0,11) != 'numberplan-'))
-			return null;
-		if (x == null) {
-			if (t.fieldbyname['comment'])
-				return t.fieldbyname['comment'];
-			else
-				return t.name;
-		}
-		ret = format_extension($('extensions'), t, x, 1);
-
-		if (ret) {
-			tmp = t.subfields[x].args.split(',');
-
-			if ((t.subfields[x].app != 'Macro') || (tmp[0] != 'trunkdial'))
-				return "|  " + ret;
-
-			tmp2 = tmp[1].split('}');
-			context = tmp2[0].substr(2);
-			t.subfields[x].trunk = context;
-			context = $('trunk').stored_config.catbyname[context];
-			return "|  " +
-				t.subfields[x].name + " via " + 
-				context.fieldbyname['trunkname'];
-			tmp = t.subfields[x].args.split(',');
-			if (tmp[1]) {
-				tmp2 = tmp[1].split('');
-				for (y=0;y<tmp2.length;y++)
-					options[tmp2[y]] = 'yes';
-			}
-		}
-		return ret;
-	}
-
-
-
-
-	function matches(box, category, index, offset) {
-		var tmp;
-		if ((offset > 0) && (offset < box.options.length)) {
-			tmp = box.options[offset].value.split(']');
-			if ((tmp.length > 1) && (tmp[0] == category)) {
-				if (box.stored_config.catbyname[category].subfields[index].name ==
-					box.stored_config.catbyname[category].subfields[tmp[1]].name)
-						return true;
-			}
-		}
-		return false;
-	}
-
-
-
-	callbacks.checkparams = function(box) {
-		// Occurs when a Pattern or a Plan is saved
-		var tmp = box.value.split(']');
-		if (tmp.length < 2) {
-			$('name').value = 'numberplan-' + $('planident').value;
-		}
-
-	}
-
-	callbacks.postselect = function(box, val) {
-		callbacks_postselect(box, val);
-	}
-
-	function callbacks_postselect(box, val){
-			// called "ON page load" and when the  extensions select box is clicked
-				var tmp;
-				tmp = val.split(']');
-				$('combobox_div').style.display = "none";
-				$('advancedi').style.display = "" ;
-
-				if (tmp.length > 1) {
-						/* Found an entry */
-						// Clicked on a SubMenu
-						$('priup').disabled = !matches(box, tmp[0], tmp[1], box.selectedIndex - 1);
-						$('pridown').disabled = !matches(box, tmp[0], tmp[1], box.selectedIndex + 1);
-						$('planident').disabled = true;
-						$('trunk').disabled = false;
-						$('planident').value =  '';
-						$('include').disabled = true;
-						$('comment').disabled = true;
-						$('newitem').disabled=true; // "Add new Pattern" is disabled
-						$('advancedi').style.display = "none" ;
-							// Hide the Advanced Panel
-							adstatus = "hidden";
-							new Rico.Effect.Size('advancedw', null, 1, 120, 8, {complete:function() { $('advancedw').style.height=1;} } );
-
-				} else {
-						// Clicked a MainMenu - The blue ones
-						$('priup').disabled = true;
-						$('pridown').disabled = true;
-						$('trunk').disabled = true;
-						$('planident').value = $('name').value.substr(11);
-						$('name').disabled = true;
-						$('newitem').disabled=false; // "Add new Pattern" is Enabled
-						$('modplan').disabled = false;
-						if ($('modplan').checked) {
-							$('planident').disabled = false;
-							$('comment').disabled = false;
-							$('include').disabled = false;
-							$('delete').disabled=false;
-							$('save').disabled=true;
-						}else{
-							$('delete').disabled=true;
-							$('save').disabled=true;
-							$('planident').disabled = true;
-							$('comment').disabled = true;
-							$('include').disabled = true;
-						}
-				}
-				$('new').disabled = !$('modplan').checked;
-				$('priority').disabled = true;
-				$('realpriority').disabled = true;
-	}
-
-
-	function updateplandel() {
-	// called "onpage load" and when the  'Customize Plans' checkbox  is  flipped
-
-		var tmp;
-		var x;
-		for (x=0;x<$('extensions').options.length;x++) {
-				tmp = $('extensions').options[x].value.split(']');
-				if (tmp.length < 2) { $('extensions').options[x].style.color = '#0000CC'; }
-				$('extensions').options[x].disabled = false;
-		}
-		$('new').disabled = !$('modplan').checked;
-		$('planident').disabled = !$('modplan').checked;
-		$('comment').disabled = !$('modplan').checked;
-		$('include').disabled = !$('modplan').checked;
-		// If the submenu is the one that is currently highlighted then donot disable the delete button
-		tmp_as =  $('extensions').value.split(']');
-		if(tmp_as.length > 1){ }else{ $('delete').disabled = !$('modplan').checked; }
-	}
-
-
-
-
-	callbacks.savechanges = function() {
-	// called when a New Plan or new Pattern is added
-		callbacks_postselect($('extensions'), $('extensions').value  );
-		updateplandel();
-	}
-
-
-	callbacks.loaded = function() {
-		$('extensions').contentEditable = 'true';
-		$('extensions').disabled = 0;
-		updateplandel();
-		parent.loadscreen(this);
-		$('newitem').disabled=true;
-		$('combosel').addEventListener('click', function(){	$('save').disabled = false; $('cancel').disabled = false; }, false);
-	}
-
-	
-	callbacks.sortfunc = function(a,b) {
-		return (a.name < b.name) ? -1 : 1;
-	}
-
-
-
-	callbacks.newsubitem = function(t) {
-		// On "Add Pattern" Click
-		var tmp = new Object;
-		var x;
-		var gen;
-		tmp['name'] = $('combosel').options[0].value;
-		numplan = $('extensions').value ;
-							// Hide the Advanced Panel
-							adstatus = "hidden";
-							new Rico.Effect.Size('advancedw', null, 1, 120, 8, {complete:function() { $('advancedw').style.height=1;} } );
-							$('advancedi').style.display = "none" ;
-
-		return new Array(numplan, 'exten', tmp);
-	}
-	
-	
-	callbacks.newcategory = function() {
-		
-		var tmp = null;
-		var x;
-		if ($('extensions').stored_config.catbyname['general'])
-			tmp = objcopy($('extensions').stored_config.catbyname['general']);
-		if (tmp) {
-			x = 1;
-			while($('extensions').stored_config.catbyname['numberplan-custom-' + x]) x++;
-			tmp.name = 'numberplan-custom-' + x;
-			tmp.fieldbyname['comment'] = 'Custom Plan ' + x;
-			tmp.fieldbyname['planident'] = 'custom-' + x;
-			tmp.fieldbyname['include'] = 'default';
-		}
-		$('modplan').disabled = true;
-		return tmp;
-	}
-	
-	callbacks.identifier = "extension";
-	callbacks.eachline = true;
-	callbacks.includecats = true;
-	
-	
-	usercallbacks.format = function(t) {
-		if (t.name.substr(0,6) != 'trunk_')
-			return null;

[... 3640 lines stripped ...]


More information about the asterisk-gui-commits mailing list