!import
1 //@line 38 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/mail/components/preferences/sendoptions.js"
2
3 var gSendOptionsDialog = {
4 mPrefsBundle: null,
5 mHTMLListBox: null,
6 mPlainTextListBox: null,
7
init
8 init: function ()
9 {
10 this.mPrefsBundle = document.getElementById('bundlePreferences');
11 this.mHTMLListBox = document.getElementById('html_domains');
12 this.mPlainTextListBox = document.getElementById('plaintext_domains');
13
14 var htmlDomainPrefString = document.getElementById('mailnews.html_domains').value;
15 this.loadDomains(document.getElementById('mailnews.html_domains').value,
16 this.mHTMLListBox);
17 this.loadDomains(document.getElementById('mailnews.plaintext_domains').value,
18 this.mPlainTextListBox);
19 },
20
saveDomainPref
21 saveDomainPref: function(aHTML)
22 {
23 var listbox = aHTML ? this.mHTMLListBox : this.mPlainTextListBox;
24 var num_domains = 0;
25 var pref_string = "";
26
27 for (var item = listbox.firstChild; item != null; item = item.nextSibling)
28 {
29 var domainid = item.getAttribute('label');
30 if (domainid.length > 1)
31 {
32 num_domains++;
33
34 //separate >1 domains by commas
35 if (num_domains > 1)
36 pref_string = pref_string + "," + domainid;
37 else
38 pref_string = domainid;
39 }
40 }
41
42 return pref_string;
43 },
44
loadDomains
45 loadDomains: function (aPrefString, aListBox)
46 {
47 var arrayOfPrefs = aPrefString.split(',');
48 if (arrayOfPrefs)
49 for (var i = 0; i < arrayOfPrefs.length; i++)
50 {
51 var str = arrayOfPrefs[i].replace(/ /g,"");
52 if (str)
53 this.addItemToDomainList(aListBox, str);
54 }
55 },
56
removeDomains
57 removeDomains: function(aHTML)
58 {
59 var listbox = aHTML ? this.mHTMLListBox : this.mPlainTextListBox;
60
61 var currentIndex = listbox.currentIndex;
62
63 while (listbox.selectedItems.length > 0)
64 listbox.removeChild(listbox.selectedItems[0]);
65
66 document.getElementById('SendOptionsDialogPane').userChangedValue(listbox);
67 },
68
addDomain
69 addDomain: function (aHTML)
70 {
71 var listbox = aHTML ? this.mHTMLListBox : this.mPlainTextListBox;
72
73 var domainName;
74 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService();
75 promptService = promptService.QueryInterface(Components.interfaces.nsIPromptService);
76
77 if (promptService)
78 {
79 var result = {value:null};
80 if (promptService.prompt(window, this.mPrefsBundle.getString(listbox.id + 'AddDomainTitle'),
81 this.mPrefsBundle.getString(listbox.id + 'AddDomain'), result, null, {value:0}))
82 domainName = result.value.replace(/ /g,"");
83 }
84
85 if (domainName && !this.domainAlreadyPresent(domainName))
86 {
87 this.addItemToDomainList(listbox, domainName);
88 document.getElementById('SendOptionsDialogPane').userChangedValue(listbox);
89 }
90
91 },
92
domainAlreadyPresent
93 domainAlreadyPresent: function(aDomainName)
94 {
95 var matchingDomains = this.mHTMLListBox.getElementsByAttribute('label', aDomainName);
96 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService();
97 promptService = promptService.QueryInterface(Components.interfaces.nsIPromptService);
98
99 if (!matchingDomains.length)
100 matchingDomains = this.mPlainTextListBox.getElementsByAttribute('label', aDomainName);
101
102 if (matchingDomains.length)
103 {
104 promptService.alert(window, this.mPrefsBundle.getString('domainNameErrorTitle'),
105 this.mPrefsBundle.getFormattedString("domainDuplicationError", [aDomainName]));
106 }
107
108 return matchingDomains.length;
109 },
110
addItemToDomainList
111 addItemToDomainList: function (aListBox, aDomainTitle)
112 {
113 var item = document.createElement('listitem');
114 item.setAttribute('label', aDomainTitle);
115 aListBox.appendChild(item);
116 }
117 };