From 8fa9229d578a9c2f265b4e46278c3f5f4329baae Mon Sep 17 00:00:00 2001 From: alecpl Date: Fri, 16 Apr 2010 13:46:54 +0000 Subject: - code formatting, cleanup and small improvements --- program/js/app.js | 1448 ++++++++++++++++++++++++-------------------------- program/js/common.js | 138 ++--- program/js/list.js | 222 ++++---- 3 files changed, 833 insertions(+), 975 deletions(-) diff --git a/program/js/app.js b/program/js/app.js index bc0962b29..1366d800a 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -20,31 +20,30 @@ function rcube_webmail() { - this.env = new Object(); - this.labels = new Object(); - this.buttons = new Object(); - this.buttons_sel = new Object(); - this.gui_objects = new Object(); - this.gui_containers = new Object(); - this.commands = new Object(); - this.command_handlers = new Object(); - this.onloads = new Array(); + this.env = {}; + this.labels = {}; + this.buttons = {}; + this.buttons_sel = {}; + this.gui_objects = {}; + this.gui_containers = {}; + this.commands = {}; + this.command_handlers = {}; + this.onloads = []; // create protected reference to myself this.ref = 'rcmail'; var ref = this; - + // webmail client settings this.dblclick_time = 500; this.message_time = 3000; - + this.identifier_expr = new RegExp('[^0-9a-z\-_]', 'gi'); - + // mimetypes supported by the browser (default settings) this.mimetypes = new Array('text/plain', 'text/html', 'text/xml', - 'image/jpeg', 'image/gif', 'image/png', - 'application/x-javascript', 'application/pdf', - 'application/x-shockwave-flash'); + 'image/jpeg', 'image/gif', 'image/png', + 'application/x-javascript', 'application/pdf', 'application/x-shockwave-flash'); // default environment vars this.env.keep_alive = 60; // seconds @@ -55,7 +54,7 @@ function rcube_webmail() this.env.blankpage = 'program/blank.gif'; // set jQuery ajax options - jQuery.ajaxSetup({ + $.ajaxSetup({ cache:false, error:function(request, status, err){ ref.http_error(request, status, err); }, beforeSend:function(xmlhttp){ xmlhttp.setRequestHeader('X-RoundCube-Request', ref.env.request_token); } @@ -63,46 +62,46 @@ function rcube_webmail() // set environment variable(s) this.set_env = function(p, value) - { + { if (p != null && typeof(p) == 'object' && !value) for (var n in p) this.env[n] = p[n]; else this.env[p] = value; - }; + }; // add a localized label to the client environment this.add_label = function(key, value) - { + { this.labels[key] = value; - }; + }; // add a button to the button list this.register_button = function(command, id, type, act, sel, over) - { + { if (!this.buttons[command]) - this.buttons[command] = new Array(); - + this.buttons[command] = []; + var button_prop = {id:id, type:type}; if (act) button_prop.act = act; if (sel) button_prop.sel = sel; if (over) button_prop.over = over; this.buttons[command][this.buttons[command].length] = button_prop; - }; + }; // register a specific gui object this.gui_object = function(name, id) - { + { this.gui_objects[name] = id; - }; - + }; + // register a container object this.gui_container = function(name, id) { this.gui_containers[name] = id; }; - + // add a GUI element (html node) to a specified container this.add_element = function(elm, container) { @@ -114,11 +113,11 @@ function rcube_webmail() this.register_command = function(command, callback, enable) { this.command_handlers[command] = callback; - + if (enable) this.enable_command(command, true); }; - + // execute the given script on load this.add_onload = function(f) { @@ -127,15 +126,15 @@ function rcube_webmail() // initialize webmail client this.init = function() - { + { var p = this; this.task = this.env.task; - + // check browser if (!bw.dom || !bw.xmlhttp_test()) { this.goto_url('error', '_code=0x199'); return; - } + } // find all registered gui containers for (var n in this.gui_containers) @@ -144,7 +143,7 @@ function rcube_webmail() // find all registered gui objects for (var n in this.gui_objects) this.gui_objects[n] = rcube_find_object(this.gui_objects[n]); - + // init registered buttons this.init_buttons(); @@ -154,18 +153,18 @@ function rcube_webmail() // enable general commands this.enable_command('logout', 'mail', 'addressbook', 'settings', true); - + if (this.env.permaurl) this.enable_command('permaurl', true); - switch (this.task) - { + switch (this.task) { + case 'mail': // enable mail commands this.enable_command('list', 'checkmail', 'compose', 'add-contact', 'search', 'reset-search', 'collapse-folder', true); - - if (this.gui_objects.messagelist) - { + + if (this.gui_objects.messagelist) { + this.message_list = new rcube_list_widget(this.gui_objects.messagelist, {multiselect:true, multiexpand:true, draggable:true, keyboard:true, dblclick_time:this.dblclick_time}); this.message_list.row_init = function(o){ p.init_message_row(o); }; @@ -184,18 +183,18 @@ function rcube_webmail() this.set_message_coltypes(this.env.coltypes); this.message_list.init(); this.enable_command('toggle_status', 'toggle_flag', 'menu-open', 'menu-save', true); - + // load messages if (this.env.messagecount) this.command('list'); - } + } if (this.gui_objects.qsearchbox) { if (this.env.search_text != null) { this.gui_objects.qsearchbox.value = this.env.search_text; - } - $(this.gui_objects.qsearchbox).focusin(function() { rcmail.message_list.blur(); }); } + $(this.gui_objects.qsearchbox).focusin(function() { rcmail.message_list.blur(); }); + } if (this.env.trash_mailbox && this.env.mailbox != this.env.trash_mailbox) this.set_alttext('delete', 'movemessagetotrash'); @@ -207,24 +206,24 @@ function rcube_webmail() if (this.env.next_uid) { this.enable_command('nextmessage', true); this.enable_command('lastmessage', true); - } + } if (this.env.prev_uid) { this.enable_command('previousmessage', true); this.enable_command('firstmessage', true); - } - + } + if (this.env.blockedobjects) { if (this.gui_objects.remoteobjectsmsg) this.gui_objects.remoteobjectsmsg.style.display = 'block'; this.enable_command('load-images', 'always-load', true); - } + } // make preview/message frame visible if (this.env.action == 'preview' && this.env.framed && parent.rcmail) { this.enable_command('compose', 'add-contact', false); parent.rcmail.show_contentframe(true); - } } + } else if (this.env.action == 'compose') { this.enable_command('add-attachment', 'send-attachment', 'remove-attachment', 'send', true); @@ -233,16 +232,16 @@ function rcube_webmail() this.set_spellcheck_state('ready'); if ($("input[name='_is_html']").val() == '1') this.display_spellcheck_controls(false); - } + } if (this.env.drafts_mailbox) this.enable_command('savedraft', true); - + document.onmouseup = function(e){ return p.doc_mouse_up(e); }; // init message compose form this.init_messageform(); - } + } // show printing dialog else if (this.env.action == 'print') window.print(); @@ -250,7 +249,7 @@ function rcube_webmail() if (this.env.messagecount) { this.enable_command('select-all', 'select-none', 'expunge', true); this.enable_command('expand-all', 'expand-unread', 'collapse-all', this.env.threading); - } + } if (this.purge_mailbox_test()) this.enable_command('purge', true); @@ -262,8 +261,8 @@ function rcube_webmail() this.env.unread_counts = {}; this.gui_objects.folderlist = this.gui_objects.mailboxlist; this.http_request('getunread', ''); - } - + } + // ask user to send MDN if (this.env.mdn_request && this.env.uid) { var mdnurl = '_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox); @@ -271,7 +270,7 @@ function rcube_webmail() this.http_post('sendmdn', mdnurl); else this.http_post('mark', mdnurl+'&_flag=mdnsent'); - } + } break; @@ -279,9 +278,9 @@ function rcube_webmail() case 'addressbook': if (this.gui_objects.folderlist) this.env.contactfolders = $.extend($.extend({}, this.env.address_sources), this.env.contactgroups); - - if (this.gui_objects.contactslist) - { + + if (this.gui_objects.contactslist) { + this.contact_list = new rcube_list_widget(this.gui_objects.contactslist, {multiselect:true, draggable:this.gui_objects.folderlist?true:false, keyboard:true}); this.contact_list.row_init = function(row){ p.triggerEvent('insertrow', { cid:row.uid, row:row }); }; @@ -299,16 +298,16 @@ function rcube_webmail() document.onmouseup = function(e){ return p.doc_mouse_up(e); }; if (this.gui_objects.qsearchbox) { $(this.gui_objects.qsearchbox).focusin(function() { rcmail.contact_list.blur(); }); - } } + } this.set_page_buttons(); - + if (this.env.address_sources && this.env.address_sources[this.env.source] && !this.env.address_sources[this.env.source].readonly) { this.enable_command('add', 'import', true); this.enable_command('group-create', this.env.address_sources[this.env.source].groups); } - + if (this.env.cid) this.enable_command('show', 'edit', true); @@ -316,7 +315,7 @@ function rcube_webmail() this.enable_command('save', true); else this.enable_command('search', 'reset-search', 'moveto', true); - + if (this.contact_list && this.contact_list.rowcount > 0) this.enable_command('export', true); @@ -326,7 +325,7 @@ function rcube_webmail() case 'settings': this.enable_command('preferences', 'identities', 'save', 'folders', true); - + if (this.env.action=='identities') { this.enable_command('add', this.env.identities_level < 2); } @@ -362,7 +361,7 @@ function rcube_webmail() case 'login': var input_user = $('#rcmloginuser'); input_user.bind('keyup', function(e){ return rcmail.login_user_keyup(e); }); - + if (input_user.val() == '') input_user.focus(); else @@ -373,7 +372,7 @@ function rcube_webmail() this.enable_command('login', true); break; - + default: break; } @@ -384,14 +383,14 @@ function rcube_webmail() // show message if (this.pending_message) this.display_message(this.pending_message[0], this.pending_message[1]); - + // map implicit containers if (this.gui_objects.folderlist) this.gui_containers.foldertray = $(this.gui_objects.folderlist); // trigger init event hook this.triggerEvent('init', { task:this.task, action:this.env.action }); - + // execute all foreign onload scripts // @deprecated for (var i=0; i=0) { + if (this.env.uid && props.mimetype && $.inArray(props.mimetype, this.mimetypes)>=0) { if (props.mimetype == 'text/html') qstring += '&_safe=1'; this.attachment_win = window.open(this.env.comm_path+'&_action=get&'+qstring+'&_frame=1', 'rcubemailattachment'); @@ -739,7 +728,7 @@ function rcube_webmail() this.goto_url('get', qstring+'&_download=1', false); break; - + case 'select-all': this.select_all_mode = props ? false : true; if (props == 'invert') @@ -787,17 +776,17 @@ function rcube_webmail() if (this.env.first_uid) this.show_message(this.env.first_uid); break; - + case 'checkmail': this.check_for_recent(true); break; - + case 'compose': var url = this.env.comm_path+'&_action=compose'; - + if (this.task=='mail') { url += '&_mbox='+urlencode(this.env.mailbox); - + if (this.env.mailbox==this.env.drafts_mailbox) { var uid; if (uid = this.get_single_uid()) @@ -814,9 +803,9 @@ function rcube_webmail() this.redirect(url + '&_to='+urlencode(props)); break; } - + // use contact_id passed as command parameter - var a_cids = new Array(); + var a_cids = []; if (props) a_cids[a_cids.length] = props; // get selected contacts @@ -825,7 +814,7 @@ function rcube_webmail() for (var n=0; n 0) { var add_url = (this.env.source ? '_source='+urlencode(this.env.source)+'&' : ''); if (this.env.search_request) add_url += '_search='+this.env.search_request; - + this.goto_url('export', add_url); } break; @@ -1025,10 +1010,10 @@ function rcube_webmail() case 'identities': this.goto_url('identities'); break; - + case 'delete-identity': this.delete_identity(); - + case 'folders': this.goto_url('folders'); break; @@ -1061,51 +1046,49 @@ function rcube_webmail() this.delete_folder(props); break; - } - + } + this.triggerEvent('after'+command, props); return obj ? false : true; - }; + }; // set command enabled or disabled this.enable_command = function() - { + { var args = arguments; - if(!args.length) return -1; + if (!args.length) + return -1; - var command; - var enable = args[args.length-1]; - - for(var n=0; n 0 && this.env.unreadchildrenicon) icon = this.env.unreadchildrenicon; @@ -1603,8 +1587,7 @@ function rcube_webmail() else if(flags.unread && this.env.unreadicon) icon = this.env.unreadicon; - var tree = expando = ''; - + // threads if (this.env.threading) { // This assumes that div width is hardcoded to 15px, var width = message.depth * 15; @@ -1631,13 +1614,12 @@ function rcube_webmail() } tree += icon ? '' : ''; - + // first col is always there - var col = document.createElement('td'); col.className = 'threads'; col.innerHTML = expando; row.appendChild(col); - + // build subject link if (!bw.ie && cols.subject) { var action = flags.mbox == this.env.drafts_mailbox ? 'compose' : 'show'; @@ -1694,7 +1676,7 @@ function rcube_webmail() $('#rcm'+this.env.sort_col).removeClass('sorted'+(this.env.sort_order.toUpperCase())); if (sort_col) $('#rcm'+sort_col).addClass('sorted'+sort_order); - + this.env.sort_col = sort_col; this.env.sort_order = sort_order; }; @@ -1707,7 +1689,7 @@ function rcube_webmail() update = 1; this.set_list_sorting(sort_col, sort_order); } - + if (this.env.threading != threads) { update = 1; add_url += '&_threads=' + threads; @@ -1796,7 +1778,7 @@ function rcube_webmail() if (page > 0 && page <= this.env.pagecount) { this.env.current_page = page; - + if (this.task=='mail') this.list_mailbox(this.env.mailbox, page); else if (this.task=='addressbook') @@ -1865,7 +1847,7 @@ function rcube_webmail() this.list_mailbox_remote(mbox, page, url); return; } - + if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) { target = window.frames[this.env.contentframe]; url += '&_framed=1'; @@ -1896,7 +1878,7 @@ function rcube_webmail() var tbody = this.gui_objects.messagelist.tBodies[0]; var new_row = tbody.firstChild; var r; - + while (new_row) { if (new_row.nodeType == 1 && (r = this.message_list.rows[new_row.uid]) && r.unread_children) { @@ -1935,7 +1917,7 @@ function rcube_webmail() case 1: this.message_list.expand_all(); break; } // this.message_list.expand(null); - } + }; // update parent in a thread this.update_thread_root = function(uid, flag) @@ -1944,7 +1926,7 @@ function rcube_webmail() return; var root = this.message_list.find_root(uid); - + if (uid == root) return; @@ -1974,7 +1956,7 @@ function rcube_webmail() var row = rows[uid] var depth = rows[uid].depth; var r, parent, count = 0; - var roots = new Array(); + var roots = []; if (!row.depth) // root message: decrease roots count count--; @@ -2023,7 +2005,7 @@ function rcube_webmail() } row = row.nextSibling; } - + // update unread_children for roots for (var i=0; i