7

I have implemented an additional tab control to the edit window at the component presentation level for a page using the approach mentioned here : http://www.curlette.com/?p=753

However I need to restrict the custom tab to appear only for a particular publication and I also want the fields in the custom tab to be mandatory and hence I need a way of validating and informing the author if they are left empty.

My questions:

  1. Is it possible to restrict the custom tab to appear on pages of a particular publication? If yes, how do we achieve it?
  2. Where to validate for the mandatory fields under custom tab?

4 Answers 4

2

1\ Tab page initialize happen when user selects tab, but not when tab control initialized. You need to implement

Extension.Tab.prototype.setParentControl = function Extension$setParentControl()
{
    this.callBase("Tridion.Controls.DeckPage", "setParentControl", arguments);

    var item = $display.getItem();
    if (item)
    {
        this._updateTabState();
    }

    // if necessary
    // $evt.addEventHandler(item, "load", this.getDelegate(this._updateTabState));
    // $evt.addEventHandler(item, "loadfailed", this.getDelegate(this._updateTabState));
};

And _updateTabState

Extension.Tab.prototype._updateTabState = function Extension$_updateTabState(result)
{
    var p = this.properties;

    if (condition)
    {
        p.parentControl.showItem(this);
    }
    else
    {
        p.parentControl.hideItem(this);
    }

};

2\ When item is saving, it fires validate event before save, which you can handle. If your validation is ok, return true or nothing, otherwise – do return false

In initialize method: $evt.addEventHandler(item, "validate", this.getDelegate(this.onItemValidate));

And

Extension.Tab.prototype.onItemValidate = function Extension$onItemValidate(event)
{
    var c = this.properties.controls;
    if (c.ExtraField.value.length == 0)
    {
        $messages.registerError("This field is empty", null, null, true);
        return false;
    }
};

UPD:

As a good practice I`d strongly suggest to avoid using hardcoded uris.

When you have a condition by which you define to show/hide tab, you can export this condition into item properties via DataExtender.

And then Use by ItemType extending get an access to this property.

In this case, updateState Condition would look like

if (Type.implementsInterface(item , "Extension.ItemType.Publication")) && item.isNewTabShouldBeShown())
1

I don't think it is possible to only show a tab for a specific Publication, once you add a tab to a certain view/control, it will always be there. But you can choose to hide it (via CSS) in its initialize method when you are not in the Publication you want it in.

Following Roberts example code, you will want to adjust the initialize() method to something like this:

RC.HelloTab.prototype.initialize = function HelloTab$initialize()
{
  var item = $display.getItem();
  var pubId = item.getPublicationId();

  if (pubId == "tcm:0-4-1")
  {
    console.log('init');
    this.callBase("Tridion.Controls.DeckPage", "initialize");
    $evt.addEventHandler(item, "load", this.getDelegate(this.updateView));
  }
  else
  {
    // hide this tab through css in case it does still show up
  }
};
4
  • I tried without using the css thing in else part but the tab still shows up. Guess hiding through css would be the only way to go. But I wonder why it still shows up when there is a if condition to initialize the custom tab.
    – Keirthana
    Commented May 23, 2014 at 10:02
  • @Keirthana I was hoping too it might not show, but the tab is placed there already because you added it in the configuration. If you fail to initialize it, then it will just not have event handlers tied to it, but it will be there. Commented May 23, 2014 at 11:00
  • As we are inserting the tab at the config level, is it possible to give the tab a separate div and hide it in the initialize method? As you said once we introduce the tab at the config level, it appears on the page view. So unless there is a way to hide it in the config file, I don't see how we can do this. Even if we are to hide the tab in the initialize method, how do we access the custom tab to hide it? Any ideas would be of great help.
    – Keirthana
    Commented May 26, 2014 at 6:11
  • The div id for the tab is being generated during run time based on the id that we are passing from the config file. For example, my config file passes the id RC.OfferConditions for that particular div. when I inspect the tab with firebug the div id is changed to RC.OfferConditions_switch. So any idea how do we apply the hidden style to this div when the id is being generated during run time?
    – Keirthana
    Commented May 29, 2014 at 10:56
1

We are able to hid the tab by validating it against the publication and hiding it using setParentControl() in anguilla framework.

if (pubId != "your publication")
         this.getParentControl().hideItem(this);
0

You can try following in your command js.

Extensions.YourExnName.prototype.isAvailable = function YourExnName$isAvailable(target)
{

//check here for publication
    return true/false;;
};

Extensions.YourExnName.prototype.isEnabled = function YourExnName$isEnabled(target) {
//check here for publication
    return true/false;
};

2) Validation can be done using javaScript also in your onclick or other events, did you try?

5
  • 1) Would this prevent the tab from loading for other publications? Because I don't want the tab to appear for other publications and I am doubting if this will only prevent the data from being stored for other publications rather than preventing the custom tab from loading at all. 2)Yes, I was also thinking on the same lines. I am trying to give a pop up while picking the value of the fields.
    – Keirthana
    Commented May 23, 2014 at 6:56
  • You can give it try. so try using either of these methods or both as per your requirements. Let me know, if works
    – Raj Kumar
    Commented May 23, 2014 at 7:00
  • 1
    I think the isAvailable() and isEnabled() only work for commands, which then could enable or make a button in the ribbon available. Commented May 23, 2014 at 7:54
  • I think Bart is right. This didn't work when I used in either methods or both methods.
    – Keirthana
    Commented May 23, 2014 at 10:01
  • cool, validation done? i will check further for any solution. please update your solution in the answer when you done
    – Raj Kumar
    Commented May 23, 2014 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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