From f869ee27311e0d8d455e0dbb269b61a7a0332b8a Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Fri, 11 Nov 2005 20:54:35 +0000 Subject: [PATCH] Moving dialplan handling javascript to its own class. Will do same with PHP code later. Still having trouble getting formatting to work. FF and IE differ WRT handling innerHTML. http://www.kenvillines.com/archives/000069.html Will try removing some of the table formatting and going to divs git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@89 06cd67b6-e706-0410-b29e-9de616bca6e9 --- andrew.webprj | 22 ++--- main/dialplan.php | 2 +- templates/dialplan/contexttree.inc | 58 ------------- templates/dialplan/extensiondetail.inc | 149 ++++++++++++++++++--------------- templates/javascript/dialplan.js | 145 ++++++++++++++++++++++++++++++++ 5 files changed, 238 insertions(+), 138 deletions(-) create mode 100644 templates/javascript/dialplan.js diff --git a/andrew.webprj b/andrew.webprj index 49a77d687..2f0db539a 100644 --- a/andrew.webprj +++ b/andrew.webprj @@ -17,7 +17,7 @@ - + @@ -71,7 +71,7 @@ - + @@ -82,12 +82,14 @@ - + - + + + @@ -120,20 +122,18 @@ - - + + + + - - - - - + diff --git a/main/dialplan.php b/main/dialplan.php index 5e399e740..6f934a4d2 100644 --- a/main/dialplan.php +++ b/main/dialplan.php @@ -34,7 +34,7 @@ foreach ($dialplan as $linetype => $linedata) { null, false, array( 'url' => $url, - 'onclick' => 'highlightExten(\''.$extension.'\')', + 'onclick' => 'dp.highlightExten(\''.$extension.'\')', ) ); // foreach ($priorities as $priority => $application) { diff --git a/templates/dialplan/contexttree.inc b/templates/dialplan/contexttree.inc index b957c40fa..dafbe7e87 100644 --- a/templates/dialplan/contexttree.inc +++ b/templates/dialplan/contexttree.inc @@ -1,61 +1,3 @@ - -
Context:
diff --git a/templates/dialplan/extensiondetail.inc b/templates/dialplan/extensiondetail.inc index 9375eb9cd..5f14248f5 100644 --- a/templates/dialplan/extensiondetail.inc +++ b/templates/dialplan/extensiondetail.inc @@ -7,95 +7,108 @@ if(!isset($dialplan['extensions'])) { + - +
$priorities) { ?> -
- + id="" + onclick="dp.highlightExten('');"> + + - + - - - + $p = 0; + foreach($priorities as $priority => $data) { + ?> + + + + + + + +
" - id=""> - - - -
- " - id=""> - $data) { - ?> - - - - - - +
+
+
" + name=""> +
" - name=""> - + - - - " - name="" - onclick="javascript:activatePriority('', '')"> - - - - " - name=""> - - - - " - name=""> - - - -
-
-
-
" + name=""> + + + - + " + name="" + onclick="javascript:dp.activatePriority('', '')"> + + + + " + name=""> + + + + " + name=""> + + + +
+
+ + + - + diff --git a/templates/javascript/dialplan.js b/templates/javascript/dialplan.js new file mode 100644 index 000000000..40748e43d --- /dev/null +++ b/templates/javascript/dialplan.js @@ -0,0 +1,145 @@ +/** + * Shout Dialplan Javascript Class + * + * Provides the javascript class to create dynamic dialplans + * + * Copyright 2005 Ben Klang + * + * See the enclosed file COPYING for license information (GPL). If you did not + * receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * $Horde: shout/templates/javascript/dialplan.js,v 1.0.0.1 2005/11/10 06:23:22 ben Exp $ + * + * @author Ben Klang + * @package Shout + * @since Shout 0.1 + */ +function Dialplan(instanceName) +{ + this._instanceName = instanceName; + this.dp = new Array(); + this.dp = eval('shout_dialplan_'+instanceName); + this.curExten = ''; + this.curPrio = ''; +} + +Dialplan.prototype.highlightExten = function(exten) +{ + if (this.curExten && this.curExten != exten) { + this.deactivatePriority(); + + document.getElementById('eBox-' + this.curExten).className = 'extensionBox'; + document.getElementById('pList-' + this.curExten).className = 'pList'; + } + + this.curExten = exten; + document.getElementById("eBox-" + exten).className = 'extensionBoxHighlight'; + document.getElementById("pList-" + exten).className = 'pListHighlight'; +} + + +Dialplan.prototype.activatePriority = function(exten, prio) +{ + prio = Number(prio); + if (this.curExten) { + this.deactivatePriority(); + } + + if (exten != this.curExten) { + this.highlightExten(exten); + } + + this.curPrio = prio; + 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'; +} + +Dialplan.prototype.deactivatePriority = function() +{ + if (this.curPrio && document.getElementById('pButtons-'+this.curExten+'-'+this.curPrio)) { + 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'; + } +} + +Dialplan.prototype.drawPrioTable = function (exten) +{ + if (!exten) { + alert('Must first choose an extension to draw'); + return false; + } + alert(document.getElementById('pList-'+exten).innerHTML); + table = ''; + table += ' \n'; + table += ' \n'; + for (var p in this.dp[exten]['priorities']) { + table += ' \n'; + table += ' \n'; + table += ' \n'; + table += ' \n'; + } + table += ' \n'; + table += ' \n'; + table += '
\n'; + table += ' +\n'; + table += ' -\n'; + table += ' \n'; + table += ' '+p+'\n'; + table += ' \n'; + table += ' \n'; + table += ' \n'; + table += ' \n'; + table += ' \n'; + table += ' ARGS\n'; + table += '
\n'; + alert(table); + document.getElementById('pList-'+exten).innerHTML = table; +} + +Dialplan.prototype.addExten = function (exten, extenName) +{ + this.dp[exten] = new Array(); +} + +Dialplan.prototype.addPrio = function(exten, prio) +{ + prio = Number(prio); + if (this.dp[exten][prio] != 'undefined') { + this._incrPrio(exten, prio); + } + this.dp[exten]['priorities'][prio] = new Array(); + this.drawPrioTable(exten); +} + +Dialplan.prototype._incrPrio = function (exten, prio) +{ + p = Number(prio) + 1; + h = Number(prio) + 101; + + // Check for error handlers + if (this.dp[exten][h] != 'undefined') { + //alert(this.dp[exten][h]); + //this._incrPrio(exten, h); + } + + // Make sure the next slot is empty. If not move it first. + if (this.dp[exten][p] != 'undefined') { + //alert(p); + //this._incrPrio(exten, p); + } + + // Copy the existing prio to its new home + this.dp[exten][p] = this.dp[exten][prio]; +} \ No newline at end of file -- 2.11.0