rbrindley: branch rbrindley/astman_revamp r4663 - /team/rbrindley/astman_reva...

SVN commits to the Asterisk-GUI project asterisk-gui-commits at lists.digium.com
Thu Mar 26 10:45:13 CDT 2009


Author: rbrindley
Date: Thu Mar 26 10:45:10 2009
New Revision: 4663

URL: http://svn.digium.com/svn-view/asterisk-gui?view=rev&rev=4663
Log:

- created pbx.trunks.rules.add


Modified:
    team/rbrindley/astman_revamp/config/js/pbx2.js

Modified: team/rbrindley/astman_revamp/config/js/pbx2.js
URL: http://svn.digium.com/svn-view/asterisk-gui/team/rbrindley/astman_revamp/config/js/pbx2.js?view=diff&rev=4663&r1=4662&r2=4663
==============================================================================
--- team/rbrindley/astman_revamp/config/js/pbx2.js (original)
+++ team/rbrindley/astman_revamp/config/js/pbx2.js Thu Mar 26 10:45:10 2009
@@ -1493,6 +1493,112 @@
 
 	return true;
 };
+
+/**
+ * Incoming Calling Rules.
+ */
+pbx.trunks.rules = {};
+
+/**
+ * Add an incoming calling rule.
+ * @param trunk The trunk.
+ * @param name Name of the rule.
+ * @param dest The destination.
+ * @param pattern The extension pattern.
+ * @param time_interval [optional] The time interval.
+ * @param digits [optional] The 'x' in '${EXTEN:x}', for when dest === 'ByDID'.
+ * @return boolean on success.
+ */
+pbx.trunks.rules.add = function(params) {
+	/* check to make sure we got everything */
+	if (typeof params !== 'object') {
+		top.log.error('pbx.trunks.rules.add: Expecting params to be an object.');
+		return false;
+	} else if (!params.trunk) {
+		top.log.error('pbx.trunks.rules.add: params.trunk not found.');
+		return false;
+	} else if (!params.name) {
+		top.log.error('pbx.trunks.rules.add: params.name not found.');
+		return false;
+	} else if (!params.dest) {
+		top.log.error('pbx.trunks.rules.add: params.dest not found.');
+		return false;
+	} else if (!params.pattern) {
+		top.log.error('pbx.trunks.rules.add: params.pattern not found.');
+		return false;
+	} if (params.dest === 'ByDID' && !params.digits) {
+		top.log.error('pbx.trunks.rules.add: Destination is ByDID, but params.digits is not found.');
+		return false;
+	}
+
+	/* easier to type/use */
+	var delim = top.session.delimiter;
+
+	/* lets form the cxt and include line, depending on time_interval or not */
+	var cxt = ASTGUI.contexts.TrunkDIDPrefix + params.trunk;
+	var include = 'include=' + cxt;
+	if (params.time_interval) {
+		cxt += '_' + ASTGUI.contexts.TimeIntervalPrefix + params.time_interval;
+		include += delim + '${' + ASTGUI.contexts.TimeIntervalPrefix + params.name + '}';
+	}
+
+	/* kk, now lets form the rule */
+	var trunk_type = parent.pbx.trunks.getType(params.trunk);
+	var prior = (trunk_type === 'analog' && params.pattern === 's') ? '3' : '1';
+	var rule = params.pattern + delim + prior + delim;
+	rule += (params.dest === 'ByDID') ? 'Goto(default,${EXTEN:'+params.digits+'}'+delim+'1)' : params.dest;
+
+	/* TODO: cache this on load, this isn't optimal even to call it on page load */
+	var extens_conf = config2json({filename: 'extensions.conf', usf:0});
+
+	/* lets make sure this incoming rule doesn't already exist */
+	if (extens_conf.hasOwnProperty(cxt) && extens_conf[cxt].indexOfLike('exten=' + params.pattern + ',') != -1) {
+		parent.ASTGUI.dialog.hide();
+		top.log.error('pbx.trunks.rules.add: incoming calling rule with this pattern already exists.');
+		/* i don't like this one bit...but am just copying for now... */
+		alert('An incoming rule already exists for this pattern in the selected Time Interval.');
+		return false;
+	}
+
+	/* potentially large request, TODO: use listOfActions instead, but not until it returns response */
+	var actions = new listOfSynActions('extensions.conf');
+
+	/* if the main trunk context doesn't already have the include line, lets add it */
+	var trunk_cxt = extens_conf[ASTGUI.contexts.TrunkDIDPrefix + params.trunk];
+	if (!trunk_cxt.contains(include) && params.time_interval) {
+		/* add time interval includes at the front */
+		trunk_cxt.splice(0,0,include);
+		trunk_cxt.each(function(line) {
+			actions.new_action('delete', ASTGUI.contexts.TrunkDIDPrefix + params.trunk, line.beforeChar('='), line.afterChar('='));
+			actions.new_action('append', ASTGUI.contexts.TrunkDIDPrefix + params.trunk, line.beforeChar('='), line.afterChar('='));
+		});
+	} else if (!trunk_cxt.contains(include)) {
+		/* add default includes at the end */
+		actions.new_action('append', ASTGUI.contexts.TrunkDIDPrefix + params.trunk, 'include', cxt);
+	}
+
+	/* create the context if it doesn't exist */
+	if (!extens_conf.hasOwnProperty(cxt)) {
+		actions.new_action('newcat', cxt, '', '');
+	}
+
+	/* lets append the rule to the cxt, special CID for analog&catchall */
+	if (prior === '3') {
+		actions.new_action('append', cxt, 'exten', ASTGUI.globals.sbcid_1);
+		actions.new_action('append', cxt, 'exten', ASTGUI.globals.sbcid_2);
+	}
+	actions.new_action('append', cxt, 'exten', rule);
+
+	/* calling the actions! */
+	var resp = actions.callActions();
+	if (!resp.contains('Response: Success')) {
+		top.log.error('pbx.trunks.rules.add: Error adding to extensions.conf.');
+		top.log.error(resp);
+		return false;
+	}
+
+	return true;
+};
 /*---------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------*/




More information about the asterisk-gui-commits mailing list