IE bugfixes, js simplification
authorPierre Habouzit <madcoder@debian.org>
Wed, 10 Sep 2003 09:41:50 +0000 (09:41 +0000)
committerPierre Habouzit <madcoder@debian.org>
Wed, 10 Sep 2003 09:41:50 +0000 (09:41 +0000)
philter/philter/include/emails.inc.php
philter/philter/philter.js

index 15935eb..4ef2277 100644 (file)
@@ -112,15 +112,15 @@ class EmailPool {
                 .   "<td align=\"center\" width=\"10%\">\n"
                 .   "    <input type=\"checkbox\" name=\"emails[$id][active]\""
                 .   ($email->is_active() ? " checked=\"checked\"" : "")." /></td>\n"
-                .   "<td align=\"center\"><input type=\"button\" name=\"d$id\" "
-                .   "value=\"Del\" onclick=\"del_onclick(this)\" /></td>\n"
+                .   "<td align=\"center\"><input type=\"button\" "
+                .   "value=\"Del\" onclick=\"del_onclick($id)\" /></td>\n"
                 .   "</tr>\n";
             $pair = !$pair;
         }
 
         $res .= "</table>\n"
             .   "<center>\n"
-            .   "    <input id=\"emailsDel\" type=\"hidden\" name=\"emails[del]\" value=\"\" />\n"
+            .   "    <input id=\"emailsDel\" type=\"hidden\" name=\"emails[del]\" value=\"-1\" />\n"
             .   "    <input type=\"submit\" name=\"emails[apply]\" value=\"Apply changes\" />\n"
             .   "</center>\n"
             .   "</form>\n";
@@ -183,13 +183,17 @@ class EmailPool {
                 $philter->set_error($_POST['emails']['new']." is not a valid email");
                 return false;
             }
-        } elseif(!empty($_POST['emails']['del'])) {      // delete one email
+        } elseif(isset($_POST['emails']['del']) && $_POST['emails']['del'] != -1) {      // delete one email
             $del_id = $_POST['emails']['del'];
             // we compute a list of all actives emails
             $allow = false;
-            foreach($this->emails as $id=>$mail)
-                if($del_id!=$id && $mail->is_active())
+
+            foreach($this->emails as $id=>$mail) {
+                if($del_id!=$id && $mail->is_active()) {
                     $allow = true;
+                    break;
+                }
+            }
             
             if($allow && isset($this->emails[$del_id])) {
                 list($count) = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM actions "
index 806062d..f8fda11 100644 (file)
@@ -29,10 +29,10 @@ function getElement(obj) {
     return false;
 }
 
-function del_onclick(button) {
-    if(window.confirm("Voulez vous rĂ©ellement supprimer cette adresse mail ?")) {
-        getElement('emailsDel').value = button.name.slice(1);
-        button.form.submit();
+function del_onclick(val) {
+    if(window.confirm("Do you really want to delete this email address ?")) {
+        getElement('emailsDel').value = val;
+        document.forms['emails'].submit();
     }
 }
 
@@ -104,12 +104,14 @@ var matches_i = 0;
 
 /********** RULE.ACTION FORM FUNCTIONS **********/
 
-function createActionSelect(data,base) {
+function createActionSelect(div,data) {
     var i,j;
     var select = document.createElement("select");
     var sel = 0;
-    select.name = base+'[0]';
+    select.name = div.name+'[0]';
 
+    // OG: must insert select node before creating options because of IE5 bug
+    div.appendChild(select);
     for(i=0, j=0; i<actions_list.length; i++) {
         if(data==i) sel = j;
         if(actions_list[i]) select.options[j++] = new Option(actions_list[i],i,false,(data==i));
@@ -135,8 +137,7 @@ function createActionRow(Node,data) {
 
     div.appendChild(document.createTextNode(" "));
 
-    var select = createActionSelect(data[0],div.name);
-    div.appendChild(select);
+    var select = createActionSelect(div,data[0]);
 
     actions_func[select.options[select.selectedIndex].value](div,data);
 }
@@ -147,12 +148,14 @@ function newAction() {
 
 /********** RULE.MATCH FORM FUNCTIONS **********/
 
-function createMatchSelect(data,base) {
+function createMatchSelect(div,data) {
     var i,j;
     var select = document.createElement("select");
     var sel = 0;
-    select.name = base+'[0]';
+    select.name = div.name+'[0]';
 
+    // OG: must insert select node before creating options because of IE5 bug
+    div.appendChild(select);
     for(i=0, j=0; i<matches_list.length; i++) {
         if(data==i) sel = j;
         if(matches_list[i]) select.options[j++] = new Option(matches_list[i],i,false,(data==i));
@@ -178,8 +181,7 @@ function createMatchRow(Node,data) {
 
     div.appendChild(document.createTextNode(" "));
 
-    var select = createMatchSelect(data[0],div.name);
-    div.appendChild(select);
+    var select = createMatchSelect(div,data[0]);
 
     matches_func[select.options[select.selectedIndex].value](div,data);
 }