Changeset 99d4f2


Ignore:
Timestamp:
Apr 18, 2008, 12:55:53 PM (14 years ago)
Author:
rene <rene@…>
Branches:
master
Children:
59411c
Parents:
6479cb
Message:

changed output to be partially object-oriented, sould be improved

Location:
chrome/content/v_identity
Files:
5 edited

Legend:

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

    r6479cb r99d4f2  
     1
     2
     3function keyTranslator() { }
     4keyTranslator.prototype = {
     5    SMTP_NAMES : null,
     6    ID_NAMES : null,
     7    __getSMTPnames : function () {
     8        this.SMTP_NAMES = [];
     9        var smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"]
     10            .getService(Components.interfaces.nsISmtpService);
     11        for (var i=0 ; i<smtpService.smtpServers.Count(); i++) {
     12            var server = smtpService.smtpServers.QueryElementAt(i, Components.interfaces.nsISmtpServer);
     13            if (!server.redirectorType)
     14                this.SMTP_NAMES[server.key] = server.description?server.description:server.hostname
     15        }
     16    },
     17    __getIDnames : function () {
     18        this.ID_NAMES = [];
     19        var accounts = queryISupportsArray(gAccountManager.accounts, Components.interfaces.nsIMsgAccount);
     20        accounts.sort(compareAccountSortOrder);
     21        for (var i in accounts) {
     22            var server = accounts[i].incomingServer;
     23            if (!server) continue;
     24            var identites = queryISupportsArray(accounts[i].identities, Components.interfaces.nsIMsgIdentity);
     25            for (var j in identites)
     26                this.ID_NAMES[identites[j].key] = identites[j].identityName;
     27        }
     28    },
     29    getSMTPname : function (smtpKey) {
     30        if (!smtpKey) return document.getElementById("bundle_messenger").getString("defaultServerTag")
     31        else {
     32            if (!this.SMTP_NAMES) this.__getSMTPnames();
     33            return this.SMTP_NAMES[smtpKey]
     34        }
     35    },
     36    getIDname : function (idKey) {
     37        if (!idKey) return "";
     38        if (!this.ID_NAMES) this.__getIDnames();
     39        return this.ID_NAMES[idKey]
     40    },
     41}
     42
     43
     44
    145var vI_helper = {
    246    // "accountname" property changed in Thunderbird 3.x, Seamonkey 1.5x to "description"
  • chrome/content/v_identity/vI_rdfDataTree.js

    r6479cb r99d4f2  
    3636   
    3737    __strings : null,
    38     __SMTP_NAMES : [],
    39     __ID_NAMES : [],
     38    __keyTranslator : null,
    4039
    4140    promptService : Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
     
    4645        vI_rdfDataTree.__treeElem = document.getElementById("rdfDataTree");
    4746        vI_rdfDataTree.__strings = document.getElementById("vI_rdfDataTreeBundle");
    48         vI_rdfDataTree.__getSMTPnames();
    49         vI_rdfDataTree.__getIDnames();
     47        vI_rdfDataTree.__keyTranslator = new keyTranslator();
    5048        vI_storageExtrasHelper.hideUnusedTreeCols();
    5149        vI_rdfDataTree.loadTable();
     
    5856    },
    5957   
    60     __getSMTPnames : function () {
    61         var smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"]
    62             .getService(Components.interfaces.nsISmtpService);
    63         for (var i=0 ; i<smtpService.smtpServers.Count(); i++) {
    64             var server = smtpService.smtpServers.QueryElementAt(i, Components.interfaces.nsISmtpServer);
    65             if (!server.redirectorType)
    66                 vI_rdfDataTree.__SMTP_NAMES[server.key] = server.description?server.description:server.hostname
    67         }
    68     },
    69 
    70     __getIDnames : function () {
    71         var accounts = queryISupportsArray(gAccountManager.accounts, Components.interfaces.nsIMsgAccount);
    72         accounts.sort(compareAccountSortOrder);
    73         for (var i in accounts) {
    74             var server = accounts[i].incomingServer;
    75             if (!server) continue;
    76             var identites = queryISupportsArray(accounts[i].identities, Components.interfaces.nsIMsgIdentity);
    77             for (var j in identites)
    78                 vI_rdfDataTree.__ID_NAMES[identites[j].key] = identites[j].identityName;
    79         }
    80     },
    81    
    8258    __addNewDatum : function(resource, type, name, values) {
    83         var smtpName = ""; var idName = "";
    84         if (!values.smtp) smtpName = document.getElementById("bundle_messenger").getString("defaultServerTag")
    85         else smtpName = vI_rdfDataTree.__SMTP_NAMES[values.smtp]
    86        
    87         if (values.id) idName = vI_rdfDataTree.__ID_NAMES[values.id]
     59        var smtpName = vI_rdfDataTree.__keyTranslator.getSMTPname(values.smtp);
     60        var idName = vI_rdfDataTree.__keyTranslator.getSMTPname(values.id);
    8861       
    8962        var pref = {    recipientCol : name,
  • chrome/content/v_identity/vI_rdfDataTree.xul

    r6479cb r99d4f2  
    4343<script type="application/x-javascript" src="chrome://v_identity/content/vI_rdfDatasource.js" />
    4444<script type="application/x-javascript" src="chrome://v_identity/content/vI_storageExtras.js" />
     45<script type="application/x-javascript" src="chrome://v_identity/content/vI_storage.js" />
    4546<script type="application/x-javascript" src="chrome://v_identity/content/vI_notificationBar.js"/>
    4647<script type="application/x-javascript" src="chrome://messenger/content/messengercompose/MsgComposeCommands.js"/>
  • chrome/content/v_identity/vI_rdfDatasource.js

    r6479cb r99d4f2  
    159159            var smtp = vI_rdfDatasource.__getRDFValue(resource, "smtp")
    160160            var extras = new vI_storageExtras(vI_rdfDatasource.__getRDFValue, resource);
    161             var values = { email : email, fullName : fullName, id : id, smtp : (smtp=="default"?"":smtp), extras : extras  };
    162161           
    163             callFunction (resource, type, name, values)     
     162            var localIdentityData = new identityData(email, fullName, id, smtp, extras)
     163            callFunction (resource, type, name, localIdentityData)     
    164164        }
    165165    },
     
    174174        vI_notificationBar.dump("## vI_rdfDatasource: readVIdentityFromRDF found stored data.\n");
    175175       
    176         var email = vI_rdfDatasource.__getRDFValue(resource, "email")
     176        email = vI_rdfDatasource.__getRDFValue(resource, "email")
    177177        var fullName = vI_rdfDatasource.__getRDFValue(resource, "fullName")
    178178        var id = vI_rdfDatasource.__getRDFValue(resource, "id")
     
    187187        vI_notificationBar.dump("## vI_rdfDatasource: extras: " + extras.status() + "\n");
    188188       
    189         return { email : email, fullName : fullName, id : id, smtp : (smtp=="default"?"":smtp), extras : extras };
     189        var localIdentityData = new identityData(email, fullName, id, smtp, extras)
     190        return localIdentityData;
    190191    },
    191192   
  • chrome/content/v_identity/vI_storage.js

    r6479cb r99d4f2  
    2828*/
    2929
     30
     31function identityData(email, fullName, id, smtp, extras) {
     32    this.email = email;
     33    this.fullName = fullName;
     34    this.id = id;
     35    this.smtp = (smtp=="default"?"":smtp);
     36    this.extras = extras;
     37    this.__keyTranslator = new keyTranslator();
     38}
     39identityData.prototype = {
     40    email : null,
     41    fullName : null,
     42    id_key : null,
     43    smtp_key : null,
     44    extras : null,
     45    __keyTranslator : null,
     46    __combineStrings : function(stringA, stringB) {
     47        var A = stringA.replace(/^\s+|\s+$/g,"");
     48        var B = stringB.replace(/^\s+|\s+$/g,"");
     49        if (!A) return B;
     50        if (!B) return A;
     51        return A + ", " + B;
     52    },
     53    identityDescription : function(index) {
     54        var senderName = vI_helper.combineNames(this.fullName, this.email);
     55        var idName = this.__keyTranslator.getIDname(this.id);
     56        var smtpName = this.__keyTranslator.getSMTPname(this.smtp);
     57        var extras = this.extras.status();
     58        return senderName + " (" +
     59            this.__combineStrings(this.__combineStrings(idName, smtpName), extras) +  ")"
     60    }
     61}
    3062
    3163function identityCollection() { }
     
    3870    id_keys : {},
    3971    smtp_keys : {},
    40     extras : {}
     72    extras : {},
    4173};
    4274
     
    285317   
    286318    __getVIdentityString : function() {
    287         var old_address = vI_helper.getAddress();       
     319        var old_address = vI_helper.getAddress();
    288320        var id_key = vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.getAttribute("oldvalue");
    289321        if (!id_key) id_key = vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.getAttribute("value");
    290322        var smtp_key = vI_smtpSelector.elements.Obj_SMTPServerList.selectedItem.getAttribute('key');
    291         return old_address.combinedName + " (" + id_key + "," +
    292         (smtp_key?smtp_key:document.getElementById("bundle_messenger").getString("defaultServerTag")) +
    293         ")"
     323        var extras = new vI_storageExtras();
     324        extras.readValues();
     325        var localIdentityData = new identityData(old_address.email, old_address.name,
     326            id_key, smtp_key, extras)
     327        return localIdentityData.identityDescription();
    294328    },
    295329
     
    298332            recipient.recDesc + " (" + recipient.recType + ")" +
    299333            vI.elements.strings.getString("vident.updateVirtualIdentity.warning2") +
    300             vI_helper.combineNames(storageData.fullName, storageData.email) +
    301             " (" + storageData.id + "," +
    302             (storageData.smtp?storageData.smtp:document.getElementById("bundle_messenger").getString("defaultServerTag")) +
    303             ")" + vI.elements.strings.getString("vident.updateVirtualIdentity.warning3");
     334            storageData.identityDescription() +
     335            vI.elements.strings.getString("vident.updateVirtualIdentity.warning3");
    304336    },
    305337   
     
    308340            recipient.recDesc + " (" + recipient.recType + ")" +
    309341            vI.elements.strings.getString("vident.updateStorage.warning2") +
    310             vI_helper.combineNames(storageData.fullName, storageData.email) +
    311             " (" + storageData.id + "," +
    312             (storageData.smtp?storageData.smtp:document.getElementById("bundle_messenger").getString("defaultServerTag")) +
    313             ")" + vI.elements.strings.getString("vident.updateStorage.warning3") +
     342            storageData.identityDescription() +
     343            vI.elements.strings.getString("vident.updateStorage.warning3") +
    314344            vI_storage.__getVIdentityString() +
    315345            vI.elements.strings.getString("vident.updateStorage.warning4");
Note: See TracChangeset for help on using the changeset viewer.