From: Michael M Slusarz Date: Thu, 4 Feb 2010 00:38:21 +0000 (-0700) Subject: Use MD5 hashes to determine when to auto-save X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=4500367b43f531420da5c643adc66873073072b9;p=horde.git Use MD5 hashes to determine when to auto-save --- diff --git a/imp/compose-dimp.php b/imp/compose-dimp.php index 105e756b4..4618855c3 100644 --- a/imp/compose-dimp.php +++ b/imp/compose-dimp.php @@ -197,7 +197,8 @@ $compose_result['js_onload'][] = 'DimpCompose.fillForm(' . Horde_Serialize::seri Horde::addInlineScript($compose_result['js_onload'], 'load'); $scripts = array( - array('compose-dimp.js', 'imp') + array('compose-dimp.js', 'imp'), + array('md5.js', 'horde') ); IMP_Dimp::header(_("Message Composition"), $scripts); diff --git a/imp/compose.php b/imp/compose.php index 73db77790..78a2e5393 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -1104,6 +1104,7 @@ if ($showmenu) { IMP::prepareMenu(); } Horde::addScriptFile('compose.js', 'imp'); +Horde::addScriptFile('md5.js', 'horde'); require IMP_TEMPLATES . '/common-header.inc'; Horde::addInlineScript($js_code); if ($showmenu) { diff --git a/imp/js/compose-dimp.js b/imp/js/compose-dimp.js index 592214ab9..c7b276583 100644 --- a/imp/js/compose-dimp.js +++ b/imp/js/compose-dimp.js @@ -10,9 +10,9 @@ var DimpCompose = { // Variables defaulting to empty/false: // auto_save_interval, compose_cursor, disabled, drafts_mbox, editor_on, - // is_popup, knl_p, knl_sm, mp_padding, resizebcc, resizecc, resizeto, - // row_height, rte, skip_spellcheck, spellcheck, sc_submit, uploading - last_msg: '', + // is_popup, knl_p, knl_sm, last_msg, mp_padding, resizebcc, resizecc, + // resizeto, row_height, rte, skip_spellcheck, spellcheck, sc_submit, + // uploading confirmCancel: function() { @@ -472,34 +472,25 @@ var DimpCompose = { identity = this.getIdentity($F('last_identity')), msgval = $('composeMessage'); - if (!this.last_msg.empty() && - this.last_msg != $F(msgval).replace(/\r/g, '') && - !window.confirm(DIMP.text_compose.fillform)) { - return; - } - // Set auto-save-drafts now if not already active. if (DIMP.conf_compose.auto_save_interval_val && !this.auto_save_interval) { this.auto_save_interval = new PeriodicalExecuter(function() { - var cur_msg = this.editor_on - ? this.rte.getData() - : $F(msgval); - cur_msg = cur_msg.replace(/\r/g, ''); - if (!cur_msg.empty() && this.last_msg != cur_msg) { + var curr_hash = MD5.hash($('to', 'cc', 'bcc', 'subject').invoke('getValue').join('\0') + (this.editor_on ? this.rte.getData() : $F(msgval))); + if (this.last_msg && curr_hash != this.last_msg) { this.uniqueSubmit('AutoSaveDraft'); - this.last_msg = cur_msg; } + this.last_msg = curr_hash; }.bind(this), DIMP.conf_compose.auto_save_interval_val * 60); + /* Immediately execute to get MD5 hash of empty message. */ + this.auto_save_interval.execute(); } if (this.editor_on) { this.rte.setData(msg); - this.last_msg = this.rte.getData().replace(/\r/g, ''); } else { msgval.setValue(msg); this.setCursorPosition(msgval); - this.last_msg = $F(msgval).replace(/\r/g, ''); } $('to').setValue(header.to); diff --git a/imp/js/compose.js b/imp/js/compose.js index 47a8020ed..e8c081a95 100644 --- a/imp/js/compose.js +++ b/imp/js/compose.js @@ -202,14 +202,13 @@ var ImpCompose = { CKEDITOR.instances.composeMessage.updateElement(); } - cur_msg = $F('composeMessage').replace(/\r/g, ''); - if (!cur_msg.empty() && this.last_msg != cur_msg) { + cur_msg = MD5.hash($('to', 'cc', 'bcc', 'subject').compact().invoke('getValue').join('\0') + $F('composeMessage')); + if (this.last_msg && curr_hash != this.last_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; } + this.last_msg = cur_msg; return; case 'toggle_editor': @@ -385,7 +384,8 @@ var ImpCompose = { document.observe('SpellChecker:noerror', this._onNoErrorSpellCheck.bind(this)); if (this.auto_save) { - new PeriodicalExecuter(this.uniqSubmit.bind(this, 'auto_save_draft'), this.auto_save * 60); + /* Immediately execute to get MD5 hash of empty message. */ + new PeriodicalExecuter(this.uniqSubmit.bind(this, 'auto_save_draft'), this.auto_save * 60).execute(); } this.resize.bind(this).delay(0.25); diff --git a/imp/templates/javascript_defs_dimp.php b/imp/templates/javascript_defs_dimp.php index 970c7938e..ae9e6aad5 100644 --- a/imp/templates/javascript_defs_dimp.php +++ b/imp/templates/javascript_defs_dimp.php @@ -169,7 +169,6 @@ if ($compose_mode) { $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?"), - 'fillform' => _("You have already changed the message body, are you sure you want to drop the changes?"), 'nosubject' => _("The message does not have a Subject entered.") . "\n" . _("Send message without a Subject?"), 'remove' => _("Remove"), 'spell_noerror' => _("No spelling errors found."),