thomascube
2010-04-13 8e3a6039cfefb8f351d2696ebdcfa26cc5d4cef9
program/js/app.js
@@ -317,7 +317,7 @@
        
        if (this.env.address_sources && this.env.address_sources[this.env.source] && !this.env.address_sources[this.env.source].readonly) {
          this.enable_command('add', 'import', true);
          this.enable_command('add-group', this.env.address_sources[this.env.source].groups);
          this.enable_command('group-create', this.env.address_sources[this.env.source].groups);
        }
        
        if (this.env.cid)
@@ -525,7 +525,7 @@
            this.reset_qsearch();
          this.list_contacts(props);
          this.enable_command('add', 'import', (this.env.address_sources && !this.env.address_sources[props].readonly));
          this.enable_command('add', 'import', (this.env.address_sources && !this.env.address_sources[this.env.source].readonly));
          }
        break;
@@ -1001,8 +1001,16 @@
          this.list_contacts(this.env.source, this.env.group);
        break;
      case 'add-group':
      case 'group-create':
        this.add_contact_group(props)
        break;
      case 'group-rename':
        this.rename_contact_group();
        break;
      case 'group-delete':
        this.delete_contact_group();
        break;
      case 'import':
@@ -1265,6 +1273,9 @@
    if (this.preview_timer)
      clearTimeout(this.preview_timer);
    
    if (this.preview_read_timer)
      clearTimeout(this.preview_read_timer);
    // save folderlist and folders location/sizes for droptarget calculation in drag_move()
    if (this.gui_objects.folderlist && model)
      {
@@ -1430,6 +1441,9 @@
    if (this.preview_timer)
      clearTimeout(this.preview_timer);
    if (this.preview_read_timer)
      clearTimeout(this.preview_read_timer);
    var selected = list.get_single_selection() != null;
    // Hide certain command buttons when Drafts folder is selected
@@ -1456,6 +1470,9 @@
    {
      if (this.preview_timer)
        clearTimeout(this.preview_timer);
      if (this.preview_read_timer)
        clearTimeout(this.preview_read_timer);
    var uid = list.get_single_selection();
    if (uid && this.env.mailbox == this.env.drafts_mailbox)
@@ -1746,24 +1763,25 @@
    var url = '&_action='+action+'&_uid='+id+'&_mbox='+urlencode(this.env.mailbox)+add_url;
    if (action == 'preview' && String(target.location.href).indexOf(url) >= 0)
      this.show_contentframe(true);
    else
      {
    else {
      this.set_busy(true, 'loading');
      target.location.href = this.env.comm_path+url;
      // mark as read and change mbox unread counter
      if (action == 'preview' && this.message_list && this.message_list.rows[id] && this.message_list.rows[id].unread)
        {
        this.set_message(id, 'unread', false);
        this.update_thread_root(id, 'read');
        if (this.env.unread_counts[this.env.mailbox])
          {
          this.env.unread_counts[this.env.mailbox] -= 1;
          this.set_unread_count(this.env.mailbox, this.env.unread_counts[this.env.mailbox], this.env.mailbox == 'INBOX');
      if (action == 'preview' && this.message_list && this.message_list.rows[id] && this.message_list.rows[id].unread && this.env.preview_pane_mark_read >= 0) {
        this.preview_read_timer = window.setTimeout(function() {
          ref.set_message(id, 'unread', false);
          ref.update_thread_root(id, 'read');
          if (ref.env.unread_counts[ref.env.mailbox]) {
            ref.env.unread_counts[ref.env.mailbox] -= 1;
            ref.set_unread_count(ref.env.mailbox, ref.env.unread_counts[ref.env.mailbox], ref.env.mailbox == 'INBOX');
          }
        }
          if (ref.env.preview_pane_mark_read > 0)
            ref.http_post('mark', '_uid='+id+'&_flag=read');
        }, this.env.preview_pane_mark_read * 1000);
      }
    };
    }
  };
  this.show_contentframe = function(show)
    {
@@ -2312,9 +2330,9 @@
  // set a specific flag to one or more messages
  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();
    var a_uids = new Array(),
      r_uids = new Array(),
      selection = this.message_list ? this.message_list.get_selection() : new Array();
    if (uid)
      a_uids[0] = uid;
@@ -2346,7 +2364,7 @@
      }
    // nothing to do
    if (!r_uids.length)
    if (!r_uids.length && !this.select_all_mode)
      return;
    switch (flag)
@@ -2405,15 +2423,12 @@
    }
    
    var all_deleted = true;
    for (var i=0; i<a_uids.length; i++)
    for (var uid, i=0; i<a_uids.length; i++)
    {
      uid = a_uids[i];
      if (rows[uid]) {
        if (!rows[uid].deleted)
        {
          all_deleted = false;
          break;
        }
      if (rows[uid] && !rows[uid].deleted) {
        all_deleted = false;
        break;
      }
    }
    
@@ -3233,9 +3248,11 @@
    var insert = '';
    
    // insert all members of a group
    if (typeof this.env.contacts[id] == 'object' && this.env.contacts[id].members) {
      for (var i=0; i < this.env.contacts[id].members.length; i++)
        insert += this.env.contacts[id].members[i] + ', ';
    if (typeof this.env.contacts[id] == 'object' && this.env.contacts[id].id) {
      insert += this.env.contacts[id].name + ', ';
      this.group2expand = $.extend({}, this.env.contacts[id]);
      this.group2expand.input = this.ksearch_input;
      this.http_request('group-expand', '_source='+urlencode(this.env.contacts[id].source)+'&_gid='+urlencode(this.env.contacts[id].id), false);
    }
    else if (typeof this.env.contacts[id] == 'string')
      insert = this.env.contacts[id] + ', ';
@@ -3246,6 +3263,14 @@
    cpos = p+insert.length;
    if (this.ksearch_input.setSelectionRange)
      this.ksearch_input.setSelectionRange(cpos, cpos);
  };
  this.replace_group_recipients = function(id, recipients)
  {
    if (this.group2expand && this.group2expand.id == id) {
      this.group2expand.input.value = this.group2expand.input.value.replace(this.group2expand.name, recipients);
      this.group2expand = null;
    }
  };
  // address search processor
@@ -3281,7 +3306,7 @@
    if (old_value && old_value.length && this.env.contacts && !this.env.contacts.length && q.indexOf(old_value) == 0)
      return;
    
    this.display_message(this.get_label('searching'), 'loading', true);
    this.display_message(this.get_label('searching'), 'loading', false);
    this.http_post('autocomplete', '_search='+urlencode(q));
  };
@@ -3403,8 +3428,7 @@
    // currently all groups belong to the local address book
    if (group)
      src = 0;
    if (!src)
    else if (!src)
      src = this.env.source;
    
    if (page && this.current_page == page && src == this.env.source && group == this.env.group)
@@ -3419,8 +3443,7 @@
    else if (group != this.env.group)
      page = this.env.current_page = 1;
    this.select_folder(src, this.env.source);
    this.select_folder(group, this.env.group, 'rcmliG');
    this.select_folder((group ? 'G'+group : src), (this.env.group ? 'G'+this.env.group : this.env.source));
    
    this.env.source = src;
    this.env.group = group;
@@ -3492,7 +3515,7 @@
    if (action && (cid || action=='add') && !this.drag_active)
      {
      this.set_busy(true);
      target.location.href = this.env.comm_path+'&_action='+action+'&_source='+urlencode(this.env.source)+'&_cid='+urlencode(cid) + add_url;
      target.location.href = this.env.comm_path+'&_action='+action+'&_source='+urlencode(this.env.source)+'&_gid='+urlencode(this.env.group)+'&_cid='+urlencode(cid) + add_url;
      }
    return true;
    };
