From ad5b64f5fd825de2723a6c2bf659ac52aec97961 Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Mon, 14 Nov 2005 04:14:57 +0000 Subject: [PATCH] The remove priority (-) buttons now work. More formatting fixes. New bug found: Opera and IE complain that the document.getElementById(foo) are returning null. My suspcicion is that it can't perform the getElementById on elements rendered in js and stuffed into innerHTML. Just a hunch.... Works fine in Konq an FF. At least one old bug: Can't edit activated priority text boxes. Daniel reports slightly different results. Needs more inspection. git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@95 06cd67b6-e706-0410-b29e-9de616bca6e9 --- andrew.webprj | 10 ++++----- templates/javascript/dialplan.js | 48 +++++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/andrew.webprj b/andrew.webprj index 7a30043f2..49f0b9919 100644 --- a/andrew.webprj +++ b/andrew.webprj @@ -1,6 +1,6 @@ - + -//w3c//dtd xhtml 1.0 strict//en @@ -13,7 +13,7 @@ - + @@ -64,7 +64,7 @@ - + @@ -90,7 +90,7 @@ - + @@ -125,7 +125,7 @@ - + diff --git a/templates/javascript/dialplan.js b/templates/javascript/dialplan.js index 211c1025c..6b10ca93c 100644 --- a/templates/javascript/dialplan.js +++ b/templates/javascript/dialplan.js @@ -59,12 +59,13 @@ Dialplan.prototype.activatePriority = function(exten, prio) } else { var form = ''; - //form += '
'; form += ' '; - form += ' '; + form += ' '; form += ' '; - //form += '
'; document.getElementById('pBox-'+this.curExten+'-'+this.curPrio).innerHTML = form; + document.getElementById('pBox-'+this.curExten+'-'+this.curPrio).p.focus; + document.getElementById('pBox-'+this.curExten+'-'+this.curPrio).p.select; } } @@ -74,6 +75,7 @@ Dialplan.prototype.deactivatePriority = function() document.getElementById('priority-'+this.curExten+'-'+this.curPrio).className = 'priority'; document.getElementById('pButtons-'+this.curExten+'-'+this.curPrio).style['visibility'] = 'hidden'; } + this.curPrio = 0; } Dialplan.prototype.drawPrioTable = function (exten) @@ -98,7 +100,9 @@ Dialplan.prototype.drawPrioTable = function (exten) table += ' \n'; table += ' \n'; - table += ' \n'; table += this.genAppList(this.dp[exten]['priorities'][p]['application']); table += ' \n'; table += ' \n'; @@ -147,7 +151,6 @@ Dialplan.prototype.addPrio = function(exten, prio) for (p in this.dp[exten]['priorities']) { p = Number(p); - prio = Number(prio); // Make a notch for the new priority by incrementing all priorities greater // than the requested one. Try to exclude error handling priorities // which are unrelated to the changed extension. See README for @@ -156,20 +159,19 @@ Dialplan.prototype.addPrio = function(exten, prio) // error handling priorities. if (p > prio && (p < prio + 90 || p > prio + 100)) { tmp[p + 1] = this.dp[exten]['priorities'][p]; - plist[i] = p + 1; + plist[i++] = p + 1; } else { tmp[p] = this.dp[exten]['priorities'][p]; - plist[i] = p; + plist[i++] = p; } - i++; } // Seed the new priority - var newP = Number(prio) + 1; - tmp[newP] = new Array(); - tmp[newP]['application'] = ''; - tmp[newP]['args'] = ''; - plist[i] = newP; + p = prio + 1; + tmp[p] = new Array(); + tmp[p]['application'] = ''; + tmp[p]['args'] = ''; + plist[i] = p; // Empty the original array @@ -178,19 +180,27 @@ Dialplan.prototype.addPrio = function(exten, prio) // Sort the priorities and put them back into the original array plist.sort(this._numCompare); for (i = 0; i < plist.length; i++) { - p = Number(plist[i]); this.dp[exten]['priorities'][p] = tmp[p]; } } + this.curPrio = 0; this.drawPrioTable(exten); + this.activatePriority(exten, prio); + return true; } Dialplan.prototype.delPrio = function(exten, prio) { prio = Number(prio); if (this.dp[exten]['priorities'][prio] != 'undefined') { + // The .length method on this array always reports number of priorities + 1; + // Haven't yet solved this mystery but the below test does work correctly. + if (this.dp[exten]['priorities'].length <= 2) { + alert('Extensions must have at least one priority'); + return false; + } // Due to javascript's inability to remove an array element while maintaining // associations, we copy the elements into a tmp array and ultimately replace // the object's copy. We will also have to sort the resulting array manually @@ -208,10 +218,10 @@ Dialplan.prototype.delPrio = function(exten, prio) // TODO: Make a decision about whether this is the best way to handle // error handling priorities. p = Number(p); - if (p != prio) { - if (p > prio && (p < prio + 90 || p > prio + 100)) { - p = Number(p) - 1; - } + if (p > prio && (p < prio + 90 || p > prio + 100)) { + tmp[p - 1] = this.dp[exten]['priorities'][p]; + plist[i++] = p - 1; + } else if (p != prio) { tmp[p] = this.dp[exten]['priorities'][p]; plist[i++] = p; } @@ -227,8 +237,10 @@ Dialplan.prototype.delPrio = function(exten, prio) this.dp[exten]['priorities'][p] = tmp[p]; } } + this.curPrio = 0; this.drawPrioTable(exten); + return true; } Dialplan.prototype._numCompare = function(a, b) -- 2.11.0