From 4e17e6c9dbac8991ee8b302cb2581241247dc8bc Mon Sep 17 00:00:00 2001 From: thomascube Date: Sun, 25 Sep 2005 14:18:03 +0000 Subject: Initial revision --- program/js/app.js | 2388 ++++++++++++++++++++++++++++++++++++++++++++++++++ program/js/common.js | 343 ++++++++ 2 files changed, 2731 insertions(+) create mode 100644 program/js/app.js create mode 100644 program/js/common.js (limited to 'program/js') diff --git a/program/js/app.js b/program/js/app.js new file mode 100644 index 000000000..d8afc0e64 --- /dev/null +++ b/program/js/app.js @@ -0,0 +1,2388 @@ +/* + +-----------------------------------------------------------------------+ + | RoundCube Webmail Client Script | + | | + | This file is part of the RoundCube Webmail client | + | Copyright (C) 2005, RoundCube Dev, - Switzerland | + | All rights reserved. | + | | + | Modified: 2005/08/19 (tbr) | + | | + +-----------------------------------------------------------------------+ + | Author: Thomas Bruederli | + +-----------------------------------------------------------------------+ +*/ + + +var rcube_webmail_client; + +function rcube_webmail() + { + this.env = new Object(); + this.buttons = new Object(); + this.gui_objects = new Object(); + this.commands = new Object(); + this.selection = new Array(); + + // 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'); + this.env.blank_img = 'skins/default/images/blank.gif'; + + // 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'); + + + // set environment variable + this.set_env = function(name, value) + { + //if (!this.busy) + this.env[name] = 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.ie && bw.vendver>=5.5 && !bw.opera) || (bw.mz && bw.vendver>=1) || (bw.safari && bw.vendver>=125) || (bw.opera && bw.vendver>=8)))) + { + 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 = this.gui_objects.messagelist; + if (msg_list) + { + this.init_messagelist(msg_list); + this.enable_command('markread', true); + } + + // enable mail commands + this.enable_command('list', 'compose', 'add-contact', true); + + if (this.env.action=='show') + { + this.enable_command('show', 'reply', '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', 'send', true); + + if (this.env.messagecount) + this.enable_command('select-all', 'select-none', 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(); + + break; + + + case 'addressbook': + var contacts_list = this.gui_objects.contactslist; + if (contacts_list) + this.init_contactslist(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); + 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', '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; } + + // flag object as complete + this.loaded = true; + + // show message + if (this.pending_message) + this.display_message(this.pending_message[0], this.pending_message[1]); + }; + + + // 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) + 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) + location.href = this.env.comm_path+'&_action=show&_uid='+this.env.prev_uid+'&_mbox='+this.env.mailbox; + break; + + case 'compose': + var url = this.env.comm_path+'&_action=compose'; + + // modify url if we're in addressbook + 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 + { + for (var n=0; n0 ? true : false); + } + else if (this.task=='addressbook') + { + this.enable_command('edit', /*'print',*/ selected); + this.enable_command('delete', 'compose', this.selection.length>0 ? true : false); + } + }; + + + this.clear_selection = function() + { + for(var n=0; n1) + page = this.env.current_page-1; + + 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') + this.list_contacts(page); + } + }; + + + // list messages of a specific mailbox + this.list_mailbox = function(mbox, page) + { + var add_url = ''; + var target = window; + + if (!mbox) + mbox = this.env.mailbox; + + // set page=1 if changeing to another mailbox + if (!page && mbox != this.env.mailbox) + { + page = 1; + this.env.current_page = page; + this.clear_selection(); + } + + if (this.env.mailbox!=mbox) + this.select_mailbox(mbox); + + // load message list remotely + if (this.gui_objects.messagelist) + { + this.list_mailbox_remote(mbox, page); + return; + } + + if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) + { + target = window.frames[this.env.contentframe]; + add_url = '&_framed=1'; + } + + // load message list to target frame/window + if (mbox) + { + this.set_busy(true, 'loading'); + target.location.href = this.env.comm_path+'&_mbox='+escape(mbox)+(page ? '&_page='+page : '')+add_url; + } + }; + + + // send remote request to load message list + this.list_mailbox_remote = function(mbox, page) + { + // clear message list + var table = this.gui_objects.messagelist; + var tbody = document.createElement('TBODY'); + table.insertBefore(tbody, table.tBodies[0]); + table.removeChild(table.tBodies[1]); + + this.message_rows = new Array(); + this.list_rows = this.message_rows; + + // send request to server + var url = '_mbox='+escape(mbox)+(page ? '&_page='+page : ''); + this.set_busy(true, 'loading'); + this.http_request('list', url); + }; + + + // move selected messages to the specified mailbox + this.move_messages = function(mbox) + { + // exit if no mailbox specified or if selection is empty + if (!mbox || !(this.selection.length || this.env.uid) || mbox==this.env.mailbox) + return; + + var a_uids = new Array(); + + if (this.env.uid) + a_uids[a_uids.length] = this.env.uid; + else + { + var id; + for (var n=0; n