From 2c200021fdf9b5d1c73e39e7c46e7db1e4152e91 Mon Sep 17 00:00:00 2001 From: alecpl <alec@alec.pl> Date: Mon, 15 Nov 2010 04:26:24 -0500 Subject: [PATCH] - Fix focused elements aren't unfocused when clicking on the list (#1487123) --- program/js/app.js | 313 +++++++++++++++++++++++++++++++-------------------- 1 files changed, 190 insertions(+), 123 deletions(-) diff --git a/program/js/app.js b/program/js/app.js index 558a8b8..7c38b14 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -37,7 +37,7 @@ // webmail client settings this.dblclick_time = 500; - this.message_time = 3000; + this.message_time = 1500; this.identifier_expr = new RegExp('[^0-9a-z\-_]', 'gi'); @@ -210,11 +210,9 @@ this.enable_command(this.env.message_commands, this.env.uid); this.enable_command('reply-list', this.env.list_post); - if (this.env.next_uid) { - this.enable_command('nextmessage', 'lastmessage', true); - } - if (this.env.prev_uid) { - this.enable_command('previousmessage', 'firstmessage', true); + if (this.env.action == 'show') { + this.http_request('pagenav', '_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox), + this.display_message('', 'loading')); } if (this.env.blockedobjects) { @@ -306,8 +304,18 @@ this.enable_command('group-create', this.env.address_sources[this.env.source].groups); } - if (this.env.cid) + if (this.env.cid) { this.enable_command('show', 'edit', true); + // register handlers for group assignment via checkboxes + if (this.gui_objects.editform) { + $('input.groupmember').change(function(){ + var cmd = this.checked ? 'group-addmembers' : 'group-delmembers'; + ref.http_post(cmd, '_cid='+urlencode(ref.env.cid) + + '&_source='+urlencode(ref.env.source) + + '&_gid='+urlencode(this.value)); + }); + } + } if ((this.env.action=='add' || this.env.action=='edit') && this.gui_objects.editform) { this.enable_command('save', true); @@ -1181,8 +1189,7 @@ clearTimeout(this.preview_read_timer); // save folderlist and folders location/sizes for droptarget calculation in drag_move() - if (this.gui_objects.folderlist && model) - { + if (this.gui_objects.folderlist && model) { this.initialBodyScrollTop = bw.ie ? 0 : window.pageYOffset; this.initialListScrollTop = this.gui_objects.folderlist.parentNode.scrollTop; @@ -1545,23 +1552,28 @@ this.init_message_row = function(row) { - var expando, self = this, uid = row.uid; + var expando, self = this, uid = row.uid, + status_icon = (this.env.status_col != null ? 'status' : 'msg') + 'icn' + row.uid; if (uid && this.env.messages[uid]) $.extend(row, this.env.messages[uid]); - row.msgicon = document.getElementById('msgicn'+row.uid); - - // set eventhandler to message status icon - if (row.icon = document.getElementById('statusicn'+row.uid)) { + // set eventhandler to status icon + if (row.icon = document.getElementById(status_icon)) { row.icon._row = row.obj; row.icon.onmousedown = function(e) { self.command('toggle_status', this); rcube_event.cancel(e); }; } + // save message icon position too + if (this.env.status_col != null) + row.msgicon = document.getElementById('msgicn'+row.uid); + else + row.msgicon = row.icon; + // set eventhandler to flag icon, if icon found - if (this.env.flagged_col != null && (row.flagged_icon = document.getElementById('flagicn'+row.uid))) { - row.flagged_icon._row = row.obj; - row.flagged_icon.onmousedown = function(e) { self.command('toggle_flag', this); rcube_event.cancel(e); }; + if (this.env.flagged_col != null && (row.flagicon = document.getElementById('flagicn'+row.uid))) { + row.flagicon._row = row.obj; + row.flagicon.onmousedown = function(e) { self.command('toggle_flag', this); rcube_event.cancel(e); }; } if (!row.depth && row.has_children && (expando = document.getElementById('rcmexpando'+row.uid))) { @@ -1622,8 +1634,15 @@ // message status icons css_class = 'msgicon'; - if (!flags.unread && flags.unread_children > 0) - css_class += ' unreadchildren'; + if (this.env.status_col === null) { + css_class += ' status'; + if (flags.deleted) + css_class += ' deleted'; + else if (flags.unread) + css_class += ' unread'; + else if (flags.unread_children > 0) + css_class += ' unreadchildren'; + } if (flags.replied) css_class += ' replied'; if (flags.forwarded) @@ -1694,6 +1713,8 @@ css_class = 'deleted'; else if (flags.unread) css_class = 'unread'; + else if (flags.unread_children > 0) + css_class = 'unreadchildren'; else css_class = 'msgicon'; html = '<span id="statusicn'+uid+'" class="'+css_class+'"> </span>'; @@ -1781,28 +1802,28 @@ if (!id) return; - var add_url = '', - target = window, - action = preview ? 'preview': 'show'; + var target = window, + action = preview ? 'preview': 'show', + url = '&_action='+action+'&_uid='+id+'&_mbox='+urlencode(this.env.mailbox); if (preview && this.env.contentframe && window.frames && window.frames[this.env.contentframe]) { target = window.frames[this.env.contentframe]; - add_url = '&_framed=1'; + url += '&_framed=1'; } if (safe) - add_url = '&_safe=1'; + url += '&_safe=1'; // also send search request to get the right messages if (this.env.search_request) - add_url += '&_search='+this.env.search_request; + url += '&_search='+this.env.search_request; - var url = '&_action='+action+'&_uid='+id+'&_mbox='+urlencode(this.env.mailbox)+add_url; if (action == 'preview' && String(target.location.href).indexOf(url) >= 0) this.show_contentframe(true); else { - if (!this.env.frame_lock) - this.env.frame_lock = this.set_busy(true, 'loading'); + if (!this.env.frame_lock) { + (parent.rcmail ? parent.rcmail : this).env.frame_lock = this.set_busy(true, 'loading'); + } target.location.href = this.env.comm_path+url; // mark as read and change mbox unread counter @@ -1815,7 +1836,7 @@ ref.set_unread_count(ref.env.mailbox, ref.env.unread_counts[ref.env.mailbox], ref.env.mailbox == 'INBOX'); } if (ref.env.preview_pane_mark_read > 0) - ref.http_post('mark', '_uid='+id+'&_flag=read'); + ref.http_post('mark', '_uid='+id+'&_flag=read&_quiet=1'); }, this.env.preview_pane_mark_read * 1000); } } @@ -1834,7 +1855,7 @@ } if (!show && this.busy) - this.set_busy(false); + this.set_busy(false, null, this.env.frame_lock); }; // list a specific page @@ -2220,84 +2241,94 @@ this.set_message_icon = function(uid) { var css_class, - rows = this.message_list.rows; + row = this.message_list.rows[uid]; - if (!rows[uid]) + if (!row) return false; - if (rows[uid].icon) { - if (rows[uid].deleted) - css_class = 'deleted'; - else if (rows[uid].unread) - css_class = 'unread'; - else - css_class = 'msgicon'; + if (row.icon) { + css_class = 'msgicon'; + if (row.deleted) + css_class += ' deleted'; + else if (row.unread) + css_class += ' unread'; + else if (row.unread_children) + css_class += ' unreadchildren'; + if (row.msgicon == row.icon) { + if (row.replied) + css_class += ' replied'; + if (row.forwarded) + css_class += ' forwarded'; + css_class += ' status'; + } - rows[uid].icon.className = css_class; + row.icon.className = css_class; } - if (rows[uid].msgicon) { + if (row.msgicon && row.msgicon != row.icon) { css_class = 'msgicon'; - if (!rows[uid].unread && rows[uid].unread_children) + if (!row.unread && row.unread_children) css_class += ' unreadchildren'; - if (rows[uid].replied) + if (row.replied) css_class += ' replied'; - if (rows[uid].forwarded) + if (row.forwarded) css_class += ' forwarded'; - rows[uid].msgicon.className = css_class; + row.msgicon.className = css_class; } - if (rows[uid].flagged_icon) { - css_class = (rows[uid].flagged ? 'flagged' : 'unflagged'); - rows[uid].flagged_icon.className = css_class; + if (row.flagicon) { + css_class = (row.flagged ? 'flagged' : 'unflagged'); + row.flagicon.className = css_class; } }; // set message status this.set_message_status = function(uid, flag, status) { - var rows = this.message_list.rows; + var row = this.message_list.rows[uid]; - if (!rows[uid]) return false; + if (!row) + return false; if (flag == 'unread') - rows[uid].unread = status; + row.unread = status; else if(flag == 'deleted') - rows[uid].deleted = status; + row.deleted = status; else if (flag == 'replied') - rows[uid].replied = status; + row.replied = status; else if (flag == 'forwarded') - rows[uid].forwarded = status; + row.forwarded = status; else if (flag == 'flagged') - rows[uid].flagged = status; + row.flagged = status; }; // set message row status, class and icon this.set_message = function(uid, flag, status) { - var rows = this.message_list.rows; + var row = this.message_list.rows[uid]; - if (!rows[uid]) return false; + if (!row) + return false; if (flag) this.set_message_status(uid, flag, status); - var rowobj = $(rows[uid].obj); + var rowobj = $(row.obj); - if (rows[uid].unread && !rowobj.hasClass('unread')) + if (row.unread && !rowobj.hasClass('unread')) rowobj.addClass('unread'); - else if (!rows[uid].unread && rowobj.hasClass('unread')) + else if (!row.unread && rowobj.hasClass('unread')) rowobj.removeClass('unread'); - if (rows[uid].deleted && !rowobj.hasClass('deleted')) + if (row.deleted && !rowobj.hasClass('deleted')) rowobj.addClass('deleted'); - else if (!rows[uid].deleted && rowobj.hasClass('deleted')) + else if (!row.deleted && rowobj.hasClass('deleted')) rowobj.removeClass('deleted'); - if (rows[uid].flagged && !rowobj.hasClass('flagged')) + if (row.flagged && !rowobj.hasClass('flagged')) rowobj.addClass('flagged'); - else if (!rows[uid].flagged && rowobj.hasClass('flagged')) + else if (!row.flagged && rowobj.hasClass('flagged')) rowobj.removeClass('flagged'); this.set_unread_children(uid); @@ -2329,6 +2360,7 @@ return; var a_uids = [], + lock = this.display_message(this.get_label('copyingmessage'), 'loading'), add_url = '&_target_mbox='+urlencode(mbox)+'&_from='+(this.env.action ? this.env.action : ''); if (this.env.uid) @@ -2341,7 +2373,7 @@ } // send request to server - this.http_post('copy', '_uid='+a_uids.join(',')+'&_mbox='+urlencode(this.env.mailbox)+add_url, false); + this.http_post('copy', '_uid='+a_uids.join(',')+'&_mbox='+urlencode(this.env.mailbox)+add_url, lock); }; // move selected messages to the specified mailbox @@ -2392,7 +2424,7 @@ return false; } // if there isn't a defined trash mailbox or we are in it - else if (!this.env.trash_mailbox || this.env.mailbox == this.env.trash_mailbox) + else if (!this.env.trash_mailbox || this.env.mailbox == this.env.trash_mailbox) this.permanently_remove_messages(); // if there is a trash mailbox defined and we're not currently in it else { @@ -2423,7 +2455,7 @@ // @private this._with_selected_messages = function(action, lock, add_url) { - var a_uids = [], count = 0; + var a_uids = [], count = 0, msg; if (this.env.uid) a_uids[0] = this.env.uid; @@ -2453,7 +2485,7 @@ } } - // also send search request to get the right messages + // also send search request to get the right messages if (this.env.search_request) add_url += '&_search='+this.env.search_request; @@ -2467,6 +2499,11 @@ this.delete_excessive_thread_rows(); add_url += '&_uid='+this.uids_to_list(a_uids); + + if (!lock) { + msg = action == 'moveto' ? 'movingmessage' : 'deletingmessage'; + lock = this.display_message(this.get_label(msg), 'loading'); + } // send request to server this.http_post(action, '_mbox='+urlencode(this.env.mailbox)+add_url, lock); @@ -2531,13 +2568,14 @@ for (var i=0; i<a_uids.length; i++) this.set_message(a_uids[i], 'unread', (flag=='unread' ? true : false)); - var url = '_uid='+this.uids_to_list(a_uids)+'&_flag='+flag; + var url = '_uid='+this.uids_to_list(a_uids)+'&_flag='+flag, + lock = this.display_message(this.get_label('markingmessage'), 'loading'); // also send search request to get the right messages if (this.env.search_request) url += '&_search='+this.env.search_request; - this.http_post('mark', url); + this.http_post('mark', url, lock); for (var i=0; i<a_uids.length; i++) this.update_thread_root(a_uids[i], flag); @@ -2550,13 +2588,14 @@ for (var i=0; i<a_uids.length; i++) this.set_message(a_uids[i], 'flagged', (flag=='flagged' ? true : false)); - var url = '_uid='+this.uids_to_list(a_uids)+'&_flag='+flag; + var url = '_uid='+this.uids_to_list(a_uids)+'&_flag='+flag, + lock = this.display_message(this.get_label('markingmessage'), 'loading'); // also send search request to get the right messages if (this.env.search_request) url += '&_search='+this.env.search_request; - this.http_post('mark', url); + this.http_post('mark', url, lock); }; // mark all message rows as deleted/undeleted @@ -2595,13 +2634,14 @@ for (var i=0, len=a_uids.length; i<len; i++) this.set_message(a_uids[i], 'deleted', false); - var url = '_uid='+this.uids_to_list(a_uids)+'&_flag=undelete'; + var url = '_uid='+this.uids_to_list(a_uids)+'&_flag=undelete', + lock = this.display_message(this.get_label('markingmessage'), 'loading'); // also send search request to get the right messages if (this.env.search_request) url += '&_search='+this.env.search_request; - this.http_post('mark', url); + this.http_post('mark', url, lock); return true; }; @@ -2638,7 +2678,8 @@ this.delete_excessive_thread_rows(); } - add_url = '&_from='+(this.env.action ? this.env.action : ''); + add_url = '&_from='+(this.env.action ? this.env.action : ''), + lock = this.display_message(this.get_label('markingmessage'), 'loading'); // ?? if (r_uids.length) @@ -2653,8 +2694,8 @@ if (this.env.search_request) add_url += '&_search='+this.env.search_request; - this.http_post('mark', '_uid='+this.uids_to_list(a_uids)+'&_flag=delete'+add_url); - return true; + this.http_post('mark', '_uid='+this.uids_to_list(a_uids)+'&_flag=delete'+add_url, lock); + return true; }; // flag as read without mark request (called from backend) @@ -2760,17 +2801,18 @@ if (!this.gui_objects.messageform) return false; - //this.messageform = this.gui_objects.messageform; - var input_from = $("[name='_from']"); - var input_to = $("[name='_to']"); - var input_subject = $("input[name='_subject']"); - var input_message = $("[name='_message']").get(0); - var html_mode = $("input[name='_is_html']").val() == '1'; + var input_from = $("[name='_from']"), + input_to = $("[name='_to']"), + input_subject = $("input[name='_subject']"), + input_message = $("[name='_message']").get(0), + html_mode = $("input[name='_is_html']").val() == '1', + ac_fields = ['cc', 'bcc', 'replyto', 'mailreplyto', 'mailfollowupto']; // init live search events this.init_address_input_events(input_to); - this.init_address_input_events($("[name='_cc']")); - this.init_address_input_events($("[name='_bcc']")); + for (var i in ac_fields) { + this.init_address_input_events($("[name='_"+ac_fields[i]+"']")); + } if (!html_mode) { this.set_caret_pos(input_message, this.env.top_posting ? 0 : $(input_message).val().length); @@ -3335,10 +3377,10 @@ return rcube_event.cancel(e); case 9: // tab - if(mod == SHIFT_KEY) + if (mod == SHIFT_KEY) break; - case 13: // enter + case 13: // enter if (this.ksearch_selected===null || !this.ksearch_input || !this.ksearch_value) break; @@ -3384,14 +3426,14 @@ return; // get cursor pos - var inp_value = this.ksearch_input.value; - var cpos = this.get_caret_pos(this.ksearch_input); - var p = inp_value.lastIndexOf(this.ksearch_value, cpos); + var inp_value = this.ksearch_input.value, + cpos = this.get_caret_pos(this.ksearch_input), + p = inp_value.lastIndexOf(this.ksearch_value, cpos), + insert = '', - // replace search string with full address - var pre = this.ksearch_input.value.substring(0, p); - var end = this.ksearch_input.value.substring(p+this.ksearch_value.length, this.ksearch_input.value.length); - var insert = ''; + // replace search string with full address + pre = inp_value.substring(0, p), + end = inp_value.substring(p+this.ksearch_value.length, inp_value.length); // insert all members of a group if (typeof this.env.contacts[id] == 'object' && this.env.contacts[id].id) { @@ -3423,6 +3465,7 @@ this.ksearch_get_results = function() { var inp_value = this.ksearch_input ? this.ksearch_input.value : null; + if (inp_value === null) return; @@ -3430,16 +3473,29 @@ this.ksearch_pane.hide(); // get string from current cursor pos to last comma - var cpos = this.get_caret_pos(this.ksearch_input); - var p = inp_value.lastIndexOf(',', cpos-1); - var q = inp_value.substring(p+1, cpos); + var cpos = this.get_caret_pos(this.ksearch_input), + p = inp_value.lastIndexOf(',', cpos-1), + q = inp_value.substring(p+1, cpos), + min = this.env.autocomplete_min_length; // trim query string - q = q.replace(/(^\s+|\s+$)/g, ''); + q = $.trim(q); // Don't (re-)search if the last results are still active if (q == this.ksearch_value) return; + + if (q.length < min) { + if (!this.env.acinfo) { + var label = this.get_label('autocompletechars'); + label = label.replace('$min', min); + this.env.acinfo = this.display_message(label); + } + return; + } + else if (this.env.acinfo && q.length == min) { + this.hide_message(this.env.acinfo); + } var old_value = this.ksearch_value; this.ksearch_value = q; @@ -3689,7 +3745,7 @@ { // exit if no mailbox specified or if selection is empty var selection = this.contact_list.get_selection(); - if (!(selection.length || this.env.cid) || (!this.env.group && !confirm(this.get_label('deletecontactconfirm')))) + if (!(selection.length || this.env.cid) || !confirm(this.get_label('deletecontactconfirm'))) return; var id, a_cids = [], qs = ''; @@ -3713,10 +3769,7 @@ qs += '&_search='+this.env.search_request; // send request to server - if (this.env.group) - this.http_post('group-delmembers', '_cid='+urlencode(a_cids.join(','))+'&_source='+urlencode(this.env.source)+'&_gid='+urlencode(this.env.group)+qs); - else - this.http_post('delete', '_cid='+urlencode(a_cids.join(','))+'&_source='+urlencode(this.env.source)+'&_from='+(this.env.action ? this.env.action : '')+qs); + this.http_post('delete', '_cid='+urlencode(a_cids.join(','))+'&_source='+urlencode(this.env.source)+'&_from='+(this.env.action ? this.env.action : '')+qs); return true; }; @@ -4003,7 +4056,8 @@ this.focus_subscription = function(id) { var row, folder, - reg = RegExp('['+RegExp.escape(this.env.delimiter)+']?[^'+RegExp.escape(this.env.delimiter)+']+$'); + delim = RegExp.escape(this.env.delimiter), + reg = RegExp('['+delim+']?[^'+delim+']+$'); if (this.drag_active && this.env.folder && (row = document.getElementById(id))) if (this.env.subscriptionrows[id] && @@ -4016,7 +4070,7 @@ $(row).addClass('droptarget'); } } - else if (this.env.folder.match(new RegExp(RegExp.escape(this.env.delimiter)))) { + else if (this.env.folder.match(new RegExp(delim))) { this.set_env('dstfolder', this.env.delimiter); $(this.subscription_list.frame).addClass('droptarget'); } @@ -4049,10 +4103,12 @@ this.subscription_move_folder = function(list) { - var reg = RegExp('['+RegExp.escape(this.env.delimiter)+']?[^'+RegExp.escape(this.env.delimiter)+']+$'); + var delim = RegExp.escape(this.env.delimiter), + reg = RegExp('['+delim+']?[^'+delim+']+$'); + if (this.env.folder && this.env.dstfolder && (this.env.dstfolder != this.env.folder) && (this.env.dstfolder != this.env.folder.replace(reg, ''))) { - var reg = new RegExp('[^'+RegExp.escape(this.env.delimiter)+']*['+RegExp.escape(this.env.delimiter)+']', 'g'); + var reg = new RegExp('[^'+delim+']*['+delim+']', 'g'); var basename = this.env.folder.replace(reg, ''); var newname = this.env.dstfolder==this.env.delimiter ? basename : this.env.dstfolder+this.env.delimiter+basename; @@ -4102,12 +4158,14 @@ } if (id && this.env.subscriptionrows[id] && (row = document.getElementById(id))) { - var reg = new RegExp('.*['+RegExp.escape(this.env.delimiter)+']'); + var delim = RegExp.escape(this.env.delimiter), + reg = new RegExp('.*['+delim+']'); + this.name_input = document.createElement('input'); this.name_input.type = 'text'; this.name_input.value = this.env.subscriptionrows[id][0].replace(reg, ''); - reg = new RegExp('['+RegExp.escape(this.env.delimiter)+']?[^'+RegExp.escape(this.env.delimiter)+']+$'); + reg = new RegExp('['+delim+']?[^'+delim+']+$'); this.name_input.__parent = this.env.subscriptionrows[id][0].replace(reg, ''); this.name_input.onkeydown = function(e){ rcmail.name_input_keydown(e); }; @@ -4555,10 +4613,15 @@ var date = new Date(), id = type + date.getTime(); - // The same message of type 'loading' is already displayed - if (type == 'loading' && this.messages[msg]) { - this.messages[msg].elements.push(id); - return id; + if (type == 'loading') { + if (!msg) + msg = this.get_label('loading'); + + // The same message of type 'loading' is already displayed + if (this.messages[msg]) { + this.messages[msg].elements.push(id); + return id; + } } var ref = this, @@ -4572,8 +4635,9 @@ return id; } else { - obj.appendTo(cont).bind('mousedown', function(){ return ref.hide_message(obj); }); - window.setTimeout(function(){ ref.hide_message(obj, true); }, this.message_time); + obj.appendTo(cont).bind('mousedown', function() { return ref.hide_message(obj); }); + window.setTimeout(function() { ref.hide_message(obj, true); }, + this.message_time * (type == 'error' ? 2 : 1)); return obj; } }; @@ -4591,14 +4655,14 @@ } else { // 'loading' message - var k, n; - for (k in this.messages) { - for (n in this.messages[k].elements) { - if (this.messages[k].elements[n] == obj) { - this.messages[k].elements.splice(n, 1); - if (!this.messages[k].elements.length) { - this.messages[k].obj[fade?'fadeOut':'hide'](); - delete this.messages[k]; + var k, n, m = this.messages; + for (k in m) { + for (n in m[k].elements) { + if (m[k] && m[k].elements[n] == obj) { + m[k].elements.splice(n, 1); + if (!m[k].elements.length) { + m[k].obj[fade?'fadeOut':'hide'](); + delete m[k]; } } } @@ -4681,6 +4745,7 @@ this.env.subject_col = null; this.env.flagged_col = null; + this.env.status_col = null; if ((n = $.inArray('subject', this.env.coltypes)) >= 0) { this.set_env('subject_col', n); @@ -4689,6 +4754,8 @@ } if ((n = $.inArray('flag', this.env.coltypes)) >= 0) this.set_env('flagged_col', n); + if ((n = $.inArray('status', this.env.coltypes)) >= 0) + this.set_env('status_col', n); this.message_list.init_header(); }; -- Gitblit v1.9.1