This is just some static backup of the original site, don't expect every link to work!

source: content/vI_storageExtras.js @ 184c6c

ng_0.9
Last change on this file since 184c6c was 184c6c, checked in by rene <rene@…>, 11 years ago

rearranged tree structure / added build-script

  • Property mode set to 100644
File size: 20.6 KB
Line 
1/* ***** BEGIN LICENSE BLOCK *****
2    This program is free software; you can redistribute it and/or modify
3    it under the terms of the GNU General Public License as published by
4    the Free Software Foundation; either version 2 of the License, or
5    (at your option) any later version.
6
7    This program is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10    GNU General Public License for more details.
11
12    You should have received a copy of the GNU General Public License
13    along with this program; if not, write to the Free Software
14    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
15
16    The Original Code is the Virtual Identity Extension.
17
18    The Initial Developer of the Original Code is Rene Ejury.
19    Portions created by the Initial Developer are Copyright (C) 2007
20    the Initial Developer. All Rights Reserved.
21
22 * ***** END LICENSE BLOCK ***** */
23
24virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
25function storageExtras_adapt(sourceId, targetId) {
26    var checked = document.getElementById(sourceId).getAttribute("checked");
27    if (targetId) var target = document.getElementById(targetId)
28    else var target = document.getElementById(sourceId.replace(/_store/,""))
29    if (checked == "true") target.removeAttribute("disabled")
30    else target.setAttribute("disabled", "true");
31}   
32
33var storageExtrasHelper = {
34    seamonkey_old : null,
35
36    preferences : Components.classes["@mozilla.org/preferences-service;1"]
37            .getService(Components.interfaces.nsIPrefService)
38            .getBranch("extensions.virtualIdentity."),
39   
40    hideUnusedEditorFields : function() {
41        var localStorageExtras = new storageExtras();
42        var allHidden = true;
43        var hide = (document.getElementById("vI_storageExtras_hideUnusedEditorFields").getAttribute("checked") == "true")
44        for( var i = 0; i < localStorageExtras.extras.length; i++ ) {
45            var hidden = hide && !storageExtrasHelper.preferences.getBoolPref(localStorageExtras.extras[i].option)
46            if (!hidden) allHidden = false
47            document.getElementById("vI_" + localStorageExtras.extras[i].option).setAttribute("hidden", hidden)
48            document.getElementById("vI_" + localStorageExtras.extras[i].option + "_store").setAttribute("hidden", hidden)
49        }
50        document.getElementById("storeValue").setAttribute("hidden", allHidden)
51        // resize the window to the content
52        window.sizeToContent();
53    }
54}
55
56function storageExtras(rdfDatasource, resource) {
57// function storageExtras_checkbox(field, option, composeDialogElementID, updateFunction, identityValue) {
58    this.extras = [
59        new storageExtras_checkbox(
60            "reciept", "storageExtras_returnReciept", "returnReceiptMenu", null, function(identity) { return identity.requestReturnReceipt; }),
61        new storageExtras_checkbox(
62            "fcc", "storageExtras_fcc", "fcc_switch", null, function(identity) { return identity.doFcc; }),
63        new storageExtras_characterEncoding(),
64        new storageExtras_msgFormat(),
65        new storageExtras_checkbox(
66            "sMimeEnc", "storageExtras_sMime_messageEncryption", "menu_securityEncryptRequire1",
67                function() { return ((typeof(setSecuritySettings)=='function')?setSecuritySettings(1):null) },
68                function(identity) { return (identity.getIntAttribute('encryptionpolicy') == 2) }),
69        new storageExtras_checkbox(
70            "sMimeSig", "storageExtras_sMime_messageSignature", "menu_securitySign1",
71                function() { return ((typeof(setSecuritySettings)=='function')?setSecuritySettings(1):null) },
72                function(identity) { return (identity.getBoolAttribute('sign_mail')) }),
73        new storageExtras_checkbox(
74            "PGPEnc", "storageExtras_openPGP_messageEncryption", "enigmail_encrypted_send",
75                function() { return ((typeof(enigSetMenuSettings)=='function')?enigSetMenuSettings(''):null) },
76                function(identity) { return (identity.getIntAttribute('defaultEncryptionPolicy') > 0) }),
77        new storageExtras_checkbox(
78            "PGPSig", "storageExtras_openPGP_messageSignature", "enigmail_signed_send",
79                function() { return ((typeof(enigSetMenuSettings)=='function')?enigSetMenuSettings(''):null) },
80                function(identity) { return ((identity.getIntAttribute('defaultEncryptionPolicy') > 0)?identity.getBoolAttribute('pgpSignEncrypted'):identity.getBoolAttribute('pgpSignPlain')) }),
81        new storageExtras_checkbox(
82            "PGPMIME", "storageExtras_openPGP_PGPMIME", "enigmail_sendPGPMime",
83                function() { return ((typeof(enigSetMenuSettings)=='function')?enigSetMenuSettings(''):null) },
84                function(identity) { return (identity.getBoolAttribute('pgpMimeMode')) })
85        ]
86    if (rdfDatasource) this.loopForRDF(rdfDatasource, resource, "get")
87}
88
89storageExtras.prototype = {
90    loopForRDF : function(rdfDatasource, resource, type) {
91        for( var i = 0; i < this.extras.length; i++ ) {
92//          if (vI.notificationBar) vI.notificationBar.dump("## vI.rdfDatasource: loopForRDF " + rdfDatasource + "\n");
93            // only if pref set and feature(element available) or for dataEditor
94            if (typeof(gMsgCompose) == "undefined" || !gMsgCompose || this.extras[i].active) {
95                switch (type) {
96                    case "get": this.extras[i].value = rdfDatasource._getRDFValue(resource, this.extras[i].field, this.extras[i].value); break;
97                    case "set": this.extras[i].value = rdfDatasource._setRDFValue(resource, this.extras[i].field, this.extras[i].value); break;
98                    case "unset": this.extras[i].value = rdfDatasource._unsetRDFValue(resource, this.extras[i].field, this.extras[i].value); break;
99                }
100            }
101        }
102    },
103   
104    // just give a duplicate of the current storageExtras, else we will work with pointers
105    getDuplicate : function() {
106        var newExtras = new storageExtras();
107        for( var i = 0; i < this.extras.length; i++ ) {
108            newExtras.extras[i].value = this.extras[i].value;
109        }
110        return newExtras;
111    },
112   
113    // copys all values of an identity. This way we can create a new object with a different document-context
114    copy : function(extras) {
115        for( var i = 0; i < this.extras.length; i++ ) {
116            this.extras[i].value = extras.extras[i].value;
117        }
118    },
119
120    equal : function(storageExtras) {
121        var equal = true;
122        for( var i = 0; i < this.extras.length; i++ ) {
123            if (this.extras[i].active) {
124                equal = (this.extras[i].equal(storageExtras.extras[i]) && equal) // in this order to compare all fields (required for Matrix)
125            }
126        }
127        return equal;
128    },
129    getMatrix : function() {
130        var prefStrings = document.getElementById("vIStorageExtrasBundle");
131        var string = "";
132        for( var i = 0; i < this.extras.length; i++ ) {
133            if (this.extras[i].active) {
134                if (this.extras[i].valueHtml)
135                    string += "<tr>" +
136                    "<td class='col1 extras '>" + prefStrings.getString("vident.identityData.extras." + this.extras[i].field) + "</td>" +
137                    "<td class='col2 extras '>" + this.extras[i].valueHtml + "</td>" +
138                    "</tr>"
139            }
140        }
141        return string;
142    },
143    getCompareMatrix : function() {
144        var prefStrings = document.getElementById("vIStorageExtrasBundle");
145        var string = "";
146        for( var i = 0; i < this.extras.length; i++ ) {
147            if (this.extras[i].active) {
148                var classEqual = (this.extras[i].comp.equal)?"equal":"unequal";
149                string += "<tr>" +
150                    "<td class='col1 extras " + classEqual + "'>" + prefStrings.getString("vident.identityData.extras." + this.extras[i].field) + "</td>" +
151                    "<td class='col2 extras " + classEqual + "'>" + this.extras[i].comp.compareValue + "</td>" +
152                    "<td class='col3 extras " + classEqual + "'>" + this.extras[i].valueHtml + "</td>" +
153                    "</tr>"
154            }
155        }
156        return string;
157    },
158    status : function() {
159        var returnVal = "";
160        for( var i = 0; i < this.extras.length; i++ )
161            if (this.extras[i].active && this.extras[i].value)
162                returnVal += " " + this.extras[i].field + "='" + this.extras[i].value + "'";
163        return returnVal
164    },
165
166    readIdentityValues : function(identity) {
167        for( var i = 0; i < this.extras.length; i++ ) {
168            if (this.extras[i].active) this.extras[i].readIdentityValue(identity)
169//          vI.notificationBar.dump("## storageExtras readIdentityValues "+ this.extras[i].field + "=" + this.extras[i].value + "\n");
170        }
171    },
172
173    setValues : function() {
174        for( var i = 0; i < this.extras.length; i++ ) {
175            if (this.extras[i].active) this.extras[i].setValue()
176//          vI.notificationBar.dump("## storageExtras setValue "+ this.extras[i].field + "=" + this.extras[i].value + "\n");
177        }
178    },
179    readValues : function() {
180        for( var i = 0; i < this.extras.length; i++ ) {
181//          vI.notificationBar.dump("## storageExtras preparing readValue "+ this.extras[i].field +"\n");
182            if (this.extras[i].active) this.extras[i].readValue()
183//              vI.notificationBar.dump("## storageExtras readValue "+ this.extras[i].field + "=" + this.extras[i].value + "\n");
184        }
185    },
186    setEditorValues : function() {
187        for( var i = 0; i < this.extras.length; i++ ) this.extras[i].setEditorValue();
188    },
189    readEditorValues : function() {
190        for( var i = 0; i < this.extras.length; i++ ) {
191            this.extras[i].readEditorValue();
192//          vI.notificationBar.dump("## storageExtras readValue " + this.extras[i].field + "=" + this.extras[i].value + "\n");
193        }
194    },
195
196    // add value's to the pref object, required for rdfDataTreeCollection
197    addPrefs : function(pref) {
198        for( var i = 0; i < this.extras.length; i++ )
199            pref[this.extras[i].field + "Col"] = this.extras[i].valueNice;
200    }
201}
202
203function storageExtras_characterEncoding_setMenuMark() {
204    var maileditCharsetMenu = document.getElementById("maileditCharsetMenu")
205    var value = maileditCharsetMenu.getAttribute("unmarkedValue")
206    if (value) {
207        var menuitem = document.getElementById(value);
208        if (menuitem) menuitem.setAttribute('checked', 'true');
209        maileditCharsetMenu.removeAttribute("unmarkedValue")
210    }
211}
212function storageExtras_characterEncoding() {
213    this.active = storageExtrasHelper.preferences.getBoolPref("storage") &&
214                storageExtrasHelper.preferences.getBoolPref(this.option)
215    this.comp = { compareValue : null, equal : null }
216}
217storageExtras_characterEncoding.prototype = {
218    active : null,
219    value : null,
220    field : "charEnc",
221    option : "storageExtras_characterEncoding",
222    comp : null,
223
224    // functions to get nicely formatted output
225    get valueHtml() { return this.valueNice; },
226    get valueNice() {
227        return this.value?gCharsetConvertManager
228                    .getCharsetTitle(gCharsetConvertManager.getCharsetAlias(this.value)):"";
229    },
230
231    // function to read the value from a given identity
232    readIdentityValue : function(identity) { }, // no charset per identity
233
234    equal : function(compareStorageExtra) {
235        this.comp.compareValue = compareStorageExtra.valueHtml;
236        this.comp.equal = (!this.value || !compareStorageExtra.value || this.value == compareStorageExtra.value);
237        return this.comp.equal;
238    },
239    // function to set or read the value from/to the MessageCompose Dialog
240    setValue : function() {
241        if (!this.value) return;
242        var menuitem = document.getElementById(this.value);
243        if (menuitem) menuitem.setAttribute('checked', 'true');
244        else {  // set menumark later if menu is not ready yet
245            var maileditCharsetMenu = document.getElementById("maileditCharsetMenu")
246            maileditCharsetMenu.setAttribute("unmarkedValue", this.value)
247            var onpopupshowing = maileditCharsetMenu.getAttribute("onpopupshowing")
248            document.getElementById("maileditCharsetMenu").setAttribute("onpopupshowing",
249                onpopupshowing + ";storageExtras_characterEncoding_setMenuMark();")
250        }
251        gMsgCompose.compFields.characterSet = this.value;
252        SetDocumentCharacterSet(this.value);
253    },
254    readValue : function() {
255        // read the value from the internal vI object, global object might not be available any more
256        // happens especially while storing after sending the message
257        this.value = vI.main.gMsgCompose.compFields.characterSet;
258        if (gCharsetConvertManager) {
259            var charsetAlias = gCharsetConvertManager.getCharsetAlias(this.value);
260            if (charsetAlias == "us-ascii") this.value = "ISO-8859-1";   // no menu item for "us-ascii"
261        }
262    },
263    // function to set or read the value from the rdfDataEditor
264    // XXX still Problem if selected Encoding is not (yet) Element of the Menu, repair this
265
266    setEditorValue : function() {
267        CreateMenu('mailedit');
268        if (this.value != null) {
269            document.getElementById("maileditCharsetMenu").selectedItem = document.getElementById(this.value);
270            document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true");
271           
272        }
273        document.getElementById("vI_" + this.option + "_store").doCommand();
274    },
275    readEditorValue : function() {
276        if (document.getElementById("vI_" + this.option + "_store").getAttribute("checked") == "true")
277            // check if element is selected (list might not contain relevant entry)
278            if (document.getElementById("maileditCharsetMenu").selectedItem)
279                this.value = document.getElementById("maileditCharsetMenu").selectedItem.id
280        else    this.value = null;
281    }
282}
283
284function storageExtras_msgFormat() {
285    this.active = storageExtrasHelper.preferences.getBoolPref("storage") &&
286                storageExtrasHelper.preferences.getBoolPref(this.option)
287    this.comp = { value : null, compareValue : null, equal : null }
288}
289storageExtras_msgFormat.prototype = {
290    active : null,
291    value : null,
292    field : "msgFormat",
293    option : "storageExtras_messageFormat",
294    comp : null,
295
296    // functions to get nicely formatted output
297    get valueHtml() { return this.valueNice; },
298    get valueNice() {
299        return this.value?document.getElementById(this.value).label:"";
300    },
301
302    // function to read the value from a given identity
303    readIdentityValue : function(identity) { }, // no msgFormat per identity
304
305    equal : function(compareStorageExtra) {
306        this.comp.compareValue = compareStorageExtra.valueHtml;
307        this.comp.equal = (!this.value || !compareStorageExtra.value || this.value == compareStorageExtra.value);
308        return this.comp.equal;
309    },
310    // function to set or read the value from/to the MessageCompose Dialog
311    setValue : function() {
312        if (!this.value) return;
313        document.getElementById(this.value).setAttribute("checked","true");
314        OutputFormatMenuSelect(document.getElementById(this.value))
315    },
316    readValue : function() {
317        switch (gSendFormat) {
318            case nsIMsgCompSendFormat.AskUser: this.value = "format_auto"; break;
319            case nsIMsgCompSendFormat.PlainText: this.value = "format_plain"; break;
320            case nsIMsgCompSendFormat.HTML: this.value = "format_html"; break;
321            case nsIMsgCompSendFormat.Both: this.value = "format_both"; break;
322        }
323    },
324    // function to set or read the value from the rdfDataEditor
325    setEditorValue : function() {
326        //~ document.getElementById(this.value).setAttribute("checked","true");
327        if (this.value != null) {
328            document.getElementById("outputFormatMenu").selectedItem = document.getElementById(this.value);
329            document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true");
330        }
331        document.getElementById("vI_" + this.option + "_store").doCommand();
332       
333    },
334    readEditorValue : function() {
335        if (document.getElementById("vI_" + this.option + "_store").getAttribute("checked") == "true")
336            this.value = document.getElementById("outputFormatMenu").selectedItem.id
337        else    this.value = null;
338    }
339}
340
341function storageExtras_sMime_messageEncryption() { 
342    this.active = storageExtrasHelper.preferences.getBoolPref("storage") &&
343                storageExtrasHelper.preferences.getBoolPref(this.option)
344    this.comp = { value : null, compareValue : null, equal : null }
345}
346storageExtras_sMime_messageEncryption.prototype = {
347    active : null,
348    value : null,
349    field : "sMimeEnc",
350    option : "storageExtras_sMime_messageEncryption",
351    comp : null,
352
353    // functions to get nicely formatted output
354    get valueHtml() {
355        if (!this.value) return "";
356        return  "<div class='bool" + ((this.value=="true")?" checked":"") + "'>" +
357                "<label class='screen'>&nbsp;</label>" +
358                "<label class='braille'>" + this.valueNice + "</label>" +
359            "</div>"
360    },
361    get valueNice() {
362        if (!this.value) return "";
363        return (this.value=="true")?"yes":"no";
364    },
365
366    equal : function(compareStorageExtra) {
367        this.comp.compareValue = compareStorageExtra.valueHtml;
368        this.comp.equal = (this.value == null || this.value == compareStorageExtra.value);
369        return this.comp.equal;
370    },
371
372    // function to read the value from a given identity
373    readIdentityValue : function(identity) {
374        this.value = (identity.getIntAttribute("encryptionpolicy") == 2)?"true":"false"
375    },
376    // function to set or read the value from/to the MessageCompose Dialog
377    setValue : function() {
378        vI.notificationBar.dump("## storageExtras_sMime_messageEncryption \n");
379        var doEncryptElem = document.getElementById("menu_securityEncryptRequire1");
380        if (this.value == null) return;
381        if (this.value == "true") var element = document.getElementById("menu_securityEncryptRequire1")
382        else var element = document.getElementById("menu_securityNoEncryption1")
383        element.setAttribute("checked", "true");
384        element.doCommand();
385    },
386    readValue : function() {
387        setSecuritySettings(1)
388        this.value = (document.getElementById("menu_securityEncryptRequire1").getAttribute("checked") == "true")?"true":"false"
389    },
390    // function to set or read the value from the rdfDataEditor
391    setEditorValue : function() { 
392        if (this.value != null) {
393            document.getElementById("vI_" + this.option).setAttribute("checked", this.value);
394            document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true");
395        }
396        document.getElementById("vI_" + this.option + "_store").doCommand();
397    },
398    readEditorValue : function() {
399        if (document.getElementById("vI_" + this.option + "_store").getAttribute("checked") == "true") {
400            var elementValue = document.getElementById("vI_" + this.option).getAttribute("checked");
401            this.value = (elementValue == "true")?"true":"false"
402        }
403        else    this.value = null;
404    }
405}
406
407// a general checkbox for extra options. Has to provide some additional information
408function storageExtras_checkbox(field, option, composeDialogElementID, updateFunction, identityValue) {
409    this.field = field;     // description of the option
410    this.option = option;       // option string to get preference settings
411    this.composeDialogElementID = composeDialogElementID;
412    this.updateFunction = updateFunction;
413    this.valueFromIdentityFunction = identityValue;
414    this.active = storageExtrasHelper.preferences.getBoolPref("storage") &&
415                storageExtrasHelper.preferences.getBoolPref(this.option) 
416//      elements are never available in DataTree, so leave this out.
417//      && document.getElementById(this.composeDialogElementID);
418    this.comp = { compareValue : null, equal : null }
419}
420storageExtras_checkbox.prototype = {
421    active : null,
422    value : null,
423    field : null,
424    option : null,
425    comp : null,
426    composeDialogElementID : null,
427    updateFunction : null, // some elements have to be updated before the can be read
428    valueFromIdentityFunction : null,
429   
430    // functions to get nicely formatted output
431    get valueHtml() {
432        if (!this.value) return "";
433        return  "<div class='bool" + ((this.value=="true")?" checked":"") + "'>" +
434                "<label class='screen'>&nbsp;</label>" +
435                "<label class='braille'>" + this.valueNice + "</label>" +
436            "</div>"
437    },
438    get valueNice() {
439        if (!this.value) return "";
440        return (this.value=="true")?"yes":"no";
441    },
442
443    equal : function(compareStorageExtra) {
444        this.comp.compareValue = compareStorageExtra.valueHtml;
445        this.comp.equal = (this.value == null || this.value == compareStorageExtra.value);
446        return this.comp.equal;
447    },
448
449    // function to read the value from a given identity
450    readIdentityValue : function(identity) {
451        this.value = (this.valueFromIdentityFunction(identity))?"true":"false";
452    },
453    // function to set or read the value from/to the MessageCompose Dialog
454    setValue : function() {
455        var element = document.getElementById(this.composeDialogElementID);
456        if (!this.value || !element) return;
457        if (typeof(this.updateFunction)=="function") this.updateFunction();
458
459        if ((element.getAttribute("checked") == "true") != (this.value == "true")) {
460            vI.notificationBar.dump("## storageExtras change "+ this.field + " to " + this.value + " with doCommand\n");
461            element.doCommand();
462        }
463    },
464    readValue : function() {
465        var element = document.getElementById(this.composeDialogElementID)
466        if (!element) return;
467        if (typeof(this.updateFunction)=="function") this.updateFunction();
468        this.value = ((element.getAttribute("checked") == "true")?"true":"false")
469    },
470    // function to set or read the value from the rdfDataEditor
471    setEditorValue : function() {
472        if (this.value != null) {
473            document.getElementById("vI_" + this.option).setAttribute("checked", this.value);
474            document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true");
475        }
476        document.getElementById("vI_" + this.option + "_store").doCommand();
477    },
478    readEditorValue : function() {
479        if (document.getElementById("vI_" + this.option + "_store").getAttribute("checked") == "true") {
480            var elementValue = document.getElementById("vI_" + this.option).getAttribute("checked");
481            this.value = (elementValue == "true")?"true":"false"
482        }
483        else    this.value = null;
484    }
485}
486
487vI.storageExtras = storageExtras;
488vI.storageExtrasHelper = storageExtrasHelper;
489vI.storageExtras_adapt = storageExtras_adapt;
490}});
Note: See TracBrowser for help on using the repository browser.