mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-22 22:08:45 +01:00
better control for cleanup of drafted messages by using onunload and onbeforeunload
This commit is contained in:
parent
f5e374ca1f
commit
f09ede587e
@ -262,11 +262,26 @@ class ajaxfelamimail
|
||||
return $response->getXML();
|
||||
}
|
||||
|
||||
function saveAsDraft($_composeID, $_data)
|
||||
function saveAsDraft($_composeID, $_data, $_autoSave=true)
|
||||
{
|
||||
if($this->_debug) error_log(__METHOD__.__LINE__.' ID:'.array2string($_composeID).' Data:'.array2string($_data));
|
||||
if($this->_debug) error_log(__METHOD__.__LINE__.' AutoSave'.$_autoSave.' ID:'.array2string($_composeID).' Data:'.array2string($_data));
|
||||
$bocompose = CreateObject('felamimail.bocompose',$_composeID,$this->charset);
|
||||
$folder = ($this->bofelamimail->mailPreferences->ic_server[$this->bofelamimail->profileID]->draftfolder ? $this->bofelamimail->mailPreferences->ic_server[$this->bofelamimail->profileID]->draftfolder : $this->bofelamimail->mailPreferences->preferences['draftFolder']);
|
||||
$folder = $messageFolder = ($this->bofelamimail->mailPreferences->ic_server[$this->bofelamimail->profileID]->draftfolder ? $this->bofelamimail->mailPreferences->ic_server[$this->bofelamimail->profileID]->draftfolder : $this->bofelamimail->mailPreferences->preferences['draftFolder']);
|
||||
// autosave should always save to Draft. Manual Save may Save to templates Folder
|
||||
if ($_autoSave)
|
||||
{
|
||||
if ($this->bofelamimail->isTemplateFolder($bocompose->sessionData['messageFolder']))
|
||||
{
|
||||
$messageFolder = $bocompose->sessionData['messageFolder'];
|
||||
$bocompose->sessionData['messageFolder'] = $folder;
|
||||
//error_log(__METHOD__.__LINE__.' MessageFolder:'.$messageFolder.' SavingDestination:'.$folder);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//error_log(__METHOD__.__LINE__.' ID:'.array2string($_composeID).'->'.$folder.' Data:'.array2string($bocompose->sessionData['messageFolder']));
|
||||
}
|
||||
|
||||
$this->bofelamimail->reopen($folder);
|
||||
$status = $this->bofelamimail->getFolderStatus($folder);
|
||||
//error_log(__METHOD__.__LINE__.array2string(array('Folder'=>$folder,'Status'=>$status)));
|
||||
@ -316,12 +331,36 @@ class ajaxfelamimail
|
||||
$lastDrafted = false;
|
||||
if (isset($bocompose->sessionData['lastDrafted'])) $lastDrafted = $bocompose->sessionData['lastDrafted'];
|
||||
$messageUid = $bocompose->saveAsDraft($formData,$folder); // folder may change
|
||||
if ($lastDrafted && is_array($lastDrafted)) $this->bofelamimail->deleteMessages((array)$lastDrafted['uid'],$lastDrafted['folder']);
|
||||
$bocompose->sessionData['lastDrafted'] = array('uid'=>$messageUid,'folder'=>$folder);
|
||||
if ($lastDrafted && is_array($lastDrafted) && isset($lastDrafted['uid']) && !empty($lastDrafted['uid'])) $lastDrafted['uid'] = trim($lastDrafted['uid']);
|
||||
if ($lastDrafted && is_array($lastDrafted) && isset($lastDrafted['uid']) && !empty($lastDrafted['uid'])) $this->bofelamimail->deleteMessages((array)$lastDrafted['uid'],$lastDrafted['folder']);
|
||||
if ($_autoSave)
|
||||
{
|
||||
$bocompose->sessionData['lastDrafted'] = array('uid'=>$messageUid,'folder'=>$folder);
|
||||
$bocompose->sessionData['messageFolder'] = $messageFolder;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($bocompose->sessionData['lastDrafted'])) unset($bocompose->sessionData['lastDrafted']);
|
||||
}
|
||||
$bocompose->saveSessionData();
|
||||
if($this->_debug) error_log(__METHOD__.__LINE__.' saved as:'.$messageUid.' in '.$folder);
|
||||
}
|
||||
|
||||
function removeLastDraftedVersion($_composeID)
|
||||
{
|
||||
if($this->_debug); error_log(__METHOD__.__LINE__.' ID:'.array2string($_composeID));
|
||||
if (!empty($_composeID))
|
||||
{
|
||||
$bocompose = CreateObject('felamimail.bocompose',$_composeID,$this->charset);
|
||||
$folder = ($this->bofelamimail->mailPreferences->ic_server[$this->bofelamimail->profileID]->draftfolder ? $this->bofelamimail->mailPreferences->ic_server[$this->bofelamimail->profileID]->draftfolder : $this->bofelamimail->mailPreferences->preferences['draftFolder']);
|
||||
$this->bofelamimail->reopen($folder);
|
||||
if (isset($bocompose->sessionData['lastDrafted'])) $lastDrafted = $bocompose->sessionData['lastDrafted'];
|
||||
if ($lastDrafted && is_array($lastDrafted) && isset($lastDrafted['uid']) && !empty($lastDrafted['uid'])) $lastDrafted['uid'] = trim($lastDrafted['uid']);
|
||||
if ($lastDrafted && is_array($lastDrafted) && isset($lastDrafted['uid']) && !empty($lastDrafted['uid'])) $this->bofelamimail->deleteMessages((array)$lastDrafted['uid'],$lastDrafted['folder']);
|
||||
if($this->_debug) error_log(__METHOD__.__LINE__.' removed last drafted:'.$lastDrafted['uid'].' in '.$lastDrafted['folder']);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleEditor($_composeID, $_content ,$_mode)
|
||||
{
|
||||
$_content = utf8_decode($_content);
|
||||
|
@ -235,6 +235,8 @@
|
||||
if (!empty($addHeadInfo['X-IDENTITY'])) {
|
||||
$this->sessionData['identity'] = $addHeadInfo['X-IDENTITY'];
|
||||
}
|
||||
// if the message is located within the draft folder, add it as last drafted version (for possible cleanup on abort))
|
||||
if ($bofelamimail->isDraftFolder($_folder)) $this->sessionData['lastDrafted'] = array('uid'=>$_uid,'folder'=>$_folder);
|
||||
$this->sessionData['uid'] = $_uid;
|
||||
$this->sessionData['messageFolder'] = $_folder;
|
||||
$this->sessionData['isDraft'] = true;
|
||||
@ -1154,7 +1156,12 @@
|
||||
}
|
||||
// handle previous drafted versions of that mail
|
||||
$lastDrafted = false;
|
||||
if (isset($this->sessionData['lastDrafted'])) $lastDrafted = $this->sessionData['lastDrafted'];
|
||||
if (isset($this->sessionData['lastDrafted']))
|
||||
{
|
||||
$lastDrafted = $this->sessionData['lastDrafted'];
|
||||
if (isset($lastDrafted['uid']) && !empty($lastDrafted['uid'])) $lastDrafted['uid']=trim($lastDrafted['uid']);
|
||||
if (isset($lastDrafted['uid']) && (empty($lastDrafted['uid']) || $lastDrafted['uid'] == $this->sessionData['uid'])) $lastDrafted=false;
|
||||
}
|
||||
if ($lastDrafted && is_array($lastDrafted)) $bofelamimail->deleteMessages((array)$lastDrafted['uid'],$lastDrafted['folder']);
|
||||
unset($this->sessionData['lastDrafted']);
|
||||
|
||||
|
@ -4646,7 +4646,7 @@ class felamimail_bo
|
||||
//error_log(__METHOD__.__LINE__.' AltBody:'.$AltBody);
|
||||
foreach ($SendAndMergeTocontacts as $k => $val)
|
||||
{
|
||||
$sendOK = $openAsDraft = false;
|
||||
$sendOK = $openComposeWindow = $openAsDraft = false;
|
||||
//error_log(__METHOD__.__LINE__.' Id To Merge:'.$val);
|
||||
if ($GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook' &&
|
||||
count($SendAndMergeTocontacts) > 1 &&
|
||||
@ -4790,6 +4790,7 @@ class felamimail_bo
|
||||
// no send, save successful, and message_uid present
|
||||
if ($savefailed===false && $messageUid && $sendOK===false)
|
||||
{
|
||||
$openComposeWindow = true;
|
||||
list($fm_width,$fm_height) = explode('x',egw_link::get_registry('felamimail','view_popup'));
|
||||
$linkData = array
|
||||
(
|
||||
@ -4797,6 +4798,7 @@ class felamimail_bo
|
||||
'uid' => $messageUid,
|
||||
'folder' => base64_encode($_folder),
|
||||
'icServer' => $this->profileID,
|
||||
'method' => 'importMessageToMergeAndSend',
|
||||
);
|
||||
$composeUrl = $GLOBALS['egw']->link('/index.php',$linkData);
|
||||
//error_log(__METHOD__.__LINE__.' ComposeURL:'.$composeUrl);
|
||||
@ -4818,7 +4820,7 @@ class felamimail_bo
|
||||
}
|
||||
else
|
||||
{
|
||||
$processStats['failed'][] = 'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
|
||||
if (!$openComposeWindow) $processStats['failed'][] = 'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -673,13 +673,17 @@
|
||||
$this->compose('body',$suppressSigOnTop=true);
|
||||
}
|
||||
|
||||
|
||||
function display_app_header()
|
||||
{
|
||||
egw_framework::validate_file('jscode','composeMessage','felamimail');
|
||||
egw_framework::validate_file('ckeditor3','ckeditor','phpgwapi');
|
||||
|
||||
$GLOBALS['egw']->js->set_onload('javascript:initAll();');
|
||||
$GLOBALS['egw']->js->set_onbeforeunload("if (do_onunload) if (draftsMayExist) {a = checkunload(browserSupportsOnUnloadConfirm?'".addslashes(lang("Please choose:"))."'+'\\n'+'".addslashes(lang("1) keep drafted message (press OK)"))."'+'\\n'+'".addslashes(lang("2) discard the message completely (press Cancel)"))."':'".addslashes(lang("if you leave this page without saving to draft, the message will be discarded completely"))."');".' if (!browserSupportsOnUnloadConfirm) return a;}');
|
||||
//$GLOBALS['egw']->js->set_onbeforeunload("if (do_onunload) if (draftsMayExist) return '".addslashes(lang("Please choose:"))."'+'\\n'+'".addslashes(lang("1) keep drafted message (press OK)"))."'+'\\n'+'".addslashes(lang("2) discard the message completely (press Cancel)"))."';");
|
||||
$GLOBALS['egw']->js->set_onunload("if (do_onunload) checkunload();");
|
||||
//$GLOBALS['egw']->js->set_onunload("if (do_onunload) egw_appWindow('felamimail').xajax_doXMLHTTPsync('felamimail.ajaxfelamimail.removeLastDraftedVersion','".$this->composeID."');");
|
||||
|
||||
$GLOBALS['egw_info']['flags']['include_xajax'] = True;
|
||||
|
||||
common::egw_header();
|
||||
|
@ -36,6 +36,10 @@ var KEYCODE_DOWN=40;
|
||||
// quickserach input field
|
||||
var disabledKeys1 = new Array(KEYCODE_TAB, KEYCODE_ENTER, KEYCODE_UP, KEYCODE_DOWN);
|
||||
//var disabledKeys1 = new Array(KEYCODE_ENTER, KEYCODE_UP, KEYCODE_DOWN);
|
||||
var browserSupportsOnUnloadConfirm = true;
|
||||
var do_onunload=false;
|
||||
var draftsMayExist=false;
|
||||
var justSavedAsDraftManually; // no value yet, as it should indicate that the message was just saved, before another autosave kicked in
|
||||
|
||||
function initAll()
|
||||
{
|
||||
@ -50,6 +54,42 @@ function initAll()
|
||||
//alert(document.onkeydown);
|
||||
var titletext = document.getElementById('fm_compose_subject').value;
|
||||
if (titletext.length>0) updateTitle(titletext);
|
||||
if (window.location.search.search(/&uid=/))
|
||||
{
|
||||
for (var i = 0; i < window.location.search.split("&").length; i++) {
|
||||
if (window.location.search.split("&")[i].search(/uid=/)!= -1)
|
||||
{
|
||||
var a = window.location.search.split("&")[i].replace(/uid=/,'');
|
||||
if (a.length >0) { draftsMayExist = true; /*alert(a+' found');*/}
|
||||
}
|
||||
if (window.location.search.split("&")[i].search(/method=/)!= -1)
|
||||
{
|
||||
var b = window.location.search.split("&")[i].replace(/method=/,'');
|
||||
if (b.length >0 && b=='importMessageToMergeAndSend')
|
||||
{
|
||||
justSavedAsDraftManually = false; /*alert(b+' found');*/
|
||||
do_onunload = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($j.browser.webkit) browserSupportsOnUnloadConfirm = false; // chrome blocks alert/confirm boxes, but displays (custom) messages on demand before leaving/closing a page
|
||||
if ($j.browser.opera) browserSupportsOnUnloadConfirm = false; // opera does not support unload or onbeforeunload for security reasons
|
||||
}
|
||||
|
||||
function checkunload(checkBrowser)
|
||||
{
|
||||
if (typeof checkBrowser != 'undefined' && justSavedAsDraftManually == false)
|
||||
{
|
||||
if (browserSupportsOnUnloadConfirm && do_onunload) do_onunload=!confirm(checkBrowser);
|
||||
if (!browserSupportsOnUnloadConfirm)
|
||||
{
|
||||
// window.setTimeout('checkunload();',1000);
|
||||
// do_onunload = false;
|
||||
return checkBrowser;
|
||||
}
|
||||
}
|
||||
if (do_onunload) xajax_doXMLHTTPsync('felamimail.ajaxfelamimail.removeLastDraftedVersion',composeID);
|
||||
}
|
||||
|
||||
function fm_startTimerSaveAsDraft(_refreshTimeOut) {
|
||||
@ -61,10 +101,10 @@ function fm_startTimerSaveAsDraft(_refreshTimeOut) {
|
||||
}
|
||||
}
|
||||
|
||||
function fm_compose_saveAsDraftBG()
|
||||
function fm_compose_saveAsDraftBG(autoSave)
|
||||
{
|
||||
//alert('composing in progress->'+composeID);
|
||||
|
||||
if (typeof autoSave == 'undefined') autoSave = true;
|
||||
var htmlFlag = document.getElementsByName('_is_html')[0];
|
||||
var mimeType = document.getElementById('mimeType');
|
||||
var currentEditor = htmlFlag.value;
|
||||
@ -96,8 +136,14 @@ function fm_compose_saveAsDraftBG()
|
||||
}
|
||||
|
||||
//call saveasdraft with xajax_doXMLHTTP, or something equivalent
|
||||
xajax_doXMLHTTP("felamimail.ajaxfelamimail.saveAsDraft", composeID, data);
|
||||
xajax_doXMLHTTP("felamimail.ajaxfelamimail.saveAsDraft", composeID, data, autoSave);
|
||||
fm_startTimerSaveAsDraft(_refreshTimeOut);
|
||||
if (autoSave)
|
||||
{
|
||||
draftsMayExist = true;
|
||||
do_onunload=true;
|
||||
justSavedAsDraftManually = false;
|
||||
}
|
||||
}
|
||||
|
||||
function addEmail(to,email)
|
||||
@ -681,12 +727,23 @@ function fm_compose_selectSuggestionOnClick(_selectedSuggestion) {
|
||||
|
||||
function fm_compose_saveAsDraft() {
|
||||
document.getElementById('saveAsDraft').value=1;
|
||||
/*
|
||||
// if we submit the form, we do not want to execute the onunload stuff
|
||||
do_onunload=false;
|
||||
document.doit.submit();
|
||||
*/
|
||||
// we use our new Background function now
|
||||
fm_compose_saveAsDraftBG(false);
|
||||
justSavedAsDraftManually = true;
|
||||
}
|
||||
|
||||
function fm_compose_printit() {
|
||||
document.getElementById('printit').value=1;
|
||||
// if we submit the form, we do not want to execute the onunload stuff
|
||||
do_onunload=false;
|
||||
// ToDo: could be done as fm_compose_saveAsDraftBG() and then reopen it in/as printview
|
||||
document.doit.submit();
|
||||
|
||||
}
|
||||
|
||||
function fm_blink_currentInputField() {
|
||||
@ -707,6 +764,8 @@ function fm_compose_sendEMail() {
|
||||
}
|
||||
|
||||
if(addressSet == true) {
|
||||
// if we submit the form, we do not want to execute the onunload stuff
|
||||
do_onunload=false;
|
||||
document.doit.submit();
|
||||
} else {
|
||||
alert(fm_compose_langNoAddressSet);
|
||||
|
@ -3,6 +3,8 @@
|
||||
(only cc/bcc) felamimail de (kein Kopie/Blindkopie)
|
||||
(separate multiple addresses by comma) felamimail de (mehrere Adressen durch Komma trennen)
|
||||
(unknown sender) felamimail de (unbekannter Absender)
|
||||
1) keep drafted message (press OK) felamimail de 1) Nachrichtenentwurf behalten (wählen Sie OK)
|
||||
2) discard the message completely (press Cancel) felamimail de 2) verwerfen der kompletten Nachricht (wählen Sie Abbrechen)
|
||||
3paneview: if you want to see a preview of a mail by single clicking onto the subject, set the height for the message-list and the preview area here (300 seems to be a good working value). the preview will be displayed at the end of the message list on demand (click). felamimail de Vorschauansicht: Wenn Sie eine Vorschauansicht von eMails wünschen, müssen Sie hier die Höhe des Vorschaubereichs und der Nachrichtenliste festlegen. (300 hat sich als zufriedenstellender Wert erwiesen). Sie können ebenfalls die Mindesthöhe der eMail Liste festlegen, indem Sie die gewünschte Mindesthöhe, durch Komma getrennt, an den Wert für die Höhe des Vorschaubereiches anhängen (Bsp.: 300,190). Die Vorschau wird durch einen einfachen Klick auf den Betreff der anzuzeigenden Nachricht aktiviert.
|
||||
aborted felamimail de abgebrochen
|
||||
activate felamimail de aktivieren
|
||||
@ -251,6 +253,7 @@ if shown, which folders should appear on main screen felamimail de Welche Ordner
|
||||
if subject contains felamimail de wenn Betreff enthält
|
||||
if to contains felamimail de wenn An enthält
|
||||
if using ssl or tls, you must have the php openssl extension loaded. felamimail de Wenn Sie SSL oder TLS benützen, muss die openssl PHP Erweiterung geladen sein.
|
||||
if you leave this page without saving to draft, the message will be discarded completely felamimail de Wenn Sie diese Seite verlassen, ohne die Nachricht als Entwurf zu speichern, wird diese komplett verworfen
|
||||
illegal folder name. please select a different name. felamimail de Ilegaler Ordnername. Bitte wählen Sie einen anderen Namen
|
||||
imap felamimail de IMAP
|
||||
imap server felamimail de IMAP Server
|
||||
@ -385,6 +388,7 @@ participants felamimail de Teilnehmer
|
||||
personal felamimail de persönlich
|
||||
personal information felamimail de persönliche Informationen
|
||||
please ask the administrator to correct the emailadmin imap server settings for you. felamimail de Bitte fragen Sie Ihren Administrator um die IMAP Einstellungen für Sie zu korrigieren
|
||||
please choose: felamimail de Bitte entscheiden Sie:
|
||||
please configure access to an existing individual imap account. felamimail de Bitte konfigurieren Sie hier den Zugang zu einem existierenden IMAP Account.
|
||||
please select a address felamimail de Bitte wählen Sie eine Adresse
|
||||
please select the number of days to wait between responses felamimail de Bitte wählen wie viele Tage zwischen den Antworten gewartet werden soll
|
||||
|
@ -3,6 +3,8 @@
|
||||
(only cc/bcc) felamimail en Only Cc/Bcc
|
||||
(separate multiple addresses by comma) felamimail en Separate multiple addresses by comma
|
||||
(unknown sender) felamimail en Unknown sender
|
||||
1) keep drafted message (press OK) felamimail en 1) keep drafted message (press OK)
|
||||
2) discard the message completely (press Cancel) felamimail en 2) discard the message completely (press Cancel)
|
||||
3paneview: if you want to see a preview of a mail by single clicking onto the subject, set the height for the message-list and the preview area here (300 seems to be a good working value). the preview will be displayed at the end of the message list on demand (click). felamimail en 3PaneView: If you want to see a preview of a mail by single click onto the subject, set the height for the message list and the preview area e.g. 300. You may specify the minimum height of the message list too, by adding it after the specified IFrame Preview height, separated by comma (e.g.: 300,190)
|
||||
aborted felamimail en Aborted
|
||||
activate felamimail en Activate
|
||||
@ -252,6 +254,7 @@ if shown, which folders should appear on main screen felamimail en If shown, whi
|
||||
if subject contains felamimail en If subject contains
|
||||
if to contains felamimail en If to contains
|
||||
if using ssl or tls, you must have the php openssl extension loaded. felamimail en If using SSL or TLS, you must have the PHP openssl extension loaded.
|
||||
if you leave this page without saving to draft, the message will be discarded completely felamimail en If you leave this page without saving to draft, the message will be discarded completely
|
||||
illegal folder name. please select a different name. felamimail en Invalid folder name. Please select a different name.
|
||||
imap felamimail en IMAP
|
||||
imap server felamimail en IMAP server
|
||||
@ -386,6 +389,7 @@ participants felamimail en Participants
|
||||
personal felamimail en personal
|
||||
personal information felamimail en Personal information
|
||||
please ask the administrator to correct the emailadmin imap server settings for you. felamimail en Ask the administrator to correct the eMailAdmin IMAP server settings
|
||||
please choose: felamimail en Please choose:
|
||||
please configure access to an existing individual imap account. felamimail en Configure access to an existing individual IMAP account
|
||||
please select a address felamimail en Select an address
|
||||
please select the number of days to wait between responses felamimail en Select the number of days to wait between responses
|
||||
|
@ -48,6 +48,8 @@
|
||||
alert("{lang_infolog_tracker_not_both}");
|
||||
return false;
|
||||
}
|
||||
// if we submit the form, we do not want to execute the onunload stuff
|
||||
do_onunload=false;
|
||||
return true;
|
||||
}
|
||||
fm_startTimerSaveAsDraft(_refreshTimeOut);
|
||||
|
Loading…
Reference in New Issue
Block a user