X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=program%2Fjs%2Fapp.js;fp=program%2Fjs%2Fapp.js;h=7622f1f2cd221a4e11470cac5ce37b4a79c59cb7;hb=0af63e79917234f76cfa7ec74e9d97b24fbf9b55;hp=0000000000000000000000000000000000000000;hpb=38f53b1d7d882df852551d91da5410d3bcc92a6a;p=roundcube.git diff --git a/program/js/app.js b/program/js/app.js new file mode 100644 index 0000000..7622f1f --- /dev/null +++ b/program/js/app.js @@ -0,0 +1,3902 @@ +/* + +-----------------------------------------------------------------------+ + | RoundCube Webmail Client Script | + | | + | This file is part of the RoundCube Webmail client | + | Copyright (C) 2005, RoundCube Dev, - Switzerland | + | Licensed under the GNU GPL | + | | + +-----------------------------------------------------------------------+ + | Authors: Thomas Bruederli | + | Charles McNulty | + +-----------------------------------------------------------------------+ + + $Id: app.js 431 2006-12-23 10:44:16Z thomasb $ +*/ + +// Constants +var CONTROL_KEY = 1; +var SHIFT_KEY = 2; +var CONTROL_SHIFT_KEY = 3; + +var rcube_webmail_client; + +function rcube_webmail() + { + this.env = new Object(); + this.labels = new Object(); + this.buttons = new Object(); + this.gui_objects = new Object(); + this.commands = new Object(); + this.selection = new Array(); + this.last_selected = 0; + this.in_message_list = false; + + // create public reference to myself + rcube_webmail_client = this; + this.ref = 'rcube_webmail_client'; + + // webmail client settings + this.dblclick_time = 600; + this.message_time = 5000; + + this.mbox_expression = 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'); + + // default environment vars + this.env.keep_alive = 60; // seconds + this.env.request_timeout = 180; // seconds + this.env.draft_autosave = 300; // seconds + + + // set environment variable + this.set_env = function(name, value) + { + this.env[name] = 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(); + + 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; + }; + + + // initialize webmail client + this.init = function() + { + this.task = this.env.task; + + // check browser + if (!bw.dom || !bw.xmlhttp_test()) + { + location.href = this.env.comm_path+'&_action=error&_code=0x199'; + return; + } + + // find all registered gui objects + for (var n in this.gui_objects) + this.gui_objects[n] = rcube_find_object(this.gui_objects[n]); + + // tell parent window that this frame is loaded + if (this.env.framed && parent.rcmail && parent.rcmail.set_busy) + parent.rcmail.set_busy(false); + + // enable general commands + this.enable_command('logout', 'mail', 'addressbook', 'settings', true); + + switch (this.task) + { + case 'mail': + var msg_list_frame = this.gui_objects.mailcontframe; + var msg_list = this.gui_objects.messagelist; + if (msg_list) + { + msg_list_frame.onmousedown = function(e){return rcube_webmail_client.click_on_list(e);}; + this.init_messagelist(msg_list); + this.enable_command('toggle_status', true); + } + + // enable mail commands + this.enable_command('list', 'checkmail', 'compose', 'add-contact', 'search', 'reset-search', true); + + if (this.env.action=='show') + { + this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'delete', 'viewsource', 'print', 'load-attachment', true); + if (this.env.next_uid) + this.enable_command('nextmessage', true); + if (this.env.prev_uid) + this.enable_command('previousmessage', true); + } + + if (this.env.action=='show' && this.env.blockedobjects) + { + if (this.gui_objects.remoteobjectsmsg) + this.gui_objects.remoteobjectsmsg.style.display = 'block'; + this.enable_command('load-images', true); + } + + if (this.env.action=='compose') + { + this.enable_command('add-attachment', 'send-attachment', 'remove-attachment', 'send', true); + if (this.env.spellcheck) + this.enable_command('spellcheck', true); + if (this.env.drafts_mailbox) + this.enable_command('savedraft', true); + } + + if (this.env.messagecount) + this.enable_command('select-all', 'select-none', 'sort', 'expunge', true); + + if (this.env.messagecount && (this.env.mailbox==this.env.trash_mailbox || this.env.mailbox==this.env.junk_mailbox)) + this.enable_command('purge', true); + + this.set_page_buttons(); + + // focus this window + window.focus(); + + // init message compose form + if (this.env.action=='compose') + this.init_messageform(); + + // show printing dialog + if (this.env.action=='print') + window.print(); + + // get unread count for each mailbox + if (this.gui_objects.mailboxlist) + this.http_request('getunread', ''); + + break; + + + case 'addressbook': + var contacts_list = this.gui_objects.contactslist; + var ldap_contacts_list = this.gui_objects.ldapcontactslist; + + if (contacts_list) + this.init_contactslist(contacts_list); + + if (ldap_contacts_list) + this.init_ldapsearchlist(ldap_contacts_list); + + this.set_page_buttons(); + + if (this.env.cid) + this.enable_command('show', 'edit', true); + + if ((this.env.action=='add' || this.env.action=='edit') && this.gui_objects.editform) + this.enable_command('save', true); + + this.enable_command('list', 'add', true); + + this.enable_command('ldappublicsearch', this.env.ldappublicsearch); + + break; + + + case 'settings': + this.enable_command('preferences', 'identities', 'save', 'folders', true); + + if (this.env.action=='identities' || this.env.action=='edit-identity' || this.env.action=='add-identity') + this.enable_command('edit', 'add', 'delete', true); + + if (this.env.action=='edit-identity' || this.env.action=='add-identity') + this.enable_command('save', true); + + if (this.env.action=='folders') + this.enable_command('subscribe', 'unsubscribe', 'create-folder', 'rename-folder', 'delete-folder', true); + + var identities_list = this.gui_objects.identitieslist; + if (identities_list) + this.init_identitieslist(identities_list); + + break; + + case 'login': + var input_user = rcube_find_object('_user'); + var input_pass = rcube_find_object('_pass'); + if (input_user && input_user.value=='') + input_user.focus(); + else if (input_pass) + input_pass.focus(); + + this.enable_command('login', true); + break; + + default: + break; + } + + + // enable basic commands + this.enable_command('logout', true); + + // disable browser's contextmenus + // document.oncontextmenu = function(){ return false; } + + // load body click event + document.onmousedown = function(){ return rcube_webmail_client.reset_click(); }; + document.onkeydown = function(e){ return rcube_webmail_client.key_pressed(e, msg_list_frame); }; + + // flag object as complete + this.loaded = true; + + // show message + if (this.pending_message) + this.display_message(this.pending_message[0], this.pending_message[1]); + + // start keep-alive interval + this.start_keepalive(); + }; + + + // start interval for keep-alive/recent_check signal + this.start_keepalive = function() + { + if (this.env.keep_alive && this.task=='mail' && this.gui_objects.messagelist) + this._int = setInterval(this.ref+'.check_for_recent()', this.env.keep_alive * 1000); + else if (this.env.keep_alive && this.task!='login') + this._int = setInterval(this.ref+'.send_keep_alive()', this.env.keep_alive * 1000); + } + + + // reset last clicked if user clicks on anything other than the message table + this.reset_click = function() + { + var id; + this.in_message_list = false; + for (var n=0; n (Number(msg_list_frame.scrollTop) + Number(msg_list_frame.offsetHeight)))) { + msg_list_frame.scrollTop = scroll_to; + } + return false; + }; + + this.use_delete_key = function(keyCode, mod_key, msg_list_frame){ + this.command('delete','',this); + return false; + } + + // get all message rows from HTML table and init each row + this.init_messagelist = function(msg_list) + { + if (msg_list && msg_list.tBodies[0]) + { + + this.message_rows = new Array(); + + var row; + for(var r=0; r=0) + { + this.attachment_win = window.open(url+'&_frame=1', 'rcubemailattachment'); + if (this.attachment_win) + { + setTimeout(this.ref+'.attachment_win.focus()', 10); + break; + } + } + + location.href = url; + break; + + case 'select-all': + this.select_all(props); + break; + + case 'select-none': + this.clear_selection(); + break; + + case 'nextmessage': + if (this.env.next_uid) + this.show_message(this.env.next_uid); + //location.href = this.env.comm_path+'&_action=show&_uid='+this.env.next_uid+'&_mbox='+this.env.mailbox; + break; + + case 'previousmessage': + if (this.env.prev_uid) + this.show_message(this.env.prev_uid); + //location.href = this.env.comm_path+'&_action=show&_uid='+this.env.prev_uid+'&_mbox='+this.env.mailbox; + break; + + case 'checkmail': + this.check_for_recent(); + break; + + case 'compose': + var url = this.env.comm_path+'&_action=compose'; + + if (this.task=='mail' && this.env.mailbox==this.env.drafts_mailbox) + { + var uid; + if (uid = this.get_single_uid()) + url += '&_draft_uid='+uid+'&_mbox='+escape(this.env.mailbox); + } + // modify url if we're in addressbook + else if (this.task=='addressbook') + { + url = this.get_task_url('mail', url); + var a_cids = new Array(); + + // use contact_id passed as command parameter + if (props) + a_cids[a_cids.length] = props; + + // get selected contacts + else + { + if (!window.frames[this.env.contentframe].rcmail.selection.length) + { + for (var n=0; n