Sorry, disregard my last email.  Here is the patch.

Erin

----- Original Message -----
> From: "Andrew Latham" <lath...@gmail.com>
> To: "Asterisk GUI project discussion" <asterisk-gui@lists.digium.com>
> Sent: Thursday, August 26, 2010 12:40:03 PM
> Subject: Re: [asterisk-gui] Manage Calling Rules + Prepend These Digits error
> We have been watching...
> 
> 
> ~
> Andrew "lathama" Latham
> lath...@gmail.com
> 
> * Learn more about OSS
> http://en.wikipedia.org/wiki/Open-source_software
> * Learn more about Linux http://en.wikipedia.org/wiki/Linux
> * Learn more about Tux http://en.wikipedia.org/wiki/Tux
> 
> 
> 
> On Thu, Aug 26, 2010 at 1:28 PM, Erin Spiceland
> <espicel...@digium.com> wrote:
> > Please forgive the out-of-thread email. I have just subscribed to
> > this list, so I cannot reply to a previous email.
> >
> > The issue where extraneous ${ and } are added to the calling rule
> > has been fixed in svn r5070.
> >
> > Regards,
> >
> > Erin
> >
> > --
> > _____________________________________________________________________
> > -- Bandwidth and Colocation Provided by http://www.api-digital.com
> > --
> >
> > asterisk-gui mailing list
> > To UNSUBSCRIBE or update options visit:
> >   http://lists.digium.com/mailman/listinfo/asterisk-gui
> >
> 
> --
> _____________________________________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
> 
> asterisk-gui mailing list
> To UNSUBSCRIBE or update options visit:
> http://lists.digium.com/mailman/listinfo/asterisk-gui
Index: js/astman.js
===================================================================
--- js/astman.js	(revision 5069)
+++ js/astman.js	(revision 5070)
@@ -1685,11 +1685,60 @@
 
 		getArgsArrayFromArgsString: function(x){ // expects x as 'context,exten,pri' or 'context,exten,pri'
 			if (typeof x != 'string') return [];
+
+			var nested_parse = function (str, sep) {
+				var buffer = '';
+				var stack = new Array();
+				var depth = 0;
+				var len = str.length;
+				for(var i=0; i<len; i++) {
+					var char = str.charAt(i);
+					switch(char) {
+					case '(':
+						depth++;
+						break;
+					case sep.toString():
+						if (!depth) {
+							if (buffer != '') {
+								stack.push(buffer);
+								buffer = '';
+							}
+
+							continue;
+						}
+
+						break;
+					case ' ':
+						if (!depth) {
+							continue;
+						}
+						break;
+					case ')':
+						if (depth) {
+							depth--;
+						} else {
+							stack.push("" + buffer + char);
+							buffer = '';
+							continue;
+						}
+						break;
+					}
+					buffer += char;
+				}
+
+				if (buffer == '') {
+					stack.push(buffer);
+				}
+
+				return stack;
+			};
+
 			if(x.contains(',') ){
-				return x.split(',');
+				nested_parse(x,',');
+				return nested_parse(x,',');
 			}
 			if(x.contains('|') ){
-				return x.split('|');
+				return nested_parse(x,'|');
 			}
 			return [x] ;
 		},
@@ -1906,16 +1955,26 @@
 				if(!WhatToDial.contains('${EXTEN')){ // if WhatToDial is in some other format that the gui does not understand
 					// TODO : replace the above if condition with a regular expression to check for the acceptable formats
 					// TODO : THROW ERROR
-					return {name : trunkname, channel : channel, prepend : WhatToDial, stripx : ''};
+					return {name : trunkname, channel : channel, prepend : WhatToDial, stripx : '', filter: ''};
 				}
 				var prepend = WhatToDial.beforeChar('$') ;
-				var extenString = WhatToDial.betweenXY('{','}') ;
+				if (WhatToDial.contains('FILTER')) {
+					var filterstring = WhatToDial.betweenXY('(', ')');
+					filterstring = filterstring.split(',');
+
+					var extenString = filterstring[1].betweenXY('{', '}');
+					var filter = filterstring[0];
+				} else {
+					var extenString = WhatToDial.betweenXY('{','}') ;
+					var filter = '';
+				}
 				var stripXdigitsfromfront = ( extenString.contains(':') ) ? extenString.afterChar(':') || '0' : '0' ;
 			} else { // WhatToDial is a plain extension string such as '911' or 'pari'
 				var prepend = WhatToDial ;
 				var stripXdigitsfromfront = 'ALL' ;
+				var filter = '';
 			}
