diff options
Diffstat (limited to 'program/js/app.js')
-rw-r--r-- | program/js/app.js | 140 |
1 files changed, 96 insertions, 44 deletions
diff --git a/program/js/app.js b/program/js/app.js index 29a53bb26..e818955bd 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -326,10 +326,7 @@ function rcube_webmail() this.enable_command('download', 'print', true); // show printing dialog else if (this.env.action == 'print' && this.env.uid) { - if (bw.safari) - setTimeout('window.print()', 10); - else - window.print(); + this.print_dialog(); } // get unread count for each mailbox @@ -440,6 +437,9 @@ function rcube_webmail() if (this.env.action == 'add' || this.env.action == 'edit' || this.env.action == 'search') this.init_contact_form(); } + else if (this.env.action == 'print') { + this.print_dialog(); + } break; @@ -1055,12 +1055,9 @@ function rcube_webmail() url = {}; if (this.task == 'mail') { - url._mbox = this.env.mailbox; + url = {_mbox: this.env.mailbox, _search: this.env.search_request}; if (props) url._to = props; - // also send search request so we can go back to search result after message is sent - if (this.env.search_request) - url._search = this.env.search_request; } // modify url if we're in addressbook else if (this.task == 'addressbook') { @@ -1155,7 +1152,7 @@ function rcube_webmail() case 'reply-list': case 'reply': if (uid = this.get_single_uid()) { - url = {_reply_uid: uid, _mbox: this.get_message_mailbox(uid)}; + url = {_reply_uid: uid, _mbox: this.get_message_mailbox(uid), _search: this.env.search_request}; if (command == 'reply-all') // do reply-list, when list is detected and popup menu wasn't used url._all = (!props && this.env.reply_all_mode == 1 && this.commands['reply-list'] ? 'list' : 'all'); @@ -1179,7 +1176,15 @@ function rcube_webmail() break; case 'print': - if (this.env.action == 'get') { + if (this.task == 'addressbook') { + if (uid = this.contact_list.get_single_selection()) { + url = '&_action=print&_cid=' + uid; + if (this.env.source) + url += '&_source=' + urlencode(this.env.source); + this.open_window(this.env.comm_path + url, true, true); + } + } + else if (this.env.action == 'get') { this.gui_objects.messagepartframe.contentWindow.print(); } else if (uid = this.get_single_uid()) { @@ -1957,7 +1962,7 @@ function rcube_webmail() // attach events $.each(fn, function(i, f) { row[i].onclick = function(e) { f(e); return rcube_event.cancel(e); }; - if (bw.touch) { + if (bw.touch && row[i].addEventListener) { row[i].addEventListener('touchend', function(e) { if (e.changedTouches.length == 1) { f(e); @@ -2487,6 +2492,16 @@ function rcube_webmail() selection.push(selected[i]); this.message_list.selection = selection; + + // reset preview frame, if currently previewed message is not selected (has been removed) + try { + var win = this.get_frame_window(this.env.contentframe), + id = win.rcmail.env.uid; + + if (id && $.inArray(id, selection) < 0) + this.show_contentframe(false); + } + catch (e) {}; }; // expand all threads with unread children @@ -3781,14 +3796,13 @@ function rcube_webmail() this.set_draft_id = function(id) { - var rc; - if (id && id != this.env.draft_id) { - if (rc = this.opener()) { - // refresh the drafts folder in opener window - if (rc.env.task == 'mail' && rc.env.action == '' && rc.env.mailbox == this.env.drafts_mailbox) - rc.command('checkmail'); - } + var filter = {task: 'mail', action: ''}, + rc = this.opener(false, filter) || this.opener(true, filter); + + // refresh the drafts folder in the opener window + if (rc && rc.env.mailbox == this.env.drafts_mailbox) + rc.command('checkmail'); this.env.draft_id = id; $("input[name='_draft_saveid']").val(id); @@ -3975,7 +3989,6 @@ function rcube_webmail() this.local_storage_remove_item('compose.index'); }; - this.change_identity = function(obj, show_sig) { if (!obj || !obj.options) @@ -4344,6 +4357,7 @@ function rcube_webmail() (this.env.search_request && (this.env.search_scope || 'base') != 'base'); }; + // action executed after mail is sent this.sent_successfully = function(type, msg, folders) { this.display_message(msg, type); @@ -4352,11 +4366,13 @@ function rcube_webmail() if (this.env.extwin) { this.lock_form(this.gui_objects.messageform); - var rc = this.opener(); + var filter = {task: 'mail', action: ''}, + rc = this.opener(false, filter) || this.opener(true, filter); + if (rc) { rc.display_message(msg, type); // refresh the folder where sent message was saved or replied message comes from - if (folders && rc.env.task == 'mail' && rc.env.action == '' && $.inArray(rc.env.mailbox, folders) >= 0) { + if (folders && $.inArray(rc.env.mailbox, folders) >= 0) { rc.command('checkmail'); } } @@ -4713,6 +4729,7 @@ function rcube_webmail() clearTimeout(this.preview_timer); var n, id, sid, contact, writable = false, + selected = list.selection.length, source = this.env.source ? this.env.address_sources[this.env.source] : null; // we don't have dblclick handler here, so use 200 instead of this.dblclick_time @@ -4721,7 +4738,7 @@ function rcube_webmail() else if (this.env.contentframe) this.show_contentframe(false); - if (list.selection.length) { + if (selected) { list.draggable = false; // no source = search result, we'll need to detect if any of @@ -4756,11 +4773,12 @@ function rcube_webmail() // if a group is currently selected, and there is at least one contact selected // thend we can enable the group-remove-selected command - this.enable_command('group-remove-selected', this.env.group && list.selection.length > 0 && writable); - this.enable_command('compose', this.env.group || list.selection.length > 0); - this.enable_command('export-selected', 'copy', list.selection.length > 0); + this.enable_command('group-remove-selected', this.env.group && selected && writable); + this.enable_command('compose', this.env.group || selected); + this.enable_command('print', selected == 1); + this.enable_command('export-selected', 'copy', selected > 0); this.enable_command('edit', id && writable); - this.enable_command('delete', 'move', list.selection.length > 0 && writable); + this.enable_command('delete', 'move', selected && writable); return false; }; @@ -4774,6 +4792,9 @@ function rcube_webmail() if (!src) src = this.env.source; + if (refresh) + group = this.env.group; + if (page && this.current_page == page && src == this.env.source && group == this.env.group) return false; @@ -4870,8 +4891,8 @@ function rcube_webmail() this.contact_list.data = {}; this.contact_list.clear(true); this.show_contentframe(false); - this.enable_command('delete', 'move', 'copy', false); - this.enable_command('compose', this.env.group ? true : false); + this.enable_command('delete', 'move', 'copy', 'print', false); + this.enable_command('compose', this.env.group); }; this.set_group_prop = function(prop) @@ -4911,7 +4932,7 @@ function rcube_webmail() this.contact_list.clear_selection(); this.enable_command('compose', rec && rec.email); - this.enable_command('export-selected', rec && rec._type != 'group'); + this.enable_command('export-selected', 'print', rec && rec._type != 'group'); } else if (framed) return false; @@ -5162,10 +5183,10 @@ function rcube_webmail() dateFormat: this.env.date_format, changeMonth: true, changeYear: true, - yearRange: '-100:+10', + yearRange: '-120:+10', showOtherMonths: true, - selectOtherMonths: true, - onSelect: function(dateText) { $(this).focus().val(dateText) } + selectOtherMonths: true +// onSelect: function(dateText) { $(this).focus().val(dateText); } }); $('input.datepicker').datepicker(); } @@ -5796,6 +5817,9 @@ function rcube_webmail() // on the list when dragging starts (and stops), this is slow, but // I didn't find a method to check droptarget on over event accept: function(node) { + if (!$(node).is('.mailbox')) + return false; + var source_folder = ref.folder_id2name($(node).attr('id')), dest_folder = ref.folder_id2name(this.id), source = ref.env.subscriptionrows[source_folder], @@ -5816,7 +5840,7 @@ function rcube_webmail() this.folder_id2name = function(id) { - return ref.html_identifier_decode(id.replace(/^rcmli/, '')); + return id ? ref.html_identifier_decode(id.replace(/^rcmli/, '')) : null; }; this.subscription_select = function(id) @@ -6724,7 +6748,7 @@ function rcube_webmail() this.set_quota = function(content) { if (this.gui_objects.quotadisplay && content && content.type == 'text') - $(this.gui_objects.quotadisplay).html(content.percent+'%').attr('title', content.title); + $(this.gui_objects.quotadisplay).text((content.percent||0) + '%').attr('title', content.title); this.triggerEvent('setquota', content); this.env.quota_content = content; @@ -7351,7 +7375,7 @@ function rcube_webmail() this.enable_command('compose', (uid && this.contact_list.rows[uid])); this.enable_command('delete', 'edit', writable); this.enable_command('export', (this.contact_list && this.contact_list.rowcount > 0)); - this.enable_command('export-selected', false); + this.enable_command('export-selected', 'print', false); } case 'move': @@ -7891,12 +7915,24 @@ function rcube_webmail() }; // get window.opener.rcmail if available - this.opener = function() + this.opener = function(deep, filter) { + var i, win = window.opener; + // catch Error: Permission denied to access property rcmail try { - if (window.opener && !opener.closed && opener.rcmail) - return opener.rcmail; + if (win && !win.closed) { + // try parent of the opener window, e.g. preview frame + if (deep && (!win.rcmail || win.rcmail.env.framed) && win.parent && win.parent.rcmail) + win = win.parent; + + if (win.rcmail && filter) + for (i in filter) + if (win.rcmail.env[i] != filter[i]) + return; + + return win.rcmail; + } } catch (e) {} }; @@ -8063,7 +8099,7 @@ function rcube_webmail() if (plugin && plugin.enabledPlugin) return 1; - if (window.ActiveXObject) { + if ('ActiveXObject' in window) { try { if (plugin = new ActiveXObject("AcroPDF.PDF")) return 1; @@ -8096,7 +8132,7 @@ function rcube_webmail() if (plugin && plugin.enabledPlugin) return 1; - if (window.ActiveXObject) { + if ('ActiveXObject' in window) { try { if (plugin = new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) return 1; @@ -8133,15 +8169,16 @@ function rcube_webmail() // wrapper for localStorage.getItem(key) this.local_storage_get_item = function(key, deflt, encrypted) { - var item; + var item, result; // TODO: add encryption try { item = localStorage.getItem(this.get_local_storage_prefix() + key); + result = JSON.parse(item); } catch (e) { } - return item !== null ? JSON.parse(item) : (deflt || null); + return result || deflt || null; }; // wrapper for localStorage.setItem(key, data) @@ -8171,6 +8208,14 @@ function rcube_webmail() return false; } }; + + this.print_dialog = function() + { + if (bw.safari) + setTimeout('window.print()', 10); + else + window.print(); + }; } // end object rcube_webmail @@ -8180,7 +8225,7 @@ rcube_webmail.long_subject_title = function(elem, indent) if (!elem.title) { var $elem = $(elem); if ($elem.width() + (indent || 0) * 15 > $elem.parent().width()) - elem.title = $elem.text(); + elem.title = rcube_webmail.subject_text(elem); } }; @@ -8197,10 +8242,17 @@ rcube_webmail.long_subject_title_ex = function(elem) tmp.remove(); if (w + $('span.branch', $elem).width() * 15 > $elem.width()) - elem.title = txt; + elem.title = rcube_webmail.subject_text(elem); } }; +rcube_webmail.subject_text = function(elem) +{ + var t = $(elem).clone(); + t.find('.skip-on-drag').remove(); + return t.text(); +}; + rcube_webmail.prototype.get_cookie = getCookie; // copy event engine prototype |