- Fix issue where draft auto-save wasn't executed after some inactivity time

- Code improvement - unified (set|clear)Timeout() usage
pull/1/head
alecpl 13 years ago
parent 55dce6801a
commit da5cadcc12

@ -272,7 +272,7 @@ function rcube_webmail()
// show printing dialog // show printing dialog
else if (this.env.action == 'print' && this.env.uid) else if (this.env.action == 'print' && this.env.uid)
if (bw.safari) if (bw.safari)
window.setTimeout('window.print()', 10); setTimeout('window.print()', 10);
else else
window.print(); window.print();
@ -771,7 +771,7 @@ function rcube_webmail()
case 'always-load': case 'always-load':
if (this.env.uid && this.env.sender) { if (this.env.uid && this.env.sender) {
this.add_contact(urlencode(this.env.sender)); this.add_contact(urlencode(this.env.sender));
window.setTimeout(function(){ ref.command('load-images'); }, 300); setTimeout(function(){ ref.command('load-images'); }, 300);
break; break;
} }
@ -789,7 +789,7 @@ function rcube_webmail()
qstring += '&_safe=1'; qstring += '&_safe=1';
this.attachment_win = window.open(this.env.comm_path+'&_action=get&'+qstring+'&_frame=1', 'rcubemailattachment'); this.attachment_win = window.open(this.env.comm_path+'&_action=get&'+qstring+'&_frame=1', 'rcubemailattachment');
if (this.attachment_win) { if (this.attachment_win) {
window.setTimeout(function(){ ref.attachment_win.focus(); }, 10); setTimeout(function(){ ref.attachment_win.focus(); }, 10);
break; break;
} }
} }
@ -912,19 +912,25 @@ function rcube_webmail()
break; break;
case 'savedraft': case 'savedraft':
var form = this.gui_objects.messageform, msgid;
// Reset the auto-save timer // Reset the auto-save timer
self.clearTimeout(this.save_timer); clearTimeout(this.save_timer);
if (!this.gui_objects.messageform) // saving Drafts is disabled
if (!form)
break; break;
// if saving Drafts is disabled in main.inc.php // compose form did not change
// or if compose form did not change if (this.cmp_hash == this.compose_field_hash()) {
if (!this.env.drafts_mailbox || this.cmp_hash == this.compose_field_hash()) this.auto_save_start();
break; break;
}
var form = this.gui_objects.messageform, // re-set keep-alive timeout
msgid = this.set_busy(true, 'savingmessage'); this.start_keepalive();
msgid = this.set_busy(true, 'savingmessage');
form.target = "savetarget"; form.target = "savetarget";
form._draft.value = '1'; form._draft.value = '1';
@ -940,7 +946,7 @@ function rcube_webmail()
break; break;
// Reset the auto-save timer // Reset the auto-save timer
self.clearTimeout(this.save_timer); clearTimeout(this.save_timer);
// all checks passed, send message // all checks passed, send message
var lang = this.spellcheck_lang(), var lang = this.spellcheck_lang(),
@ -959,7 +965,7 @@ function rcube_webmail()
case 'send-attachment': case 'send-attachment':
// Reset the auto-save timer // Reset the auto-save timer
self.clearTimeout(this.save_timer); clearTimeout(this.save_timer);
this.upload_file(props || this.gui_objects.uploadform); this.upload_file(props || this.gui_objects.uploadform);
break; break;
@ -1006,7 +1012,7 @@ function rcube_webmail()
if (uid = this.get_single_uid()) { if (uid = this.get_single_uid()) {
ref.printwin = window.open(this.env.comm_path+'&_action=print&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox)+(this.env.safemode ? '&_safe=1' : '')); ref.printwin = window.open(this.env.comm_path+'&_action=print&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox)+(this.env.safemode ? '&_safe=1' : ''));
if (this.printwin) { if (this.printwin) {
window.setTimeout(function(){ ref.printwin.focus(); }, 20); setTimeout(function(){ ref.printwin.focus(); }, 20);
if (this.env.action != 'show') if (this.env.action != 'show')
this.mark_message('read', uid); this.mark_message('read', uid);
} }
@ -1017,7 +1023,7 @@ function rcube_webmail()
if (uid = this.get_single_uid()) { if (uid = this.get_single_uid()) {
ref.sourcewin = window.open(this.env.comm_path+'&_action=viewsource&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox)); ref.sourcewin = window.open(this.env.comm_path+'&_action=viewsource&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox));
if (this.sourcewin) if (this.sourcewin)
window.setTimeout(function(){ ref.sourcewin.focus(); }, 20); setTimeout(function(){ ref.sourcewin.focus(); }, 20);
} }
break; break;
@ -1162,7 +1168,7 @@ function rcube_webmail()
// set timer for requests // set timer for requests
if (a && this.env.request_timeout) if (a && this.env.request_timeout)
this.request_timer = window.setTimeout(function(){ ref.request_timed_out(); }, this.env.request_timeout * 1000); this.request_timer = setTimeout(function(){ ref.request_timed_out(); }, this.env.request_timeout * 1000);
return id; return id;
}; };
@ -1214,7 +1220,7 @@ function rcube_webmail()
if (this.is_framed()) if (this.is_framed())
parent.rcmail.reload(delay); parent.rcmail.reload(delay);
else if (delay) else if (delay)
window.setTimeout(function(){ rcmail.reload(); }, delay); setTimeout(function(){ rcmail.reload(); }, delay);
else if (window.location) else if (window.location)
location.href = this.env.comm_path + (this.env.action ? '&_action='+this.env.action : ''); location.href = this.env.comm_path + (this.env.action ? '&_action='+this.env.action : '');
}; };
@ -1347,7 +1353,7 @@ function rcube_webmail()
this.env.last_folder_target = null; this.env.last_folder_target = null;
if (this.folder_auto_timer) { if (this.folder_auto_timer) {
window.clearTimeout(this.folder_auto_timer); clearTimeout(this.folder_auto_timer);
this.folder_auto_timer = null; this.folder_auto_timer = null;
this.folder_auto_expand = null; this.folder_auto_expand = null;
} }
@ -1400,15 +1406,15 @@ function rcube_webmail()
// if the folder is collapsed, expand it after 1sec and restart the drag & drop process. // if the folder is collapsed, expand it after 1sec and restart the drag & drop process.
if (div.hasClass('collapsed')) { if (div.hasClass('collapsed')) {
if (this.folder_auto_timer) if (this.folder_auto_timer)
window.clearTimeout(this.folder_auto_timer); clearTimeout(this.folder_auto_timer);
this.folder_auto_expand = this.env.mailboxes[k].id; this.folder_auto_expand = this.env.mailboxes[k].id;
this.folder_auto_timer = window.setTimeout(function() { this.folder_auto_timer = setTimeout(function() {
rcmail.command('collapse-folder', rcmail.folder_auto_expand); rcmail.command('collapse-folder', rcmail.folder_auto_expand);
rcmail.drag_start(null); rcmail.drag_start(null);
}, 1000); }, 1000);
} else if (this.folder_auto_timer) { } else if (this.folder_auto_timer) {
window.clearTimeout(this.folder_auto_timer); clearTimeout(this.folder_auto_timer);
this.folder_auto_timer = null; this.folder_auto_timer = null;
this.folder_auto_expand = null; this.folder_auto_expand = null;
} }
@ -1560,7 +1566,7 @@ function rcube_webmail()
// start timer for message preview (wait for double click) // start timer for message preview (wait for double click)
if (selected && this.env.contentframe && !list.multi_selecting && !this.dummy_select) if (selected && this.env.contentframe && !list.multi_selecting && !this.dummy_select)
this.preview_timer = window.setTimeout(function(){ ref.msglist_get_preview(); }, 200); this.preview_timer = setTimeout(function(){ ref.msglist_get_preview(); }, 200);
else if (this.env.contentframe) else if (this.env.contentframe)
this.show_contentframe(false); this.show_contentframe(false);
}; };
@ -1577,7 +1583,7 @@ function rcube_webmail()
clearTimeout(this.preview_timer); clearTimeout(this.preview_timer);
if (this.preview_read_timer) if (this.preview_read_timer)
clearTimeout(this.preview_read_timer); clearTimeout(this.preview_read_timer);
this.preview_timer = window.setTimeout(function(){ ref.msglist_get_preview(); }, 200); this.preview_timer = setTimeout(function(){ ref.msglist_get_preview(); }, 200);
} }
} }
}; };
@ -1963,7 +1969,7 @@ function rcube_webmail()
// mark as read and change mbox unread counter // mark as read and change mbox unread counter
if (action == 'preview' && this.message_list && this.message_list.rows[id] && this.message_list.rows[id].unread && this.env.preview_pane_mark_read >= 0) { if (action == 'preview' && this.message_list && this.message_list.rows[id] && this.message_list.rows[id].unread && this.env.preview_pane_mark_read >= 0) {
this.preview_read_timer = window.setTimeout(function() { this.preview_read_timer = setTimeout(function() {
ref.set_message(id, 'unread', false); ref.set_message(id, 'unread', false);
ref.update_thread_root(id, 'read'); ref.update_thread_root(id, 'read');
if (ref.env.unread_counts[ref.env.mailbox]) { if (ref.env.unread_counts[ref.env.mailbox]) {
@ -3152,7 +3158,7 @@ function rcube_webmail()
tinyMCE.execCommand('mceAddControl', false, props.id); tinyMCE.execCommand('mceAddControl', false, props.id);
if (this.env.default_font) if (this.env.default_font)
window.setTimeout(function() { setTimeout(function() {
$(tinyMCE.get(props.id).getBody()).css('font-family', rcmail.env.default_font); $(tinyMCE.get(props.id).getBody()).css('font-family', rcmail.env.default_font);
}, 500); }, 500);
} }
@ -3251,7 +3257,7 @@ function rcube_webmail()
this.auto_save_start = function() this.auto_save_start = function()
{ {
if (this.env.draft_autosave) if (this.env.draft_autosave)
this.save_timer = self.setTimeout(function(){ ref.command("savedraft"); }, this.env.draft_autosave * 1000); this.save_timer = setTimeout(function(){ ref.command("savedraft"); }, this.env.draft_autosave * 1000);
// Unlock interface now that saving is complete // Unlock interface now that saving is complete
this.busy = false; this.busy = false;
@ -3536,7 +3542,7 @@ function rcube_webmail()
this.upload_progress_start = function(action, name) this.upload_progress_start = function(action, name)
{ {
window.setTimeout(function() { rcmail.http_request(action, {_progress: name}); }, setTimeout(function() { rcmail.http_request(action, {_progress: name}); },
this.env.upload_progress_time * 1000); this.env.upload_progress_time * 1000);
}; };
@ -3641,7 +3647,7 @@ function rcube_webmail()
{ {
this.display_message(msg, type); this.display_message(msg, type);
// before redirect we need to wait some time for Chrome (#1486177) // before redirect we need to wait some time for Chrome (#1486177)
window.setTimeout(function(){ ref.list_mailbox(); }, 500); setTimeout(function(){ ref.list_mailbox(); }, 500);
}; };
@ -3699,11 +3705,11 @@ function rcube_webmail()
case 37: // left case 37: // left
case 39: // right case 39: // right
if (mod != SHIFT_KEY) if (mod != SHIFT_KEY)
return; return;
} }
// start timer // start timer
this.ksearch_timer = window.setTimeout(function(){ ref.ksearch_get_results(props); }, 200); this.ksearch_timer = setTimeout(function(){ ref.ksearch_get_results(props); }, 200);
this.ksearch_input = obj; this.ksearch_input = obj;
return true; return true;
@ -4011,7 +4017,7 @@ function rcube_webmail()
source = this.env.source ? this.env.address_sources[this.env.source] : null; source = this.env.source ? this.env.address_sources[this.env.source] : null;
if (id = list.get_single_selection()) if (id = list.get_single_selection())
this.preview_timer = window.setTimeout(function(){ ref.load_contact(id, 'show'); }, 200); this.preview_timer = setTimeout(function(){ ref.load_contact(id, 'show'); }, 200);
else if (this.env.contentframe) else if (this.env.contentframe)
this.show_contentframe(false); this.show_contentframe(false);
@ -5553,7 +5559,7 @@ function rcube_webmail()
} }
// add element and set timeout // add element and set timeout
this.messages[key].elements.push(id); this.messages[key].elements.push(id);
window.setTimeout(function() { ref.hide_message(id, type == 'loading'); }, timeout); setTimeout(function() { ref.hide_message(id, type == 'loading'); }, timeout);
return id; return id;
} }
@ -5573,7 +5579,7 @@ function rcube_webmail()
this.triggerEvent('message', { message:msg, type:type, timeout:timeout, object:obj }); this.triggerEvent('message', { message:msg, type:type, timeout:timeout, object:obj });
if (timeout > 0) if (timeout > 0)
window.setTimeout(function() { ref.hide_message(id, type == 'loading'); }, timeout); setTimeout(function() { ref.hide_message(id, type == 'loading'); }, timeout);
return id; return id;
}; };

Loading…
Cancel
Save