-			return { name : trunkname, channel : channel, prepend : prepend, stripx : stripXdigitsfromfront };
+			return { name : trunkname, channel : channel, prepend : prepend, stripx : stripXdigitsfromfront, filter: filter};
 		},
 
 		obCallingRule: function(str){ // usage ASTGUI.parseContextLine.obCallingRule(str)
@@ -1953,16 +2012,19 @@
 					cr.firstTrunk = t1.name ;
 					cr.firstPrepend = t1.prepend ;
 					cr.stripdigits_firstTrunk = t1.stripx ;
+					cr.firstFilter = t1.filter;
 		
 				if( macroargs.length <= 2  || ( macroargs.length > 2 && macroargs[2].trim() == '') ){ // if a failback trunk is not defined
 					cr.secondTrunk = '' ;
 					cr.secondPrepend = '' ;
 					cr.stripdigits_secondTrunk = '' ;
+					cr.secondFilter = '';
 				}else{
 					var t2 = ASTGUI.parseContextLine.parseTrunkDialArgument( macroargs[2] ) ;
 					cr.secondTrunk = t2.name ;
 					cr.secondPrepend = t2.prepend ;
 					cr.stripdigits_secondTrunk = t2.stripx ;
+					cr.secondFilter = t2.filter;
 				}
 			}else{
 				cr.destination = ASTGUI.parseContextLine.getAppWithArgs( str ) ;
Index: js/callingrules.js
===================================================================
--- js/callingrules.js	(revision 5069)
+++ js/callingrules.js	(revision 5070)
@@ -46,6 +46,9 @@
 	isNew = false;
 	_$('cr_dialog_title').innerHTML ='&nbsp;&nbsp;Edit Calling Rule';
 
+	DOM_new_crl_tr_filter.value = '';
+	DOM_new_crl_fotr_filter.value = '';
+
 	EDIT_CR = a;
 	EDIT_CR_RULE = b;
 	var tmp_cr = ASTGUI.parseContextLine.obCallingRule(b) ;
@@ -63,11 +66,13 @@
 
 		DOM_new_crl_tr_stripx.value = tmp_cr.stripdigits_firstTrunk  ;
 		DOM_new_crl_tr_prepend.value = tmp_cr.firstPrepend ;
+		DOM_new_crl_tr_filter.value = tmp_cr.firstFilter;
 		if(tmp_cr.secondTrunk){
 			DOM_new_crl_foChkbx.checked = true 
 			ASTGUI.selectbox.selectOption(DOM_new_crl_fotrunk, tmp_cr.secondTrunk );
 			DOM_new_crl_fotr_stripx.value = tmp_cr.stripdigits_secondTrunk ;
 			DOM_new_crl_fotr_prepend.value = tmp_cr.secondPrepend ;
+			DOM_new_crl_fotr_filter.value = tmp_cr.secondFilter;
 		} else {
 			DOM_new_crl_foChkbx.checked = false;
 		}
@@ -335,12 +340,12 @@
 		}
 
 		var t1_braces = (t1 == 'Skype') ? t1 : '${' + t1 + '}' ;
-		var Trunk_Build_str = ',' + t1_braces + '/' + DOM_new_crl_tr_prepend.value + '${' + DOM_new_crl_tr_filter.value +',${EXTEN:' + tmp_stripx  + '})}' ;
+		var Trunk_Build_str = ',' + t1_braces + '/' + DOM_new_crl_tr_prepend.value + '${FILTER(' + DOM_new_crl_tr_filter.value +',${EXTEN:' + tmp_stripx  + '})}' ;
 		var foTrunk_Build_str = ',' ;
 
 		if(DOM_new_crl_foChkbx.checked){
 			var t2_braces = (t2 == 'Skype') ? t2 : '${' + t2 + '}' ;
-			foTrunk_Build_str += t2_braces + '/' + DOM_new_crl_fotr_prepend.value + '${EXTEN:' + tmp_fotr_stripx + '}' ;
+			foTrunk_Build_str += t2_braces + '/' + DOM_new_crl_fotr_prepend.value + '${FILTER(' + DOM_new_crl_fotr_filter.value + ',${EXTEN:' + tmp_fotr_stripx + '})}' ;
 		}
 
 		var t1_cidarg = ( t1 == 'Skype') ? ',' : ',' + t1 ;
-- 
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-gui mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-gui

Reply via email to