[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hacking the Zimbra UI




----- "Steve Hillman" <hillman@sfu.ca> wrote:
>
> Thanks everyone for the help. I've managed to put together a possible solution, though we've only deployed it to our dev environment so far. I've also voted for the bug below, since their solution would almost certainly end up being more elegant than mine!
>
> Here's what I did
>  - modified the zimbraGalLdapAttrMap parameter and mapped ldap 'ou' to 'company'. That put our dept into one of the available Zimbra Contract attributes
>  - modified both CalendarCore_all.js and ContactsCore_all.js with the following patch:



It turns out that my hack had a bug in it - it would only append the department while you were typing the first word of an entry. Once you added a space and started on the second word, the department name was removed. I've now fixed that, and below is the entire function with my additions. Note that this function appears in both CalendarCore_all.js and ContactsCore_all.js and that they get minimized before being turned into the .zgz files, so you'd need to do a bit of work to integrate this into the zgz files (our developer has already done that work, so if anyone wants the diff for the minimized version, let me know)



ZmContactList.prototype._getMatches =
function(contact, str, galOnly) {
        contact = (contact instanceof ZmContact) ? contact : (contact && contact.id) ?
                                this.getById(contact.id) : this.getById(contact);

        if (galOnly && !contact.isGal) { return; }

        var match = this._testAcMatch(contact, str, true);
        if (!match) {
                DBG.println(AjxDebug.DBG1, "Matched contact with ID " + contact.id + " no longer matches '" + str + "' (possibly deleted)");
                return;
        }

        // SFU Change - add department (stored in Company attribute)
        // to the end of any name retrieved from the GAL - Steve H. (hillman@sfu.ca)

        var name;
        var names = [];
        if (match.matchedField == ZmContact.X_fullName ||
                match.matchedField == ZmContact.X_firstLast ||
                match.matchedField == ZmContact.F_fileAs)
        {
                // if one of these matched, it will already be highlighted
                // SFU Change: push this name onto the stack so that the dept can still be added to it
                names.push(match.savedMatch);
        } else {
                // construct name - first or last may have matched and been highlighted
                for (var i = 0; i < ZmContactList.AC_NAME_FIELDS.length; i++) {
                        var field = ZmContactList.AC_NAME_FIELDS[i];
                        var val = ZmContact.getAttr(contact, field);
                        if (val) {
                                names.push((match.matchedField == field) ? match.savedMatch : val);
                        }
                }
        }

        // Fetch the company attribute and, if defined, add it to the name in (brackets)
        var val = ZmContact.getAttr(contact, ZmContact.F_company);
        if  (val && (val != "na")) {
            names.push(" (" + val + ")");
        }
        // *** End of SFU Change

        name = names.join(" ");

        var results = [];
        var fullName = contact.getFullName();
        if (match.matchedField == ZmContact.F_email || match.matchedField == ZmContact.F_email2 || match.matchedField == ZmContact.F_email3) {
                results.push(this._createMatch(name, match.savedMatch, fullName, ZmContact.getAttr(contact, match.matchedField), contact));
        } else {
                if (contact.isGroup()) {
                        var val = contact.getGroupMembers().good;
                        results.push(this._createMatch(name, val, fullName, val, contact));
                } else {
                        var emailAttrs = contact.isGal ? [ZmContact.F_email] : ZmContact.F_EMAIL_FIELDS;
                        for (var i = 0; i < emailAttrs.length; i++) {
                                var val = ZmContact.getAttr(contact, emailAttrs[i]);
                                if (val) {
                                        results.push(this._createMatch(name, val, fullName, val, contact));
                                }
                        }
                }
        }

        return results;
};


--
Steve Hillman                                IT Architect
hillman@sfu.ca                               IT Infrastructure
778-782-3960                                 Simon Fraser University