}
break;
+case 'auto_save_draft':
+case 'save_draft':
case 'send_message':
- if ($compose_disable) {
+ // Drafts readonly is handled below.
+ if (($actionID == 'send_message') && $compose_disable) {
break;
}
$notification->push($e);
break;
}
- $header['replyto'] = $identity->getValue('replyto_addr');
$header['to'] = $imp_ui->getAddressList(Horde_Util::getFormData('to'));
if ($prefs->getValue('compose_cc')) {
$header['bcc'] = $imp_ui->getAddressList(Horde_Util::getFormData('bcc'));
}
- $message = Horde_Util::getFormData('message');
$header['subject'] = Horde_Util::getFormData('subject', '');
+ $message = Horde_Util::getFormData('message');
+
+ /* Save the draft. */
+ if (($actionID == 'auto_save_draft') || ($actionID == 'save_draft')) {
+ if (!$readonly_drafts) {
+ try {
+ $old_uid = $imp_compose->getMetadata('draft_uid');
+
+ $result = $imp_compose->saveDraft($header, $message, Horde_Nls::getCharset(), $rtemode);
+
+ /* Delete existing draft. */
+ $imp_ui->removeDraft($old_uid);
+
+ /* Closing draft if requested by preferences. */
+ if ($actionID == 'save_draft') {
+ $imp_compose->destroy();
+
+ if ($isPopup) {
+ if ($prefs->getValue('close_draft')) {
+ Horde_Util::closeWindowJS();
+ exit;
+ } else {
+ $notification->push($result, 'horde.success');
+ }
+ } else {
+ $notification->push($result);
+ header('Location: ' . _mailboxReturnURL(false));
+ exit;
+ }
+ }
+ } catch (IMP_Compose_Exception $e) {
+ if ($actionID == 'save_draft') {
+ $notification->push($e, 'horde.error');
+ }
+ }
+ }
+
+ if ($actionID == 'auto_save_draft') {
+ $request = new stdClass;
+ $request->requestToken = Horde::getRequestToken('imp.compose');
+ $request->formToken = Horde_Token::generateId('compose');
+ Horde::sendHTTPResponse(Horde::prepareResponse($request), 'json');
+ exit;
+ }
+
+ $get_sig = false;
+ break;
+ }
+
+ $header['replyto'] = $identity->getValue('replyto_addr');
if ($smf = Horde_Util::getFormData('sent_mail_folder')) {
$sent_mail_folder = $smf;
try {
$sent = $imp_compose->buildAndSendMessage($message, $header, $charset, $rtemode, $options);
- if ($prefs->getValue('auto_delete_drafts')) {
+ if ($prefs->getValue('auto_save_drafts') ||
+ $prefs->getValue('auto_delete_drafts')) {
$imp_ui->removeDraft($imp_compose->getMetadata('draft_uid'));
}
}
exit;
-case 'save_draft':
- if ($readonly_drafts) {
- break;
- }
-
- /* Set up the From address based on the identity. */
- try {
- $header['from'] = $identity->getFromLine(null, Horde_Util::getFormData('from'));
- } catch (Horde_Exception $e) {
- $header['from'] = '';
- $get_sig = false;
- $notification->push($e);
- break;
- }
- foreach (array('to', 'cc', 'bcc', 'subject') as $val) {
- $header[$val] = Horde_Util::getFormData($val);
- }
- $message = Horde_Util::getFormData('message', '');
-
- /* Save the draft. */
- try {
- $result = $imp_compose->saveDraft($header, $message, Horde_Nls::getCharset(), $rtemode);
- $imp_compose->destroy();
-
- /* Closing draft if requested by preferences. */
- if ($isPopup) {
- if ($prefs->getValue('close_draft')) {
- Horde_Util::closeWindowJS();
- exit;
- } else {
- $notification->push($result, 'horde.success');
- }
- } else {
- $notification->push($result);
- header('Location: ' . _mailboxReturnURL(false));
- exit;
- }
- } catch (IMP_Compose_Exception $e) {
- $notification->push($e, 'horde.error');
- }
-
- $get_sig = false;
- break;
-
case 'fwd_digest':
$indices = Horde_Util::getFormData('fwddigest');
if (!empty($indices)) {
/* Define some variables used in the javascript code. */
$js_code = array(
+ 'ImpCompose.auto_save = ' . intval($prefs->getValue('auto_save_drafts')),
'ImpCompose.cancel_url = \'' . $cancel_url . '\'',
- 'ImpCompose.spellcheck = ' . intval($spellcheck && $prefs->getValue('compose_spellcheck')),
'ImpCompose.cursor_pos = ' . (is_null($cursor_pos) ? 'null' : $cursor_pos),
'ImpCompose.max_attachments = ' . (($max_attach === true) ? 'null' : $max_attach),
'ImpCompose.popup = ' . intval($isPopup),
'ImpCompose.redirect = ' . intval($redirect),
+ 'ImpCompose.reloaded = ' . intval($token),
'ImpCompose.rtemode = ' . intval($rtemode),
'ImpCompose.smf_check = ' . intval($smf_check),
- 'ImpCompose.reloaded = ' . intval($token)
+ 'ImpCompose.spellcheck = ' . intval($spellcheck && $prefs->getValue('compose_spellcheck'))
);
/* Create javascript identities array. */
var ImpCompose = {
// Variables defined in compose.php:
- // cancel_url, spellcheck, cursor_pos, identities, max_attachments,
- // popup, redirect, reloaded, rtemode, smf_check, skip_spellcheck
+ // cancel_url, spellcheck, cursor_pos, identities, last_msg,
+ // max_attachments, popup, redirect, reloaded, rtemode, smf_check,
+ // skip_spellcheck
display_unload_warning: true,
confirmCancel: function(e)
uniqSubmit: function(actionID, e)
{
- var form;
+ var cur_msg, form;
if (!Object.isUndefined(e)) {
e.stop();
$('actionID').setValue(actionID);
break;
+ case 'auto_save_draft':
+ // Move HTML text to textarea field for submission.
+ if (this.rtemode) {
+ CKEDITOR.instances.composeMessage.updateElement();
+ }
+
+ cur_msg = $F('composeMessage').replace(/\r/g, '');
+ if (!cur_msg.empty() && this.last_msg != cur_msg) {
+ // Use an AJAX submit here so that the page doesn't reload.
+ $('actionID').setValue(actionID);
+ $('compose').request({ onComplete: this._autoSaveDraft.bind(this) });
+
+ this.last_msg = cur_msg;
+ }
+ return;
+
case 'toggle_editor':
form = $('compose');
break;
this.uniqSubmit(actionID, e);
},
+ _autoSaveDraft: function(r, o)
+ {
+ if (r.responseJSON && r.responseJSON.response) {
+ r = r.responseJSON.response;
+ $('compose_formToken').setValue(r.formToken);
+ $('compose_requestToken').setValue(r.requestToken);
+ }
+ },
+
attachmentChanged: function()
{
var fields = [],
document.observe('click', this.clickHandler.bindAsEventListener(this));
document.observe('change', this.changeHandler.bindAsEventListener(this));
+ if (this.auto_save) {
+ new PeriodicalExecuter(this.uniqSubmit.bind(this, 'auto_save_draft'), this.auto_save * 60);
+ }
+
this.resize.bind(this).delay(0.25);
},