home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / messenger.jar / content / messenger / messengercompose / askSendFormat.js < prev    next >
Text File  |  2001-02-14  |  7KB  |  197 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. var msgCompSendFormat = Components.interfaces.nsIMsgCompSendFormat;
  3. var msgCompConvertible = Components.interfaces.nsIMsgCompConvertible;
  4. var param = null;
  5.  
  6. /* There is 3 preferences that let you customize the behavior of this dialog
  7.  
  8. 1. pref("mail.asksendformat.default", 1); //1=plaintext, 2=html, 3=both
  9.    This define the default action selected when the dialog open. This could be overwritten by the preference
  10.    mail.asksendformat.recommended_as_default (described here after)
  11.  
  12.  
  13. 2. pref("mail.asksendformat.recommended_as_default", true);
  14.    If you set this preference to true and we have a recommended action, this action will be selected by default.
  15.    In this case, we ignore the preference mail.asksendformat.default
  16.  
  17.  
  18. 3. pref("mail.asksendformat.display_recommendation", true);
  19.    When this preference is set to false, the recommended action label will not be displayed next to the action
  20.    radio button. However, the default action might be change to the recommended one if the preference
  21.    mail.asksendformat.recommended_as_default is set.
  22. */
  23.  
  24. var defaultAction = msgCompSendFormat.PlainText;
  25. var recommended_as_default = true;
  26. var display_recommendation = true;
  27.  
  28. var prefs = Components.classes["@mozilla.org/preferences;1"].getService();
  29. if (prefs) {
  30.   prefs = prefs.QueryInterface(Components.interfaces.nsIPref);
  31.   if (prefs) {
  32.     try {
  33.       defaultAction = prefs.GetIntPref("mail.asksendformat.default");
  34.     } catch (ex) {}
  35.     try {
  36.       recommended_as_default = prefs.GetBoolPref("mail.asksendformat.recommended_as_default");
  37.     } catch (ex) {}
  38.     try {
  39.       display_recommendation = prefs.GetBoolPref("mail.asksendformat.display_recommendation");
  40.     } catch (ex) {}
  41.   }
  42. }
  43.  
  44. function Startup()
  45. {
  46.   if (window.arguments && window.arguments[0])
  47.   {    
  48.     var defaultElement;
  49.     switch (defaultAction)
  50.     {
  51.       case msgCompSendFormat.HTML:  defaultElement = document.getElementById("SendHtmlOnly");           break
  52.       case msgCompSendFormat.Both:  defaultElement = document.getElementById("SendPlainTextAndHtml");   break
  53.       default:                      defaultElement = document.getElementById("SendPlainTextOnly");      break
  54.     }     
  55.  
  56.     param = window.arguments[0];
  57.     param.abort = true;    //if the user hit the close box, we will abort.
  58.     if (param.action)
  59.     {
  60.       // Set the question label
  61.       var labeldeck = document.getElementById("mailSendFormatExplanation");
  62.       var icon = document.getElementById("convertDefault");
  63.       switch (param.convertible)
  64.       {
  65.         case msgCompConvertible.Plain:
  66.           // We shouldn't be here at all
  67.           labeldeck.setAttribute("index", 1);
  68.           // No icon
  69.           break;
  70.         case msgCompConvertible.Yes:
  71.           labeldeck.setAttribute("index", 1);
  72.           icon.setAttribute("id", "convertYes");
  73.           break;
  74.         case msgCompConvertible.Altering:
  75.           labeldeck.setAttribute("index", 2);
  76.           icon.setAttribute("id", "convertAltering");
  77.           break;
  78.         case msgCompConvertible.No:
  79.           labeldeck.setAttribute("index", 3);
  80.           icon.setAttribute("id", "convertNo");
  81.           break;
  82.       }
  83.  
  84.       // Set the default radio array value and recommendation
  85.       var group = document.getElementById("mailDefaultHTMLAction");
  86.       var element;
  87.       var recommlabels = document.getElementById("hiddenLabels");
  88.       var label;
  89.       var haveRecommendation = false;
  90.       switch (param.action)
  91.       {
  92.         case msgCompSendFormat.AskUser:
  93.           //haveRecommendation = false;
  94.           break;
  95.         case msgCompSendFormat.PlainText:
  96.           element = document.getElementById("SendPlainTextOnly");
  97.           //label = recommlabels.getAttribute("plainTextOnlyRecommendedLabel");
  98.           label = document.getElementById("plainTextOnlyRecommended");
  99.                // elements for "recommended" are a workaround for bug 49623
  100.           haveRecommendation = true;
  101.           break;
  102.         case msgCompSendFormat.Both:
  103.           element = document.getElementById("SendPlainTextAndHtml");
  104.           //label = recommlabels.getAttribute("plainTextAndHtmlRecommendedLabel");
  105.           label = document.getElementById("plainTextAndHtmlRecommended");
  106.           haveRecommendation = true;
  107.           break;
  108.         case msgCompSendFormat.HTML:
  109.           element = document.getElementById("SendHtmlOnly");
  110.           //label = recommlabels.getAttribute("htmlOnlyRecommendedLabel");
  111.           label = document.getElementById("htmlOnlyRecommended");
  112.           haveRecommendation = true;
  113.           break;
  114.       }
  115.       if (haveRecommendation)
  116.       {
  117.         if (display_recommendation)
  118.         {
  119.           /*
  120.           dump(element.getAttribute("value"));
  121.           element.setAttribute("value", label);
  122.           element.setAttribute("value", "foo");
  123.           dump(element.getAttribute("value"));
  124.           */
  125.           
  126.           label.removeAttribute("hidden");
  127.         }
  128.         if (recommended_as_default)
  129.         {
  130.           group.selectedItem = element;
  131.           group.data = element.data;
  132.         }
  133.       }
  134.       if (!haveRecommendation || !recommended_as_default)
  135.       {
  136.         group.selectedItem = defaultElement;
  137.         group.data = defaultElement.data;
  138.       }
  139.  
  140.       //change the button label
  141.       var buttonlabels = document.getElementById("okCancelButtons");
  142.       element = document.getElementById("ok");
  143.       element.setAttribute("value", buttonlabels.getAttribute("button1Label"));
  144.       element = document.getElementById("cancel");
  145.       element.setAttribute("value", buttonlabels.getAttribute("button2Label"));
  146. /*
  147.       element = document.getElementById("Button2");
  148.       element.setAttribute("value", buttonlabels.getAttribute("button3Label"));
  149.       element.removeAttribute("hidden");
  150.       element.setAttribute("disabled", "true");
  151.       element = document.getElementById("Button3");
  152.       element.setAttribute("value", buttonlabels.getAttribute("button4Label"));
  153.       element.removeAttribute("hidden");
  154.       element.setAttribute("disabled", "true");
  155. */        
  156.       //set buttons action
  157.       doSetOKCancel(Send, Cancel, Recipients, Help);
  158.     }
  159.   }
  160.   else 
  161.   {
  162.     dump("error, no return object registered\n");
  163.   }
  164. }
  165.  
  166. function Send()
  167. {
  168.   if (param)
  169.   {
  170.     switch (document.getElementById("mailDefaultHTMLAction").data)
  171.     {
  172.       case "0": param.action = msgCompSendFormat.Both;    break;
  173.       case "1": param.action = msgCompSendFormat.PlainText;  break;
  174.       case "2": param.action = msgCompSendFormat.HTML;    break;
  175.     }
  176.     param.abort = false;
  177.   }
  178.   return true;
  179. }
  180.  
  181. function Cancel()
  182. {
  183.   if (param)
  184.     param.abort = true;
  185.   return true;
  186. }
  187.  
  188. function Recipients()
  189. {
  190.   return false;
  191. }
  192.  
  193. function Help()
  194. {
  195.   return false;
  196. }
  197.