rbrindley: branch rbrindley/features_revamp r4743 - in /team/rbrindley/featur...

SVN commits to the Asterisk-GUI project asterisk-gui-commits at lists.digium.com
Fri Apr 17 08:25:44 CDT 2009


Author: rbrindley
Date: Fri Apr 17 08:25:40 2009
New Revision: 4743

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

- added autocomplete for amaps
- added enable and disable amap js funcs
- amaps default to enabled
- validateAmap can check for all or just one now
- features page update is now complete


Modified:
    team/rbrindley/features_revamp/config/features2.html
    team/rbrindley/features_revamp/config/js/features2.js

Modified: team/rbrindley/features_revamp/config/features2.html
URL: http://svn.digium.com/svn-view/asterisk-gui/team/rbrindley/features_revamp/config/features2.html?view=diff&rev=4743&r1=4742&r2=4743
==============================================================================
--- team/rbrindley/features_revamp/config/features2.html (original)
+++ team/rbrindley/features_revamp/config/features2.html Fri Apr 17 08:25:40 2009
@@ -246,7 +246,7 @@
 			<tbody>
 			<tr class="template">
 				<td class="enabled">
-					<input type="checkbox" />
+					<input type="checkbox" checked="checked" />
 				</td>
 				<td class="name">
 					<input type="text" size="10" />
