From 01ffe039089e08fd6faaf03f4170853defd41fc8 Mon Sep 17 00:00:00 2001 From: thomascube Date: Tue, 6 Oct 2009 06:55:08 +0000 Subject: Hold attachment info in a js list in order to simplify things + codestyle --- program/js/app.js | 78 ++++++++++++++++++++------------------ program/js/editor_images.js | 20 +++------- program/steps/mail/attachments.inc | 6 ++- program/steps/mail/compose.inc | 6 ++- 4 files changed, 57 insertions(+), 53 deletions(-) diff --git a/program/js/app.js b/program/js/app.js index d4161714e..d72f9eebb 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -2172,14 +2172,11 @@ function rcube_webmail() } // check if all files has been uploaded - if (this.gui_objects.attachmentlist) { - var list = this.gui_objects.attachmentlist.getElementsByTagName("li"); - for (i=0;i'+content; if (this.env.cancelicon) content = ''+content; - this.add2attachment_list(ts, content); + this.add2attachment_list(ts, { name:'', html:content, complete:false }); } // set reference to the form object @@ -2506,26 +2503,35 @@ function rcube_webmail() // add file name to attachment list // called from upload page - this.add2attachment_list = function(name, content, upload_id) - { + this.add2attachment_list = function(name, att, upload_id) + { if (!this.gui_objects.attachmentlist) return false; + var li = $('
  • ').attr('id', name).html(att.html); var indicator; + // replace indicator's li if (upload_id && (indicator = document.getElementById(upload_id))) { - var li = document.createElement('li'); - $(li).attr('id', name).html(content); - indicator.parentNode.replaceChild(li, indicator); - } else { // add new li - $('
  • ').attr('id', name).html(content).appendTo(this.gui_objects.attachmentlist); - } + li.replaceAll(indicator); + } + else { // add new li + li.appendTo(this.gui_objects.attachmentlist); + } + + if (upload_id && this.env.attachments[upload_id]) + delete this.env.attachments[upload_id]; + + this.env.attachments[name] = att; return true; - }; + }; this.remove_from_attachment_list = function(name) - { + { + if (this.env.attachments[name]) + delete this.env.attachments[name]; + if (!this.gui_objects.attachmentlist) return false; @@ -2533,11 +2539,11 @@ function rcube_webmail() for (i=0;icommand('add2attachment_list', "rcmfile$id", $content, $uploadid); + $OUTPUT->command('add2attachment_list', "rcmfile$id", array( + 'html' => $content, + 'name' => $attachment['name'], + 'mimetype' => $attachment['mimetype'], + 'complete' => true), $uploadid); } else { // upload failed $err = $_FILES['_attachments']['error'][$i]; diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index c894da776..276efda56 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -781,6 +781,7 @@ function rcmail_compose_attachment_list($attrib) $attrib['id'] = 'rcmAttachmentList'; $out = "\n"; + $jslist = array(); if (is_array($_SESSION['compose']['attachments'])) { @@ -798,12 +799,14 @@ function rcmail_compose_attachment_list($attrib) if (empty($a_prop)) continue; - $out .= html::tag('li', array('id' => "rcmfile".$id), + $out .= html::tag('li', array('id' => 'rcmfile'.$id), html::a(array( 'href' => "#delete", 'title' => rcube_label('delete'), 'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%s', this)", JS_OBJECT_NAME, $id)), $button) . Q($a_prop['name'])); + + $jslist['rcmfile'.$id] = array('name' => $a_prop['name'], 'complete' => true, 'mimetype' => $a_prop['mimetype']); } } @@ -814,6 +817,7 @@ function rcmail_compose_attachment_list($attrib) if ($attrib['loadingicon']) $OUTPUT->set_env('loadingicon', $CONFIG['skin_path'] . $attrib['loadingicon']); + $OUTPUT->set_env('attachments', $jslist); $OUTPUT->add_gui_object('attachmentlist', $attrib['id']); return html::tag('ul', $attrib, $out, html::$common_attrib); -- cgit v1.2.3