alecpl
2010-05-30 c3eab29e1930d80bdd0ef6d19e58e8f1dca8c170
program/js/app.js
@@ -166,7 +166,7 @@
          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, column_fixed:0, dblclick_time:this.dblclick_time
            column_movable:this.env.col_movable, dblclick_time:this.dblclick_time
            });
          this.message_list.row_init = function(o){ p.init_message_row(o); };
          this.message_list.addEventListener('dblclick', function(o){ p.msglist_dbl_click(o); });
@@ -199,9 +199,11 @@
        if (this.env.trash_mailbox && this.env.mailbox != this.env.trash_mailbox)
          this.set_alttext('delete', 'movemessagetotrash');
        this.env.message_commands = ['show', 'reply', 'reply-all', 'forward', 'moveto', 'copy', 'delete',
          'open', 'mark', 'edit', 'viewsource', 'download', 'print', 'load-attachment', 'load-headers'];
        if (this.env.action=='show' || this.env.action=='preview') {
          this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'copy', 'delete',
            'open', 'mark', 'edit', 'viewsource', 'download', 'print', 'load-attachment', 'load-headers', true);
          this.enable_command(this.env.message_commands, true);
          if (this.env.next_uid) {
            this.enable_command('nextmessage', 'lastmessage', true);
@@ -1047,21 +1049,25 @@
    return obj ? false : true;
  };
  // set command enabled or disabled
  // set command(s) enabled or disabled
  this.enable_command = function()
  {
    var args = arguments, len = args.length;
    if (!len)
      return -1;
    var args = Array.prototype.slice.call(arguments),
      enable = args.pop(), cmd;
    var command, enable = args[len-1];
    for (var n=0, len=len-1; n<len; n++) {
      command = args[n];
      this.commands[command] = enable;
      this.set_button(command, (enable ? 'act' : 'pas'));
    for (var n=0; n<args.length; n++) {
      cmd = args[n];
      // argument of type array
      if (typeof cmd === 'string') {
        this.commands[cmd] = enable;
        this.set_button(cmd, (enable ? 'act' : 'pas'));
      }
      // push array elements into commands array
      else {
        for (var i in cmd)
          args.push(cmd[i]);
      }
    }
    return true;
  };
  // lock/unlock interface
@@ -1398,9 +1404,12 @@
    var selected = list.get_single_selection() != null;
    this.enable_command(this.env.message_commands, selected);
    // Hide certain command buttons when Drafts folder is selected
    this.enable_command('reply', 'reply-all', 'forward', this.env.mailbox == this.env.drafts_mailbox ? false : selected);
    this.enable_command('show', 'print', 'open', 'edit', 'download', 'viewsource', selected);
    if (selected && this.env.mailbox == this.env.drafts_mailbox) {
      this.enable_command('reply', 'reply-all', 'forward', false);
    }
    // Multi-message commands
    this.enable_command('delete', 'moveto', 'copy', 'mark', (list.selection.length > 0 ? true : false));
    // reset all-pages-selection
@@ -1636,11 +1645,6 @@
    tree += icon ? '<img id="msgicn'+uid+'" src="'+icon+'" alt="" class="msgicon" />' : '';
    // first col is always there
    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';
@@ -1662,6 +1666,8 @@
        else if(!flags.flagged && this.env.unflaggedicon)
          html = '<img id="flaggedicn'+uid+'" src="'+this.env.unflaggedicon+'" class="flagicon" alt="" />';
      }
      else if (c == 'threads')
        html = expando;
      else if (c == 'attachment')
        html = flags.attachment && this.env.attachmenticon ? '<img src="'+this.env.attachmenticon+'" alt="" />' : '&nbsp;';
      else if (c == 'subject')
@@ -1721,15 +1727,15 @@
        name = oldcols[i] == 'to' ? 'from' : oldcols[i];
        idx = $.inArray(name, cols);
        if (idx != -1) {
          newcols[newcols.length] = name;
          newcols.push(name);
          delete cols[idx];
        }
      }
      for (i=0; i<cols.length; i++)
        if (cols[i])
          newcols[newcols.length] = cols[i];
          newcols.push(cols[i]);
      if (newcols.join() != this.env.coltypes.join()) {
      if (newcols.join() != oldcols.join()) {
        update = 1;
        add_url += '&_cols=' + newcols.join(',');
      }
@@ -2325,7 +2331,7 @@
      this.show_contentframe(false);
    // Hide message command buttons until a message is selected
    this.enable_command('reply', 'reply-all', 'forward', 'delete', 'mark', 'print', 'open', 'edit', 'viewsource', 'download', false);
    this.enable_command(this.env.message_commands, false);
    this._with_selected_messages('moveto', lock, add_url);
  };
