espiceland: branch 2.0 r5185 - in /branches/2.0/config: index.html js/astman.js

SVN commits to the Asterisk-GUI project asterisk-gui-commits at lists.digium.com
Thu Apr 21 09:33:26 CDT 2011


Author: espiceland
Date: Thu Apr 21 09:33:21 2011
New Revision: 5185

URL: http://svnview.digium.com/svn/asterisk-gui?view=rev&rev=5185
Log:
Fix use of reserved JavaScript keyword as variable name in context-parsing
routine and modify file-caching behavior to cache contexts separately. Fixes
ASTGUI-383.

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

Modified: branches/2.0/config/index.html
URL: http://svnview.digium.com/svn/asterisk-gui/branches/2.0/config/index.html?view=diff&rev=5185&r1=5184&r2=5185
==============================================================================
--- branches/2.0/config/index.html (original)
+++ branches/2.0/config/index.html Thu Apr 21 09:33:21 2011
@@ -3,9 +3,10 @@
  *
  * Top level index page
  *
- * Copyright (C) 2011, Digium, Inc.
+ * Copyright (C) 2009-2011, Digium, Inc.
  *
  * Pari Nannapaneni <pari at digium.com>
+ * Erin Spiceland <espiceland at digium.com>
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk project. Please do not directly contact
@@ -309,7 +310,10 @@
 			'g723' : 'G.723'
 		},
 		directories:{},// sessionData.directories
-		FileCache:{}, // Object to Cache config files .. sessionData.FileCache['users.conf'].content , sessionData.FileCache['users.conf'].modified
+		FileCache:{}, 		/* Object to Cache config files:
+					sessionData.FileCache['users.conf'][context].content,
+					sessionData.FileCache['users.conf'].modified
+					sessionData.FileCache['users.conf'][context].modified, */ 
 		FXO_PORTS_DETECTED : [], // so that we do not have to parse ztscan output each time where we want this list
 					// sessionData.FXO_PORTS_DETECTED
 		FXS_PORTS_DETECTED : [], // so that we do not have to parse ztscan output each time where we want this list

Modified: branches/2.0/config/js/astman.js
URL: http://svnview.digium.com/svn/asterisk-gui/branches/2.0/config/js/astman.js?view=diff&rev=5185&r1=5184&r2=5185
==============================================================================
--- branches/2.0/config/js/astman.js (original)
+++ branches/2.0/config/js/astman.js Thu Apr 21 09:33:21 2011
@@ -2902,9 +2902,11 @@
 		var catno = -1 ;
 		var l_catno , catname , tlc , subfield , v, subfield_a, subfield_b;
 		var catfound = false;
+		var cat_for_cache = "";
 		for(var r=0, tl =  t.length ; r < tl ; r++){
 			tlc = t[r].toLowerCase();
 			if( tlc.beginsWith("category-") ){
+				cat_for_cache = t[r] + "\n";
 				catname = t[r].afterChar(':');
 				catname = catname.trim() ;
 				if( catname != params.context){ catno = -1; continue; }
@@ -2913,6 +2915,7 @@
 			}
 			if( catno == -1 ){ continue; }
 			if( tlc.beginsWith("line-") ){
+				cat_for_cache += t[r] + "\n";
 				var l_catno = Number( t[r].betweenXY('-','-') );
 				if( l_catno != catno ){ continue; }
 
@@ -2920,8 +2923,8 @@
 				subfield = subfield.trim();
 				if(params.usf){
 					v = subfield.indexOf('=');
-					subfield_a = subfield.substring(0,v);//subfield variable
-					subfield_b =  subfield.substr(v+1) ;//subfield variable value
+					subfield_a = subfield.substring(0,v); //subfield variable
+					subfield_b = subfield.substr(v+1); //subfield variable value
 					if( cat.hasOwnProperty(subfield_a) ){
 						cat[subfield_a] += ',' + subfield_b ;
 					}else{
@@ -2932,42 +2935,49 @@
 				}
 			}
 		}
-		return (catfound)?cat : null ;
-	};
+		top.sessionData.FileCache[params.filename] = {};
+		if (!params.context) { params.context = "default"; }
+		top.sessionData.FileCache[params.filename][params.context] = {};
+		top.sessionData.FileCache[params.filename][params.context].content = cat_for_cache;
+		top.sessionData.FileCache[params.filename][params.context].modified = false;
+		return catfound ? cat : null;
+	};
+
 
 	if( params.hasOwnProperty('configFile_output') ){
 		return toJSO( params.configFile_output );
 	};
 
 