@@ -308,21 +308,21 @@
 			.delegate('click', 'span.delete', function() {
 				removeAmap($(this));
 			}).delegate('click', 'span.save', function() {
-				editAmap($(this));
+				if (editAmap($(this))) {
+					$(this).parents('tr').find('.buttons > span.save').hide();
+				}
 			}).delegate('change', 'input, select', function() {
 				if ($(this).parents('td').hasClass('enabled')) {
 					if ($(this).attr('checked') === true) {
-						enableAmap();
+						enableAmap($(this));
 					} else {
-						disableAmap();
+						disableAmap($(this));
 					}
 				} else {
 					var obj = $(this).parents('tr');
-					var name = obj.find('.name > :text').val();
-					var digits = obj.find('.digits > :text').val();
-					var app_name = obj.find('.app_name :text').val();
-
-					if (validateAmap(obj, name, digits, app_name)) {
+					var vari = $(this).parents('td').attr('class');
+					var val = $(this).text();
+					if (validateAmap(obj, {variable: vari, value: val}, false)) {
 						$(this).parents('td').siblings('.buttons').children('.save').show();
 					} else {
 						$(this).parents('td').siblings('.buttons').children('.save').hide();

Modified: team/rbrindley/features_revamp/config/js/features2.js
URL: http://svn.digium.com/svn-view/asterisk-gui/team/rbrindley/features_revamp/config/js/features2.js?view=diff&rev=4743&r1=4742&r2=4743
==============================================================================
--- team/rbrindley/features_revamp/config/js/features2.js (original)
+++ team/rbrindley/features_revamp/config/js/features2.js Fri Apr 17 08:25:40 2009
@@ -24,6 +24,7 @@
 var vals = {};
 var dial_options;
 var dial_options_list = ['t', 'T', 'h', 'H', 'k', 'K'];
+var apps = [ 'Answer', 'Background', 'Busy', 'Congestion', 'DigitTimeout', 'DISA', 'ResponseTimeout', 'Playback' , 'UserEvent' , 'Wait', 'WaitExten', 'Hangup' ];
 
 /**
  * function to edit options
@@ -267,13 +268,20 @@
 
 	var row = $('#application_map_list > tbody > tr.template').clone();
 	/* only set id if its an existing amap */
+	/* only check for enabled if its an existing amap */
 	if (name !== '') {
 		row.attr('id', 'amap_' + name);
-	}
-	row.find('.enabled :checkbox').attr('checked', (amap_enabled.contains(name)?true:false));
+		row.find('.enabled :checkbox').attr('checked', (amap_enabled.contains(name)?true:false));
+	}
 	row.find('.name :text').attr('value', name);
 	row.find('.digits :text').attr('value', amap_fields[0]);
-	row.find('.app_name :text').attr('value', amap_fields[2]);
+	row.find('.active option[value='+amap_fields[1]+']').attr('selected', true);
+	row.find('.app_name :text')
+		.attr('value', amap_fields[2])
+		.autocomplete(apps, {
+			autoFill: true,
+			width: 150	
+	});
 	row.find('.app_args :text').attr('value', amap_fields[3]);
 	amap_table.append(row);
 	row.removeClass('template');
@@ -299,7 +307,7 @@
 	var app_name = obj.find('.app_name :text').val();
 	var app_args = obj.find('.app_args :text').val();
 
-	if (!validateAmap(obj, name, digits, app_name)) {
+	if (!validateAmap(obj, {name: name, digits: digits, app_name: app_name}, true)) {
 		return false;
 	}
 
@@ -337,6 +345,57 @@
 	}
 
 	obj.attr('id', 'name');
+	return true;
+};
+
+var disableAmap = function(obj) {
+	/* if it doesn't exist, do nothing */
+	if (!amap_enabled.contains(obj.parents('tr').attr('id').substring(5))) {
+		return true;
+	}
+
+	/* remove from list and make string */
+	amap_enabled.splice(amap_enabled.indexOf(obj.parents('tr').attr('id').substring(5)), 1);
+	var str = amap_enabled.join('#');
+	
+	/* update Asterisk */
+	var actions = new listOfSynActions('extensions.conf');
+	actions.new_action('update', 'globals', 'FEATURES', str);
+
+	var resp = actions.callActions();
+	if (!resp.contains('Response: Success')) {
+		top.log.error('disableAmap: error updating extensions.conf.');
+		top.log.error(resp);
+		amap_enabled.push(obj.parents('tr').attr('id').substring(5));
+		return false;
+	}
+
+	return true;
+};
+
+var enableAmap = function(obj) {
+	/* if it already exists, do nothing */
+	if (amap_enabled.contains(obj.parents('tr').attr('id').substring(5))) {
+		return true;
+	}
+
+	/* add to list and make string */
+	amap_enabled.push(obj.parents('tr').attr('id').substring(5));
+	var str = amap_enabled.join('#');
+	
+	/* update Asterisk */
+	var actions = new listOfSynActions('extensions.conf');
+	actions.new_action('update', 'globals', 'FEATURES', str);
+
+	var resp = actions.callActions();
+	if (!resp.contains('Response: Success')) {
+		top.log.error('enableAmap: error updating extensions.conf.');
+		top.log.error(resp);
+		amap_enabled.splice(amap_enabled.indexOf(obj.parents('tr').attr('id').substring(5)), 1);
+		return false;
+	}
+
+	return true;
 };
 
 var removeAmap = function(obj) {
@@ -386,17 +445,38 @@
 	});
 };
 
-var validateAmap = function(obj, name, digits, app_name) {
+var validateAmap = function(obj, params, focus) {
+	/* used for single validatation */
+	if (params.variable) {
+		switch(params.variable) {
+		case 'name':
+			params.name = params.value;
+		case 'digits':
+			params.digits = params.value;
+		case 'app_name':
+			params.app_name = params.value;
+		default:
+		}	
+	}
 	/* lets validate all the variables before we send */
 	try {
-		vali = 'name';
-		validate(name, {notnull: true, str: true, aststr: true});
-		vali = 'digits';
-		validate(digits, {notnull: true, num: true});
-		vali = 'app_name';
-		validate(app_name, {notnull: true, str: true});
+		if (params.name) {
+			vali = 'name';
+			validate(params.name, {notnull: true, str: true, aststr: true});
+		}
+		if (params.digits) {
+			vali = 'digits';
+			validate(params.digits, {notnull: true, num: true});
+		}
+		if (params.app_name) {
+			vali = 'app_name';
+			validate(params.app_name, {notnull: true, str: true});
+		}
 	} catch(e) {
-		obj.find('td.'+vali+' input').focus().addClass('error');
+		if (focus) {
+			obj.find('td.'+vali+' input').focus()
+		}
+		obj.find('td.'+vali+' input').addClass('error');
 		top.log.error(e.message);
 		return false;
 	}




More information about the asterisk-gui-commits mailing list