@@ -3770,7 +3776,7 @@
  {
    var li, key = 'G'+prop.source+prop.id;
    if ((li = this.get_folder_li(key))) {
      this.triggerEvent('removegroup', { source:prop.source, id:prop.id, li:li });
      this.triggerEvent('group_delete', { source:prop.source, id:prop.id, li:li });
      li.parentNode.removeChild(li);
      delete this.env.contactfolders[key];
@@ -3842,7 +3848,7 @@
      .append(link)
      .insertAfter(this.get_folder_li(prop.source));
    this.triggerEvent('insertgroup', { id:prop.id, source:prop.source, name:prop.name, li:li[0] });
    this.triggerEvent('group_insert', { id:prop.id, source:prop.source, name:prop.name, li:li[0] });
  };
  // callback for renaming a contact group
@@ -3856,7 +3862,7 @@
      link.innerHTML = prop.name;
    this.env.contactfolders[key].name = this.env.contactgroups[key].name = name;
    this.triggerEvent('updategroup', { id:prop.id, source:prop.source, name:prop.name, li:li[0] });
    this.triggerEvent('group_update', { id:prop.id, source:prop.source, name:prop.name, li:li[0] });
  };
@@ -4557,58 +4563,54 @@
  // for reordering column array (Konqueror workaround)
  // and for setting some message list global variables
  this.set_message_coltypes = function(coltypes, repl)
  {
  {
    this.env.coltypes = coltypes;
    // set correct list titles
    var thead = this.gui_objects.messagelist ? this.gui_objects.messagelist.tHead : null;
    var thead = this.gui_objects.messagelist ? this.gui_objects.messagelist.tHead : null,
      cell, col, n, len;
    // replace old column headers
    if (thead && repl) {
      for (var cell, c=0; c < repl.length; c++) {
        cell = thead.rows[0].cells[c];
        if (!cell) {
    if (thead) {
      if (repl) {
        var th = document.createElement('thead'),
          tr = document.createElement('tr');
        for (c=0, len=repl.length; c < len; c++) {
          cell = document.createElement('td');
          thead.rows[0].appendChild(cell);
          cell.innerHTML = repl[c].html;
          if (repl[c].id) cell.id = repl[c].id;
          if (repl[c].className) cell.className = repl[c].className;
          tr.appendChild(cell);
        }
        cell.innerHTML = repl[c].html;
        if (repl[c].id) cell.id = repl[c].id;
        if (repl[c].className) cell.className = repl[c].className;
        th.appendChild(tr);
        thead.parentNode.replaceChild(th, thead);
      }
      for (n=0, len=this.env.coltypes.length; n<len; n++) {
        col = this.env.coltypes[n];
        if ((cell = thead.rows[0].cells[n]) && (col=='from' || col=='to')) {
          cell.id = 'rcm'+col;
          // if we have links for sorting, it's a bit more complicated...
          if (cell.firstChild && cell.firstChild.tagName.toLowerCase()=='a') {
            cell = cell.firstChild;
            cell.onclick = function(){ return rcmail.command('sort', this.__col, this); };
            cell.__col = col;
          }
          cell.innerHTML = this.get_label(col);
        }
      }
    }
    var cell, col, n;
    for (n=0; thead && n<this.env.coltypes.length; n++) {
      col = this.env.coltypes[n];
      if ((cell = thead.rows[0].cells[n+1]) && (col=='from' || col=='to')) {
        // if we have links for sorting, it's a bit more complicated...
        if (cell.firstChild && cell.firstChild.tagName.toLowerCase()=='a') {
          cell.firstChild.innerHTML = this.get_label(this.env.coltypes[n]);
          cell.firstChild.onclick = function(){ return rcmail.command('sort', this.__col, this); };
          cell.firstChild.__col = col;
        }
        else
          cell.innerHTML = this.get_label(this.env.coltypes[n]);
        cell.id = 'rcm'+col;
      }
    }
    // remove excessive columns
    for (var i=n+1; thead && i<thead.rows[0].cells.length; i++)
      thead.rows[0].removeChild(thead.rows[0].cells[i]);
    this.env.subject_col = null;
    this.env.flagged_col = null;
    var found;
    if ((found = $.inArray('subject', this.env.coltypes)) >= 0) {
      this.set_env('subject_col', found);
    if ((n = $.inArray('subject', this.env.coltypes)) >= 0) {
      this.set_env('subject_col', n);
      if (this.message_list)
        this.message_list.subject_col = found+1;
        this.message_list.subject_col = n;
    }
    if ((found = $.inArray('flag', this.env.coltypes)) >= 0)
      this.set_env('flagged_col', found);
    if ((n = $.inArray('flag', this.env.coltypes)) >= 0)
      this.set_env('flagged_col', n);
    this.message_list.init_header();
  };
@@ -4875,9 +4877,19 @@
  // send a http request to the server
  this.http_request = function(action, querystring, lock)
  {
    querystring += (querystring ? '&' : '') + '_remote=1';
    var url = this.env.comm_path + '&_action=' + action + '&' + querystring
    // trigger plugin hook
    var result = this.triggerEvent('request'+action, querystring);
    if (typeof result != 'undefined') {
      // abort if one the handlers returned false
      if (result === false)
        return false;
      else
        querystring = result;
    }
    querystring += (querystring ? '&' : '') + '_remote=1';
    var url = this.env.comm_path + '&_action=' + action + '&' + querystring;
    // send request
    console.log('HTTP GET: ' + url);
    $.get(url, { _unlock:(lock?1:0) }, function(data){ ref.http_response(data); }, 'json');
@@ -4894,6 +4906,16 @@
    }
    else
      postdata += (postdata ? '&' : '') + '_remote=1' + (lock ? '&_unlock=1' : '');
    // trigger plugin hook
    var result = this.triggerEvent('request'+action, postdata);
    if (typeof result != 'undefined') {
      // abort if one the handlers returned false
      if (result === false)
        return false;
      else
        postdata = result;
    }
    // send request
    console.log('HTTP POST: ' + url);
@@ -4930,6 +4952,7 @@
    if (response.callbacks && response.callbacks.length) {
      for (var i=0; i < response.callbacks.length; i++)
        this.triggerEvent(response.callbacks[i][0], response.callbacks[i][1]);
    }
    // process the response data according to the sent action
    switch (response.action) {
@@ -4944,21 +4967,24 @@
      case 'moveto':
        if (this.env.action == 'show') {
          // re-enable commands on move/delete error
          this.enable_command('reply', 'reply-all', 'forward', 'delete', 'mark', 'print', 'open', 'edit', 'viewsource', 'download', true);
          this.enable_command(this.env.message_commands, true);
        }
        break;
        else if (this.task == 'addressbook') {
          this.triggerEvent('listupdate', { folder:this.env.source, rowcount:this.contact_list.rowcount });
        }
      case 'purge':
      case 'expunge':
        if (!this.env.messagecount && this.task == 'mail') {
          // clear preview pane content
          if (this.env.contentframe)
            this.show_contentframe(false);
          // disable commands useless when mailbox is empty
          this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'copy', 'delete',
            'mark', 'viewsource', 'open', 'edit', 'download', 'print', 'load-attachment',
            'purge', 'expunge', 'select-all', 'select-none', 'sort',
            'expand-all', 'expand-unread', 'collapse-all', false);
        if (this.task == 'mail') {
          if (!this.env.messagecount) {
            // clear preview pane content
            if (this.env.contentframe)
              this.show_contentframe(false);
            // disable commands useless when mailbox is empty
            this.enable_command(this.env.message_commands, 'purge', 'expunge',
              'select-all', 'select-none', 'sort', 'expand-all', 'expand-unread', 'collapse-all', false);
          }
          this.triggerEvent('listupdate', { folder:this.env.mailbox, rowcount:this.message_list.rowcount });
        }
        break;