@@ -3504,7 +3527,7 @@
      cid = this.contact_list.get_selection().join(',');
    if (to.type == 'group')
      this.http_post('add2group', '_cid='+urlencode(cid)+'&_source='+urlencode(this.env.source)+'&_gid='+urlencode(to.id));
      this.http_post('group-addmembers', '_cid='+urlencode(cid)+'&_source='+urlencode(this.env.source)+'&_gid='+urlencode(to.id));
    else if (to.id != this.env.source && cid && this.env.address_sources[to.id] && !this.env.address_sources[to.id].readonly)
      this.http_post('copy', '_cid='+urlencode(cid)+'&_source='+urlencode(this.env.source)+'&_to='+urlencode(to.id));
    };
@@ -3543,7 +3566,7 @@
    // send request to server
    if (this.env.group)
      this.http_post('removefromgroup', '_cid='+urlencode(a_cids.join(','))+'&_source='+urlencode(this.env.source)+'&_gid='+urlencode(this.env.group)+qs);
      this.http_post('group-delmembers', '_cid='+urlencode(a_cids.join(','))+'&_source='+urlencode(this.env.source)+'&_gid='+urlencode(this.env.group)+qs);
    else
      this.http_post('delete', '_cid='+urlencode(a_cids.join(','))+'&_source='+urlencode(this.env.source)+'&_from='+(this.env.action ? this.env.action : '')+qs);
      
