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

source: content/vI_storage.js @ d56c39

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

added new preferences module

  • Property mode set to 100644
File size: 9.1 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    Contributor(s): Mike Krieger, Sebastian Apel
23 * ***** END LICENSE BLOCK ***** */
24 
25/**
26* some code copied and adapted from 'addressContext' and from 'Birthday Reminder'
27* thanks to Mike Krieger and Sebastian Apel
28*/
29
30Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
31virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
32
33Components.utils.import("resource://gre/modules/AddonManager.jsm");
34let Log = vI.setupLogging("virtualIdentity.storage");
35Components.utils.import("resource://v_identity/vI_rdfDatasource.js", virtualIdentityExtension);
36Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
37
38var storage = {
39    focusedElement : null,
40   
41    lastCheckedEmail : {},  // array of last checked emails per row,
42                // to prevent ugly double dialogs and time-consuming double-checks
43   
44    _rdfDatasourceAccess : null,    // local storage
45
46    clean: function() {
47        Log.debug("clean.\n");
48        storage.multipleRecipients = null;
49        storage.lastCheckedEmail = {};
50        storage.firstUsedInputElement = null;
51        awSetInputAndPopupValue = storage.original_functions.awSetInputAndPopupValue;
52        if (storage._rdfDatasourceAccess) storage._rdfDatasourceAccess.clean();
53    },
54   
55    original_functions : {
56        awSetInputAndPopupValue : null
57    },
58
59    replacement_functions : {
60        awSetInputAndPopupValue : function (inputElem, inputValue, popupElem, popupValue, rowNumber) {
61            Log.debug("awSetInputAndPopupValue '" + inputElem.id +"'\n");
62            storage.original_functions.awSetInputAndPopupValue(inputElem, inputValue, popupElem, popupValue, rowNumber);
63            storage.updateVIdentityFromStorage(inputElem);
64        }
65    },
66       
67    awOnBlur : function (element) {
68        // only react on events triggered by addressCol2 - textinput Elements
69        if (!element || ! element.id.match(/^addressCol2*/)) return;
70        Log.debug("\nawOnBlur '" + element.id +"'\n");
71        storage.updateVIdentityFromStorage(element);
72        storage.focusedElement = null;
73    },
74
75    awOnFocus : function (element) {
76        if (!element || ! element.id.match(/^addressCol2*/)) return;
77        storage.focusedElement = element;
78    },
79
80    awPopupOnCommand : function (element) {
81        Log.debug("\nawPopupOnCommand'" + element.id +"'\n");
82        storage.updateVIdentityFromStorage(document.getElementById(element.id.replace(/^addressCol1/,"addressCol2")));
83        if (element.selectedItem.getAttribute("value") == "addr_reply") // if reply-to is manually entered disable AutoReplyToSelf
84            document.getElementById("virtualIdentityExtension_autoReplyToSelfLabel").setAttribute("hidden", "true");
85
86    },
87   
88    initialized : null,
89    init: function() {
90        if (!storage.initialized) {
91            storage._rdfDatasourceAccess = new vI.rdfDatasourceAccess();
92
93            // better approach would be to use te onchange event, but this one is not fired in any change case
94            // see https://bugzilla.mozilla.org/show_bug.cgi?id=355367
95            // same seems to happen with the ondragdrop event
96            if (top.MAX_RECIPIENTS == 0) top.MAX_RECIPIENTS = 1;
97            for (var row = 1; row <= top.MAX_RECIPIENTS ; row ++) {
98                var input = awGetInputElement(row);
99                if (input) {
100                    var oldBlur = input.getAttribute("onblur")
101                    input.setAttribute("onblur", (oldBlur?oldBlur+"; ":"") +
102                        "window.setTimeout(virtualIdentityExtension.storage.awOnBlur, 250, this.parentNode.parentNode.parentNode);")
103                    var oldFocus = input.getAttribute("onfocus")
104                    input.setAttribute("onfocus", (oldFocus?oldFocus+"; ":"") +
105                        "window.setTimeout(virtualIdentityExtension.storage.awOnFocus, 250, this.parentNode.parentNode.parentNode);")
106                }
107                var popup = awGetPopupElement(row);
108                if (popup) {
109                    var oldCommand = popup.getAttribute("oncommand")
110                    popup.setAttribute("oncommand", (oldCommand?oldCommand+"; ":"") +
111                        "window.setTimeout(virtualIdentityExtension.storage.awPopupOnCommand, 250, this);")
112                }
113            }
114            storage.initialized = true;
115        }
116        storage.original_functions.awSetInputAndPopupValue = awSetInputAndPopupValue;
117        awSetInputAndPopupValue = function (inputElem, inputValue, popupElem, popupValue, rowNumber) {
118            storage.replacement_functions.awSetInputAndPopupValue (inputElem, inputValue, popupElem, popupValue, rowNumber) }
119
120        // reset unavailable storageExtras preferences
121        AddonManager.getAddonByID("{847b3a00-7ab1-11d4-8f02-006008948af5}", function(addon) {
122          if (addon && !addon.userDisabled && !addon.appDisable) {
123            vI.vI_prefs.commit("storageExtras_openPGP_messageEncryption", false)
124            vI.vI_prefs.commit("storageExtras_openPGP_messageSignature", false)
125            vI.vI_prefs.commit("storageExtras_openPGP_PGPMIME", false)
126          }
127        }); 
128    },
129   
130    firstUsedInputElement : null,   // this stores the first Element for which a Lookup in the Storage was successfull
131    updateVIdentityFromStorage: function(inputElement) {
132        if (!vI.vIprefs.get("storage"))
133            { Log.debug("Storage deactivated\n"); return; }
134        Log.debug("updateVIdentityFromStorage()\n");
135
136        var recipientType = document.getElementById(inputElement.id.replace(/^addressCol2/,"addressCol1"))
137            .selectedItem.getAttribute("value");
138        var row = inputElement.id.replace(/^addressCol2#/,"")
139        if (recipientType == "addr_reply" || recipientType == "addr_followup" || storage.__isDoBcc(row)) {
140            // reset firstUsedInputElement if recipientType was changed (and don't care about doBcc fields)
141            if (storage.firstUsedInputElement == inputElement)
142                storage.firstUsedInputElement = null;
143            Log.debug("field is a 'reply-to' or 'followup-to' or preconfigured 'doBcc'. not searched.\n")
144            return;
145        }
146       
147        if (inputElement.value == "") {
148            Log.debug("no recipient found, not checked.\n"); return;
149        }
150       
151        var row = inputElement.id.replace(/^addressCol2#/,"")
152        if (storage.lastCheckedEmail[row] && storage.lastCheckedEmail[row] == inputElement.value) {
153            Log.debug("same email than before, not checked again.\n"); return;
154        }
155        storage.lastCheckedEmail[row] = inputElement.value;
156       
157        // firstUsedInputElement was set before and we are not editing the same
158        var isNotFirstInputElement = (storage.firstUsedInputElement && storage.firstUsedInputElement != inputElement)
159        var currentIdentity = document.getElementById("virtualIdentityExtension_msgIdentityClone").identityData
160        var storageResult = storage._rdfDatasourceAccess.updateVIdentityFromStorage(inputElement.value, recipientType,
161            currentIdentity, document.getElementById("virtualIdentityExtension_msgIdentityClone").vid, isNotFirstInputElement);
162       
163        if (storageResult.identityCollection.number == 0) return; // return if there was no match
164        Log.debug("updateVIdentityFromStorage result: " + storageResult.result + "\n");
165        // found storageData, so store InputElement
166        if (!storage.firstUsedInputElement) storage.firstUsedInputElement = inputElement;
167       
168        var newMenuItem = null;
169        if (storageResult.result != "equal") {
170            for (var j = 0; j < storageResult.identityCollection.number; j++) {
171                Log.debug("updateVIdentityFromStorage adding: " + storageResult.identityCollection.identityDataCollection[j].combinedName + "\n");
172                let menuItem = document.getElementById("virtualIdentityExtension_msgIdentityClone")
173                  .addIdentityToCloneMenu(storageResult.identityCollection.identityDataCollection[j])
174                if (!newMenuItem) newMenuItem = menuItem;
175            }
176        }
177        if (storageResult.result == "accept") {
178            Log.debug("updateVIdentityFromStorage selecting: " + storageResult.identityCollection.identityDataCollection[0].combinedName + "\n");
179            document.getElementById("virtualIdentityExtension_msgIdentityClone").selectedMenuItem = newMenuItem;
180            if (document.getElementById("virtualIdentityExtension_msgIdentityClone").vid)
181                vI.StorageNotification.info(vI.main.elements.strings.getString("vident.smartIdentity.vIStorageUsage") + ".");
182        }
183    },
184   
185    __isDoBcc : function(row) {
186        var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value");
187        if (recipientType != "addr_bcc" || !getCurrentIdentity().doBcc) return false
188
189        var doBccArray = gMsgCompose.compFields.splitRecipients(getCurrentIdentity().doBccList, false, {});
190
191        for (var index = 0; index < doBccArray.count; index++ ) {
192            if (doBccArray.StringAt(index) == awGetInputElement(row).value) {
193                Log.debug("ignoring doBcc field '" +
194                    doBccArray.StringAt(index) + "'.\n");
195                return true;
196            }
197        }       
198        return false
199    }
200}
201vI.storage = storage;
202}});
Note: See TracBrowser for help on using the repository browser.