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

SVN commits to the Asterisk-GUI project asterisk-gui-commits at lists.digium.com
Wed Mar 11 14:14:50 CDT 2009


Author: rbrindley
Date: Wed Mar 11 14:14:47 2009
New Revision: 4616

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

- fixed a bug in pbx.time_intervals.add related to ext_conf.callActions()
- implemented pbx.time_intervals.edit


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=4616&r1=4615&r2=4616
==============================================================================
--- team/rbrindley/astman_revamp/config/js/pbx2.js (original)
+++ team/rbrindley/astman_revamp/config/js/pbx2.js Wed Mar 11 14:14:47 2009
@@ -389,8 +389,9 @@
 
 	/* update extensions.conf */
 	var ext_conf = new listOfActions('extensions.conf');
-
-	var resp = ext_cont.new_action('update', 'globals', name, value);
+	ext_conf.new_action('update', 'globals', ASTGUI.contexts.TimeIntervalPrefix + name, value);
+
+	var resp = ext_conf.callActions();
 	if (!resp.contains('Response: Success')) {
 		top.log.error('pbx.time_intervals.add: error updating extensions.conf');
 		return false;
@@ -398,6 +399,94 @@
 
 	/* TODO: add new time interval to gui cache */
 
+	ASTGUI.feedback({ msg: 'Created time interval!', showfor: 3, color: 'green', bgcolor: '#ffffff'});
+	return true;
+};
+
+/**
+ * Edit a Time Interval.
+ * @param oldname Old Name of the Interval.
+ * @param newname New Name of the Interval.
+ * @param interval contains: time, weekdays, days, months
+ * @return boolean on success.
+ */
+pbx.time_intervals.edit = function(oldname, newname, interval) {
+	/* check the basics */
+	if (!name) {
+		top.log.error('pbx.time_intervals.add: name is empty.');
+		return false;
+	} else if (typeof interval !== 'undefined') {
+		top.log.error('pbx.time_intervals.add: interval is undefined.');
+		return false;
+	}
+
+	/* validate the name */
+	if (newname.contains(' ')) {
+		top.log.error('pbx.time_intervals.add: name contains spaces.');
+		return false;
+	}
+
+	/* set defaults. can't loop through members, that assumes they exist. */
+	interval.time = interval.time || '*';
+	interval.weekdays = interval.weekdays || '*';
+	interval.days = interval.days || '*';
+	interval.months = interval.months || '*';
+
+	/* validate all the args */
+	if (!this.validate.time(interval.time)) {
+		top.log.error('pbx.time_intervals.add: invalid time.');
+		return false;
+	} else if (!this.validate.weekdays(interval.weekdays)) {
+		top.log.error('pbx.time_intervals.add: invalid days of the week.');
+		return false;
+	} else if (!this.validate.day(interval.days)) {
+		top.log.error('pbx.time_intervals.add: invalid day.');
+		return false;
+	} else if (!this.validate.month(interval.months)) {
+		top.log.error('pbx.time_intervals.add: invalid month.');
+		return false;
+	}
+
+	/* create the time interval string */
+	var value = interval.time.toString() + top.session.delimiter
+		+ interval.weekdays.toString() + top.session.delimiter
+		+ interval.days.toString() + top.session.delimiter
+		+ interval.months.toString();
+
+	/* update extensions.conf */
+	var actions = new listOfActions('extensions.conf');
+	actions.new_action('delete', 'globals', ASTGUI.contexts.TimeIntervalPrefix + oldname, '', '');
+
+	var exten_conf = config2json({filename:'extensions.conf', usf:0});
+	for (var cxt in exten_conf) {
+		if (!exten_conf.hasOwnProperty(cxt)) {
+			continue;
+		}
+
+		if (cxt.beginsWith(ASTGUI.contexts.TrunkDIDPrefix) && !cxt.contains('_' + ASTGUI.contexts.TimeInteralPrefix)) {
+			var lines = exten_conf[cxt];
+			lines.each(function(line) {
+				if (line.beginsWith('include=') && line.contains(ASTGUI.contexts.TrunkDIDPrefix) && (line.contains(oldname + ',${') || line.contains(oldname + '|${'))) {
+					actions.new_action('update', cxt, 'include', line.afterChar('=').replaceXY(oldname, newname), line.afterChar('='));
+				}
+			});
+		}
+
+		if (cxt.beginsWith(ASTGUI.contexts.TrunkDIDPrefix) && cxt.endsWith(oldname)) {
+			actions.new_action('renamecat', cxt, '', cxt.replace(oldname, newname));
+		}
+	}
+
+	actions.new_action('update', 'globals', ASTGUI.contexts.TimeIntervalPrefix + newname, value);
+	var resp = actions.callActions();
+	if (!resp.contains('Response: Success')) {
+		top.log.error('pbx.time_intervals.add: error updating extensions.conf');
+		return false;
+	}
+
+	/* TODO: add new time interval to gui cache */
+
+	ASTGUI.feedback({ msg: 'Updated time interval!', showfor: 3, color: 'green', bgcolor: '#ffffff'});
 	return true;
 };
 




More information about the asterisk-gui-commits mailing list