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

Ignore:
Timestamp:
Nov 3, 2014, 12:35:40 PM (8 years ago)
Author:
rene <rene@…>
Branches:
ng_0.9
Children:
7204cb
Parents:
3c9c29
Message:

code formatting (no code changes)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • content/vI_storage.js

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