thomascube
2008-02-05 a02d486cc8988ad367cd635f4929ce707ec6f542
program/js/app.js
@@ -149,6 +149,9 @@
        // enable mail commands
        this.enable_command('list', 'checkmail', 'compose', 'add-contact', 'search', 'reset-search', true);
        if (this.env.search_text != null && document.getElementById('quicksearchbox') != null)
          document.getElementById('quicksearchbox').value = this.env.search_text;
        
        if (this.env.action=='show' || this.env.action=='preview')
          {
@@ -203,8 +206,11 @@
        this.set_page_buttons();
        // focus this window
        window.focus();
        // focus main window
        if (this.env.framed && window.parent)
          window.parent.focus();
        else
          window.focus();
        // init message compose form
        if (this.env.action=='compose')
@@ -219,6 +225,16 @@
        {
          this.gui_objects.folderlist = this.gui_objects.mailboxlist;
          this.http_request('getunread', '');
        }
        // ask user to send MDN
        if (this.env.mdn_request && this.env.uid)
        {
          var mdnurl = '_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox);
          if (confirm(this.get_label('mdnrequest')))
            this.http_post('sendmdn', mdnurl);
          else
            this.http_post('mark', mdnurl+'&_flag=mdnsent');
        }
        break;
@@ -285,6 +301,9 @@
          if (this.env.iid)
            this.identity_list.highlight_row(this.env.iid);
          }
        if (this.gui_objects.subscriptionlist)
          this.init_subscription_list();
        break;
@@ -481,7 +500,7 @@
      case 'list':
        if (this.task=='mail')
          {
          if (this.env.search_request<0 || (this.env.search_request && props != this.env.mailbox))
          if (this.env.search_request<0 || (props != '' && (this.env.search_request && props != this.env.mailbox)))
            this.reset_qsearch();
          this.list_mailbox(props);
@@ -814,7 +833,7 @@
        if (!this.check_compose_input())
          break;
        // Reset the auto-save timer
        self.clearTimeout(this.save_timer);
@@ -935,8 +954,7 @@
        break;
      case 'delete-folder':
        if (confirm(this.get_label('deletefolderconfirm')))
          this.delete_folder(props);
        this.delete_folder(props);
        break;
      }
@@ -1138,6 +1156,8 @@
      this.command('show');
    else if (list.key_pressed == list.DELETE_KEY)
      this.command('delete');
    else
      list.shiftkey = false;
    };
@@ -1157,6 +1177,8 @@
      return (id != this.env.mailbox);
    else if (this.task == 'addressbook')
      return (id != this.env.source && this.env.address_sources[id] && !this.env.address_sources[id].readonly);
    else if (this.task == 'settings')
      return (id != this.env.folder);
  };
@@ -1179,6 +1201,10 @@
    if (safe)
      add_url = '&_safe=1';
    // also send search request to get the right messages
    if (this.env.search_request)
      add_url += '&_search='+this.env.search_request;
    if (id)
      {
@@ -1435,10 +1461,8 @@
        {
        id = selection[n];
        a_uids[a_uids.length] = id;
        this.message_list.remove_row(id);
        this.message_list.remove_row(id, (n == selection.length-1));
        }
      this.message_list.select_next();
      }
      
    // also send search request to get the right messages 
@@ -1667,7 +1691,7 @@
    var input_message = rcube_find_object('_message');
    // check for empty recipient
    if (input_to && !rcube_check_email(input_to.value, true))
    if (input_to && !rcube_check_email(input_to.value.replace(/^\s+/, '').replace(/[\s,;]+$/, ''), true))
      {
      alert(this.get_label('norecipientwarning'));
      input_to.focus();
@@ -1854,8 +1878,11 @@
      }
      
    // clear upload form
    if (!a && this.gui_objects.attachmentform && this.gui_objects.attachmentform!=this.gui_objects.messageform)
      this.gui_objects.attachmentform.reset();
   try {
      if (!a && this.gui_objects.attachmentform != this.gui_objects.messageform)
         this.gui_objects.attachmentform.reset();
   }
   catch(e){}  // ignore errors
    
    return true;  
    };
