Dynamically Hiding Attributes on Basic Asset Forms

image

Content Editor: "Why does it show all these fields on this form?  I don't want to see the ones that our site doesn't use."

You: "Because other sites require those fields."

Content Editor: "Can you please remove them, it is confusing."

You:  "Hmmm."

Well actually this common scenario isn't that hard to accomplish.

For every basic asset there is a ContentForm and ContentDetails element created in the OpenMarket/Xcelerate/AssetType/[your asset type].

We can hook into these elements to make customizations to the forms.  In our case we will create a new element which encapsulates our customizations in order to keep our code DRY.  The convention I normally use is to simply create another element called ContentCustomizations inside of that same directory.  By creating it in this directory it will move around every where with your asset.  For the rest of this article I will assume we are modifying an asset type called "MyAsset."

There are two distinct places where you need to call your custom element.   

Inside of OpenMarket/Xcelerate/AssetType/MyAsset/ContentForm.xml you will add it right at the beginning of the element:

<CALLELEMENT NAME="OpenMarket/Xcelerate/AssetType/MyAsset/ContentCustomizations"/>
<div dojoType="dijit.layout.BorderContainer" class="bordercontainer">
<INPUT TYPE="hidden" NAME="upcommand" VALUE="submit"/>
<INPUT TYPE="hidden" NAME="Prefix" VALUE="Variables.AssetType" REPLACEALL="Variables.AssetType"/>
<CALLELEMENT NAME="OpenMarket/Xcelerate/Actions/AssetMgt/AssetChildrenFormNewJavascript"/>

Inside of OpenMarket/Xcelerate/AssetType/MyAsset/ContentDetails.xml you will need to add it after the Java call to AssetMaker.

<div dojoType="dijit.layout.BorderContainer" class="bordercontainer">
<setvar NAME="errno" VALUE="0"/>
<setvar NAME="command" VALUE="parseproperties"/>
<CALLJAVA CLASS="com.openmarket.assetmaker.asset.AssetMaker" TYPE="1">
    <ARGUMENT NAME="command" VALUE="Variables.command"/>
    <ARGUMENT NAME="propertytags" VALUE="storage, inputform"/>
    <ARGUMENT NAME="assettype" VALUE="Variables.AssetType"/>
</CALLJAVA>
<CALLELEMENT NAME="OpenMarket/Xcelerate/AssetType/MyAsset/ContentCustomizations"/>

Now for the fun part!

In order to hide certain properties based upon what site we are working on we need to set a specific variable.  For our purposes we will try to hide the "Site2Specific" attribute.

Inside of our content customizations element all we have to do is check what site we are working on and then hide it if we are on a site that doesn't want to see it.

if("1112198287026".equals(ics.GetSSVar("pubid"))){
    ics.SetVar("assetmaker/property/Site2Specific/inputform/hidden", "YES");
}

And that is it.  Setting that little variable will make the attribute disappear.   We can safely check based upon pubid since pubid does not change when publishing or using the CSDT tool. 

The beautiful part of this is that it involves almost 0 modifications to OOTB elements.  Also because we put our element in the place we did, it will travel around with the asset.  If you use CSDT or publishing to move around the asset, sites will automatically move along all of the files in the OpenMarket/Xcelerate/AssetType/MyAsset directory.  Finally, it involves no flaky dojo JavaScript, which is liable to break with any given patch.

Now our users are happy and not confused anymore.

Comments

Subscribe to Our Newsletter

Stay In Touch