rbrindley: branch 2.0 r4560 - in /branches/2.0/config: ./ js/

SVN commits to the Asterisk-GUI project asterisk-gui-commits at lists.digium.com
Wed Mar 4 09:03:20 CST 2009


Author: rbrindley
Date: Wed Mar  4 09:03:16 2009
New Revision: 4560

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

- merged next round of changes from astman_revamp


Modified:
    branches/2.0/config/index.html
    branches/2.0/config/js/astman2.js
    branches/2.0/config/js/index.js
    branches/2.0/config/js/log.js
    branches/2.0/config/js/object.customs.js

Modified: branches/2.0/config/index.html
URL: http://svn.digium.com/svn-view/asterisk-gui/branches/2.0/config/index.html?view=diff&rev=4560&r1=4559&r2=4560
==============================================================================
--- branches/2.0/config/index.html (original)
+++ branches/2.0/config/index.html Wed Mar  4 09:03:16 2009
@@ -87,10 +87,11 @@
 
 </script>
 <script src="js/jquery.js"></script>
+<script src="js/tooltip.js"></script>
 <script src="js/astman.js"></script>
 <script src="js/pbx.js"></script>
+<script src="js/log.js"></script>
 <script src="js/index.js"></script>
-<script src="js/tooltip.js"></script>
 <head>
 	<title>Asterisk Configuration GUI</title>
 	<link rel="shortcut icon" href="images/favicon.ico" />
@@ -325,4 +326,18 @@
 	<div>
 </div>
 
+<script>
+	var session = {
+		debug_log: [],
+		log: true,
+		log_modes: {
+			ajax: true,
+			console: true,
+			debug: true,
+			error: true,
+			info: true,
+			warn: true
+		}
+	};
+</script>
 </body>

Modified: branches/2.0/config/js/astman2.js
URL: http://svn.digium.com/svn-view/asterisk-gui/branches/2.0/config/js/astman2.js?view=diff&rev=4560&r1=4559&r2=4560
==============================================================================
--- branches/2.0/config/js/astman2.js (original)
+++ branches/2.0/config/js/astman2.js Wed Mar  4 09:03:16 2009
@@ -25,7 +25,9 @@
  * Asterisk Manager object
  * This object contains all the methods and variables necessary to communicate with Asterisk.
  */
-var astman = {};
+var astman = {
+	rawman: '../../rawman' /**< string variable. This holds the HTTP location of rawman. Was formerly named ASTGUI.paths.rawman */
+};
 
 /**
  * Manage Asterisk's Internal Database.
@@ -35,7 +37,7 @@
 	 * Object contain default values.
 	 */
 	defaults: {
-		dbname: "astgui"
+		dbname: 'astgui' /**< string variable. This holds the default dbname. Was formerly named ASTGUI.globals.GUI_DB */ 
 	},
 
 	/**
@@ -78,14 +80,14 @@
 
 			var s = astman.cliCommand('database get ' + k.dbname + ' ' + k.key);
 			if (!s.contains('Value: ')) {
-				throw new Error(astman.parseCLIResponse(s));
+				throw new Error(astman.parseCLI(s));
 			}
 		} catch (err) {
 			log.error(err.message);
 			return null;
 		}
 
-		var val = astman.parseCLIResponse(s);
+		var val = astman.parseCLI(s);
 		val.trim().withOut('Value: ');
 		return val.trim();
 	},
@@ -109,7 +111,7 @@
 				throw new Error(s);
 			}
 		
-			var op = astman.parseCLIResponse(s);
+			var op = astman.parseCLI(s);
 			if (op.trim() === '') {
 				return null;
 			}
@@ -161,3 +163,57 @@
 		return true;
 	}
 };
+
+/**
+ * Executes a CLI Command.
+ * This function takes a string CLI command and sends it to Asterisk to be executed. This function was formerly named ASTGUI.cliCommand
+ * @param {String} cmd The CLI Command to be executed.
+ * @return the CLI output
+ */
+astman.cliCommand = function(cmd) {
+	if (typeof cmd !== 'string') {
+		log.warn('cliCommand: Expecting cmd as String');
+		return '';
+	}
+
+	log.debug('cliCommand: Executing manager command: "' + cmd + '"');
+	return this.makeSyncRequest( {action: 'command', command: cmd });
+};
+
+/**
+ * Makes a sync request.
+ * This function takes an object and makes a synchronous ajax request. This function was formerly named makeSyncRequest
+ * @param {Object} params the object containg all the parameters/options
+ * @return {String} response text from the ajax call.
+ */
+astman.makeSyncRequest = function(params) {
+	if (top.session && top.session.debug_mode) {
+		log.ajax('makeSyncRequest: AJAX Request: "' + params.getProperties() + '"');
+	}
+
+	if (typeof params !== 'object') {
+		log.error('makeSyncRequest: Expecting params to be an object.');
+		return '';
+	}
+
+	var s = $.ajax({ url: astman.rawman, data: params, async: false});
+	return s.responseText;
+};
+
+/**
+ * Parses CLI Responses.
+ * The function takes a raw CLI response and strips unnecessary info, returning only the useful info. This function use to be called ASTGUI.parseCLIResponse.
+ * @param resp The CLI Response to be parsed.
+ * @return {String} the parsed CLI responsed
+ */
+astman.parseCLI = function(resp) {
+	if (typeof resp !== 'string') {
+		return resp;
+	}
+
+	resp = resp.replace(/Response: Follows/, '');
+	resp = resp.replace(/Privilege: Command/, '');
+	resp = resp.replace(/--END COMMAND--/, '');
+
+	return resp;
+};

