Changeset 218ad9


Ignore:
Timestamp:
Aug 11, 2008, 5:59:40 PM (12 years ago)
Author:
rene <rene@…>
Branches:
master
Children:
750a78
Parents:
103470
Message:

use new Dialog and StatusMenu? Implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • chrome/content/v_identity/vI_storage.js

    r103470 r218ad9  
    2828*/
    2929
    30 
    3130function identityData(email, fullName, id, smtp, extras) {
     31    this.__keyTranslator = new keyTranslator();
     32    this.smtpService =
     33            Components.classes["@mozilla.org/messengercompose/smtp;1"].getService(Components.interfaces.nsISmtpService);
    3234    this.email = email;
    3335    this.fullName = (fullName?fullName:'');
    34     this.id = id;
    35     this.smtp = (smtp=="default"?"":smtp);
     36    this.id = (this.__keyTranslator.isValidID(id))?id:"";
     37    this.idName = this.__keyTranslator.getIDname(this.id);
     38    this.smtp = (this.__keyTranslator.isValidSMTP(smtp))?smtp:""
     39    this.smtpName = this.__keyTranslator.getSMTPname(this.smtp);
    3640    this.extras = extras;
    37     this.__keyTranslator = new keyTranslator();
    38     if (!this.__keyTranslator.isValidID(this.id)) this.id = ""
    39     if (!this.__keyTranslator.isValidSMTP(this.smtp)) this.smtp = "";
     41    this.comp = {
     42        compareID : null,
     43        labels : { fullName : {}, email : {}, smtpName : {}, idName : {}, extras : {} },
     44        equals : { fullName : {}, email : {}, smtpName : {}, idName : {}, extras : {} }
     45    }
    4046}
    4147identityData.prototype = {
     
    4349    fullName : null,
    4450    id : null,
     51    idName : null,
    4552    smtp : null,
     53    smtpName : null,
    4654    extras : null,
     55
     56    comp : null,   
     57
    4758    __keyTranslator : null,
     59    smtpService : null,
     60
    4861    __combineStrings : function(stringA, stringB) {
    4962        var A = (stringA)?stringA.replace(/^\s+|\s+$/g,""):"";
     
    5669    identityDescription : function(index) {
    5770        var senderName = vI_helper.combineNames(this.fullName, this.email);
    58         var idName = this.__keyTranslator.getIDname(this.id);
    59         var smtpName = this.__keyTranslator.getSMTPname(this.smtp);
    6071        var extras = this.extras?this.extras.status():"";
    6172        return senderName + " (" +
    62             this.__combineStrings(this.__combineStrings(idName, smtpName), extras) +  ")"
    63     },
    64    
    65     __equalCurrentSMTP : function() {
    66         var smtp_key = vI_smtpSelector.elements.Obj_SMTPServerList.selectedItem.getAttribute('key');
    67         return (!this.__keyTranslator.getSMTP(this.smtp) && !smtp_key ||
    68             smtp_key == this.smtp)
    69     },
    70    
    71     __equalCurrentID : function() {
    72         var id_key = vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.base_id_key;
    73         if (!id_key) id_key = vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.getAttribute("value");
    74         return ((!this.__keyTranslator.getID(this.id) && (id_key == gAccountManager.defaultAccount.defaultIdentity.key)) ||
    75             id_key == this.id)
    76     },
    77    
    78     equalsCurrentIdentity : function() {
    79         var curAddress = vI_helper.getAddress();       
    80         var curExtras = new vI_storageExtras();
    81         curExtras.readValues(); // initialize with current MsgComposeDialog Values
    82         vI_notificationBar.dump("## identityData: __equalCurrentID = '" + this.__equalCurrentID() + "'.\n")
    83         vI_notificationBar.dump("## identityData: __equalCurrentSMTP = '" + this.__equalCurrentSMTP() + "'.\n")
    84         vI_notificationBar.dump("## identityData: curAddress.email = '" + (curAddress.email == this.email) + "'.\n")
    85         vI_notificationBar.dump("## identityData: curAddress.name = '" + (curAddress.name == this.fullName) + "'.\n")
    86         vI_notificationBar.dump("## identityData: this.extras.equal(curExtras) = '" + this.extras.equal(curExtras) + "'.\n")
    87 
    88         var equal = (   (this.__equalCurrentID()) &&
    89                 (this.__equalCurrentSMTP()) &&
    90                 (curAddress.email == this.email) &&
    91                 (curAddress.name == this.fullName) &&
    92                 (this.extras.equal(curExtras))  )
    93         if (equal) vI_notificationBar.dump("## identityData: Identities are the same.\n")
    94         else vI_notificationBar.dump("## identityData: Identities differ.\n")
    95         return equal;
    96     },
    97 
     73            this.__combineStrings(this.__combineStrings(this.idName, this.smtpName), extras) +  ")"
     74    },
     75   
    9876    isExistingIdentity : function() {
    9977        var identity = gAccountManager.defaultAccount.defaultIdentity
    10078        if (this.__keyTranslator.getID(this.id))
    10179            identity = gAccountManager.getIdentity(this.id)
    102        
    103         var defaultSMTP = null;
    104         for (var i in gAccountManager.accounts) {
    105             for (var j in gAccountManager.accounts[i].identities) {
    106                 if (this.id == gAccountManager.accounts[i].identities[j].key)
    107                     defaultSMTP = gAccountManager.accounts[i].defaultIdentity.smtpServerKey;
    108             }
    109         }
    110         if (!defaultSMTP) defaultSMTP = gAccountManager.defaultAccount.defaultIdentity.smtpServerKey
    111 
    112         equal = ((this.smtp == identity.smtpServerKey ||
    113             (!this.__keyTranslator.getSMTP(this.smtp) && identity.smtpServerKey == defaultSMTP) ||
    114             (!this.__keyTranslator.getSMTP(identity.smtpServerKey) && this.smtp == defaultSMTP)) &&
     80        equal = (this.__keyTranslator.getSMTP(this.smtp) == this.__keyTranslator.getSMTP(identity.smtpServerKey) &&
    11581            identity.getUnicharAttribute("fullName") == this.fullName &&
    11682            identity.getUnicharAttribute("useremail") == this.email)
     
    11884        if (equal) return identity.key
    11985        else return null
    120     }
     86    },
     87
     88    __equalSMTP : function(compareSmtp) {
     89        var mainSmtp = this.smtp;
     90        if (!mainSmtp || !this.__keyTranslator.isValidSMTP(mainSmtp)) mainSmtp = this.smtpService.defaultServer.key;
     91        if (!compareSmtp || !this.__keyTranslator.isValidSMTP(compareSmtp)) compareSmtp = this.smtpService.defaultServer.key;
     92        return (mainSmtp == compareSmtp);
     93    },
     94   
     95    __equalID : function(compareID) {
     96        // if basic ID is not set (default) than answer equal
     97        if (!this.__keyTranslator.getID(this.id)) return true;
     98        return (this.id == compareID);
     99    },
     100
     101    __getCurrentIdentityData : function() {
     102        var curAddress = vI_helper.getAddress();
     103        var curIdKey = vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.base_id_key;
     104        var curSmtpKey = vI_smtpSelector.elements.Obj_SMTPServerList.selectedItem.getAttribute('key');
     105       
     106        var curExtras = new vI_storageExtras();
     107        curExtras.readValues(); // initialize with current MsgComposeDialog Values
     108        var curIdentity = new identityData(curAddress.email,
     109                curAddress.name, curIdKey, curSmtpKey, curExtras)
     110       
     111        return curIdentity;
     112    },
     113
     114    __equals : function(compareIdentityData) {
     115        this.comp.compareID = compareIdentityData;
     116
     117        this.comp.equals.fullName = (this.fullName == compareIdentityData.fullName)
     118        this.comp.equals.email = (this.email == compareIdentityData.email)
     119        this.comp.equals.smtpName = this.__equalSMTP(compareIdentityData.smtp);
     120        this.comp.equals.idName = this.__equalID(compareIdentityData.id);
     121        this.comp.equals.extras = this.extras.equal(compareIdentityData.extras)
     122
     123        return (this.comp.equals.fullName && this.comp.equals.email && this.comp.equals.smtpName && this.comp.equals.idName && this.comp.equals.extras)
     124    },
     125
     126    equalsCurrentIdentity : function() {
     127        var compareIdentityData = this.__getCurrentIdentityData();
     128
     129        return this.__equals(compareIdentityData);
     130    },
     131
     132    // vI only exists in composeDialog, not in storageEditor, so initialize only if getCompareMatrix is called
     133    __setLabels : function() {
     134        this.comp.labels.fullName = vI.elements.strings.getString("vident.identityData.Name") + ":";
     135        this.comp.labels.email = vI.elements.strings.getString("vident.identityData.Address") + ":";
     136        this.comp.labels.smtpName = vI.elements.strings.getString("vident.identityData.SMTP") + ":";
     137        this.comp.labels.idName = vI.elements.strings.getString("vident.identityData.baseID") + ":";
     138    },
     139
     140    getCompareMatrix : function() {
     141        const Items = Array("fullName", "email", "smtpName", "idName");
     142        this.__setLabels();
     143        var string = "";
     144        for each (item in Items) {
     145            var classEqual = (this.comp.equals[item])?"equal":"nonequal";
     146            string += "<tr>" +
     147                "<td class='col1 " + classEqual + "'>" + this.comp.labels[item] + "</td>" +
     148                "<td class='col2 " + classEqual + "'>" + this.comp.compareID[item].replace(/>/g,"&gt;").replace(/</g,"&lt;") + "</td>" +
     149                "<td class='col3 " + classEqual + "'>" + this[item].replace(/>/g,"&gt;").replace(/</g,"&lt;") + "</td>" +
     150                "</tr>"
     151        }
     152        return string;
     153    },
    121154}
    122155
     
    214247                // to prevent ugly double dialogs and time-consuming double-checks
    215248   
    216     elements : { Obj_storageSave : null },
    217    
    218249    promptService : Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
    219250            .getService(Components.interfaces.nsIPromptService),
     
    245276        },
    246277    },
    247    
    248     observe: function() {
    249         vI_storage.elements.Obj_storageSave.setAttribute("hidden",
    250             !vI.preferences.getBoolPref("storage_show_switch"));
    251         vI_storage.elements.Obj_storageSave.checked = vI.preferences.getBoolPref("storage_storedefault");
    252     },
    253    
    254     addObserver: function() {
    255         vI_storage.prefroot.addObserver("extensions.virtualIdentity.storage_show_switch", vI_storage, false);
    256         vI_storage.prefroot.addObserver("extensions.virtualIdentity.storage_storedefault", vI_storage, false); 
    257     },
    258    
    259     removeObserver: function() {
    260         vI_storage.prefroot.removeObserver("extensions.virtualIdentity.storage_show_switch", vI_storage);
    261         vI_storage.prefroot.removeObserver("extensions.virtualIdentity.storage_storedefault", vI_storage);
    262     },
    263    
     278       
    264279    awOnBlur : function (element) {
    265280        // only react on events triggered by addressCol2 - textinput Elements
     
    274289    },
    275290   
    276    
     291    initialized : null,
    277292    init: function() {
    278         if (!vI_storage.elements.Obj_storageSave) {
    279             vI_storage.elements.Obj_storageSave = document.getElementById("storage_save");
    280             vI_storage.addObserver();
    281             vI_storage.observe();
    282            
     293        if (!vI_storage.initialized) {
    283294            // better approach would be to use te onchange event, but this one is not fired in any change case
    284295            // see https://bugzilla.mozilla.org/show_bug.cgi?id=355367
     
    299310                }
    300311            }
     312            vI_storage.initialized = true;
    301313        }
    302314        vI_storage.original_functions.awSetInputAndPopupValue = awSetInputAndPopupValue;
     
    355367            // add Identity to dropdown-menu
    356368            var menuItem = vI_msgIdentityClone.addIdentityToCloneMenu(storageData)
    357             var warning = vI_storage.__getReplaceVIdentityWarning(recipient, storageData);
     369            var warning = vI_storage.__getWarning("replaceVIdentity", recipient, storageData.getCompareMatrix());
    358370           
    359371            if (    vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.getAttribute("timeStamp") ||
    360372                vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.getAttribute("value") != "vid" ||
    361373                !vI.preferences.getBoolPref("storage_warn_vI_replace") ||
    362                 vI_storage.promptService.confirm(window,"Warning",warning)) {
     374                vI_storage.__askWarning(warning)) {
    363375                    vI_msgIdentityClone.setMenuToMenuItem(menuItem)
    364376/*                  vI_msgIdentityClone.setMenuToIdentity(storageData.id);
     
    386398        if (!vI.preferences.getBoolPref("storage"))
    387399            { vI_notificationBar.dump("## vI_storage: Storage deactivated\n"); return; }
     400       
     401        if (vI_statusmenu.objStorageSaveMenuItem.getAttribute("checked") != "true") {
     402            vI_notificationBar.dump("## vI_storage: SaveMenuItem not checked.\n")
     403            return;
     404        }
     405       
    388406        vI_notificationBar.dump("## vI_storage: storeVIdentityToAllRecipients()\n");
    389        
    390         if (!vI_storage.elements.Obj_storageSave) {
    391             // ugly temp. fix for https://www.absorb.it/virtual-id/ticket/44
    392             vI_notificationBar.dump("## vI_storage: Obj_storageSave doesn't exist, shouldn't happen")
    393             vI_storage.elements.Obj_storageSave = document.getElementById("storage_save");
    394         }
    395         if (vI_storage.elements.Obj_storageSave.getAttribute("hidden") == "false" ) {
    396             vI_notificationBar.dump("## vI_storage: switch shown.\n")
    397             if (!vI_storage.elements.Obj_storageSave.checked) {
    398                 vI_notificationBar.dump("## vI_storage: save button not checked.\n")
    399                 return;
    400             }
    401         }
    402         else {
    403             vI_notificationBar.dump("## vI_storage: switch hidden.\n")
    404             if (!vI.preferences.getBoolPref("storage_storedefault")) {
    405                 vI_notificationBar.dump("## vI_storage: not be safed by default.\n")
    406                 return;
    407             }
    408         }
    409407       
    410408        // check if there are multiple recipients
     
    436434        var old_address = vI_helper.getAddress();
    437435        var id_key = vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.base_id_key;
    438         if (!id_key) id_key = vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.getAttribute("value");
    439436        var smtp_key = vI_smtpSelector.elements.Obj_SMTPServerList.selectedItem.getAttribute('key');
    440437        var extras = new vI_storageExtras();
     
    445442    },
    446443
    447     __getReplaceVIdentityWarning : function(recipient, storageData) {
    448         return  vI.elements.strings.getString("vident.updateVirtualIdentity.warning1") +
    449             recipient.recDesc + " (" + recipient.recType + ")" +
    450             vI.elements.strings.getString("vident.updateVirtualIdentity.warning2") +
    451             storageData.identityDescription() +
    452             vI.elements.strings.getString("vident.updateVirtualIdentity.warning3");
    453     },
    454    
    455     __getOverwriteStorageWarning : function(recipient, storageData) {
    456         return  vI.elements.strings.getString("vident.updateStorage.warning1") +
    457             recipient.recDesc + " (" + recipient.recType + ")" +
    458             vI.elements.strings.getString("vident.updateStorage.warning2") +
    459             storageData.identityDescription() +
    460             vI.elements.strings.getString("vident.updateStorage.warning3") +
    461             vI_storage.__getVIdentityString() +
    462             vI.elements.strings.getString("vident.updateStorage.warning4");
     444    __getWarning : function(warningCase, recipient, compareMatrix) {
     445        return  "<h1> " +
     446                vI.elements.strings.getString("vident." + warningCase + ".title") + "</h1>" +
     447            "<h2> " +
     448            "<span class='recLabel'>" +
     449                vI.elements.strings.getString("vident." + warningCase + ".recipient") +
     450                " (" + recipient.recType + "):</span>" +
     451            "<span class='recipient'>" +
     452                recipient.recDesc.replace(/>/g,"&gt;").replace(/</g,"&lt;") + "</span></h2>" +
     453            "<table><thead><tr><th class='col1'/>" +
     454                "<th class='col2'>" + vI.elements.strings.getString("vident." + warningCase + ".currentIdentity") + "</th>" +
     455                "<th class='col3'>" + vI.elements.strings.getString("vident." + warningCase + ".storedIdentity") + "</th>" +
     456            "</tr></thead>" +
     457            "<tbody>" + compareMatrix + "</tbody>" +
     458            "</table>" +
     459            "<div class='question'>" +
     460                vI.elements.strings.getString("vident." + warningCase + ".query") +
     461                "</div>"
     462    },
     463
     464    __askWarning : function(warning) {
     465        retVar = { return: null };             
     466        var answer = window.openDialog("chrome://v_identity/content/vI_Dialog.xul",0,
     467                    "chrome, dialog, modal, alwaysRaised, resizable=yes",
     468                     warning, "vI_DialogBrowser.css", retVar)
     469        return retVar.return;
    463470    },
    464471   
     
    471478        var storageData = vI_rdfDatasource.readVIdentityFromRDF(recipient.recDesc, recipient.recType);
    472479        if (storageData) {
    473             if (!storageData.equalsCurrentIdentity(storageData) &&
     480            if (!storageData.equalsCurrentIdentity() &&
    474481                !dontUpdateMultipleNoEqual) {
    475                 var warning = vI_storage.__getOverwriteStorageWarning(recipient, storageData);
     482                var warning = vI_storage.__getWarning("updateStorage", recipient, storageData.getCompareMatrix());
    476483                vI_notificationBar.dump("## vI_storage: " + warning + ".\n")
    477484                if (!vI.preferences.getBoolPref("storage_warn_update") ||
    478                         vI_storage.promptService.confirm(window,"Warning",warning))
     485                        vI_storage.__askWarning(warning))
     486//                      vI_storage.promptService.confirm(window,"Warning",warning))
    479487                vI_rdfDatasource.updateRDFFromVIdentity(recipient.recDesc, recipient.recType);
    480488            }
     
    591599    }
    592600}
    593 window.addEventListener("unload", function(e) { try {vI_storage.removeObserver();} catch (ex) { } }, false);
Note: See TracChangeset for help on using the changeset viewer.