-	if( top.sessionData.FileCache.hasOwnProperty(params.filename) &&  top.sessionData.FileCache[params.filename].modified == false){ // if file is in cache and is not modified since
-		top.log.debug("reading '" +  params.filename + "' from cache.");
-		var s = top.sessionData.FileCache[params.filename].content ;
-	}else{
+	if (params.context
+			&& top.sessionData.FileCache.hasOwnProperty(params.filename)
+			&& top.sessionData.FileCache[params.filename].hasOwnProperty(params.context)
+			&& top.sessionData.FileCache[params.filename][params.context].modified == false
+			&& top.sessionData.FileCache[params.filename].modified == false) { // the context we want is up to date in cache
+		top.log.debug("reading '" +  params.filename + "(" + params.context + ")" + "' from cache.");
+		var s = top.sessionData.FileCache[params.filename][params.context].content;
+	} else {
 		top.log.ajax("AJAX Request : reading '" +  params.filename + "'");
-		if( parent.sessionData.PLATFORM.isAST_1_6 ){
+		if (!parent.sessionData.PLATFORM.isAST_1_4) {
 			var s = $.ajax({ url: ASTGUI.paths.rawman+'?action=getconfig&filename='+params.filename+'&category='+params.context, async: false }).responseText;
-		}else{
+		} else {
 			var s = $.ajax({ url: ASTGUI.paths.rawman+'?action=getconfig&filename='+params.filename, async: false}).responseText;
 		}
 
-		top.sessionData.FileCache[params.filename] = {};
-		top.sessionData.FileCache[params.filename].content = s;
-		top.sessionData.FileCache[params.filename].modified = false;
+		if(s.contains('Response: Error') && ( s.contains('Message: Config file not found') || s.contains('Message: Permission denied') ) ){
+			// return ASTGUI.globals.fnf; // return 'file not found'
+			if(s.contains('Message: Config file not found'))
+				top.log.error( ' config file(' + params.filename +') not found ' );
+			if(s.contains('Message: Permission denied'))
+				top.log.error('permission denied for reading file ' + params.filename );
+
+			return (params.usf) ? new ASTGUI.customObject : [] ;
+		}
+		if( s.contains('Response: Error') ){
+			return (params.usf) ? new ASTGUI.customObject : [] ;
+		}
 	}
 
-	if(s.contains('Response: Error') && ( s.contains('Message: Config file not found') || s.contains('Message: Permission denied') ) ){
-		// return ASTGUI.globals.fnf; // return 'file not found'
-		if(s.contains('Message: Config file not found'))
-			top.log.error( ' config file(' + params.filename +') not found ' );	
-		if(s.contains('Message: Permission denied'))
-			top.log.error('permission denied for reading file ' + params.filename );
-
-		return (params.usf) ? new ASTGUI.customObject : [] ;
-	}
-	if( s.contains('Response: Error') ){
-		return (params.usf) ? new ASTGUI.customObject : [] ;
-	}
 	return toJSO(s);
 };
 
@@ -2996,11 +3006,18 @@
 		var a = new ASTGUI.customObject ;
 		var json_data = "";
 		var t = z.split("\n");
-		var catname, subfield, v, subfield_a , subfield_b; 
+		var catname, subfield, v, subfield_a , subfield_b;
+		var cat_for_cache = [];
 		for(var r=0, tl =  t.length ; r < tl ; r++){
 			if( t[r].toLowerCase().beginsWith("category") ){
 				catname = t[r].afterChar(':'); // category 
 				catname = catname.trim() ;
+				if (!catname) { catname = "default"; }
+				if (!top.sessionData.FileCache[params.filename][catname]) {
+					top.sessionData.FileCache[params.filename][catname] = {};
+				}
+				top.sessionData.FileCache[params.filename][catname].content = t[r] + "\n";
+				top.sessionData.FileCache[params.filename][catname].modified = false;
 				if(!a[catname]){ // contexts could be spread at different places in the config file
 					if(!p){
 						a[catname] = [];
@@ -3009,9 +3026,10 @@
 					}
 				}
 			}else if ( t[r].toLowerCase().beginsWith("line") ){
+				top.sessionData.FileCache[params.filename][catname].content += t[r] + "\n";
 				subfield = t[r].afterChar(':'); // subfield
 				subfield = subfield.trim();
-					if(!p){
+				if(!p){
 					a[catname].push(subfield);
 				}else{
 					v = subfield.indexOf("=");




More information about the asterisk-gui-commits mailing list