Modified: branches/2.0/config/js/index.js
URL: http://svn.digium.com/svn-view/asterisk-gui/branches/2.0/config/js/index.js?view=diff&rev=4560&r1=4559&r2=4560
==============================================================================
--- branches/2.0/config/js/index.js (original)
+++ branches/2.0/config/js/index.js Wed Mar  4 09:03:16 2009
@@ -1079,6 +1079,10 @@
 			miscFunctions.DEBUG_START();
 			$(".debugWindow").show();
 		}
+		if (top.session.log) {
+			log.init('blah');
+			$(".debugWindow").show();
+		}
 	};
 
 	ASTGUI.dialog.waitWhile(' Loading ...');

Modified: branches/2.0/config/js/log.js
URL: http://svn.digium.com/svn-view/asterisk-gui/branches/2.0/config/js/log.js?view=diff&rev=4560&r1=4559&r2=4560
==============================================================================
--- branches/2.0/config/js/log.js (original)
+++ branches/2.0/config/js/log.js Wed Mar  4 09:03:16 2009
@@ -25,39 +25,168 @@
  * Main Log Object.
  * This log object contains all the needed logging functions for the GUI.
  */
-var log = {};
+var log = {
+	colors: {
+		ajax: '#96997c',
+		debug: '#4c9996',
+		error: '#992b23',
+		info: '#9a9a9a',
+		warn: '#f47a00'
+	},
+	html: '' /**< jQuery selector, or jQuery object for holding all the log messages. */
+};
 
 /**
  * Log as ajax.
+ * @param msg The message.
  */
-log.ajax = function () {};
+log.ajax = function(msg) {
+	if (!msg || top.session.log_modes.ajax !== true) {
+		return true;
+	}
+	this.doLog(msg, this.colors.ajax);
+};
 
 /**
  * Log to the Console.
+ * @param msg The message.
  */
-log.console = function () {};
+log.console = function(msg) {
+	if (!msg || top.session.log_modes.console !== true || window.console || window.console.firebug) {
+		return true;
+	}
+	console.log(msg);
+};
+
+/**
+ * Clear log messages.
+ */
+log.clear = function() {
+	top.session.debug_log = [];
+	$(this.html).html('No log messages');
+};
 
 /**
  * Debug log.
+ * @param msg The message.
  */
-log.debug = function () {};
+log.debug = function(msg) {
+	if (!msg || top.session.log_modes.debug !== true) {
+		return true;
+	}
+	this.doLog(msg, this.colors.debug);
+};
 
 /**
  * Core Log Function.
+ * @param msg The message.
+ * @param color The HTML hexademical color code.
  */
-log.doLog = function () {};
+log.doLog = function() {
+	if (!top.session.log) {
+		return true;
+	}
+
+	if (typeof msg === 'object') {
+		msg = 'OBJECT: ' + msg.getProperties();
+	}
+
+	var now = new Date();
+	var h = now.getHours().addZero() + ':' + now.getMinutes().addZero() + ':' + now.getSeconds().addZero();
+
+	if (top.session.debug_log.length > 250) {
+		top.session.debug_log = top.session.debug_log.slice(0,50);
+	}
+
+	top.session.debug_log.unshift( h + ' <font color='+ color + '>' + msg + '</font>');
+};
 
 /**
  * Log as Error.
+ * @param msg The message.
  */
-log.error = function () {};
+log.error = function(msg) {
+	if (!msg || top.session.log_modes.error !== true) {
+		return true;
+	}
+	this.doLog(msg, this.colors.error);
+};
 
 /**
  * Log as Info.
+ * @param msg The message.
  */
