11

I'm trying to build a GUI Extension for Audience Manager to disable the Email address field. My attempt (below) is failing because the field is disabled by default (at the point that I attempt to disable it in my code) and then re-enabled when the data has finished loading.

Is there an event I can hook into which will tell me when the whole view or the specific field have finished loading?

$evt.addEventHandler($display, 'start', function() {

    var handlers = {
        'GeneralTab': handleGeneralTab,
        'DetailsTab': handleDetailsTab,
        'CategoriesAndKeywordsTab': handleCategoriesTab
    }

    function handleGeneralTab($display) {
        // This works, but is overridden when details are loaded
        $j('#EmailAddress').attr('disabled', 'disabled');   
    }

    var tabs = $display.getView().properties.controls.TabControl;
    tabs && tabs.addEventListener('select', function(e) {
        var id = e.data.element.id;
        handlers[id] && handlers[id].call(this, $display);
    });

    // Initially we'll be in the general tab
    handleGeneralTab($display);
});
7

I afraid there is no simple solution.

Email address field is the control which state (enabled/disabled) updated each time then View state is changed.

Usually it happens when Item or some parts of the view are loaded or unloaded. Means, for instance when you save an item, it would get reloaded with new data, and all controls state will be re-set (new view state).

As this functionality is up to view, there are no general mechanis to handle it.

As a first option would be to override the updateView method (or method related for changing this field status) from Contact view JS file (or any other view where you want to diable the field).

Like this:

if (Tridion.OutboundEmail.UI.Editor.Views.Contact)
{
    (function ()
    {
        var NOT_RECOMMENDED$UIBeardcore$overriden$updateView = Tridion.OutboundEmail.UI.Editor.Views.Contact.prototype.updateView;
        Tridion.OutboundEmail.UI.Editor.Views.Contact.prototype.updateView = function NOT_RECOMMENDED$Editor$Views$Contact$updateView()
        {
            NOT_RECOMMENDED$UIBeardcore$overriden$updateView.apply(this, arguments) || {};

            var eAddr = this.properties.controls.emailAddress;
            if (eAddr)
            {
                eAddr.disabled = true;
            }
        };
    })();
}

Right after view will be updated, the field will re-update its state to disabled.

As a second, cheap-cheat option, if you have to have email address option disabled ALL time, I`d probably hide the field via CSS, and would implement TabInitializeExtended which will add the “fake” EmailAdress field. Plus functionality to synchronize the values, initialize methof will look like:

UIBeardcore.Extension.Tab.Views.Tabs.DisableEmailFieldExtender.prototype.initialize = function DisableEmailFieldExtender$initialize(id, parentTab)
{
    /* TODO: Create fake field and inject it into the place of previous one */

    var emailAddress = $("#EmailAddress");
    var fakeEmailAddress = $("#FakeEmailAddress");

    function DisableEmailFieldExtender$initialize$_onChangeHandler()
    {
        fakeEmailAddress.value = emailAddress.value;
    };

    $evt.addEventHandler(emailAddress, "valuepropertychange", DisableEmailFieldExtender$initialize$_onChangeHandler);

};
  • Thanks very much for this. I think the second option looks the tidiest, but I'm not sure how I'd set up my config file to include this (this is the first extension I've written). Do you know of an example XML which would be a good starting point? – net.uk.sweet Jul 1 '13 at 13:51
  • You have to create an implementation. The implementation sample you can grab from previous question about TabInitializeExtender: gist.github.com/anonymous/8a2e0ce4c5cf8ba934ef Put it in a JS file. Then put this js file in a configuration group. And associate this group with the one of the existing groups used in the view by extensiongroup in your configuration. I hope this video won`t make you more confused tridion.uibeardcore.com/2013/04/editor-extension Good luck! – UI Beardcore Jul 1 '13 at 14:27
  • Thanks a lot for all your help. Your videos are fantastic - just a shame SDL don't seem to want to document this stuff properly themselves as it's clearly a really powerful API. I went for the hacky, unrecommended override in the end as it seemed to best fit what I was already doing (ie. hacky). Thanks again. – net.uk.sweet Jul 2 '13 at 9:16
2

I am not sure if this will help you, but please have a look on my article about Read-only Tridion fields.

This code is a bit different than yours, but not sure if it will solve your issue...

var view = $display.getView();
if (view && Tridion.OO.implementsInterface(view, "Tridion.Cme.Views.Component"))
{
    var fieldBuilder = view.properties.controls.fieldBuilder;
    $evt.addEventHandler(fieldBuilder, "load", Extension$onDisplayStartedReadonly$_collectProperties);
}
  • Thanks for your help. Your articles have been really instructive. – net.uk.sweet Jul 2 '13 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.