Aleksander Machniak
2012-11-27 8beceebb55294cbb65d597d5e3924b2bc5d2689f
program/js/app.js
@@ -21,7 +21,6 @@
function rcube_webmail()
{
  this.env = { recipients_separator:',', recipients_delimiter:', ' };
  this.labels = {};
  this.buttons = {};
  this.buttons_sel = {};
@@ -33,21 +32,24 @@
  this.messages = {};
  this.group2expand = {};
  // create protected reference to myself
  this.ref = 'rcmail';
  var ref = this;
  // webmail client settings
  this.dblclick_time = 500;
  this.message_time = 4000;
  this.identifier_expr = new RegExp('[^0-9a-z\-_]', 'gi');
  // default environment vars
  this.env.request_timeout = 180;  // seconds
  this.env.draft_autosave = 0;     // seconds
  this.env.comm_path = './';
  this.env.blankpage = 'program/resources/blank.gif';
  // environment defaults
  this.env = {
    request_timeout: 180,  // seconds
    draft_autosave: 0,     // seconds
    comm_path: './',
    blankpage: 'program/resources/blank.gif',
    recipients_separator: ',',
    recipients_delimiter: ', '
  };
  // create protected reference to myself
  this.ref = 'rcmail';
  var ref = this;
  // set jQuery ajax options
  $.ajaxSetup({
@@ -57,6 +59,7 @@
    beforeSend: function(xmlhttp){ xmlhttp.setRequestHeader('X-Roundcube-Request', ref.env.request_token); }
  });
  // unload fix
  $(window).bind('beforeunload', function() { rcmail.unload = true; });
  // set environment variable(s)
@@ -81,13 +84,14 @@
  // add a button to the button list
  this.register_button = function(command, id, type, act, sel, over)
  {
    if (!this.buttons[command])
      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;
    if (!this.buttons[command])
      this.buttons[command] = [];
    this.buttons[command].push(button_prop);
@@ -187,7 +191,6 @@
        this.enable_command('list', 'checkmail', 'add-contact', 'search', 'reset-search', 'collapse-folder', true);
        if (this.gui_objects.messagelist) {
          this.message_list = new rcube_list_widget(this.gui_objects.messagelist, {
            multiselect:true, multiexpand:true, draggable:true, keyboard:true,
            column_movable:this.env.col_movable, dblclick_time:this.dblclick_time
@@ -214,9 +217,8 @@
        }
        if (this.gui_objects.qsearchbox) {
          if (this.env.search_text != null) {
          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(); });
        }
@@ -322,7 +324,6 @@
        this.enable_command('list', 'listgroup', 'listsearch', 'advanced-search', true);
        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 }); };
@@ -338,9 +339,8 @@
          this.gui_objects.contactslist.parentNode.onmousedown = function(e){ return p.click_on_list(e); };
          document.onmouseup = function(e){ return p.doc_mouse_up(e); };
          if (this.gui_objects.qsearchbox) {
          if (this.gui_objects.qsearchbox)
            $(this.gui_objects.qsearchbox).focusin(function() { rcmail.contact_list.blur(); });
          }
          this.update_group_commands();
          this.command('list');
@@ -364,9 +364,8 @@
              this.init_contact_form();
        }
        if (this.gui_objects.qsearchbox) {
        if (this.gui_objects.qsearchbox)
          this.enable_command('search', 'reset-search', 'moveto', true);
        }
        break;
@@ -507,6 +506,11 @@
    if (this.busy)
      return false;
    // let the browser handle this click (shift/ctrl usually opens the link in a new window/tab)
    if ((obj && obj.href && String(obj.href).indexOf(location.href) < 0) && rcube_event.get_modifier(event)) {
      return true;
    }
    // command not supported or allowed
    if (!this.commands[command]) {
      // pass command to parent window
@@ -562,7 +566,7 @@
        break;
      case 'about':
        location.href = '?_task=settings&_action=about';
        this.redirect('?_task=settings&_action=about', false);
        break;
      case 'permaurl':
@@ -592,7 +596,7 @@
      case 'open':
        if (uid = this.get_single_uid()) {
          obj.href = '?_task='+this.env.task+'&_action=show&_mbox='+urlencode(this.env.mailbox)+'&_uid='+uid;
          obj.href = this.url('show', {_mbox: this.env.mailbox, _uid: uid});
          return true;
        }
        break;
@@ -605,9 +609,8 @@
      case 'list':
        if (props && props != '')
          this.reset_qsearch();
        if (this.env.action == 'compose' && this.env.extwin) {
        if (this.env.action == 'compose' && this.env.extwin)
          window.close();
        }
        else if (this.task == 'mail') {
          this.list_mailbox(props);
          this.set_button_titles();
@@ -775,9 +778,8 @@
          uid = props._row.uid;
          // toggle read/unread
          if (this.message_list.rows[uid].deleted) {
          if (this.message_list.rows[uid].deleted)
            flag = 'undelete';
          }
          else if (!this.message_list.rows[uid].unread)
            flag = 'unread';
        }
@@ -796,7 +798,7 @@
          // toggle flagged/unflagged
          if (this.message_list.rows[uid].flagged)
            flag = 'unflagged';
          }
        }
        this.mark_message(flag, uid);
        break;