@@ -1864,7 +1891,6 @@
  // upload attachment file
  this.upload_file = function(form)
    {
    if (!form)
      return false;
      
@@ -2362,7 +2388,7 @@
        {
        id = selection[n];
        a_cids[a_cids.length] = id;
        this.contact_list.remove_row(id);
        this.contact_list.remove_row(id, (n == selection.length-1));
        }
      // hide content frame if we delete the currently displayed contact
@@ -2396,6 +2422,26 @@
  /*********************************************************/
  /*********        user settings methods          *********/
  /*********************************************************/
  this.init_subscription_list = function()
    {
    var p = this;
    this.subscription_list = new rcube_list_widget(this.gui_objects.subscriptionlist, {multiselect:false, draggable:true, keyboard:false, toggleselect:true});
    this.subscription_list.addEventListener('select', function(o){ p.subscription_select(o); });
    this.subscription_list.addEventListener('dragstart', function(o){ p.drag_active = true; });
    this.subscription_list.addEventListener('dragend', function(o){ p.subscription_move_folder(o); });
    this.subscription_list.row_init = function (row)
      {
      var anchors = row.obj.getElementsByTagName('A');
      if (anchors[0])
        anchors[0].onclick = function() { p.rename_folder(row.id); return false; };
      if (anchors[1])
        anchors[1].onclick = function() { p.delete_folder(row.id); return false; };
      row.obj.onmouseover = function() { p.focus_subscription(row.id); };
      row.obj.onmouseout = function() { p.unfocus_subscription(row.id); };
      }
    this.subscription_list.init();
    }
  this.identity_select = function(list)
    {
@@ -2444,6 +2490,72 @@
    };
  this.focus_subscription = function(id)
    {
    var row, folder;
    var reg = RegExp('['+RegExp.escape(this.env.delimiter)+']?[^'+RegExp.escape(this.env.delimiter)+']+$');
    if (this.drag_active && (row = document.getElementById(id)))
      if (this.env.subscriptionrows[id] &&
          (folder = this.env.subscriptionrows[id][0]))
        {
        if (this.check_droptarget(folder) &&
            (folder != this.env.folder.replace(reg, '')) &&
            (!folder.match(new RegExp('^'+RegExp.escape(this.env.folder+this.env.delimiter)))))
          {
          this.set_env('dstfolder', folder);
          this.set_classname(row, 'droptarget', true);
          }
        }
      else if (this.env.folder.match(new RegExp(RegExp.escape(this.env.delimiter))))
        {
        this.set_env('dstfolder', this.env.delimiter);
        this.set_classname(this.subscription_list.frame, 'droptarget', true);
        }
    }
  this.unfocus_subscription = function(id)
    {
      var row;
      this.set_env('dstfolder', null);
      if (this.env.subscriptionrows[id] &&
          (row = document.getElementById(id)))
        this.set_classname(row, 'droptarget', false);
      else
        this.set_classname(this.subscription_list.frame, 'droptarget', false);
    }
  this.subscription_select = function(list)
    {
    var id, folder;
    if ((id = list.get_single_selection()) &&
        this.env.subscriptionrows['rcmrow'+id] &&
        (folder = this.env.subscriptionrows['rcmrow'+id][0]) &&
        (find_in_array(this.env.defaultfolders, folder)!=0))
      this.set_env('folder', folder);
    else
      this.set_env('folder', null);
    };
  this.subscription_move_folder = function(list)
    {
    var reg = RegExp('['+RegExp.escape(this.env.delimiter)+']?[^'+RegExp.escape(this.env.delimiter)+']+$');
    if (this.env.folder && this.env.dstfolder && (this.env.dstfolder != this.env.folder) &&
        (this.env.dstfolder != this.env.folder.replace(reg, '')))
      {
      var reg = new RegExp('[^'+RegExp.escape(this.env.delimiter)+']*['+RegExp.escape(this.env.delimiter)+']', 'g');
      var basename = this.env.folder.replace(reg, '');
      var newname = this.env.dstfolder==this.env.delimiter ? basename : this.env.dstfolder+this.env.delimiter+basename;
      this.http_post('rename-folder', '_folder_oldname='+urlencode(this.env.folder)+'&_folder_newname='+urlencode(newname));
      }
    this.drag_active = false;
    this.unfocus_subscription(this.get_folder_row_id(this.env.dstfolder));
    };
  // tell server to create and subscribe a new mailbox
  this.create_folder = function(name)
    {
@@ -2453,6 +2565,8 @@
    var form;
    if ((form = this.gui_objects.editform) && form.elements['_folder_name'])
      name = form.elements['_folder_name'].value;
    if (this.env.folder)
      name = this.env.folder+this.env.delimiter+name;
    if (name)
      this.http_post('create-folder', '_name='+urlencode(name), true);
@@ -2461,33 +2575,11 @@
    };
  // entry point for folder renaming
  this.rename_folder = function(props)
    {
    var form, oldname, newname;
    // rename a specific mailbox
    if (props)
      this.edit_foldername(props);
    // use a dropdown and input field (old behavior)
    else if ((form = this.gui_objects.editform) && form.elements['_folder_oldname'] && form.elements['_folder_newname'])
      {
      oldname = form.elements['_folder_oldname'].value;
      newname = form.elements['_folder_newname'].value;
      }
    if (oldname && newname)
      this.http_post('rename-folder', '_folder_oldname='+urlencode(oldname)+'&_folder_newname='+urlencode(newname));
    };
  // start editing the mailbox name.
  // start renaming the mailbox name.
  // this will replace the name string with an input field
  this.edit_foldername = function(folder)
  this.rename_folder = function(id)
    {
    var temp, row, form;
    var id = this.get_folder_row_id(folder);
    // reset current renaming
  if (temp = this.edit_folder)
@@ -2497,11 +2589,15 @@
      return;
    }
    if (id && (row = document.getElementById(id)))
    if (id && this.env.subscriptionrows[id] && (row = document.getElementById(id)))
      {
      var reg = new RegExp('.*['+RegExp.escape(this.env.delimiter)+']');
      this.name_input = document.createElement('INPUT');
      this.name_input.value = this.env.subscriptionrows[id][1];
      this.name_input.value = this.env.subscriptionrows[id][1].replace(reg, '');
      this.name_input.style.width = '100%';
      reg = new RegExp('['+RegExp.escape(this.env.delimiter)+']?[^'+RegExp.escape(this.env.delimiter)+']+$');
      this.name_input.__parent = this.env.subscriptionrows[id][0].replace(reg, '');
      this.name_input.onkeypress = function(e){ rcmail.name_input_keypress(e); };
      
      row.cells[0].replaceChild(this.name_input, row.cells[0].firstChild);
@@ -2519,7 +2615,10 @@
    {
    var cell = this.name_input ? this.name_input.parentNode : null;
    if (cell && this.edit_folder && this.env.subscriptionrows[this.edit_folder])
      cell.innerHTML = this.env.subscriptionrows[this.edit_folder][1];
      {
      var reg = new RegExp('[^'+RegExp.escape(this.env.delimiter)+']*['+RegExp.escape(this.env.delimiter)+']', 'g');
      cell.innerHTML = this.env.subscriptionrows[this.edit_folder][1].replace(reg, '&nbsp;&nbsp;&nbsp;&nbsp;');
      }
      
    this.edit_folder = null;
    };
@@ -2535,7 +2634,11 @@
      {
      var newname = this.name_input ? this.name_input.value : null;
      if (this.edit_folder && newname)
        {
        if (this.name_input.__parent)
          newname = this.name_input.__parent + this.env.delimiter + newname;
        this.http_post('rename-folder', '_folder_oldname='+urlencode(this.env.subscriptionrows[this.edit_folder][0])+'&_folder_newname='+urlencode(newname));
        }
      }
    // escape
    else if (key==27)
@@ -2544,13 +2647,18 @@
  // delete a specific mailbox with all its messages
  this.delete_folder = function(folder)
  this.delete_folder = function(id)
    {
  if (this.edit_folder)
    this.reset_folder_rename();
    if (folder)
    var folder = this.env.subscriptionrows[id][0];
    if (this.edit_folder)
      this.reset_folder_rename();
    if (folder && confirm(this.get_label('deletefolderconfirm')))
      {
      this.http_post('delete-folder', '_mboxes='+urlencode(folder));
      this.set_env('folder', null);
      }
    };
@@ -2567,7 +2675,8 @@
    var refrow, form;
    var tbody = this.gui_objects.subscriptionlist.tBodies[0];
    var id = replace && replace.id ? replace.id : tbody.childNodes.length+1;
    var id = replace && replace.id ? replace.id : 'rcmrow'+(tbody.childNodes.length+1);
    var selection = this.subscription_list.get_single_selection();
    if (!id || !(refrow = document.getElementById(refid)))
      {
@@ -2578,7 +2687,7 @@
      {
      // clone a table row if there are existing rows
      var row = this.clone_table_row(refrow);
      row.id = 'rcmrow'+id;
      row.id = id;
      if (replace)
        tbody.replaceChild(row, replace);
      else
@@ -2596,11 +2705,6 @@
      row.cells[1].firstChild.checked = true;
      }
       
    if (row.cells[2] && row.cells[2].firstChild.tagName=='A')
      row.cells[2].firstChild.onclick = new Function(this.ref+".command('rename-folder','"+name.replace('\'','\\\'')+"')");
    if (row.cells[3] && row.cells[3].firstChild.tagName=='A')
      row.cells[3].firstChild.onclick = new Function(this.ref+".command('delete-folder','"+name.replace('\'','\\\'')+"')");
    // add new folder to rename-folder list and clear input field
    if (!replace && (form = this.gui_objects.editform))
      {
@@ -2611,6 +2715,12 @@
      }
    this.sort_subscription_list();
    this.init_subscription_list();
    if (selection && document.getElementById('rcmrow'+selection))
      this.subscription_list.select_row(selection);
    if (document.getElementById(id).scrollIntoView)
      document.getElementById(id).scrollIntoView();
    };
@@ -2622,7 +2732,6 @@
    
    // replace an existing table row (if found)
    this.add_folder_row(newfolder, display_name, row);
    this.env.subscriptionrows[id] = null;
    
    // rename folder in rename-folder dropdown
    var form, elm;
@@ -2765,19 +2874,19 @@
    var index = new Array();
    var tbody = this.gui_objects.subscriptionlist.tBodies[0];
    var swapped = false;
    for (var i = 0; i<(tbody.childNodes.length-1); i++)
    for (var i = 0; i<tbody.childNodes.length; i++)
      if (this.env.subscriptionrows[tbody.childNodes[i].id]!=null)
        index.push(i);
    for (i = 0; i<(index.length-1); i++)
      {
      if (this.env.subscriptionrows[tbody.childNodes[index[i]].id][0]>
          this.env.subscriptionrows[tbody.childNodes[index[i+1]].id][0])
      var one = tbody.childNodes[index[i]];
      var two = tbody.childNodes[index[i+1]];
      if (this.env.subscriptionrows[one.id][0].toLowerCase()>
          this.env.subscriptionrows[two.id][0].toLowerCase())
        {
        var swap = tbody.replaceChild(tbody.childNodes[index[i]], tbody.childNodes[index[i+1]]);
        if (typeof(tbody.childNodes[index[i]]) != 'undefined')
          tbody.insertBefore(swap, tbody.childNodes[index[i]])
        else
          tbody.appendChild(swap);
        var swap = one.cloneNode(true);
        tbody.replaceChild(swap, two);
        tbody.replaceChild(two, one);
        swapped = true;
        }
      }
@@ -3350,6 +3459,7 @@
      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);
      case 'expunge':
        this.enable_command('select-all', 'select-none', 'expunge', this.env.messagecount ? true : false);
@@ -3385,13 +3495,10 @@
  this.check_for_recent = function()
    {
    if (this.busy)
      {
      this.send_keep_alive();
      return;
      }
    this.set_busy(true, 'checkingmail');
    this.http_request('check-recent', '_t='+(new Date().getTime()), true);
    this.http_request('check-recent', (this.env.search_request ? '_search='+this.env.search_request+'&' : '') + '_t='+(new Date().getTime()), true);
    };