thomascube
2008-09-15 f645ce169e11339d45cbc0b5b4cf6154346fd4c7
program/js/app.js
@@ -122,6 +122,9 @@
    // enable general commands
    this.enable_command('logout', 'mail', 'addressbook', 'settings', true);
    
    if (this.env.permaurl)
      this.enable_command('permaurl', true);
    switch (this.task)
      {
      case 'mail':
@@ -159,7 +162,7 @@
        
        if (this.env.action=='show' || this.env.action=='preview')
          {
          this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'delete', 'mark', 'viewsource', 'print', 'load-attachment', true);
          this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'delete', 'mark', 'viewsource', 'print', 'load-attachment', 'load-headers', true);
          if (this.env.next_uid)
            {
            this.enable_command('nextmessage', true);
@@ -292,8 +295,10 @@
      case 'settings':
        this.enable_command('preferences', 'identities', 'save', 'folders', true);
        
        if (this.env.action=='identities' || this.env.action=='edit-identity' || this.env.action=='add-identity')
          this.enable_command('edit', 'add', 'delete', true);
        if (this.env.action=='identities' || this.env.action=='edit-identity' || this.env.action=='add-identity') {
          this.enable_command('add', 'delete', this.env.multiple_identities);
          this.enable_command('edit', true);
        }
        if (this.env.action=='edit-identity' || this.env.action=='add-identity')
          this.enable_command('save', true);
@@ -510,7 +515,6 @@
        return false;
     }
    // process command
    switch (command)
      {
@@ -530,6 +534,12 @@
        this.switch_task(command);
        break;
      case 'permaurl':
        if (obj && obj.href && obj.target)
          return true;
        else if (this.env.permaurl)
          parent.location.href = this.env.permaurl;
          break;
      // misc list commands
      case 'list':
@@ -551,6 +561,11 @@
          this.list_contacts(props);
          this.enable_command('add', (this.env.address_sources && !this.env.address_sources[props].readonly));
          }
        break;
      case 'load-headers':
        this.load_headers(obj);
        break;
@@ -3635,13 +3650,21 @@
  this.toggle_editor = function(checkbox, textAreaId)
    {
    var ischecked = checkbox.checked;
    var composeElement = document.getElementById(textAreaId);
    if (ischecked)
      {
        tinyMCE.execCommand('mceAddControl', true, textAreaId);
      var existingPlainText = composeElement.value;
      var htmlText = "<pre>" + existingPlainText + "</pre>";
      composeElement.value = htmlText;
      tinyMCE.execCommand('mceAddControl', true, textAreaId);
      }
    else
      {
        tinyMCE.execCommand('mceRemoveControl', true, textAreaId);
      var thisMCE = tinyMCE.get(textAreaId);
      var existingHtml = thisMCE.getContent();
      this.html2plain(existingHtml, textAreaId);
      tinyMCE.execCommand('mceRemoveControl', true, textAreaId);
      }
    };
@@ -3653,6 +3676,81 @@
      addrbook_show_images.disabled = !checkbox.checked;
    }
  // display fetched raw headers
  this.set_headers = function(content)
    {
    if (this.gui_objects.all_headers_row && this.gui_objects.all_headers_box && content)
      {
      var box = this.gui_objects.all_headers_box;
      box.innerHTML = content;
      box.style.display = 'block';
      if (this.env.framed && parent.rcmail)
   parent.rcmail.set_busy(false);
      else
        this.set_busy(false);
      }
    };
  // display all-headers row and fetch raw message headers
  this.load_headers = function(elem)
    {
    if (!this.gui_objects.all_headers_row || !this.gui_objects.all_headers_box || !this.env.uid)
      return;
    this.set_classname(elem, 'show-headers', false);
    this.set_classname(elem, 'hide-headers', true);
    this.gui_objects.all_headers_row.style.display = bw.ie ? 'block' : 'table-row';
    elem.onclick = function() { rcmail.hide_headers(elem); }
    // fetch headers only once
    if (!this.gui_objects.all_headers_box.innerHTML)
      {
      this.display_message(this.get_label('loading'), 'loading', true);
      this.http_post('headers', '_uid='+this.env.uid);
      }
    }
  // hide all-headers row
  this.hide_headers = function(elem)
    {
    if (!this.gui_objects.all_headers_row || !this.gui_objects.all_headers_box)
      return;
    this.set_classname(elem, 'hide-headers', false);
    this.set_classname(elem, 'show-headers', true);
    this.gui_objects.all_headers_row.style.display = 'none';
    elem.onclick = function() { rcmail.load_headers(elem); }
    }
  /********************************************************/
  /*********  html to text conversion functions   *********/
  /********************************************************/
  this.html2plain = function(htmlText, id)
    {
    var http_request = new rcube_http_request();
    var url = this.env.bin_path+'html2text.php';
    var rcmail = this;
    this.set_busy(true, 'converting');
    console.log('HTTP POST: '+url);
    http_request.onerror = function(o) { rcmail.http_error(o); };
    http_request.oncomplete = function(o) { rcmail.set_text_value(o, id); };
    http_request.POST(url, htmlText, 'application/octet-stream');
    }
  this.set_text_value = function(httpRequest, id)
    {
    this.set_busy(false);
    document.getElementById(id).value = httpRequest.get_text();
    console.log(httpRequest.get_text());
    }
  /********************************************************/
@@ -3760,7 +3858,7 @@
    }
    if (request_obj.__lock)
        this.set_busy(false);
      this.set_busy(false);
    console.log(request_obj.get_text());