@@ -3621,6 +3644,50 @@
    this.name_input.select();
  };
  
  this.rename_contact_group = function()
  {
    if (!this.env.group || !this.gui_objects.folderlist)
      return;
    if (!this.name_input) {
      this.enable_command('list', 'listgroup', false);
      this.name_input = document.createElement('input');
      this.name_input.type = 'text';
      this.name_input.value = this.env.contactgroups['G'+this.env.group].name;
      this.name_input.onkeypress = function(e){ return rcmail.add_input_keypress(e); };
      this.env.group_renaming = true;
      var link, li = this.get_folder_li(this.env.group, 'rcmliG');
      if (li && (link = li.firstChild)) {
        $(link).hide();
        li.insertBefore(this.name_input, link);
      }
    }
    this.name_input.select();
  };
  this.delete_contact_group = function()
  {
    if (this.env.group)
      this.http_post('group-delete', '_source='+urlencode(this.env.source)+'&_gid='+urlencode(this.env.group), true);
  };
  // callback from server upon group-delete command
  this.remove_group_item = function(id)
  {
    var li, key = 'G'+id;
    if ((li = this.get_folder_li(key))) {
      this.triggerEvent('removegroup', { id:id, li:li });
      li.parentNode.removeChild(li);
      delete this.env.contactfolders[key];
      delete this.env.contactgroups[key];
    }
    this.list_contacts(null, 0);
  };
  // handler for keyboard events on the input field
  this.add_input_keypress = function(e)
  {
@@ -3632,7 +3699,10 @@
      
      if (newname) {
        this.set_busy(true, 'loading');
        this.http_post('create-group', '_source='+urlencode(this.env.source)+'&_name='+urlencode(newname), true);
        if (this.env.group_renaming)
          this.http_post('group-rename', '_source='+urlencode(this.env.source)+'&_gid='+urlencode(this.env.group)+'&_name='+urlencode(newname), true);
        else
          this.http_post('group-create', '_source='+urlencode(this.env.source)+'&_name='+urlencode(newname), true);
      }
      return false;
    }
@@ -3646,16 +3716,48 @@
  this.reset_add_input = function()
  {
    if (this.name_input) {
      if (this.env.group_renaming) {
        var li = this.name_input.parentNode;
        $(li.lastChild).show();
        this.env.group_renaming = false;
      }
      this.name_input.parentNode.removeChild(this.name_input);
      this.name_input = null;
    }
    this.enable_command('list', 'listgroup', true);
  };
  
  // callback for creating a new contact group
  this.insert_contact_group = function(prop)
  {
    this.reset_add_input();
  }
    prop.type = 'group';
    var key = 'G'+prop.id;
    this.env.contactfolders[key] = this.env.contactgroups[key] = prop;
    var link = $('<a>').attr('href', '#').attr('onclick', "return rcmail.command('listgroup','"+prop.id+"',this)").html(prop.name);
    var li = $('<li>').attr('id', 'rcmli'+key).addClass('contactgroup').append(link);
    $(this.gui_objects.folderlist).append(li);
    this.triggerEvent('insertgroup', { id:prop.id, name:prop.name, li:li[0] });
  };
  // callback for renaming a contact group
  this.update_contact_group = function(id, name)
  {
    this.reset_add_input();
    var key = 'G'+id;
    var link, li = this.get_folder_li(key);
    if (li && (link = li.firstChild) && link.tagName.toLowerCase() == 'a')
      link.innerHTML = name;
    this.env.contactfolders[key].name = this.env.contactgroups[key].name = name;
    this.triggerEvent('updategroup', { id:id, name:name, li:li[0] });
  };
  /*********************************************************/
@@ -4568,6 +4670,13 @@
      addrbook_show_images.disabled = !checkbox.checked;
    }
  this.toggle_preview_pane = function(checkbox)
    {
    var preview_pane_mark_read;
    if (preview_pane_mark_read = document.getElementById('rcmfd_preview_pane_mark_read'))
      preview_pane_mark_read.disabled = !checkbox.checked;
    }
  // display fetched raw headers
  this.set_headers = function(content)
  {
@@ -4825,8 +4934,8 @@
          this.enable_command('export', (this.contact_list && this.contact_list.rowcount > 0));
          
          if (response.action == 'list') {
            this.enable_command('add-group', this.env.address_sources[this.env.source].groups);
            // disabeld for now: this.enable_command('rename-group', 'delete-group', this.env.address_sources[this.env.source].groups && this.env.group);
            this.enable_command('group-create', this.env.address_sources[this.env.source].groups);
            this.enable_command('group-rename', 'group-delete', this.env.address_sources[this.env.source].groups && this.env.group);
            this.triggerEvent('listupdate', { folder:this.env.source, rowcount:this.contact_list.rowcount });
          }
        }