From 365ecb0b235d7419cc1cc8416d8c08ec591dcd3b Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Sun, 13 Nov 2005 06:46:52 +0000 Subject: [PATCH] Finished implementing XML application list. Trying to get the priority subtract button but javascript is giving me fits (again...). git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@94 06cd67b6-e706-0410-b29e-9de616bca6e9 --- andrew.webprj | 15 ++-- lib/Dialplan.php | 23 +++--- lib/Shout.php | 52 ++++++++++--- templates/javascript/dialplan.js | 161 +++++++++++++++++++++++++-------------- 4 files changed, 166 insertions(+), 85 deletions(-) diff --git a/andrew.webprj b/andrew.webprj index 0130f5763..7a30043f2 100644 --- a/andrew.webprj +++ b/andrew.webprj @@ -1,6 +1,6 @@ - + -//w3c//dtd xhtml 1.0 strict//en @@ -11,9 +11,9 @@ - + - + @@ -60,11 +60,11 @@ - + - + @@ -90,7 +90,7 @@ - + @@ -123,10 +123,9 @@ - - + diff --git a/lib/Dialplan.php b/lib/Dialplan.php index 37a8aa5ca..125bd8588 100644 --- a/lib/Dialplan.php +++ b/lib/Dialplan.php @@ -148,16 +148,16 @@ class Shout_Dialplan function generateAppList() { - # $applist = Shout::getApplist(); + $applist = Shout::getApplist(); print ''."\n"; return true; @@ -195,18 +195,20 @@ class Shout_Dialplan print '//-->'."\n"; print ''."\n"; + print '
'."\n"; print '
'."\n"; $e = 0; foreach($this->_dialplan['extensions'] as $extension => $priorities) { print '
'."\n"; - print '
'."\n"; + print ''."\n"; + print ''."\n"; + print '
'."\n"; print '
'."\n"; print '
'."\n"; $e++; @@ -219,6 +221,7 @@ class Shout_Dialplan print ''."\n"; } print '
'."\n"; + print ''."\n"; } } } \ No newline at end of file diff --git a/lib/Shout.php b/lib/Shout.php index 9d960f64a..0292e130f 100644 --- a/lib/Shout.php +++ b/lib/Shout.php @@ -19,6 +19,9 @@ require_once SHOUT_BASE . "/lib/defines.php"; // {{{ Class Shout class Shout { + var $applist = array(); + var $_applist_curapp = ''; + var $_applist_curfield = ''; // {{{ getMenu method /** @@ -323,17 +326,21 @@ class Shout } } - function xml2applist() + function getApplist() { + if (isset($_SESSION['shout']['applist'])) { + return $_SESSION['shout']['applist']; + } + $file = SHOUT_BASE . '/config/applist.xml'; $xml_parser = xml_parser_create(); $ShoutObject = new Shout; xml_set_element_handler($xml_parser, - array($ShoutObject, '_xml2applist_startElement'), - array($ShoutObject, '_xml2applist_startElement')); + array(&$ShoutObject, '_xml2applist_startElement'), + array(&$ShoutObject, '_xml2applist_startElement')); xml_set_character_data_handler($xml_parser, - array($ShoutObject, '_xml2applist_characterData')); + array(&$ShoutObject, '_xml2applist_characterData')); if (!$fp = fopen($file, 'r')) { return PEAR::raiseError('Unable to open applist.xml for reading'); @@ -346,25 +353,50 @@ class Shout xml_get_current_line_number($xml_parser))); } } + ksort($ShoutObject->applist); xml_parser_free($xml_parser); + $_SESSION['shout']['applist'] = $ShoutObject->applist; + unset($ShoutObject); + return $_SESSION['shout']['applist']; } function _xml2applist_startElement($parser, $name, $attrs = array()) { - print "Name: $name
\n"; - print_r($attrs); - print "
\n"; - print "
\n"; + if (count($attrs) > 1) { print_r($attrs); } + switch($name) { + case 'APPLICATION': + if (isset($attrs['NAME'])) { + $this->_applist_curapp = $attrs['NAME']; + if (!isset($this->applist[$name])) { + $this->applist[$this->_applist_curapp] = array(); + } + $this->_applist_curfield = ''; + } + break; + case 'SYNOPSIS': + case 'USAGE': + $this->_applist_curfield = $name; + if (!isset($this->applist[$name])) { + $this->applist[$this->_applist_curapp][$name] = ""; + } + break; + } } function _xml2applist_endElement($parser, $name) { - echo ''; + print ''; #NOOP } function _xml2applist_characterData($parser, $string) { - print "Data: $string
\n"; + $string = preg_replace('/^\s+/', '', $string); + $string = preg_replace('/\s+$/', '', $string); + if (strlen($string) > 1) { + $field = $this->_applist_curfield; + $app = $this->_applist_curapp; + $this->applist[$app][$field] .= "$string "; + } } } // }}} \ No newline at end of file diff --git a/templates/javascript/dialplan.js b/templates/javascript/dialplan.js index f51549c2b..211c1025c 100644 --- a/templates/javascript/dialplan.js +++ b/templates/javascript/dialplan.js @@ -56,10 +56,7 @@ Dialplan.prototype.activatePriority = function(exten, prio) this.curPrio = prio; document.getElementById('priority-'+exten+'-'+prio).className = 'priorityHighlight'; document.getElementById('pButtons-'+exten+'-'+prio).style['visibility'] = 'visible'; - // document.getElementById('pButtons-'+exten+'-'+prio).className = 'pButtonsHighlight'; - // document.getElementById('pNumber-'+exten+'-'+prio).className = 'pElementHighlight'; - // document.getElementById('pApp-'+exten+'-'+prio).className = 'pElementHighlight'; - // document.getElementById('pArgs-'+exten+'-'+prio).className = 'pElementHighlight'; + } else { var form = ''; //form += '
'; @@ -76,10 +73,6 @@ Dialplan.prototype.deactivatePriority = function() if (this.curPrio && document.getElementById('pButtons-'+this.curExten+'-'+this.curPrio)) { document.getElementById('priority-'+this.curExten+'-'+this.curPrio).className = 'priority'; document.getElementById('pButtons-'+this.curExten+'-'+this.curPrio).style['visibility'] = 'hidden'; -// document.getElementById('pButtons-'+this.curExten+'-'+this.curPrio).className = 'pButtons'; -// document.getElementById('pNumber-'+this.curExten+'-'+this.curPrio).className = 'pElement'; -// document.getElementById('pApp-'+this.curExten+'-'+this.curPrio).className = 'pElement'; -// document.getElementById('pArgs-'+this.curExten+'-'+this.curPrio).className = 'pElement'; } } @@ -90,7 +83,6 @@ Dialplan.prototype.drawPrioTable = function (exten) alert('Must first choose an extension to draw'); return false; } - //alert(document.getElementById('pList-'+exten).innerHTML); for (var p in this.dp[exten]['priorities']) { table += '
\n'; table += ' \n'; table += ' \n'; - table += ' \n'; table += this.genAppList(this.dp[exten]['priorities'][p]['application']); table += ' \n'; table += ' \n'; @@ -114,18 +106,25 @@ Dialplan.prototype.drawPrioTable = function (exten) table += ' \n'; table += ' ARGS\n'; + table += ' name="args-'+exten+'-'+p+'">'; + table += this.dp[exten]['priorities'][p]['args']+'\n'; table += ' \n'; table += '
\n'; } - //alert(table); document.getElementById('pList-'+exten).innerHTML = table; } Dialplan.prototype.genAppList = function (app) { - applist = '\n'; - return applist; + var appstring = ''; + for (var a in this.applist) { + appstring += '