pari: branch 2.0 r3640 - /branches/2.0/config/js/astman.js

SVN commits to the Asterisk-GUI project asterisk-gui-commits at lists.digium.com
Fri Aug 8 11:40:40 CDT 2008


Author: pari
Date: Fri Aug  8 11:40:40 2008
New Revision: 3640

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

 Asterisk 1.6.0/trunk compatibility - the elegant way !

 Update listOfActions() and listOfSynActions() such that 

   * 'update' will be replaced with 'append' if the variable does not already exist
   * 'delcat' will be skipped if the category does not already exist
   * 'delete' will be ignored if the variable does not already exist in the category
   *  and finally do not take all this trouble if Asterisk 1.4




Modified:
    branches/2.0/config/js/astman.js

Modified: branches/2.0/config/js/astman.js
URL: http://svn.digium.com/view/asterisk-gui/branches/2.0/config/js/astman.js?view=diff&rev=3640&r1=3639&r2=3640
==============================================================================
--- branches/2.0/config/js/astman.js (original)
+++ branches/2.0/config/js/astman.js Fri Aug  8 11:40:40 2008
@@ -2626,16 +2626,42 @@
 		u.callActions(); // this is Synchronus function - these actions will be called immediately and the result will be returned
 	*/
 	//
+	this.FILE_CONTENT = null ;
 	this.params = {} ;
 	this.params.action = 'updateconfig';
 	this.params.srcfilename = file;
 	this.params.dstfilename = file;
+	if( !parent.sessionData.PLATFORM.isAST_1_4 ){
+		this.FILE_CONTENT = config2json({ filename: file , usf:0 }) ;
+	}
 	this.actionCount = 0;
 };
 
 listOfSynActions.prototype = {
 	new_action: function(action, cat, name, value, match){
-		//if( (action == 'update' || action == 'append') && !value ){ return; }
+		if( !parent.sessionData.PLATFORM.isAST_1_4 && this.FILE_CONTENT != null ){
+			// the update/delete/delcat commands fail in Asterisk 1.6.X/trunk if the corresponding category/variables are not found
+			// In Asterisk 1.4 we do not have to do this check
+			switch( action ){
+				case 'update':
+					if( !this.FILE_CONTENT.hasOwnProperty(cat) || this.FILE_CONTENT[cat].indexOfLike(name+'=') == -1 ){
+						action = 'append';
+					}
+					break;
+				case 'delete':
+					if( !this.FILE_CONTENT.hasOwnProperty(cat) || this.FILE_CONTENT[cat].indexOfLike(name+'=') == -1 ){
+						return ;
+					}
+					break;
+				case 'delcat':
+					if( !this.FILE_CONTENT.hasOwnProperty(cat) ){
+						return ;
+					}
+					break;
+				default: break;
+			}
+		}
+
 		var s="";
 		var cnt = "" + this.actionCount;
 		if(this.actionCount > 5){
@@ -2655,6 +2681,9 @@
 		this.params = {} ;
 		this.params.action = 'updateconfig';
 		this.params.srcfilename = this.params.dstfilename = fn;
+		if( !parent.sessionData.PLATFORM.isAST_1_4 ){
+			this.FILE_CONTENT = config2json({ filename: fn , usf:0 }) ;
+		}
 	},
 	callActions: function(){
 		if(!this.actionCount){ return 'Response: Success'; }
@@ -2681,21 +2710,58 @@
 		x.callActions(after); // where after is the callback function
 
 	*/
+	this.FILE_CONTENT = null ;
 	this.current_batch = 1 ;
 	this.current_batch_actionnumber = 0 ;
 	this.actions = {};
-	if(fn){ this.filename = fn; }
+	if(fn){ 
+		this.filename = fn;
+		if( !parent.sessionData.PLATFORM.isAST_1_4 ){
+			this.FILE_CONTENT = config2json({ filename: fn , usf:0 }) ;
+		}
+	}
 };
 
 listOfActions.prototype = {
 	filename: function(fn){
 		this.filename = fn;
+		if( !parent.sessionData.PLATFORM.isAST_1_4 ){
+			this.FILE_CONTENT = config2json({ filename: fn , usf:0 }) ;
+		}
 	},
 	getacn: function(nc){
 		return this.current_batch_actionnumber;
 	},
 	build_action: function(action, count, cat, name, value, match){
-		//if( (action == 'update' || action == 'append') && !value ){ return null; }
+		if( !parent.sessionData.PLATFORM.isAST_1_4 && this.FILE_CONTENT != null ){
+			// the update/delete/delcat commands fail in Asterisk 1.6.X/trunk if the corresponding category/variables are not found
+			// In Asterisk 1.4 we do not have to do this check
+			switch( action ){
+				case 'update':
+					if( !this.FILE_CONTENT.hasOwnProperty(cat) || this.FILE_CONTENT[cat].indexOfLike(name+'=') == -1 ){
+						action = 'append';
+					}
+					break;
+				case 'delete':
+					if( !this.FILE_CONTENT.hasOwnProperty(cat) || this.FILE_CONTENT[cat].indexOfLike(name+'=') == -1 ){
+						return ;
+					}
+					break;
+				case 'delcat':
+					if( !this.FILE_CONTENT.hasOwnProperty(cat) ){
+						return ;
+					}
+					break;
+				default: break;
+			}
+			// TODO : handle the case where , a new category is added in 'batch 1' and is deleted in 'batch 2'
+			//		the 'delcat' in 'batch 2' would fail cause the switch does not know that the file has been after 'batch 1',
+			//		even if we update the FILE_CONTENT after each start_sqreqs() it would still fail cause the batches are already generated by then
+			//	we could possibly generate the batches during callActions() and read the file before generating each batch and move this switch inside the batch
+
+			//	This should not be a problem for the time being, but I will fix this issue once i get everything else working with 'asterisk 1.4/1.6.0/trunk'
+			//	Note: this is not an issue with listOfSynActions() as clearActions() will take care of updating the file changes
+		}
 		var s="";
 		var cnt = "" + count;
 		while(cnt.length < 6)




More information about the asterisk-gui-commits mailing list