rbrindley: branch rbrindley/astman_revamp r4541 - /team/rbrindley/astman_reva...
SVN commits to the Asterisk-GUI project
asterisk-gui-commits at lists.digium.com
Mon Mar 2 15:30:48 CST 2009
Author: rbrindley
Date: Mon Mar 2 15:30:45 2009
New Revision: 4541
URL: http://svn.digium.com/svn-view/asterisk-gui?view=rev&rev=4541
Log:
- cleaned astman2.js and created astman object.
Modified:
team/rbrindley/astman_revamp/config/js/astman2.js
Modified: team/rbrindley/astman_revamp/config/js/astman2.js
URL: http://svn.digium.com/svn-view/asterisk-gui/team/rbrindley/astman_revamp/config/js/astman2.js?view=diff&rev=4541&r1=4540&r2=4541
==============================================================================
--- team/rbrindley/astman_revamp/config/js/astman2.js (original)
+++ team/rbrindley/astman_revamp/config/js/astman2.js Mon Mar 2 15:30:45 2009
@@ -1,7 +1,7 @@
/*
* Asterisk-GUI - an Asterisk configuration interface
*
- * Javascript functions for accessing manager over HTTP and Some UI components/functions used in AsteriskGUI.
+ * Javascript functions for accessing manager over HTTP
*
* Copyright (C) 2006-2008, Digium, Inc.
*
@@ -21,2848 +21,10 @@
*
*/
-_$ = function(x){
- if ( typeof x != 'string' ){ return null ;}
- try{
- return document.getElementById(x);
- }catch(err){ return null; }
-};
-
-// The ASTGUI Object - global varibles and various core GUI component functions
-var ASTGUI = {
- includeContexts: [], // updated below
-
- globals: {
- providerUrl: './js/providers.js', // ASTGUI.globals.providerUrl
- firmwareVersionUrl: 'https://gui-dl.digium.com/aa50/fw_version.js', // ASTGUI.globals.firmwareVersionUrl
- appname : 'Asterisk GUI',
- lang : 'en',
- GUI_DB : 'astgui', // name of the ASTDB database used by GUI -- ASTGUI.globals.GUI_DB
- msg_notLoggedIn: 'Message: Authentication Required',
- configfile : 'guipreferences.conf', // will be created if the file does not exist , ASTGUI.globals.configfile
- g729RegInfo: 'g729reginfo.conf', // ASTGUI.globals.g729RegInfo, the sessionData.directories.script_Registerg729 script will read this file to generate tab delimited file
- hwcfgFile: 'gui_confighw.conf', // file to store configured hardware information, to detect hardware changes
- dahdiIncludeFile: 'dahdi_guiread.conf', // file that will be used to read zaptel.conf or dahdi/system.conf , ASTGUI.globals.dahdiIncludeFile
- dahdiScanOutput: 'dahdi_scan.conf', // file that will be used to read output from ztscan or dahdi_scan, ASTGUI.globals.dahdiScanOutput
- pingInterval : 5000,
- app_factoryReset : '/bin/reset_config', // ASTGUI.globals.app_factoryReset
- fnf : 'ERROR:FNF',
- obcidstr : 'GLOBAL_OUTBOUNDCID', // ASTGUI.globals.obcidstr
- obcidNamestr : 'GLOBAL_OUTBOUNDCIDNAME', // ASTGUI.globals.obcidNamestr
- obcidUsrPrefix : 'CID_', // ASTGUI.globals.obcidUsrPrefix
- sbcid_1 : 's,1,ExecIf($[ "${CALLERID(num)}"="" ],SetCallerPres,unavailable)', // ASTGUI.globals.sbcid_1
- sbcid_2 : 's,2,ExecIf($[ "${CALLERID(num)}"="" ],Set,CALLERID(all)=unknown <0000000>)',
- timeservers: [ 'north-america.pool.ntp.org', 'asia.pool.ntp.org', 'europe.pool.ntp.org', 'oceania.pool.ntp.org', 'south-america.pool.ntp.org' ],
- version : '2.0' // gui version
- },
-
- contexts: {
- guitools : 'asterisk_guitools', // gui tools context
- dialtrunks : 'trunkdial-failover-0.3', // trunkdial macro with failback trunk and setcid, ASTGUI.contexts.dialtrunks
- CONFERENCES : 'conferences', // ASTGUI.contexts.CONFERENCES
- QUEUES : 'queues', //ASTGUI.contexts.QUEUES
- TrunkDIDPrefix : 'DID_', // context for trunks - - ASTGUI.contexts.TrunkDIDPrefix
- TrunkDefaultSuffix : '_default', // ASTGUI.contexts.TrunkDefaultSuffix - to create 'DID_trunk_default' that will be included in [DID_trunk]
- RingGroupPrefix: 'ringroups-custom-', // ASTGUI.contexts.RingGroupPrefix
- RingGroupExtensions: 'ringgroups', // ASTGUI.contexts.RingGroupExtensions
- PageAnExtension :'page_an_extension', // ASTGUI.contexts.PageAnExtension
- PageGroups : 'pagegroups', // ASTGUI.contexts.PageGroups
- TimeBasedRulePrefix: 'timebasedrule-custom-', // ASTGUI.contexts.TimeBasedRulePrefix
- TimeIntervalPrefix: 'timeinterval_', // ASTGUI.contexts.TimeIntervalPrefix
- VoiceMenuPrefix: 'voicemenu-custom-', // ASTGUI.contexts.VoiceMenuPrefix
- VoiceMenuExtensions: 'voicemenus', // ASTGUI.contexts.VoiceMenuExtensions
- VoiceMailGroups: 'voicemailgroups', // ASTGUI.contexts.VoiceMailGroups
- Directory: 'directory', // ASTGUI.contexts.Directory
- CallingRulePrefix : 'CallingRule_', // context for calling rules being with - ASTGUI.contexts.CallingRulePrefix
- CallingPlanPrefix: 'DLPN_', // context for DialPlans -- ASTGUI.contexts.CallingPlanPrefix
- gtalkIncomingContext: 'gtalk_incoming_', // ASTGUI.contexts.gtalkIncomingContext
- skypeIncomingContext: 'skype_incoming_', // ASTGUI.contexts.skypeIncomingContext
- mohdirPrefix : 'guimohdir_' // ASTGUI.contexts.mohdirPrefix
- // music on hold directories created by gui will have this prefix
- // also post_mappings definitions in http.conf will have this name
- },
-
- errorCodes:{
- 'AG101':'Aborting Upload : Action not defined for upload Form <BR>' +
- 'Please set the Form action in the parent page via onUploadForm_beforeUploading()',
- 'AG102':'Disabling all Upload forms in the gui: <BR>' +
- 'Either post_mappings or post_mappings->uploads is not defined in http.conf',
- 'AG150':' SyncActions being used for more than 5 actions'
- },
-
- ASTDB:{
- updateKey : function( k ){
- // ASTGUI.ASTDB.updateKey( { dbname: 'astgui', key : 'keyname', keyvalue : 'keyvalue' } );
- // dbname is optional, defaults to ASTGUI.globals.GUI_DB
- // returns true if success, false otherwise
- if( !k.hasOwnProperty('dbname') ){
- k.dbname = ASTGUI.globals.GUI_DB ;
- }
-
- var s = ASTGUI.cliCommand('database put '+ k.dbname + ' ' + k.key + ' ' + k.keyvalue );
- if(s.contains('successfully')) return true;
- return false;
- },
-
- deleteKey : function( k ){
- // ASTGUI.ASTDB.deleteKey( { dbname: 'astgui', key : 'keyname' } );
- // dbname is optional, defaults to ASTGUI.globals.GUI_DB
- // returns true if success, false otherwise
- if( !k.hasOwnProperty('dbname') ){
- k.dbname = ASTGUI.globals.GUI_DB ;
- }
-
- var s = ASTGUI.cliCommand('database del '+ k.dbname + ' ' + k.key);
- if(s.contains('entry removed')) return true;
- return false;
- },
+/**
+ * Asterisk Manager object
+ * This object contains all the methods and variables necessary to communicate with Asterisk.
+ */
+var astman = {};
- getKey : function(k){
- // ASTGUI.ASTDB.getKey( { dbname: 'astgui', key : 'keyname' } );
- // dbname is optional, defaults to ASTGUI.globals.GUI_DB
- // returns null if key is not found, otherwise returns the key-value
- if( !k.hasOwnProperty('dbname') ){
- k.dbname = ASTGUI.globals.GUI_DB ;
- }
-
- var s = ASTGUI.cliCommand('database get '+ k.dbname + ' ' + k.key);
- if( s.contains('entry not found')) return null;
- var op = ASTGUI.parseCLIResponse( s );
- op = op.trim();
- op = op.withOut('Value:')
- return op.trim();
- },
-
- getAllKeys : function(k){
- // ASTGUI.ASTDB.getAllKeys( { dbname: 'astgui' } );
- // dbname is optional, defaults to ASTGUI.globals.GUI_DB
- // returns an object with all the keys in the database as properties and key-values as propertyvalues
- // returns a null if database not found
-
- if( !k.hasOwnProperty('dbname') ){
- k.dbname = ASTGUI.globals.GUI_DB ;
- }
-
- var db_keys = {};
- var tmp_dbpath = '/' + k.dbname + '/' ;
- var s = ASTGUI.cliCommand('database show '+ k.dbname);
-
- if(s.contains('entry not found')) return null;
- var op = ASTGUI.parseCLIResponse( s );
- if( op.trim() == ''){ return {}; }
-
- var tmp_lines = op.trim().split('\n');
- tmp_lines.each( function(this_line){
- var this_line = this_line.withOut(tmp_dbpath);
- var this_key = this_line.beforeChar(':').trim();
- var this_keyVal = this_line.afterChar(':').trim();
- db_keys[ this_key ] = this_keyVal ;
- });
-
- return db_keys;
- }
- },
-
- checkRequiredFields: function( fields ){
- // fields is an array of fieldnames or elements
- if(!ASTGUI.isArray(fields)){
- return true;
- }
- for(var g=0; g < fields.length ; g++ ){
- var field = fields[g];
- if(typeof field =='string'){
- field = _$(field);
- }
- var required = $(field).attr('required');
- if( required && required.isAstTrue() ){
- var x = field.value.trim() ;
- var pcn = ( field.className ) ? field.className : '' ;
- if( !x ){
- ASTGUI.feedback( { msg:'Required Field', showfor:2 } );
- field.className = 'inputValidationFailed';
- setTimeout( function(){ field.className = pcn ; } , 4000 );
- try{ field.focus(); }catch(e){}
- return false;
- }
- }
- }
- return true;
- },
-
- cliCommand : function(cmd) {
- // ASTGUI.cliCommand(cmd);
- // Execute an asterisk CLI command and return the output
- if( typeof cmd != 'string' ) {
- ASTGUI.Log.Warn( 'cliCommand: Expecting cmd as String' );
- return '';
- }
- ASTGUI.Log.Debug("Executing manager command : '" + cmd + "'");
- return makeSyncRequest ( { action :'command', command: cmd } );
- },
-
- getUser_DeviceStatus : function( usr ){
- // ASTGUI.getUser_DeviceStatus(usr)
- // Get the DeviceStatus for a UserExtension
- if( typeof usr == 'number' ) usr = String(usr);
- if( typeof usr != 'string' ){
- ASTGUI.Log.Warn( 'getUser_DeviceStatus: Expecting usr as String' );
- return 'U';
- }
- var t = makeSyncRequest({ action :'ExtensionState', Exten: usr }) ;
- if( t.contains('Status: 0') ) return 'F' ; // No Device is Busy/InUse
- if( t.contains('Status: 1') ) return 'B' ; // 1 or more devices InUse
- if( t.contains('Status: 2') ) return 'B' ; // All Devices Busy
- if( t.contains('Status: 4') ) return 'U' ; // All Devices Unavailable/Unregistered
- if( t.contains('Status: 8') ) return 'R' ; // All Devices Ringing
- return null;
- },
-
- getUser_DeviceStatus_Image : function( usr ){
- // ASTGUI.getUser_DeviceStatus_Image(usr)
- // Get the DeviceStatus Image for a UserExtension
- var s = this.getUser_DeviceStatus(usr) ;
- switch(s){
- case 'F': // No Device is Busy/InUse
- return "<img src='images/status_green.png' border=0>";
- break ;
- case 'B': // Busy
- return "<img src='images/status_red.png' border=0>";
- break ;
- case 'R': // Ringing
- return "<img src='images/status_orange.png' border=0>";
- break ;
- case 'U': // UnAvailable
- default :
- return "<img src='images/status_gray.png' border=0>";
- break ;
- }
- },
-
- mailboxCount : function(mbox){
- // ASTGUI.mailboxCount(mbox)
- // returns the number of New/Old Voicemail Messages for a user
- // returns an object "{count_new: 1, count_old: 2}"
-
- var tr = { count_new:0 , count_old : 0 };
- if( typeof mbox == 'number' ) mbox = String(mbox);
- if( typeof mbox != 'string' ){
- ASTGUI.Log.Warn( 'mailboxCount: Expecting mbox as String' );
- return tr;
- }
- if(!mbox.contains('@')){ mbox = mbox + '@default' ; }
- var t = makeSyncRequest ( { action :'MailboxCount', Mailbox: mbox } );
- try{
- var lines = t.split('\n');
- lines.each(function( this_line){
- if(!this_line.contains('Messages:') ) return;
- this_line = this_line.trim();
- if( this_line.contains('NewMessages:') ){
- tr.count_new = Number(this_line.afterChar(':').trim());
- }
- if( this_line.contains('OldMessages:') ){
- tr.count_old = Number(this_line.afterChar(':').trim());
- }
- });
- }finally{
- return tr;
- }
- },
-
- doTransfer : function(from, to) {
- // ASTGUI.doTransfer(from, to)
- // issue channel redirect
- ASTGUI.Log.Debug("About to transfer " + from + " to " + to);
- return makeSyncRequest ( { action :'redirect', channel :from, exten :to, context :'default', priority :'1' } );
- },
-
- doHangup : function(chan) {
- // ASTGUI.doHangup(chan)
- // Hangsup a given channel
- ASTGUI.Log.Debug("Executing hangup on channel : '" + chan + "'");
- return makeSyncRequest ( { action :'hangup', channel: chan } );
- },
-
- cookies: {
- getCookie: function(x){ // ASTGUI.cookies.getCookie('username')
- var ck = top.document.cookie; // mansession_id="6f3fadcb"; username=admin
- if( ck.indexOf( x + '=' ) == -1 ){
- return '';
- }
- var cookies = ck.split(';');
- for(var y=0; y < cookies.length; y++){
- cookies[y] = cookies[y].strip();
- if( cookies[y].beginsWith(x +'=') ){
- return cookies[y].split( x + '=' )[1] ;
- }
- }
- return '';
- },
-
- setCookie: function(x , y){ // ASTGUI.cookies.setCookie( 'something' , 'valueofSomething' );
- var tmp = x + '=' + y + '; path = /' ;
- top.document.cookie = tmp;
- },
-
- removeCookie: function(x){
- top.document.cookie = x + '=somevalue; expires=Fri, 22 Oct 1999 00:00:00 UTC; path=/' ;
- },
-
- clearCookies: function(){ // ASTGUI.cookies.clearCookies()
- top.document.cookie = '';
- }
- },
-
- cloneObject: function(a){ // ASTGUI.cloneObject(obj)
- if(ASTGUI.isArray(a)){
- return [].concat(a);
- }
- if( typeof a != 'object' ){
- return a;
- }
- var b = new ASTGUI.customObject ;
- for( var i in a ){
- if( a.hasOwnProperty(i) ){
- b[i] = ASTGUI.toCustomObject( a[i] );
- }
- }
- return b;
- },
-
- CODECSLIST: {
- getSelectedCodecs : function(el){ // ASTGUI.CODECSLIST.getSelectedCodecs(el);
- if ( typeof el == 'string'){ el = _$(el) ; }
- var s = [];
- el.CODECS_SELECTEDORDER.each(function(codec){
- var t = codec.trim();
- if(t != ''){ s.push(codec); }
- });
- return s.join(',') ;
- },
-
- populateCodecsList : function(el){ // ASTGUI.CODECSLIST.populateCodecsList(el);
- // create codecs check boxes inside el and bind events to each checkbox such that the selected codecs
- var r = 'codecs_chkbx_class' + Math.round( 10000 * Math.random() );
- if ( typeof el == 'string'){ el = _$(el) ; }
- el.checkboxClass = r;
- el.CODECS_SELECTEDORDER = [];
- ASTGUI.domActions.populateCheckBoxes(el , parent.sessionData.listOfCodecs , r);
- $('.' + r).click(
- function() {
- if(this.checked){
- el.CODECS_SELECTEDORDER.push(this.value);
- return;
- }
- var t = el.CODECS_SELECTEDORDER.withOut(this.value);
- el.CODECS_SELECTEDORDER = t ;
- return ;
- }
- );
- },
-
- selectCodecs : function(el, codecs){ // ASTGUI.CODECSLIST.selectCodecs(el, codecs);
- // el is the element in which codec checkboxes are populated, codecs is the codecs string
- if ( typeof el == 'string'){ el = _$(el) ; }
- if( codecs == 'all' ){
- ASTGUI.domActions.CheckAll(el.checkboxClass);
- el.CODECS_SELECTEDORDER = ASTGUI.domActions.get_checked(el.checkboxClass);
- }else{
- if( codecs.trim() == '' ){
- el.CODECS_SELECTEDORDER = [] ;
- }else{
- el.CODECS_SELECTEDORDER = ( codecs.contains(',') ) ? codecs.split(',') : codecs;
- }
- ASTGUI.domActions.checkSelected( el.checkboxClass , el.CODECS_SELECTEDORDER ) ;
- }
- }
- },
-
- COMBOBOX: function (a,w){ // Usage - ASTGUI.COMBOBOX.call( element , OptionsArray, width(Optional) );
- // this.comboDiv - the div element created
- // this.comboOptions - the array of options
- var e = this;
- $(e).autocomplete(a, { width: w } );
- },
-
- customObject : function(){
- // eliminates the need of 'hasOwnProperty' to read this objects propeties, look for this objects prototype below.
- if ( !(this instanceof ASTGUI.customObject) ) { return new ASTGUI.customObject(); }
- },
-
- TABLE : function(a){
- if(!a) return;
- if ( !(this instanceof ASTGUI.TABLE) ) { return new ASTGUI.TABLE(a); }
- this.TableElement = ( typeof a == 'string' ) ? _$(a) : a ;
- this.TableRow = null ;
- },
-
- toCustomObject : function(a){// if a is a native object returns an ASTGUI.customObject version of a
- if( ASTGUI.isArray(a) || a === null || typeof a =='number' || typeof a =='string' || typeof a =='boolean' || typeof a != 'object' ) return a;
-
- var b = new ASTGUI.customObject ;
- for( var i in a ){ if( a.hasOwnProperty(i) ){
- b[i] = ASTGUI.toCustomObject( a[i] );
- }}
- return b;
- },
-
- Log: {
- doLog: function(msg, color){
- if(!top.sessionData.DEBUG_MODE ){ return true; }
- if( typeof msg == 'object' ){
- msg = 'OBJECT : ' + ASTGUI.getObjectPropertiesAsString(msg) ;
- }
-
- var now = new Date();
- var h = now.getHours().addZero() + ':' + now.getMinutes().addZero() + ':' + now.getSeconds().addZero() ;
- if( top.sessionData.DEBUG_LOG.length > 250 ){
- top.sessionData.DEBUG_LOG = top.sessionData.DEBUG_LOG.slice(0,50);
- }
- top.sessionData.DEBUG_LOG.unshift( h + ' <font color='+ color +'>' + msg + '</font>' );
- },
-
- Ajax: function(msg){ // ASTGUI.Log.Ajax(msg);
- if ( top.sessionData.DEBUG_WHICH.Ajax == true ) this.doLog( msg , '#96997C' );
- },
-
- Debug: function( msg ){ // ASTGUI.Log.Debug();
- if ( top.sessionData.DEBUG_WHICH.Debug == true ) this.doLog( msg , '#4C9996' );
- },
-
- Error: function( msg ){ // ASTGUI.Log.Error();
- if( !msg || !top.sessionData || !top.sessionData.DEBUG_WHICH.Error ) return;
- if( msg.length <=5 && ASTGUI.errorCodes[msg] ){
- this.doLog( '<B>' + ASTGUI.errorCodes[msg] + '</B>' , '#992b23' );
- }else{
- this.doLog( '<B>' + msg + '</B>' , '#992b23' );
- }
- },
-
- Console: function( msg ){ // ASTGUI.Log.Console();
- if( top.sessionData.DEBUG_WHICH.Console == true && window.console && window.console.firebug ) console.log ( msg );
- },
-
- Info: function( msg ){ // ASTGUI.Log.Info(msg);
- if( top.sessionData.DEBUG_WHICH.Info == true ) this.doLog( msg , '#9A9A9A' );
- },
-
- Warn: function( msg ){ // ASTGUI.Log.Warn( msg );
- if( top.sessionData.DEBUG_WHICH.Warn == true ) this.doLog( msg , '#F47A00' );
- }
- },
-
- dialog : {
- defaultMessage : 'Loading ...',
- load_iframe : function(msg){
- top.alertframename = "alertiframe" ;
- top.alertmsg = msg ;
- var h,_hs;
- if( !top.document.getElementById(top.alertframename)){
- h= top.document.createElement("IFRAME");
- h.setAttribute("id", top.alertframename );
- h.setAttribute("ALLOWTRANSPARENCY", "true");
- _hs = h.style ;
- _hs.position="absolute";
- _hs.left= 0;
- _hs.top= 0;
- _hs.width= '100%';
- _hs.height= '100%';
- _hs.zIndex = 9999 ;
- h.src = "guialert.html" ;
- h.frameBorder="0";
- h.scrolling="no";
- _hs.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=90)';
- //h.style.MozOpacity = .90;
- top.document.body.appendChild(h);
- }else{
- top.document.getElementById( top.alertframename ).contentWindow.update( );
- top.document.getElementById( top.alertframename ).style.display = "";
- }
- },
-
- waitWhile : function(msg){
- // ASTGUI.dialog.waitWhile('Saving...');
- // use this dialog when you want to inform the user about an action in progress - Ex: 'Saving...' or 'Applying CHanges..' or 'Reloading Asteisk...' etc
- if ( typeof msg != 'string') return;
- top.alertmsgtype = 2 ;
- this.load_iframe(msg);
- },
-
- alertmsg : function(msg){
- // ASTGUI.dialog.alertmsg('Some Alert Message');
- // Display custom alert message with an 'Ok' button
- if ( typeof msg != 'string') return;
- top.alertmsgtype = 1 ;
- this.load_iframe(msg);
- },
-
- hide : function(){
- // ASTGUI.dialog.hide();
- // Hide the dialog message, use this when you want to hide the 'waitWhile' message
- try{
- top.document.getElementById( top.alertframename ).style.display = "none";
- } catch (err){ }
- },
-
- show : function(){
- try{
- top.document.getElementById( top.alertframename ).style.display = '';
- } catch (err){ }
- }
- },
-
- domActions: {
- alignBbelowA: function(a,b, offsetLeft, offsetTop ){
- // ASTGUI.domActions.alignBbelowA( element1, element2 )
- // Moves/Aligns Element-B below Element-A
- // You can further control the position by sending additional offset parameters (optional)
- try{
- if ( typeof a == 'string'){ a = _$(a) ; }
- if ( typeof b == 'string'){ b = _$(a) ; }
- b.style.position = 'absolute';
- var tmp_left = a.offsetLeft;
- var tmp_top = a.offsetTop + a.offsetHeight;
- var tmp_parent = a;
-
- while(tmp_parent.offsetParent != document.body){
- tmp_parent = tmp_parent.offsetParent;
- tmp_left += tmp_parent.offsetLeft;
- tmp_top += tmp_parent.offsetTop;
- }
- b.style.left = tmp_left + ( offsetLeft || 0 );
- b.style.top = tmp_top + (offsetTop || 1);
- }catch(err){
- ASTGUI.Log.Error(err.description);
- }
- },
-
- alignBontopofA: function(a,b){
- // ASTGUI.domActions.alignBontopofA();
- // set Element-B's co-ordinates to those of Element-A
- try{
- if ( typeof a == 'string'){ a = _$(a) ; }
- if ( typeof b == 'string'){ b = _$(b) ; }
- ASTGUI.domActions.alignBbelowA(a,b);
- b.style.top = b.style.top - a.offsetHeight ;
- }catch(err){
- ASTGUI.Log.Error(err.description);
- }
- },
-
- CheckAll: function(x){ // check all checkboxes of class x - ASTGUI.domActions.CheckAll();
- var y = $("." + x) ;
- for(var g=0, h = y.length; g < h; g++){
- y[g].checked = true;
- }
- },
-
- disableAllofClass: function(x){ // disable all fields of class x
- var y = $("." + x) ;
- for(var g=0, h = y.length; g < h; g++){
- y[g].disabled = true;
- }
- },
-
- checkIf_isAstTrue: function(el, str){ // ASTGUI.domActions.checkIf_isAstTrue(el,str);
- if ( typeof str != 'string' ){ return; }
- if ( typeof el == 'string' ){ el = _$(el); }
- el.checked = ( str.isAstTrue() ) ? true:false ;
- },
-
- checkSelected: function(x,y){ // ASTGUI.domActions.checkSelected( 'class', [val1,val2,...]);
- // x is class of checkboxes, y is an array of values, this functions checks a checkbox if it its value is present in array 'y'
- //try{
- var y_copy = ASTGUI.cloneObject(y);
- var chbs = $( "." + x ) ; //jquery selector
- for( var g=0, h = chbs.length; g < h ; g++ ) {
- chbs[g].checked = ( y_copy.contains(chbs[g].value) ) ? true : false;
- }
- //}catch(err){ }
- },
-
- disableSelected: function(x,y){ // disable some fields (whose "values" (not names or ids) are in array y), of class x
- // ASTGUI.domActions.disableSelected( 'class', [1,2] );
- var chbs = $( "." + x ) ; //jquery selector
- for( var g=0, h = chbs.length; g < h ; g++ ) {
- chbs[g].disabled = ( y.contains(chbs[g].value) ) ? true : false ;
- }
- },
-
- clear_table: function(h){ // ASTGUI.domActions.clear_table($el)
- ASTGUI.domActions.removeAllChilds(h);
- },
-
- findPos: function (el){ // returns the 'el.left, el.top' in pixels of a given element
- if ( typeof el == 'string'){ el = _$(el) ; }
- var curleft = curtop = 0;
- if (el.offsetParent) {
- do {
- curleft += el.offsetLeft;
- curtop += el.offsetTop;
- } while (el = el.offsetParent);
- }
- return { cleft: curleft, ctop:curtop } ;
- },
-
- get_checked: function (x){ // returns an array of selected checkbox values from a set of checkboxes of class x
- var chk = [] ;
- var y = $( "." + x ) ; //jquery selector
- for( var g=0, h = y.length; g < h ; g++){
- if(y[g].checked){
- chk.push( y[g].value );
- }
- }
- return chk;
- },
-
- removeAllChilds: function(x){ // ASTGUI.domActions.removeAllChilds(el);
- if ( typeof x == 'string'){ x = _$(x) ; }
- while(x.firstChild){
- x.removeChild(x.firstChild);
- }
- },
-
- setTextbox_DefaultValue: function(el, defval){ // usage :: ASTGUI.domActions.setTextbox_DefaultValue(el, "Default Value") ;
- if ( typeof el == 'string'){ el = _$(el) ; }
- el.defaultValue = defval;
- el.value = defval;
- $(el).focus(
- function(){
- if( this.value == this.defaultValue ){
- this.value = '' ;
- };
- }
- ).blur(
- function () {
- if( this.value == '' ){
- this.value = this.defaultValue ;
- }
- }
- );
- },
-
- tr_addCell: function(tr, nc){ // usage :: ASTGUI.domActions.tr_addCell( el, { html:'newCell Text' , align:'center', width:'20px' } )
- try{
- var ih = nc.html; delete nc.html;
- var newcell = tr.insertCell( tr.cells.length );
- if( nc.id ){ newcell.id = nc.id ; delete nc.id; }
- newcell.innerHTML = ih;
- if( nc.onclickFunction && typeof nc.onclickFunction == "function" ){
- ASTGUI.events.add( newcell , 'click' , nc.onclickFunction ) ;
- $(newcell).css('cursor', 'pointer');
- delete nc.onclickFunction;
- }
- for( var k in nc){
- if( nc.hasOwnProperty(k) ){
- if(k.toLowerCase() == 'colspan'){
- newcell.colSpan = nc[k];
- }else{
- newcell[k] = nc[k];
- }
- }
- }
- }catch(err){
- ASTGUI.Log.Error(err.description);
- }
- },
-
- unCheckAll: function(x){ // uncheck all checkboxes of class x
- var y = $("." + x) ; //jquery selector
- for(var g=0, h = y.length; g < h; g++){
- y[g].checked = false;
- }
- },
-
- populateCheckBoxes: function( div, values, ofclass, withBR){ // ASTGUI.domActions.populateCheckBoxes(div, values, ofclass);
- // represent 'array values' OR 'Object values' as a list of checkboxes of class 'ofclass' as childnodes of element 'div'
- // Ex: values = { '1':'One', '1':'Two' } or values = [1,2]
- try{
- var c = {};
- if(ASTGUI.isArray(values)){
- values.each( function(tv){ c[tv] = tv; } );
- }else{
- c = values;
- }
- if ( typeof div == 'string'){ div = _$(div) ; }
- for(var d in c){
- if(c.hasOwnProperty(d)){
- var nbr = document.createElement( 'SPAN' ) ;
- var lbl = document.createElement( 'label' ) ;
- var ncbx = document.createElement('input') ;
- ncbx.type = 'checkbox' ;
- ncbx.value = d ;
- ncbx.id = Math.round(10000*Math.random()) + '_' + d ;
- ncbx.className = ofclass ;
- var span = document.createElement('SPAN') ;
-
- span.innerHTML = (withBR) ? c[d] + ' <BR>' : c[d] + ' ' ;
-
- lbl.appendChild( ncbx ) ;
- lbl.appendChild( span ) ;
- //var tmp_span = document.createElement('SPAN') ; tmp_span.innerHTML = '­'; //tmp_span.innerHTML = '­';
- nbr.appendChild(lbl) ;
- div.appendChild( nbr ) ;
- }
- }
- }catch(err){
- ASTGUI.Log.Error(err.description);
- }
- },
-
- showHideByCheckBox: function(chk , el){ // ASTGUI.domActions.showHideByCheckBox (chk, el) ;
- if ( typeof chk == 'string'){ chk = _$(chk) ; }
- if ( typeof el == 'string'){ el = _$(el) ; }
- chk.updateStatus = function(){ el.style.display = (chk.checked)?'':'none'; } ;
- ASTGUI.events.add( chk, 'click' , chk.updateStatus );
- },
-
- showHideClassByCheckBox: function(chk , cLass , reverse_behaviour){ // ASTGUI.domActions.showHideClassByCheckBox(chk, cLass) ;
- if ( typeof chk == 'string'){ chk = _$(chk) ; }
- chk.updateStatus = function(){
- if(reverse_behaviour ){
- if(chk.checked){
- $('.'+cLass).hide();
- }else{
- $('.'+cLass).show();
- }
- }else{
- if(chk.checked){
- $('.'+cLass).show();
- }else{
- $('.'+cLass).hide();
- }
- }
- };
- ASTGUI.events.add( chk, 'click' , chk.updateStatus );
- },
-
- enableDisableByCheckBox: function(chk , el, reverse_behaviour) { // ASTGUI.domActions.enableDisableByCheckBox (chk, el) ;
- // this function can also use for radio boxes
- if ( typeof chk == 'string'){ chk = _$(chk) ; }
- if ( typeof el == 'string'){ el = _$(el) ; }
- if( ASTGUI.isArray(el) ){
- chk.updateStatus = function(){
- el.each( function(el_this){
- if ( typeof el_this == 'string'){ el_this = _$(el_this) ; }
- if(!reverse_behaviour){
- el_this.disabled = !(chk.checked);
- }else{
- el_this.disabled = chk.checked;
- }
- });
-
- };
- }else{
- if(!reverse_behaviour){
- chk.updateStatus = function(){ el.disabled = !(chk.checked) } ;
- }else{
- chk.updateStatus = function(){ el.disabled = chk.checked; } ;
- }
- }
-
- ASTGUI.events.add( chk, 'click' , chk.updateStatus );
- }
- },
-
- events: {
- getTarget: function(x){
- x = x || window.event;
- return x.target || x.srcElement;
- },
- add: function(a,b,c){ // a is element , b is event (string) , c is the function
- if ( typeof a == 'string'){ a = _$(a) ; }
- if($.browser.msie){
- a.attachEvent('on'+b, c);
- return;
- }
- if(a.addEventListener){
- a.addEventListener(b, c, false);
- return;
- }
- a['on'+b] = c ;
- },
- remove: function(a,b,c){
- if ( typeof a == 'string'){ a = _$(a) ; }
- if($.browser.msie){
- a.detachEvent('on'+b, c);
- return;
- }
- if(a.removeEventListener){
- a.removeEventListener(b, c, false);
- return;
- }
- a['on'+b] = null ;
- }
- },
-
- feedback : function( fb ){
- // usage :: ASTGUI.feedback( { msg:'your message here', showfor:2, color:'#000000', bgcolor:'#FFFFFF' } );
- top.miscFunctions.setFeedback(fb);
- },
-
- getFieldValue : function(el){ // ASTGUI.getFieldValue(el)
- if( !el ){ return ''; }
- if ( typeof el == 'string'){ el = _$(el) ; }
- switch(el.type){
- case 'checkbox':
- return (el.checked) ? 'yes':'no' ;
- break;
- case 'radio':
- return (el.checked) ? el.value : '' ;
- break;
- case 'select-one':
- return el.value ; //.trim()
- break;
-
- case 'text':
- case 'textarea':
- case 'password':
- default:
- return el.value.trim() ;
- break;
- }
- return '';
- },
-
- getObjectPropertiesAsString : function(a){ // takes an object and returns all its properties, values as a string
- var ar = [];
- for(var d in a){
- if(!a.hasOwnProperty(d)){ continue; }
-
- if( typeof a[d] == 'object' ){
- if( ASTGUI.isArray(a[d]) ){
- ar.push( d + ' : [' + a[d].join(',') + ']' );
- }else{
- ar.push( d + ' : ' + ASTGUI.getObjectPropertiesAsString(a[d]) );
- }
- }else{
- ar.push(d + ' : '+ a[d]);
- }
- }
- return '{' + ar.join(' ,') + '}' ;
- },
-
- getTrunkStatus : function (registry , trunkname, ttype){ // ASTGUI.getTrunkStatus (registry, trunkname);
- /* registry should be == {
- iax2 : ASTGUI.parseCLIResponse( ASTGUI.cliCommand('iax2 show registry') ) ,
- sip : ASTGUI.parseCLIResponse( ASTGUI.cliCommand('sip show registry') )
- } ;
- */
- // trunkname == trunkname as trunk_x
- //var ttype = parent.astgui_managetrunks.misc.getTrunkType(trunkname) ;
- try{
- var this_IP = '';
- if(!ttype || ( ttype != 'sip' && ttype != 'iax' && ttype != 'providers' ) ){ return '--'; }
- if( ttype == 'providers' ){
- var uname = parent.sessionData.pbxinfo.trunks[ttype][trunkname]['username'];
- var host = parent.sessionData.pbxinfo.trunks[ttype][trunkname]['host'];
- ttype = parent.astgui_managetrunks.misc.getProviderTrunkType(trunkname); // find 'sip' or 'iax'
- if ( ttype != 'sip' && ttype != 'iax'){
- return '--';
- }
- }else{
- var uname = parent.sessionData.pbxinfo.trunks[ttype][trunkname]['username'];
- var host = parent.sessionData.pbxinfo.trunks[ttype][trunkname]['host'];
- }
- if( !uname) {return '';}
-
- (function(){
- if(ttype=='iax'){var a ='iax2';}
- if(ttype=='sip'){var a ='sip';}
- var t = ASTGUI.cliCommand(a + ' show peer ' + trunkname) ;
- t = ASTGUI.parseCLIResponse( t );
- var IP = '';
- var s = t.split('\n');
- for(var i=0; i < s.length; i++ ){
- var line = s[i];
- if(line.contains('Addr->IP') ){ // if line is 'Addr->IP : 68.62.219.197 Port 5060'
- var tmp = line.afterChar(':'); // tmp = '68.62.219.197 Port 5060' ;
- var tmp2 = tmp.split(' Port ');
- IP = tmp2.join(':');
- IP = IP.trim();
- this_IP = IP;
- return;
- }
- }
- })();
-
- if(ttype=='iax'){
- var lines = registry.iax2.split('\n');
- }else if(ttype=='sip'){
- var lines = registry.sip.split('\n');
- }
-
- //var uname_lc = uname.toLowerCase();
- // TODO: come up with a better alternative than this
- // cli output of 'sip show registry' shows only a part of long usernames
- // We should use action: status like we do for active channel monitoring.
-
- var uname_lc = uname.toLowerCase().substr(0,10);
-
- for(var i = 0; i < lines.length; i++) {
- var line = lines[i].trim().toLowerCase();
- if (!line || line.beginsWith('host') ){ continue; }
- if( ( line.beginsWith(host+':') || ( this_IP && line.beginsWith(this_IP + ' ') ) ) && line.contains( ' ' + uname_lc + ' ' ) ){
- if( line.contains(' registered') ){
- return '<font color=green>Registered</font>' ;
- }else if( line.contains('auth. sent') ){
- return '<font color=red>Waiting for Authentication</font>';
- }else if( line.contains('request sent') ){
- return '<font color=red>Request Sent</font>';
- }else if( line.contains('rejected') ){
- return '<font color=red>Rejected</font>';
- }else if( line.contains('unregistered') ){
- return '<font color=red>Unregistered</font>';
- }else{
- return '<font color=red>Unregistered</font>';
- }
- }
- }
- return '<font color=red>Unregistered</font>';
- }catch(err){
- ASTGUI.Log.Error(err.description);
- }
- },
-
- parseGETparam : function(url_string, getparam ){ // ASTGUI.parseGETparam( url , 'EXTENSION_EDIT');
- // parse a URL string and return the value of a GET parameter
- // url can be in '....html?EXTENSION_EDIT=XXXX&YYYYYYY...' or '....html?EXTENSION_EDIT=XXXX'
- var t = getparam + '=' ;
- if( url_string.contains(t) ){
- var g = url_string.afterStr(t);
- return g.contains('&') ? g.beforeChar('&') : g ;
- }
- return '';
- },
-
- hideDrag : function(event){
- // Use this as a Cancel Button event, DONOT use this for hiding the div after save()/update(), use the '$().hideWithBg()' instead
- var et = ASTGUI.events.getTarget(event) ;
- while( et.nodeName.toUpperCase() != 'DIV' ){ et = et.parentNode ; }
- et.style.display = 'none';
- ASTGUI.feedback( { msg:'Changes cancelled !', showfor:2, color:'#32633d' } );
- try{
- et.ownerDocument.getElementById('bg_transparent').style.display ='none';
- }catch(err){}
- },
-
- isNull : function(a){
- // ASTGUI.isNull(a) ;
- return a===null
- },
-
- isArray: function(a){
- // ASTGUI.isArray(a) ;
- return a instanceof Array || ( a!= null && typeof a=="object" && typeof a.push == "function" && typeof a.concat == "function" )
- },
-
- loadHTML: function(u , cb){
- // ASTGUI.loadHTML(url)
- // loads URL 'url' in synchronus mode. note that 'url' is restricted by same origin policy
- var r = Math.round(10000*Math.random());
-
- if( cb && typeof cb == 'function' ) {
- $.ajax({ url: u + '?r=' + r , async: true, success: function(msg){
- cb(msg);
- }});
- }else{
- var s = $.ajax({ url: u + '?r=' + r , async: false });
- return s.responseText;
- }
- },
-
- listSystemFiles : function( dir , cb ){
- // ASTGUI.listSystemFiles( dir , callBackFunction )
- // list of files in 'dir' will be sent to callBackFunction as an array
- if ( typeof dir != 'string') cb([]) ;
- try{
- this.systemCmd( top.sessionData.directories.script_ListFiles + ' ' + dir , function(){
- ASTGUI.loadHTML( top.sessionData.directories.output_SysInfo , function(op){
- var tmp_files = op.split('\n');
- var files = [];
- for( var i =0 ; i < tmp_files.length ; i++){
- if( typeof tmp_files[i] == "undefined" ){ continue; }
- tmp_files[i] = tmp_files[i].trim();
- if( tmp_files[i] == "" ){ continue; }
- files.push(tmp_files[i]);
- }
- cb(files);
- });
- });
- }catch(err){
- ASTGUI.Log.Error(err.description);
- cb([]);
- }
- },
-
- miscFunctions: {
- getChunksFromManagerOutput : function( op , usf){
- // ASTGUI.miscFunctions.getChunksFromManagerOutput( output_str ) ;
- if ( typeof op != 'string') return [] ;
- try{
- var tr_Array = [];
- var tmp_chunk = (usf) ? {} : [] ;
- var count = 0;
- var tmp_lines = op.split('\n');
- if( tmp_lines[0].contains('Response: ') ) tmp_lines.removeFirst();
- if( tmp_lines[0].contains('Message: ') ) tmp_lines.removeFirst();
-
- for( var r = 0; r < tmp_lines.length ; r++ ){
- var this_line = tmp_lines[r];
- if( this_line.trim() == '' ){
- if( !count ){ continue; }
- tr_Array.push(tmp_chunk);
- tmp_chunk = (usf) ? {} : [] ;
- count = 0;
- continue;
- }
-
- if( !this_line.contains(': ') ){ continue; }
-
- if( usf ){
- tmp_chunk[ this_line.beforeStr(': ').trim() ] = this_line.afterStr(': ').trim() ;
- }else{
- tmp_chunk.push(this_line) ;
- }
- count++ ;
- }
-
- return tr_Array ;
- }catch(err){
- ASTGUI.Log.Error(err.description);
- return [] ;
- }
- },
-
- createConfig : function( fileName, callback){ // ASTGUI.miscFunctions.createConfig( 'filaName', function(){ } ) ;
- if ( typeof fileName != 'string') callback() ;
- if( parent.sessionData.PLATFORM.isAST_1_6 ){
- var s = $.ajax({ url: ASTGUI.paths.rawman+'?action=createconfig&filename='+ fileName , async: false }).responseText;
- callback();
- }else{
- ASTGUI.systemCmd( 'touch ' + top.sessionData.directories.asteriskConfig + fileName, callback );
- }
- },
-
- ArrayContains : function(arr, str){ // ASTGUI.miscFunctions.ArrayContains(arr, str )
- // There is already an Array.prototype function for this
- // but IE is going crazy when using the prototype method on a parent window array
- for(var i=0, j = arr.length ; i < j; i++ ){
- if( arr[i] === str ) return true;
- }
- return false;
- },
-
- moveUpDown_In_context: function(context, line , updown , cbf ){
- // ASTGUI.miscFunctions.moveUpDown_In_context( ct , line , bool , cbf ) ; bool = true for Up, false for Down (default)
- // Use this function when you want to move a line Up/Down with in a context
- // Example:
- //
- // [somcontext]
- // include=context2
- // include=context1
- //
- // use:
- // ASTGUI.miscFunctions.moveUpDown_In_context( 'somcontext' , 'include=context2' , false , someCallBackFunction ) ;
- // to move the 'include=context2' below the 'include=context1'
-
- try{
- updown = Number(updown);
- var t = context2json({ filename:'extensions.conf' , context : context , usf: 0 });
-
- if( !t.contains(line) ){ // Could not find the rule in this context.
- cbf(t);
- }
-
- for( var ti = 0 ; ti < t.length ; ti++ ){
- if( t[ti] == line ){
- var tmp_a = (updown) ? t[ ti - 1 ] : t[ ti + 1 ] ;
- t[ti] = tmp_a ;
- if( updown ){ // move up
- t[ti-1] = line ;
- }else{ // move down
- t[ti+1] = line ;
- }
- break;
- }
- }
-
- ASTGUI.miscFunctions.empty_context({ filename:'extensions.conf', context : context, cb : function(){
- var x = new listOfActions('extensions.conf');
- t.each(function( this_line ){
- x.new_action('append', context , this_line.beforeChar('=') , this_line.afterChar('=') );
- });
- x.callActions( function(){
- cbf(t);
- });
- }});
- }catch(err){
- ASTGUI.Log.Error(err.description);
- }
- },
-
- empty_context: function( ct ){ // ASTGUI.miscFunctions.empty_context({ filename:'somefile.conf', context : 'context_x', cb : fn })
- try{
- //if( parent.sessionData.PLATFORM.isAST_1_6 ){
- // var u = new listOfSynActions(ct.filename);
- // u.new_action('emptycat', ct.context , '', '' ) ;
- // u.callActions();
- // ct.cb();
- // return;
- //}else{
- var sel_cxt = context2json({ filename: ct.filename , context : ct.context , usf:0 });
- var x = new listOfActions(ct.filename);
- sel_cxt.each(function(line){
- var var_name = line.beforeChar('=');
- var var_value = line.afterChar('=');
- x.new_action('delete', ct.context , var_name, '', var_value);
- });
- x.callActions(ct.cb);
- //}
- }catch(err){
- ASTGUI.Log.Error(err.description);
- }
- },
-
- delete_LinesLike: function( ct ){
- // ASTGUI.miscFunctions.delete_LinesLike({ context_name : 'voicemailgroups' , beginsWithArr: ['exten=6050,'] , filename: 'extensions.conf', hasThisString:'somestring', cb:function(){} });
- // deletes all line in the context 'voicemailgroups' that beings with 'exten=6050,' and contains the string hasThisString (optional)
-
- try{
[... 1738 lines stripped ...]
More information about the asterisk-gui-commits
mailing list