From 31d9efd97d9da09605d4329457ee218cba48f82f Mon Sep 17 00:00:00 2001 From: thomascube <thomas@roundcube.net> Date: Fri, 10 Aug 2007 04:51:41 -0400 Subject: [PATCH] Simplified code + removed debug log --- program/js/app.js | 107 ++++++++++++++++++++++++++++------------------------- 1 files changed, 56 insertions(+), 51 deletions(-) diff --git a/program/js/app.js b/program/js/app.js index 125e44f..78e2b1a 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -35,7 +35,7 @@ // webmail client settings this.dblclick_time = 500; - this.message_time = 5000; + this.message_time = 3000; this.identifier_expr = new RegExp('[^0-9a-z\-_]', 'gi'); @@ -343,9 +343,9 @@ var uid = row.uid; if (uid && this.env.messages[uid]) { - row.deleted = this.env.messages[uid].deleted; - row.unread = this.env.messages[uid].unread; - row.replied = this.env.messages[uid].replied; + row.deleted = this.env.messages[uid].deleted ? true : false; + row.unread = this.env.messages[uid].unread ? true : false; + row.replied = this.env.messages[uid].replied ? true : false; } // set eventhandler to message icon @@ -463,7 +463,7 @@ break; case 'logout': - this.goto_url('logout'); + this.goto_url('logout', true); break; // commands to switch task @@ -694,7 +694,7 @@ } } - this.goto_url('get', qstring+'&_download=1'); + this.goto_url('get', qstring+'&_download=1', false); break; case 'select-all': @@ -968,7 +968,7 @@ this.display_message(msg, 'loading', true); } - else if (!a && this.busy) + else if (!a) this.hide_message(); this.busy = a; @@ -1063,7 +1063,9 @@ this.unfocus_folder(id); this.command('moveto', id); } - + + // Hide message command buttons until a message is selected + this.enable_command('reply', 'reply-all', 'forward', 'delete', 'print', false); return false; }; @@ -1088,15 +1090,16 @@ clearTimeout(this.preview_timer); var selected = list.selection.length==1; + + // Hide certain command buttons when Drafts folder is selected if (this.env.mailbox == this.env.drafts_mailbox) { - this.enable_command('show', selected); - this.enable_command('delete', 'moveto', list.selection.length>0 ? true : false); + this.enable_command('reply', 'reply-all', 'forward', false); + this.enable_command('show', 'delete', 'moveto', selected); } else { - this.enable_command('show', 'reply', 'reply-all', 'forward', 'print', selected); - this.enable_command('delete', 'moveto', list.selection.length>0 ? true : false); + this.enable_command('show', 'reply', 'reply-all', 'forward', 'print', 'delete', 'moveto', selected); } // start timer for message preview (wait for double click) @@ -1244,12 +1247,14 @@ if (!page && mbox != this.env.mailbox) { page = 1; - add_url += '&_refresh=1'; this.env.current_page = page; if (this.message_list) this.message_list.clear_selection(); this.show_contentframe(false); } + + if (mbox != this.env.mailbox || (mbox == this.env.mailbox && !page && !sort)) + add_url += '&_refresh=1'; this.select_folder(mbox, this.env.mailbox); this.env.mailbox = mbox; @@ -1304,7 +1309,7 @@ // send request to server var url = '_mbox='+urlencode(mbox); - this.http_request('expunge', url+add_url, lock); + this.http_post('expunge', url+add_url, lock); }; @@ -1326,7 +1331,7 @@ // send request to server var url = '_mbox='+urlencode(mbox); - this.http_request('purge', url+add_url, lock); + this.http_post('purge', url+add_url, lock); return true; }; @@ -1432,7 +1437,7 @@ add_url += '&_search='+this.env.search_request; // send request to server - this.http_request(action, '_uid='+a_uids.join(',')+'&_mbox='+urlencode(this.env.mailbox)+add_url, lock); + this.http_post(action, '_uid='+a_uids.join(',')+'&_mbox='+urlencode(this.env.mailbox)+add_url, lock); }; @@ -1511,7 +1516,7 @@ } } - this.http_request('mark', '_uid='+a_uids.join(',')+'&_flag='+flag); + this.http_post('mark', '_uid='+a_uids.join(',')+'&_flag='+flag); }; // mark all message rows as deleted/undeleted @@ -1588,7 +1593,7 @@ } } - this.http_request('mark', '_uid='+a_uids.join(',')+'&_flag=undelete'); + this.http_post('mark', '_uid='+a_uids.join(',')+'&_flag=undelete'); return true; }; @@ -1615,7 +1620,7 @@ } } - this.http_request('mark', '_uid='+a_uids.join(',')+'&_flag=delete'); + this.http_post('mark', '_uid='+a_uids.join(',')+'&_flag=delete'); return true; }; @@ -1678,13 +1683,10 @@ } // check for empty body - if ((input_message.value=='')&&(tinyMCE.getContent()=='')) + if ((input_message.value == '' || (window.tinyMCE && tinyMCE.getContent() == '')) && !confirm(this.get_label('nobodywarning'))) { - if (!confirm(this.get_label('nobodywarning'))) - { - input_message.focus(); - return false; - } + input_message.focus(); + return false; } return true; @@ -1709,6 +1711,9 @@ { if (this.env.draft_autosave) this.save_timer = self.setTimeout(function(){ ref.command("savedraft"); }, this.env.draft_autosave * 1000); + + // Unlock interface now that saving is complete + this.busy = false; }; @@ -1926,7 +1931,7 @@ this.remove_attachment = function(name) { if (name) - this.http_request('remove-attachment', '_file='+urlencode(name)); + this.http_post('remove-attachment', '_file='+urlencode(name)); return true; }; @@ -2356,7 +2361,7 @@ } // send request to server - this.http_request('delete', '_cid='+urlencode(a_cids.join(','))+'&_from='+(this.env.action ? this.env.action : '')); + this.http_post('delete', '_cid='+urlencode(a_cids.join(','))+'&_from='+(this.env.action ? this.env.action : '')); return true; }; @@ -2440,7 +2445,7 @@ name = form.elements['_folder_name'].value; if (name) - this.http_request('create-folder', '_name='+urlencode(name), true); + this.http_post('create-folder', '_name='+urlencode(name), true); else if (form.elements['_folder_name']) form.elements['_folder_name'].focus(); }; @@ -2463,7 +2468,7 @@ } if (oldname && newname) - this.http_request('rename-folder', '_folder_oldname='+urlencode(oldname)+'&_folder_newname='+urlencode(newname)); + this.http_post('rename-folder', '_folder_oldname='+urlencode(oldname)+'&_folder_newname='+urlencode(newname)); }; @@ -2520,7 +2525,7 @@ { var newname = this.name_input ? this.name_input.value : null; if (this.edit_folder && newname) - this.http_request('rename-folder', '_folder_oldname='+urlencode(this.env.subscriptionrows[this.edit_folder][0])+'&_folder_newname='+urlencode(newname)); + this.http_post('rename-folder', '_folder_oldname='+urlencode(this.env.subscriptionrows[this.edit_folder][0])+'&_folder_newname='+urlencode(newname)); } // escape else if (key==27) @@ -2535,7 +2540,7 @@ this.reset_folder_rename(); if (folder) - this.http_request('delete-folder', '_mboxes='+urlencode(folder)); + this.http_post('delete-folder', '_mboxes='+urlencode(folder)); }; @@ -2662,7 +2667,7 @@ if ((form = this.gui_objects.editform) && form.elements['_unsubscribed']) this.change_subscription('_unsubscribed', '_subscribed', 'subscribe'); else if (folder) - this.http_request('subscribe', '_mboxes='+urlencode(folder)); + this.http_post('subscribe', '_mboxes='+urlencode(folder)); }; @@ -2672,7 +2677,7 @@ if ((form = this.gui_objects.editform) && form.elements['_subscribed']) this.change_subscription('_subscribed', '_unsubscribed', 'unsubscribe'); else if (folder) - this.http_request('unsubscribe', '_mboxes='+urlencode(folder)); + this.http_post('unsubscribe', '_mboxes='+urlencode(folder)); }; @@ -2706,7 +2711,7 @@ list_to[index] = new Option(a_folders[n]); } - this.http_request(action, '_mboxes='+urlencode(a_folders.join(','))); + this.http_post(action, '_mboxes='+urlencode(a_folders.join(','))); } } @@ -2913,17 +2918,16 @@ // display a system message this.display_message = function(msg, type, hold) { - // pass command to parent window - if (this.env.framed && parent.rcmail ) - return parent.rcmail.display_message(msg, type, hold); - - this.set_busy(false); if (!this.loaded) // save message in order to display after page loaded { this.pending_message = new Array(msg, type); return true; } - + + // pass command to parent window + if (this.env.framed && parent.rcmail) + return parent.rcmail.display_message(msg, type, hold); + if (!this.gui_objects.message) return false; @@ -2934,12 +2938,12 @@ if (type) cont = '<div class="'+type+'">'+cont+'</div>'; - this.gui_objects.message._rcube = this; + var _rcube = this; this.gui_objects.message.innerHTML = cont; this.gui_objects.message.style.display = 'block'; - + if (type!='loading') - this.gui_objects.message.onmousedown = function(){ this._rcube.hide_message(); return true; }; + this.gui_objects.message.onmousedown = function(){ _rcube.hide_message(); return true; }; if (!hold) this.message_timer = setTimeout(function(){ ref.hide_message(); }, this.message_time); @@ -3186,9 +3190,11 @@ /********* remote request methods *********/ /********************************************************/ - this.redirect = function(url) + this.redirect = function(url, lock) { - this.set_busy(true); + if (lock || lock === null) + this.set_busy(true); + if (this.env.framed && window.parent) parent.location.href = url; else @@ -3197,11 +3203,8 @@ this.goto_url = function(action, query, lock) { - if (lock) - this.set_busy(true); - var querystring = query ? '&'+query : ''; - this.redirect(this.env.comm_path+'&_action='+action+querystring); + this.redirect(this.env.comm_path+'&_action='+action+querystring, lock); }; @@ -3492,12 +3495,13 @@ return false; } - var ref = this; + var _ref = this; this.url = url; this.busy = true; - this.xmlhttp.onreadystatechange = function(){ ref.xmlhttp_onreadystatechange(); }; + this.xmlhttp.onreadystatechange = function(){ _ref.xmlhttp_onreadystatechange(); }; this.xmlhttp.open('GET', url); + this.xmlhttp.setRequestHeader('X-RoundCube-Referer', bw.get_cookie('sessid')); this.xmlhttp.send(null); }; @@ -3531,6 +3535,7 @@ this.xmlhttp.onreadystatechange = function() { ref.xmlhttp_onreadystatechange(); }; this.xmlhttp.open('POST', url, true); this.xmlhttp.setRequestHeader('Content-Type', contentType); + this.xmlhttp.setRequestHeader('X-RoundCube-Referer', bw.get_cookie('sessid')); this.xmlhttp.send(req_body); }; -- Gitblit v1.9.1