Bug #9073: More IE fixes for clearing a file input field
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 3 Jun 2010 17:54:10 +0000 (11:54 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 3 Jun 2010 17:55:38 +0000 (11:55 -0600)
While we are here, do a little bit less dynamic DOM node creation.
Also, fix issue where, if attachment was removed when at attachment
limit, the upload box would not appear.

imp/js/compose-dimp.js
imp/templates/dimp/chunks/compose.php
imp/templates/dimp/javascript_defs_dimp.php

index d973cd4..3931091 100644 (file)
@@ -214,8 +214,7 @@ var DimpCompose = {
 
     uniqueSubmitCallback: function(r)
     {
-        var elt,
-            d = r.response;
+        var d = r.response;
 
         if (!d) {
             return;
@@ -285,15 +284,9 @@ var DimpCompose = {
                 if (d.success) {
                     this.addAttach(d.atc.num, d.atc.name, d.atc.type, d.atc.size);
                 }
-                if (DIMP.conf_compose.attach_limit != -1 &&
-                    $('attach_list').childElements().size() > DIMP.conf_compose.attach_limit) {
-                    $('upload').enable();
-                    elt = new Element('DIV', [ DIMP.text_compose.atc_limit ]);
-                } else {
-                    elt = new Element('INPUT', { type: 'file', name: 'file_1' });
-                }
-                $('upload_wait').next().show();
-                $('upload_wait').replace(elt.writeAttribute('id', 'upload'));
+
+                $('upload_wait').hide();
+                this.initAttachList();
                 this.resizeMsgArea();
                 break;
             }
@@ -626,6 +619,7 @@ var DimpCompose = {
             n.fade({
                 afterFinish: function() {
                     n.remove();
+                    this.initAttachList();
                     this.resizeMsgArea();
                 }.bind(this),
                 duration: 0.4
@@ -637,6 +631,31 @@ var DimpCompose = {
         DimpCore.doAction('deleteAttach', { atc_indices: ids, imp_compose: $F('composeCache') });
     },
 
+    initAttachList: function()
+    {
+        var u = $('upload'),
+            u_parent = u.up();
+
+        if (DIMP.conf_compose.attach_limit != -1 &&
+            $('attach_list').childElements().size() >= DIMP.conf_compose.attach_limit) {
+            $('upload_limit').show();
+        } else if (!u_parent.visible()) {
+            $('upload_limit').hide();
+
+            if (Prototype.Browser.IE) {
+                // Trick to allow us to clear the file input on IE without
+                // creating a new node.  Need to re-add the event handler
+                // however, as it won't survive this assignment.
+                u.stopObserving();
+                u_parent.innerHTML = u_parent.innerHTML;
+                u = $('upload');
+                u.observe('change', this.changeHandler.bindAsEventListener(this));
+            }
+
+            u.clear().up().show().next().show();
+        }
+    },
+
     resizeMsgArea: function()
     {
         var mah, rows,
@@ -681,8 +700,8 @@ var DimpCompose = {
     {
         var u = $('upload');
         this.uniqueSubmit('addAttachment');
-        u.next().hide();
-        u.replace(new Element('SPAN', { id: 'upload_wait' }).insert(DIMP.text_compose.uploading + ' (' + $F(u) + ')'));
+        u.up().hide().next().hide();
+        $('upload_wait').update(DIMP.text_compose.uploading + ' (' + $F(u) + ')').show();
     },
 
     attachmentComplete: function()
index d56be8d..ec33c30 100644 (file)
@@ -123,7 +123,11 @@ $compose_disable = !IMP::canCompose();
    <tr class="atcrow">
     <td class="label"><span class="iconImg attachmentImg"></span>: </td>
     <td id="attach_cell">
-     <input type="file" id="upload" name="file_1" />
+     <span id="upload_limit" style="display:none"><?php echo _("The attachment limit has been reached.") ?></span>
+     <span id="upload_wait" style="display:none"></span>
+     <span>
+      <input type="file" id="upload" name="file_1" />
+     </span>
 <?php if (strpos($save_attach, 'prompt') !== false): ?>
      <label style="display:none"><input type="checkbox" class="checkbox" name="save_attachments_select"<?php if (strpos($save_attach, 'yes') !== false) echo ' checked="checked"' ?> /> <?php echo _("Save Attachments in sent folder") ?></label><br />
 <?php endif; ?>
index d0f0fb0..fffbdb0 100644 (file)
@@ -166,7 +166,6 @@ if (in_array(basename($_SERVER['PHP_SELF']), array('compose-dimp.php', 'message-
 
     /* Gettext strings used in compose page. */
     $code['text_compose'] = array(
-        'atc_limit' => _("The attachment limit has been reached."),
         'cancel' => _("Cancelling this message will permanently discard its contents and will delete auto-saved drafts.\nAre you sure you want to do this?"),
         'nosubject' => _("The message does not have a Subject entered.") . "\n" . _("Send message without a Subject?"),
         'remove' => _("Remove"),