From: Ben Klang Date: Tue, 8 Nov 2005 06:12:56 +0000 (+0000) Subject: Reworking dialplan management to be more responive. Heavy use of javascript X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=9bb92850a5b5cd190b08f6901bcd8f092166cc5c;p=horde.git Reworking dialplan management to be more responive. Heavy use of javascript and DHTML should make this feel much nicer. git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@83 06cd67b6-e706-0410-b29e-9de616bca6e9 --- diff --git a/andrew.webprj b/andrew.webprj index c627bafcd..fdd45f686 100644 --- a/andrew.webprj +++ b/andrew.webprj @@ -6,48 +6,48 @@ - + - - + + - - + + - + - + - + - + - - + + - + - - + + - - - - + + + + @@ -55,59 +55,60 @@ - + - - + + - + - - + + - - - - + + + + - + - + - + + - - - + + + - + - + - - + + - - + + templates/ toolbars/ - + Ben Klang ben@alkaloid.net No Debugger @@ -118,9 +119,10 @@ - - - + + + + @@ -129,6 +131,7 @@ + diff --git a/index.php b/index.php index 896c7c4b3..8d29eaed4 100644 --- a/index.php +++ b/index.php @@ -49,11 +49,9 @@ if (!$section) { require SHOUT_TEMPLATES . '/common-header.inc'; require SHOUT_TEMPLATES . '/menu.inc'; - -echo "
"; // if (!$section) { // $section = - +print '
'; echo $tabs->render($section); switch ($section) { case "conference": @@ -77,9 +75,12 @@ switch ($section) { default: require SHOUT_TEMPLATES . '/common-footer.inc'; + require $registry->get('templates', 'horde') . '/common-footer.inc'; exit(); break; } require "main/$section.php"; +print '
'; +require SHOUT_TEMPLATES . '/common-footer.inc'; require $registry->get('templates', 'horde') . '/common-footer.inc'; \ No newline at end of file diff --git a/lib/Driver/ldap.php b/lib/Driver/ldap.php index 362df8ff8..b2c91681a 100644 --- a/lib/Driver/ldap.php +++ b/lib/Driver/ldap.php @@ -313,11 +313,15 @@ for $context")); * * @param string $context Context to return extensions for * + * @param boolean $preprocess Parse includes and barelines and add their + * information into the extensions array + * * @return array Multi-dimensional associative array of extensions data * */ - function &getDialplan($context) + function &getDialplan($context, $preprocess = false) { + # FIXME Implement preprocess functionality. Don't forget to cache! static $dialplans = array(); if (isset($dialplans[$context])) { return $dialplans[$context]; @@ -349,26 +353,30 @@ for $context")); if (strlen($line) < 5) { break; } - # Can't use strtok here because there may be ','s in the arg - # string + # Can't use strtok here because there may be commass in the + # arg string # Get the extension $token1 = strpos($line, ','); $token2 = strpos($line, ',', $token1 + 1); + $token3 = strpos($line, '(', $token2 + 1); $extension = substr($line, 0, $token1); - if (!isset($dialplans[$context][$extension])) { - $dialplan[$context][$extension] = array(); + if (!isset($dialplans[$context]['extensions'][$extension])) { + $dialplan[$context]['extensions'][$extension] = array(); } $token1++; # Get the priority $priority = substr($line, $token1, $token2 - $token1); - $dialplans[$context][$extension][$priority] = array(); + $dialplans[$context]['extensions'][$extension][$priority] = + array(); $token2++; # Get Application and args $application = substr($line, $token2); + #$args = strpos($) + # Merge all that data into the returning array $dialplans[$context]['extensions'][$extension][$priority] = $application; @@ -380,7 +388,8 @@ for $context")); $extension => $data) { ksort($dialplans[$context]['extensions'][$extension]); } - ksort($dialplans[$context]['extensions']); + uksort($dialplans[$context]['extensions'], + array(new Shout, "extensort")); } # Handle include lines if (isset($res[$i]['asteriskincludeline'])) { @@ -764,6 +773,16 @@ for $context")); } // }}} + + /* Needed because uksort can't take a classed function as its callback arg */ + function _sortexten($e1, $e2) + { + print "$e1 and $e2\n"; + $ret = Shout::extensort($e1, $e2); + print "returning $ret"; + return $ret; + } + // {{{ connect method /** * Attempts to open a connection to the LDAP server. diff --git a/lib/Shout.php b/lib/Shout.php index 26cfdd056..fe927ba95 100644 --- a/lib/Shout.php +++ b/lib/Shout.php @@ -223,5 +223,104 @@ class Shout return $array[$int]; } + /** + * Convert Asterisk's special extensions to friendly names + * + * @param string $extension Extension to search for friendly name. + */ + function exten2name($exten) + { + # Cast as a string to avoid misinterpreted digits + switch((string)$exten) { + case 'i': + $nodetext = 'Invalid Handler'; + break; + case 's': + $nodetext = 'Entry Point'; + break; + case 't': + $nodetext = 'Timeout Handler'; + break; + case 'o': + $nodetext = 'Operator'; + break; + case 'h': + $nodetext = 'Hangup Handler'; + break; + case 'fax': + $nodetext = 'FAX Detection'; + break; + default: + $nodetext = "Extension $exten"; + break; + } + + return $nodetext; + } + + /** + * Compare two inputs as extensions and return them in the following order: + * 's', numbers (low to high), single chars, multi-chars + * 's' comes first because in Asterisk it is commonly the 'starting' exten. + * This function is expected to be used with uksort() + * + * @param string $e1 + * + * @param string $e2 + * + * @return int Relation of $e1 to $e2 + */ + function extensort($e1, $e2) + { + # Assumptions: We don't have to deal with negative numbers. If we do + # they'll sort as strings + $e1 = (string)$e1; + $e2 = (string)$e2; + # Try to return quickly if either extension is 's' + if ($e1 == 's' || $e2 == 's') { + if ($e1 == $e2) { + # They are both s? + # FIXME Should we warn here? Or assume the rest of the app + # is smart enough to handle this condition? + return 0; + } + + return ($e1 == 's') ? -1 : 1; + } + + # Next check for numeric extensions + if (preg_match('/^[*#0-9]+$/', $e1)) { + # e1 is a numeric extension + if (preg_match('/^[*#0-9]+$/', $e2)) { + # e2 is also numeric + if (strlen($e1) == 1 || strlen($e2) == 1) { + if (strlen($e1) == strlen($e2)) { + # Both are 1 digit long + return ($e1 < $e2) ? -1 : 1; + } else { + return (strlen($e1) == 1) ? -1 : 1; + } + } + return ($e1 < $e2) ? -1 : 1; + } else { + # e2 is not a numeric extension so it must sort after e1 + return -1; + } + } elseif (preg_match('/^[*#0-9]+$/', $e2)) { + # e2 is numeric but e1 is not. e2 must sort before e1 + return 1; + } + + # e1 and e2 are both strings + if (strlen($e1) == 1 || strlen($e2) == 1) { + # e1 or e2 is a single char extension (reserved in Asterisk) + return (strlen($e1) == 1) ? -1 : 1; + } else { + # e1 and e2 are both multi-char strings. Sort them equally. + # FIXME Should add logic to make one multi-char take precedence + # over another? + return 0; + } + } } // }}} \ No newline at end of file diff --git a/main/dialplan.php b/main/dialplan.php index e9cd3f71c..5e399e740 100644 --- a/main/dialplan.php +++ b/main/dialplan.php @@ -20,36 +20,23 @@ require_once 'Horde/Block/Collection.php'; // Set up the tree. $tree = &Horde_Tree::singleton('shout_dialplan_menu', 'javascript'); - foreach ($dialplan as $linetype => $linedata) { switch($linetype) { case 'extensions': - $tree->addNode('extensions', null, 'Extensions', null); + $url = '#top'; + $tree->addNode('extensions', null, 'Extensions', null, array('url' => $url)); foreach ($linedata as $extension => $priorities) { - switch($extension) { - case 'i': - $nodetext = 'Invalid Extension'; - break; - case 's': - $nodetext = 'Main'; - break; - case 't': - $nodetext = 'Timeout'; - break; - case 'o': - $nodetext = 'Operator'; - break; - case 'h': - $nodetext = 'Hangup'; - break; - default: - $nodetext = $extension; - break; - } + $nodetext = Shout::exten2name($extension); $url = Horde::applicationUrl('index.php?section=dialplan' . '&extension=' . $extension . '&context=' . $context); - $tree->addNode($extension, 'extensions', $nodetext, null, false, - array('url' => $url)); + $url = "#$extension"; + $tree->addNode("extension_".$extension, 'extensions', $nodetext, + null, false, + array( + 'url' => $url, + 'onclick' => 'highlightExten(\''.$extension.'\')', + ) + ); // foreach ($priorities as $priority => $application) { // $tree->addNode("$extension-$priority", $extension, "$priority: $application", null); // } @@ -60,25 +47,26 @@ foreach ($dialplan as $linetype => $linedata) { $tree->addNode('includes', null, 'Includes', null); foreach ($linedata as $include) { $url = Horde::applicationUrl('index.php?section=dialplan&context='.$include); - $tree->addNode($include, 'includes', $include, null, true, array('url' => $url)); + $tree->addNode("include_$include", 'includes', $include, null, + true, array('url' => $url)); } break; # TODO Ignoring ignorepat lines for now + case 'barelines': $tree->addNode('barelines', null, 'Extra Settings', null); + $i = 0; foreach ($linedata as $bareline) { - $tree->addNode($bareline, 'barelines', $bareline, null); + $tree->addNode("bareline_".$i, 'barelines', $bareline, null); + $i++; } break; } } require SHOUT_TEMPLATES . '/dialplan/contexttree.inc'; - -if ($extension = Util::getFormData('extension')) { - require SHOUT_TEMPLATES . '/dialplan/extensiondetail.inc'; -} +require SHOUT_TEMPLATES . '/dialplan/extensiondetail.inc'; // Horde::addScriptFile('httpclient.js', 'horde', true); // Horde::addScriptFile('hideable.js', 'horde', true); diff --git a/templates/dialplan/contexttree.inc b/templates/dialplan/contexttree.inc index 101326a49..6b40cc4f4 100644 --- a/templates/dialplan/contexttree.inc +++ b/templates/dialplan/contexttree.inc @@ -1,3 +1,55 @@ -
-renderTree(); ?> -
\ No newline at end of file + + +
+
Context:
+
+ +
+renderTree(true); ?> +
+Back to Top +
diff --git a/templates/dialplan/dialplanlist.inc b/templates/dialplan/dialplanlist.inc index 8e7f6b69f..7ede9d86a 100644 --- a/templates/dialplan/dialplanlist.inc +++ b/templates/dialplan/dialplanlist.inc @@ -10,27 +10,7 @@ if (isset($dialplan['extensions']) && (count($dialplan['extensions']) > 0)) { foreach ($dialplan['extensions'] as $extension => $priorities) { - unset($extname); - # Cast as a string to avoid misinterpreted digits - switch ((string)$extension) { - case "h": - $extname = "Hangup"; - break; - case "i": - $extname = "Invalid"; - break; - case "t": - $extname = "Timeout"; - break; - case "s": - $extname = "Start"; - break; - case "o": - $extname = "Operator"; - break; - default: - break; - } + $extname = Shout::exten2name($extension); ?> diff --git a/templates/dialplan/extensiondetail.inc b/templates/dialplan/extensiondetail.inc index e931bcf7b..426273a0b 100644 --- a/templates/dialplan/extensiondetail.inc +++ b/templates/dialplan/extensiondetail.inc @@ -1 +1,87 @@ -
This is where extension details will be printed.
\ No newline at end of file + +
+
No Configured Extensions
+
+ + + $priorities) { ?> + + + + + + + + + + +
" + id=""> + + + +
+ " + id=""> + $application) { + ?> + + + + + + + +
" + name=""> + + + - + " + name="" + onclick="javascript:activatePriority('', '')"> + + + + " + name=""> + + + + " + name=""> + + + +
+
+
+ diff --git a/templates/menu.inc b/templates/menu.inc index 3297c0c94..80e0324e5 100644 --- a/templates/menu.inc +++ b/templates/menu.inc @@ -1,3 +1,4 @@ + getValue('widget_accesskey') ? Horde::getAccessKey(_("Select _Context")) : ''; @@ -14,7 +15,7 @@ $menu_view = $prefs->getValue('menu_view'); getContexts(); foreach ($contexts as $c => $cdata) { - print "