-log.info = function () {};
+log.info = function(msg) {
+	if (!msg || top.session.log_modes.info !== true) {
+		return true;
+	}
+	this.doLog(msg, this.colors.info);
+};
+
+/**
+ * Init Logging.
+ * @param html the jQuery selector or jQuery object storing mesgs
+ */
+log.init = function(html) {
+	if (top.session.DEBUG_PROFILER_BEGIN) {
+		return;
+	}
+
+	var m = _$('debug_messages');
+	var aaaaa = function() {
+		if (top.session.log && top.session.debug_log.length) {
+			if (m.style.display == '') {
+				m.innerHTML = '<li>' + top.session.debug_log.join('<li>');
+			}
+		}
+	};
+	m.innerHTML = 'No log messages';
+	var now = new Date();
+	top.session.DEBUG_PROFILER_BEGIN = now.getTime();
+	setInterval(aaaaa, 3000);
+
+	m.style.display = '';
+	$('#dbw_flip').click( function() {
+		if (m.style.display == '') {
+			m.style.display = 'none';
+			this.innerHTML = 'Show debug messages';
+			this.className = 'dbw_flip_hide';
+		} else if ( m.style.display == 'none') {
+			m.innerHTML = (top.session.debug_log.length) ? '<li>' + top.session.debug_log.join('<li>') : 'No log messages';
+			m.style.display = '';
+			this.innerHTML = 'Hide debug messages';
+			this.className = 'dbw_flip_show';
+		}
+	});
+
+	aaaaa();
+
+	_$('debugWindow_which_Ajax').checked = sessionData.DEBUG_WHICH.Ajax ;
+	$('#debugWindow_which_Ajax').click(function(){ sessionData.DEBUG_WHICH.Ajax =  this.checked ; });
+
+	_$('debugWindow_which_Debug').checked = sessionData.DEBUG_WHICH.Debug ;
+	$('#debugWindow_which_Debug').click(function(){ sessionData.DEBUG_WHICH.Debug = this.checked ; });
+
+	_$('debugWindow_which_Error').checked = sessionData.DEBUG_WHICH.Error ;
+	$('#debugWindow_which_Error').click(function(){ sessionData.DEBUG_WHICH.Error = this.checked ; });
+
+	_$('debugWindow_which_Console').checked = sessionData.DEBUG_WHICH.Console ;
+	$('#debugWindow_which_Console').click(function(){ sessionData.DEBUG_WHICH.Console = this.checked ; });
+
+	_$('debugWindow_which_Info').checked = sessionData.DEBUG_WHICH.Info ;
+	$('#debugWindow_which_Info').click(function(){ sessionData.DEBUG_WHICH.Info = this.checked ; });
+
+	_$('debugWindow_which_Warnings').checked = sessionData.DEBUG_WHICH.Warn ;
+	$('#debugWindow_which_Warnings').click(function(){ sessionData.DEBUG_WHICH.Warn = this.checked ; });
+};
 
 /**
  * Log as Warning.
+ * @param msg The message.
  */
-log.warn = function () {};
+log.warn = function(msg) {
+	if (!msg || top.session.log_modes.warn !== true) {
+		return true;
+	}
+	this.doLog(msg, this.colors.warn);
+};

Modified: branches/2.0/config/js/object.customs.js
URL: http://svn.digium.com/svn-view/asterisk-gui/branches/2.0/config/js/object.customs.js?view=diff&rev=4560&r1=4559&r2=4560
==============================================================================
--- branches/2.0/config/js/object.customs.js (original)
+++ branches/2.0/config/js/object.customs.js Wed Mar  4 09:03:16 2009
@@ -151,6 +151,35 @@
 	return x ;
 };
 
+/******************************************
+ * Custom methods for Javascript's Object
+ *****************************************/
+/**
+ * Get Properties As String.
+ * Gets Object's properties and returns them as a string. Use to be ASTGUI.getObjectPropertiesAsString.
+ * @returns a string of the object's properties
+ */
+Object.prototype.getProperties = function() {
+	var props = [];
+
+	for (var d in this) {
+		if (!this.hasOwnProperty(d)) {
+			continue;
+		}
+
+		if (typeof this[d] === 'object') {
+			if (this[d] instanceof Array) {
+				props.push(d + ': [' + this[d].join(',') + ']');
+			} else {
+				props.push(d + ': ' + this[d].getProperties());
+			}
+		} else {
+			props.push(d + ': ' + this[d]);
+		}
+	}
+	return '{' + props.join(' ,') + '}';
+};
+
 // String Manipulation, and other custom methods for String Objects
 String.prototype.addZero = function(){
 	return ( Number(this) < 10)? "0" + this : this;




More information about the asterisk-gui-commits mailing list