@@ -816,7 +818,7 @@
        var qstring = '_mbox='+urlencode(this.env.mailbox)+'&_uid='+this.env.uid+'&_part='+props.part;
        // open attachment in frame if it's of a supported mimetype
        if (this.env.uid && props.mimetype && this.env.mimetypes && $.inArray(props.mimetype, this.env.mimetypes)>=0) {
        if (this.env.uid && props.mimetype && this.env.mimetypes && $.inArray(props.mimetype, $.map(this.env.mimetypes, function(v,k){ return v })) >= 0) {
          if (props.mimetype == 'text/html')
            qstring += '&_safe=1';
          this.attachment_win = window.open(this.env.comm_path+'&_action=get&'+qstring+'&_frame=1', 'rcubemailattachment');
@@ -872,7 +874,7 @@
      case 'previousmessage':
        if (this.env.prev_uid)
          this.show_message(this.env.prev_uid, false, this.env.action=='preview');
          this.show_message(this.env.prev_uid, false, this.env.action == 'preview');
        break;
      case 'firstmessage':
@@ -2611,7 +2613,7 @@
    for (i=0, len=selection.length; i<len; i++) {
      uid = selection[i];
      if (list.rows[uid].has_children && !list.rows[uid].expanded)
        list.select_childs(uid);
        list.select_children(uid);
    }
    // if config is set to flag for deletion
@@ -3415,6 +3417,10 @@
            message = message.substring(0, p) + sig + message.substring(p, message.length);
            cursor_pos = p - 1;
          }
          else if (!message) { // empty message
            cursor_pos = 0;
            message = '\n\n' + sig;
          }
          else if (pos = this.get_caret_pos(input_message.get(0))) { // at cursor position
            message = message.substring(0, pos) + '\n' + sig + '\n\n' + message.substring(pos, message.length);
            cursor_pos = pos;
@@ -3487,20 +3493,26 @@
    if (!form)
      return false;
    // get file input field, count files on capable browser
    var i, size = 0, field = $('input[type=file]', form).get(0),
      files = field.files ? field.files.length : field.value ? 1 : 0;
    // count files and size on capable browser
    var size = 0, numfiles = 0;
    $('input[type=file]', form).each(function(i, field) {
      var files = field.files ? field.files.length : (field.value ? 1 : 0);
      // check file size
      if (field.files) {
        for (var i=0; i < files; i++)
          size += field.files[i].size;
      }
      numfiles += files;
    });
    // create hidden iframe and post upload form
    if (files) {
      // check file size
      if (field.files && this.env.max_filesize && this.env.filesizeerror) {
        for (i=0; i<files; i++)
          size += field.files[i].size;
        if (size && size > this.env.max_filesize) {
          this.display_message(this.env.filesizeerror, 'error');
          return;
        }
    if (numfiles) {
      if (this.env.max_filesize && this.env.filesizeerror && size > this.env.max_filesize) {
        this.display_message(this.env.filesizeerror, 'error');
        return;
      }
      var frame_name = this.async_upload_form(form, 'upload', function(e) {
@@ -3525,7 +3537,7 @@
      });
      // display upload indicator and cancel button
      var content = '<span>' + this.get_label('uploading' + (files > 1 ? 'many' : '')) + '</span>',
      var content = '<span>' + this.get_label('uploading' + (numfiles > 1 ? 'many' : '')) + '</span>',
        ts = frame_name.replace(/^rcmupload/, '');
      this.add2attachment_list(ts, { name:'', html:content, classname:'uploading', frame:frame_name, complete:false });
@@ -5587,7 +5599,7 @@
      // save message in order to display after page loaded
      if (type != 'loading')
        this.pending_message = [msg, type, timeout];
      return false;
      return 1;
    }
    type = type ? type : 'notice';
@@ -5648,6 +5660,9 @@
    // pass command to parent window
    if (this.is_framed())
      return parent.rcmail.hide_message(obj, fade);
    if (!this.gui_objects.message)
      return;
    var k, n, i, msg, m = this.messages;
@@ -6300,6 +6315,11 @@
    else if (request.status == 0 && status != 'abort')
      this.display_message(this.get_label('servererror') + ' (No connection)', 'error');
    // redirect to url specified in location header if not empty
    var location_url = request.getResponseHeader("Location");
    if (location_url)
      this.redirect(location_url);
    // re-send keep-alive requests after 30 seconds
    if (action == 'keep-alive')
      setTimeout(function(){ ref.keep_alive(); ref.start_keepalive(); }, 30000);
@@ -6561,7 +6581,8 @@
  {
    if (obj.selectionEnd !== undefined)
      return obj.selectionEnd;
    else if (document.selection && document.selection.createRange) {
    if (document.selection && document.selection.createRange) {
      var range = document.selection.createRange();
      if (range.parentElement() != obj)
        return 0;
@@ -6575,10 +6596,10 @@
      gm.setEndPoint('EndToStart', range);
      var p = gm.text.length;
      return p<=obj.value.length ? p : -1;
      return p <= obj.value.length ? p : -1;
    }
    else
      return obj.value.length;
    return obj.value.length;
  };
  // moves cursor to specified position