alecpl
2008-04-12 3d35312cc4badb64a2c26db8e80c1a01f2d1c12b
program/js/app.js
@@ -179,7 +179,6 @@
          {
          this.enable_command('compose', 'add-contact', false);
          parent.rcmail.show_contentframe(true);
          parent.rcmail.mark_message('read', this.env.uid);
          }
        if ((this.env.action=='show' || this.env.action=='preview') && this.env.blockedobjects)
@@ -202,7 +201,7 @@
          }
        if (this.env.messagecount)
          this.enable_command('select-all', 'select-none', 'sort', 'expunge', true);
          this.enable_command('select-all', 'select-none', '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);
@@ -488,7 +487,7 @@
        break;
      case 'logout':
        this.goto_url('logout', true);
        this.goto_url('logout', '', true);
        break;      
      // commands to switch task
@@ -892,7 +891,7 @@
          {
            setTimeout(function(){ ref.printwin.focus(); }, 20);
            if (this.env.action != 'show')
              this.toggle_read_status('read', [uid]);
              this.mark_message('read', uid);
          }
        }
        break;
@@ -1408,7 +1407,7 @@
  this.delete_messages = function()
    {
    var selection = this.message_list ? this.message_list.get_selection() : new Array();
    // exit if no mailbox specified or if selection is empty
    if (!this.env.uid && !selection.length)
        return;
@@ -1459,8 +1458,9 @@
  this._with_selected_messages = function(action, lock, add_url)
    {
    var a_uids = new Array();
    if (this.env.uid)
      a_uids[a_uids.length] = this.env.uid;
      a_uids[0] = this.env.uid;
    else
      {
      var selection = this.message_list.get_selection();
@@ -1469,10 +1469,11 @@
        {
        id = selection[n];
        a_uids[a_uids.length] = id;
        this.message_list.remove_row(id, (n == selection.length-1));
        }
      }
    // also send search request to get the right messages 
    if (this.env.search_request) 
      add_url += '&_search='+this.env.search_request;
@@ -1486,36 +1487,49 @@
  this.mark_message = function(flag, uid)
    {
    var a_uids = new Array();
    var r_uids = new Array();
    var selection = this.message_list ? this.message_list.get_selection() : new Array();
    if (uid)
      a_uids[0] = uid;
    else if (this.env.uid)
      a_uids[0] = this.env.uid;
    else if (this.message_list)
      {
      for (var id, n=0; n<selection.length; n++)
      for (var n=0; n<selection.length; n++)
        {
        id = selection[n];
        if ((flag=='read' && this.message_list.rows[id].unread) || (flag=='unread' && !this.message_list.rows[id].unread)
            || (flag=='delete' && !this.message_list.rows[id].deleted) || (flag=='undelete' && this.message_list.rows[id].deleted))
          a_uids[a_uids.length] = id;
         a_uids[a_uids.length] = selection[n];
        }
      }
    if (!this.message_list)
      r_uids = a_uids;
    else
      for (var id, n=0; n<a_uids.length; n++)
      {
        id = a_uids[n];
        if ((flag=='read' && this.message_list.rows[id].unread)
       || (flag=='unread' && !this.message_list.rows[id].unread)
            || (flag=='delete' && !this.message_list.rows[id].deleted)
       || (flag=='undelete' && this.message_list.rows[id].deleted))
     {
       r_uids[r_uids.length] = id;
     }
      }
    // nothing to do
    if (!a_uids.length)
    if (!r_uids.length)
      return;
    switch (flag)
      {
        case 'read':
        case 'unread':
          this.toggle_read_status(flag, a_uids);
          this.toggle_read_status(flag, r_uids);
          break;
        case 'delete':
        case 'undelete':
          this.toggle_delete_status(a_uids);
          this.toggle_delete_status(r_uids);
          break;
      }
    };
@@ -1525,16 +1539,12 @@
  {
    // mark all message rows as read/unread
    var icn_src;
    var res_uids = new Array();
    var rows = this.message_list.rows;
    for (var i=0; i<a_uids.length; i++)
      {
      uid = a_uids[i];
      // check if flag isn't set yet
      if (rows[uid] && ((flag=='unread' && !rows[uid].unread) || (flag=='read' && rows[uid].unread)))
      if (rows[uid])
        {
        res_uids[res_uids.length] = uid;
        rows[uid].unread = (flag=='unread' ? true : false);
        
        if (rows[uid].classname.indexOf('unread')<0 && rows[uid].unread)
@@ -1561,24 +1571,39 @@
        }
      }
    if (res_uids.length)
      this.http_post('mark', '_uid='+res_uids.join(',')+'&_flag='+flag);
    this.http_post('mark', '_uid='+a_uids.join(',')+'&_flag='+flag);
  };
  // set class to read/unread
  this.mark_as_read_from_preview = function(uid)
  {
    var icn_src;
    var rows = parent.rcmail.message_list.rows;
    if(rows[uid].unread)
      {
        rows[uid].unread = false;
        rows[uid].classname = rows[uid].classname.replace(/\s*unread/, '');
        parent.rcmail.set_classname(rows[uid].obj, 'unread', false);
        if (rows[uid].replied && parent.rcmail.env.repliedicon)
         icn_src = parent.rcmail.env.repliedicon;
        else if (parent.rcmail.env.messageicon)
          icn_src = parent.rcmail.env.messageicon;
   if (rows[uid].icon && icn_src)
          rows[uid].icon.src = icn_src;
      }
  }
  
  // mark all message rows as deleted/undeleted
  this.toggle_delete_status = function(a_uids)
  {
    if (this.env.read_when_deleted)
      this.toggle_read_status('read',a_uids);
    // if deleting message from "view message" don't bother with delete icon
    if (this.env.action == "show")
      return false;
    var rows = this.message_list.rows;
    var rows = this.message_list ? this.message_list.rows : new Array();
    if (a_uids.length==1)
    {
      if (rows[a_uids[0]] && rows[a_uids[0]].classname.indexOf('deleted') < 0)
      if (!rows.length || (rows[a_uids[0]] && rows[a_uids[0]].classname.indexOf('deleted') < 0))
        this.flag_as_deleted(a_uids);
      else
        this.flag_as_undeleted(a_uids);
@@ -1610,12 +1635,8 @@
  this.flag_as_undeleted = function(a_uids)
  {
    // if deleting message from "view message" don't bother with delete icon
    if (this.env.action == "show")
      return false;
    var icn_src;
    var rows = this.message_list.rows;
    var rows = this.message_list ? this.message_list.rows : new Array();
      
    for (var i=0; i<a_uids.length; i++)
    {
@@ -1634,6 +1655,7 @@
          icn_src = this.env.repliedicon;
        else if (this.env.messageicon)
          icn_src = this.env.messageicon;
        if (rows[uid].icon && icn_src)
          rows[uid].icon.src = icn_src;
      }
@@ -1646,30 +1668,66 @@
  
  this.flag_as_deleted = function(a_uids)
  {
    // if deleting message from "view message" don't bother with delete icon
    if (this.env.action == "show")
      return false;
    var rows = this.message_list.rows;
    var add_url = '';
    var r_uids = new Array();
    var rows = this.message_list ? this.message_list.rows : new Array();
    for (var i=0; i<a_uids.length; i++)
    {
      {
      uid = a_uids[i];
      if (rows[uid]) {
      if (rows[uid])
        {
        rows[uid].deleted = true;
        
        if (rows[uid].classname.indexOf('deleted')<0) {
        if (rows[uid].classname.indexOf('deleted')<0)
     {
          rows[uid].classname += ' deleted';
          this.set_classname(rows[uid].obj, 'deleted', true);
        }
        if (rows[uid].icon && this.env.deletedicon)
          }
   if (rows[uid].icon && this.env.deletedicon)
          rows[uid].icon.src = this.env.deletedicon;
      }
    }
    this.http_post('mark', '_uid='+a_uids.join(',')+'&_flag=delete');
   if (rows[uid].unread)
     r_uids[r_uids.length] = uid;
        }
      }
    if (r_uids.length)
      add_url = '&_ruid='+r_uids.join(',');
    this.http_post('mark', '_uid='+a_uids.join(',')+'&_flag=delete'+add_url);
    return true;  
  };
  // flag as read without mark request (called from backend)
  // argument should be a coma-separated list of uids
  this.flag_deleted_as_read = function(uids)
  {
    var icn_src;
    var rows = this.message_list ? this.message_list.rows : new Array();
    var str = String(uids);
    var a_uids = new Array();
    a_uids = str.split(',');
    for (var uid, i=0; i<a_uids.length; i++)
      {
      uid = a_uids[i];
      if (rows[uid])
        {
        rows[uid].unread = false;
   rows[uid].read = true;
        rows[uid].classname = rows[uid].classname.replace(/\s*unread/, '');
        this.set_classname(rows[uid].obj, 'unread', false);
        if (rows[uid].icon)
          rows[uid].icon.src = this.env.deletedicon;
        }
      }
  };
  /*********************************************************/
  /*********           login form methods          *********/
@@ -2113,6 +2171,22 @@
    };
  // handler for mouse events on address-fields
  this.ksearch_onmousemove = function(li)
    {
    var last = document.getElementById('rcmksearchSelected');
    if (last)
      {
        last.removeAttribute('id');
        this.set_classname(last, 'selected', false);
      }
    li.setAttribute('id', 'rcmksearchSelected');
    this.set_classname(li, 'selected', true);
    this.ksearch_selected = li._rcm_id;
    };
  this.insert_recipient = function(id)
  {
    if (!this.env.contacts[id] || !this.ksearch_input)
@@ -2203,7 +2277,8 @@
        li = document.createElement('LI');
        li.innerHTML = a_results[i].replace(/</, '&lt;').replace(/>/, '&gt;');
        li.onmousedown = function(e){ ref.insert_recipient(this._rcm_id); ref.ksearch_pane.show(0); return rcube_event.cancel(e); };
        li.style.cursor = 'pointer';
        li.onmouseover = function(e){ ref.ksearch_onmousemove(this); };
       li.style.cursor = 'pointer';
        li._rcm_id = a_result_ids[i];
        ul.appendChild(li);
        }
@@ -2825,59 +2900,17 @@
  this.subscribe_folder = function(folder)
    {
    var form;
    if ((form = this.gui_objects.editform) && form.elements['_unsubscribed'])
      this.change_subscription('_unsubscribed', '_subscribed', 'subscribe');
    else if (folder)
      this.http_post('subscribe', '_mboxes='+urlencode(folder));
    if (folder)
      this.http_post('subscribe', '_mbox='+urlencode(folder));
    };
  this.unsubscribe_folder = function(folder)
    {
    var form;
    if ((form = this.gui_objects.editform) && form.elements['_subscribed'])
      this.change_subscription('_subscribed', '_unsubscribed', 'unsubscribe');
    else if (folder)
      this.http_post('unsubscribe', '_mboxes='+urlencode(folder));
    if (folder)
      this.http_post('unsubscribe', '_mbox='+urlencode(folder));
    };
    
  this.change_subscription = function(from, to, action)
    {
    var form;
    if (form = this.gui_objects.editform)
      {
      var a_folders = new Array();
      var list_from = form.elements[from];
      for (var i=0; list_from && i<list_from.options.length; i++)
        {
        if (list_from.options[i] && list_from.options[i].selected)
          {
          a_folders[a_folders.length] = list_from.options[i].value;
          list_from[i] = null;
          i--;
          }
        }
      // yes, we have some folders selected
      if (a_folders.length)
        {
        var list_to = form.elements[to];
        var index;
        for (var n=0; n<a_folders.length; n++)
          {
          index = list_to.options.length;
          list_to[index] = new Option(a_folders[n]);
          }
        this.http_post(action, '_mboxes='+urlencode(a_folders.join(',')));
        }
      }
    };
  // helper method to find a specific mailbox row ID
  this.get_folder_row_id = function(folder)
@@ -3274,16 +3307,13 @@
    this.set_page_buttons();
    };
  // replace content of quota display
  this.set_quota = function()
  this.set_quota = function(content)
    {
    if (this.gui_objects.quotadisplay &&
        this.gui_objects.quotadisplay.attributes.getNamedItem('display') &&
        this.gui_objects.quotadisplay.attributes.getNamedItem('id'))
      this.http_request('quotadisplay', '_display='+
      this.gui_objects.quotadisplay.attributes.getNamedItem('display').nodeValue+
      '&_id='+this.gui_objects.quotadisplay.attributes.getNamedItem('id').nodeValue, false);
     };
    if (this.gui_objects.quotadisplay && content)
      this.gui_objects.quotadisplay.innerHTML = content;
    };
  // update the mailboxlist
@@ -3328,7 +3358,12 @@
      }
    };
  // update parent's mailboxlist (from preview)
  this.set_unread_count_from_preview = function(mbox, count, set_title)
  {
    parent.rcmail.set_unread_count(mbox, count, set_title);
  }
  // add row to contacts list
  this.add_contact_row = function(cid, cols, select)
    {
@@ -3490,22 +3525,38 @@
    // process the response data according to the sent action
    switch (request_obj.__action)
      {
      case 'delete':
      case 'moveto':
        if (this.env.action=='show')
          this.command('list');
        else if (this.message_list)
          this.message_list.init();
        break;
      case 'purge':
      case 'expunge':
   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('show', 'reply', 'reply-all', 'forward', 'moveto', 'delete', 'mark', 'viewsource',
         'print', 'load-attachment', 'purge', 'expunge', 'select-all', 'select-none', 'sort', false);
     }
   break;
      case 'list':
        if (this.env.messagecount)
          this.enable_command('purge', (this.env.mailbox==this.env.trash_mailbox || this.env.mailbox==this.env.junk_mailbox));
        this.msglist_select(this.message_list);
   this.msglist_select(this.message_list);
      case 'expunge':
        this.enable_command('select-all', 'select-none', 'expunge', this.env.messagecount ? true : false);
        break;
      case 'check-recent':
      case 'getunread':
   this.enable_command('show', 'expunge', 'select-all', 'select-none', 'sort', (this.env.messagecount > 0));
   this.enable_command('purge', (this.env.messagecount && (this.env.mailbox==this.env.trash_mailbox || this.env.mailbox==this.env.junk_mailbox)));
   break;
      }
    request_obj.reset();