From c00b2d26d2177e47764980cee35982ecbfd127d5 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 5 Jun 2009 15:08:43 -0600 Subject: [PATCH] Dynamically update message information in preview --- imp/compose-dimp.php | 35 +++++++++++++++++++++------------ imp/js/src/DimpBase.js | 49 +++++++++++++++++++++++++++++++++++----------- imp/js/src/compose-dimp.js | 4 ++++ 3 files changed, 65 insertions(+), 23 deletions(-) diff --git a/imp/compose-dimp.php b/imp/compose-dimp.php index a51d76464..34c37d04c 100644 --- a/imp/compose-dimp.php +++ b/imp/compose-dimp.php @@ -62,14 +62,14 @@ $imp_ui = new IMP_UI_Compose(); if (count($_POST)) { $result = new stdClass; $result->action = $action; - $result->success = false; + $result->success = 0; /* Update the file attachment information. */ if ($action == 'add_attachment') { if ($_SESSION['imp']['file_upload'] && $imp_compose->addFilesFromUpload('file_')) { $info = DIMP::getAttachmentInfo($imp_compose); - $result->success = true; + $result->success = 1; $result->info = end($info); $result->imp_compose = $imp_compose->getCacheId(); } @@ -98,7 +98,7 @@ if (count($_POST)) { /* Save the draft. */ try { $res = $imp_compose->saveDraft($header, Util::getFormData('message', ''), NLS::getCharset(), Util::getFormData('html')); - $result->success = true; + $result->success = 1; /* Delete existing draft. */ _removeAutoSaveDraft(Util::getFormData('draft_index')); @@ -140,9 +140,11 @@ if (count($_POST)) { $message = Util::getFormData('message'); $html = Util::getFormData('html'); - $result->reply_type = Util::getFormData('reply_type'); - $result->index = Util::getFormData('index'); - $result->reply_folder = Util::getFormData('folder'); + $result->index = intval(Util::getFormData('index')); + if ($reply_type = Util::getFormData('reply_type')) { + $result->reply_folder = Util::getFormData('folder'); + $result->reply_type = $reply_type; + } /* Use IMP_Tree to determine whether the sent mail folder was * created. */ @@ -150,14 +152,14 @@ if (count($_POST)) { $imptree->eltDiffStart(); $options = array( + 'readreceipt' => Util::getFormData('request_read_receipt'), + 'reply_index' => $result->index . IMP::IDX_SEP . $result->reply_folder, + 'reply_type' => $reply_type, + 'save_attachments' => Util::getFormData('save_attachments_select'), 'save_sent' => (($prefs->isLocked('save_sent_mail')) ? $identity->getValue('save_sent_mail') : (bool)Util::getFormData('save_sent_mail')), 'sent_folder' => $identity->getValue('sent_mail_folder'), - 'save_attachments' => Util::getFormData('save_attachments_select'), - 'reply_type' => $result->reply_type, - 'reply_index' => $result->index . IMP::IDX_SEP . $result->reply_folder, - 'readreceipt' => Util::getFormData('request_read_receipt') ); try { @@ -166,19 +168,28 @@ if (count($_POST)) { $notification->push($e->getMessage(), 'horde.error'); break; } - $result->success = true; + $result->success = 1; /* Remove any auto-saved drafts. */ if ($prefs->getValue('auto_save_drafts') || $prefs->getValue('auto_delete_drafts')) { _removeAutoSaveDraft(Util::getFormData('draft_index')); - $result->draft_delete = true; + $result->draft_delete = 1; } if ($sent && $prefs->getValue('compose_confirm')) { $notification->push(_("Message sent successfully."), 'horde.success'); } + /* Update maillog information. */ + if (!empty($header['in_reply_to']) && + !empty($GLOBALS['conf']['maillog']['use_maillog'])) { + $result->log = array(); + foreach (IMP_Maillog::parseLog($header['in_reply_to']) as $val) { + $result->log[] = htmlspecialchars($val['msg']); + } + } + $res = DIMP::getFolderResponse($imptree); if (!empty($res)) { $result->folder = $res['a'][0]; diff --git a/imp/js/src/DimpBase.js b/imp/js/src/DimpBase.js index 45d8a3d6f..c6b8a2f88 100644 --- a/imp/js/src/DimpBase.js +++ b/imp/js/src/DimpBase.js @@ -904,7 +904,7 @@ var DimpBase = { return; } this.pp = data; - pp_uid = data.imapuid + data.view; + pp_uid = this._getPPId(data.imapuid, data.view); if (this.ppfifo.indexOf(pp_uid) != -1) { // There is a chance that the message may have been marked @@ -952,7 +952,7 @@ var DimpBase = { } // Store in cache. - ppuid = r.index + r.folder; + ppuid = this._getPPId(r.index, r.folder); this._expirePPCache([ ppuid ]); this.ppcache[ppuid] = resp; this.ppfifo.push(ppuid); @@ -1006,15 +1006,7 @@ var DimpBase = { // Add message information if (r.log) { - $('msgInfo').show(); - $('infolist_col').show(); - $('infolist_exp').hide(); - - tmp = ''; - r.log.each(function(entry) { - tmp += '' + entry + ''; - }); - $('infolist').down('TABLE').update(tmp); + this.updateMsgInfo(r.log); } else { $('msgInfo').hide(); } @@ -1032,6 +1024,36 @@ var DimpBase = { this._addHistory('msg:' + row.view + ':' + row.imapuid); }, + // opts = index, mailbox + updateMsgInfo: function(log, opts) + { + var tmp = ''; + + if (!opts || + (this.pp.imapuid == opts.index && + this.pp.view == opts.mailbox)) { + $('msgInfo').show(); + + if (opts) { + $('infolist_col').show(); + $('infolist_exp').hide(); + } + + log.each(function(entry) { + tmp += '' + entry + ''; + }); + + $('infolist').down('TABLE').update(tmp); + } + + if (opts) { + tmp = this._getPPId(opts.index, opts.mailbox); + if (this.ppcache[tmp]) { + this.ppcache[tmp].response.log = log; + } + } + }, + initPreviewPane: function() { var sel = this.viewport.getSelected(); @@ -1072,6 +1094,11 @@ var DimpBase = { } }, + _getPPId: function(index, mailbox) + { + return index + '|' + mailbox; + }, + // Labeling functions updateSeenUID: function(r, setflag) { diff --git a/imp/js/src/compose-dimp.js b/imp/js/src/compose-dimp.js index 4590d479c..3433850dd 100644 --- a/imp/js/src/compose-dimp.js +++ b/imp/js/src/compose-dimp.js @@ -248,6 +248,10 @@ var DimpCompose = { DIMP.baseWindow.DimpBase.poll(); } + if (d.log) { + DIMP.baseWindow.DimpBase.updateMsgInfo(d.log, { index: d.index, mailbox: d.reply_folder }); + } + DIMP.baseWindow.DimpCore.showNotifications(r.msgs); } return this.closeCompose(); -- 2.11.0