Thank you, Sharyn. This code was very helpful. I did a little tweaking and a little cleanup and produced a version that meets my own needs.
For anyone else interested here’s the control code I wound up with… It’s essentially the same as Sharyn’s, but without unreachable artifact code, and instead of storing the result of a template, it stores the content id and template id (and site and folder id if you’ve selected to in the browser window) in JSON code.
Stored values will look like this:
{“contentid”:123,“templateid”:456,“siteid”:789,“folderid”:345}
Combine this with the JSONtools I posted previously, and you can treat each link as a complex data object in your template, and load whatever data you need from it.
This version also used jQuery to traverse the form elements and DOM. And to display the output of the selected template in a preview div.
To use:
By default, this control allows linking to items that would normally be available in the system inline_link_slot (slot id 103). If you wish to link to items available in a different slot, select “All Properties” for the control and enter the slot id of your inline slot for the “inlineSlot” parameter.
After that, it’s just a matter of parsing and utilizing the data within your templates.
File linklookup.js:
/**
* This file holds the functions for the custom search button on the question answer image control.
*/
/**
* Global variables needed for the browse dialog
*/
var ___cBackFunction = null;
var ___slotId = null;
var ___bws = null;
var ___bwsMode = null;
var __rxroot = "/Rhythmyx";
var ___serverProperties = null;
var ___selectedContent = null;
/**
* Creates CMS search box for inline links and CMS Image creation:
*/
function launchLinkSearchBox( fieldObj, inlineslotid )
{
// create local variable so it can be referenced by the callback.
var field = fieldObj;
var ctypeid = document.forms["EditForm"].sys_contenttypeid.value;
___slotId ='["1",null,null,null,null,null,null,"'
+ ctypeid + '",null,"' + inlineslotid + '",null,null,null,null,null]';
___cBackFunction = function(objectId) {
var oId = new ps.aa.ObjectId(objectId.toString());
var buff = '{"contentid":' + oId.getContentId() + ',"templateid":' + oId.getTemplateId();
if( oId.getSiteId() != null ) {
buff += ',"siteid":' + oId.getSiteId();
}
if( oId.getFolderId() != null ) {
buff += ',"folderid":' + oId.getFolderId();
}
buff += '}';
field.value = buff;
___bws.close();
displayLinkPreview(jQuery(field).siblings('.rx_LinkLookup_preview'),buff);
};
___bwsMode = ps.util.BROWSE_MODE_RTE_INLINE;
___bws = window.open(ps.util.CONTENT_BROWSE_URL, "contentBrowerDialog",
"resizable=1;status=0,toolbar=0,scrollbars=0,menubar=0,location=0,directories=0,width=750,height=500");
}
function displayLinkPreview( dom, obj )
{
var o = eval('('+obj+')');
var sid = o.siteid != undefined ? o.siteid : 'null';
var fid = o.folderid != undefined ? o.folderid : 'null';
var objId = new ps.aa.ObjectId('["1",'+ o.contentid +','+ o.templateid +','+ sid +','+ fid
+',null,null,null,null,null,null,null,null,null,null]');
var response = ps.io.Actions.getSnippetContent(objId, false, "");
if(response.isSuccess())
{
jQuery(dom).html(unicode2entity(response.getValue()));
}
else
{
ps.io.Actions.maybeReportActionError(response);
}
}
// Converts unicode chars into the hexidecimal reference
// entity
function unicode2entity(str)
{
var sPos = 0;
var ePos = -1;
var result = "";
while((sPos = str.indexOf("%u", sPos)) != -1)
{
if(ePos == -1)
{
ePos = 0;
result += str.substring(ePos, sPos);
}
else if(sPos - ePos > 0)
{
result += str.substring(ePos + 1, sPos);
}
result += "&#x" + str.substr(sPos + 2, 4) + ";";
sPos += 5;
ePos = sPos;
}
result += str.substring(ePos + 1);
return result;
}
function minIgnoreNegative(a, b)
{
if(a == -1)
return b;
if(b == -1)
return a;
return Math.min(a,b);
}
Excerpt from file rx_Templates.xsl:
<!--
rx_LinkLookup
-->
<psxctl:ControlMeta name="rx_LinkLookup" dimension="single" choiceset="none">
<psxctl:Description>Opens a link browser dialog to link a content item without using the Active Assembly interface.</psxctl:Description>
<psxctl:ParamList>
<psxctl:Param name="id" datatype="String" paramtype="generic">
<psxctl:Description>This parameter assigns a name to an element. This name must be unique in a document.</psxctl:Description>
</psxctl:Param>
<psxctl:Param name="class" datatype="String" paramtype="generic">
<psxctl:Description>This parameter assigns a class name or set of class names to an element. Any number of elements may be assigned the same class name or names. Multiple class names must be separated by white space characters. The default value is "datadisplay".</psxctl:Description>
<psxctl:DefaultValue>datadisplay</psxctl:DefaultValue>
</psxctl:Param>
<psxctl:Param name="style" datatype="String" paramtype="generic">
<psxctl:Description>This parameter specifies style information for the current element. The syntax of the value of the style attribute is determined by the default style sheet language.</psxctl:Description>
</psxctl:Param>
<psxctl:Param name="tabindex" datatype="Number" paramtype="generic">
<psxctl:Description>This parameter specifies the position of the current element in the tabbing order for the current document. This value must be a number between 0 and 32767.</psxctl:Description>
</psxctl:Param>
<psxctl:Param name="inlineSlot" datatype="String" paramtype="generic">
<psxctl:Description>This parameter specifies the id of inline slot. The inline search dialog box shows the content types that have at least one variant added to the inline slot. The default value is system inline image slotid 104.</psxctl:Description>
<psxctl:DefaultValue>104</psxctl:DefaultValue>
</psxctl:Param>
<psxctl:Param name="formname" datatype="String" paramtype="jscript">
<psxctl:Description>This parameter specifies the name of the form that contains this control. It is used by the link control's JavaScript. The default value is "EditForm". Values other than EditForm may produce unreliable results.</psxctl:Description>
<psxctl:DefaultValue>EditForm</psxctl:DefaultValue>
</psxctl:Param>
</psxctl:ParamList>
<psxctl:AssociatedFileList>
<psxctl:FileDescriptor name="dojo.js" type="script" mimetype="text/javascript">
<psxctl:FileLocation>../sys_resources/dojo/dojo.js</psxctl:FileLocation>
<psxctl:Timestamp/>
</psxctl:FileDescriptor>
<psxctl:FileDescriptor name="linkLookup.js" type="script" mimetype="text/javascript">
<psxctl:FileLocation>../rx_resources/js/linkLookup.js</psxctl:FileLocation>
<psxctl:Timestamp/>
</psxctl:FileDescriptor>
</psxctl:AssociatedFileList>
</psxctl:ControlMeta>
<!-- read only template for rx_LinkLookup-->
<xsl:template match="Control[@name='rx_LinkLookup' and @isReadOnly='yes']" priority="10" mode="psxcontrol">
<input type="hidden" name="{@paramName}" value="{Value}"/>
<xsl:choose>
<xsl:when test="(string-length(Value) = 0)">None</xsl:when>
<xsl:otherwise>
<script type="text/javascript">jQuery(function(){displayLinkPreview(jQuery(<xsl:value-of select="concat('document.',$formname,'.',$name)"/>).siblings('.rx_LinkLookup_preview'),'<xsl:value-of select="Value"/>');});</script>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="Control[@name='rx_LinkLookup' and @isReadOnly='no']" mode="psxcontrol">
<input type="hidden" name="{@paramName}" value="{Value}">
<xsl:if test="@accessKey!=''">
<xsl:attribute name="accesskey">
<xsl:call-template name="getaccesskey">
<xsl:with-param name="label" select="preceding-sibling::DisplayLabel"/>
<xsl:with-param name="sourceType" select="preceding-sibling::DisplayLabel/@sourceType"/>
<xsl:with-param name="paramName" select="@paramName"/>
<xsl:with-param name="accessKey" select="@accessKey"/>
</xsl:call-template></xsl:attribute>
</xsl:if>
<xsl:call-template name="parametersToAttributes">
<xsl:with-param name="controlClassName" select="'rx_EditBox'"/>
<xsl:with-param name="controlNode" select="."/>
</xsl:call-template>
</input>
<xsl:variable name="apos" select='"'"'/>
<xsl:variable name="amp" select='"&"'/>
<xsl:variable name="formname">
<xsl:choose>
<xsl:when test="ParamList/Param[@name='formname']">
<xsl:value-of select="ParamList/Param[@name='formname']"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="document('')/*/psxctl:ControlMeta[@name='rx_LinkLookup']/psxctl:ParamList/psxctl:Param[@name='formname']/psxctl:DefaultValue"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="InlineImageSlot">
<xsl:choose>
<xsl:when test="ParamList/Param[@name='inlineSlot']">
<xsl:value-of select="ParamList/Param[@name='inlineSlot']"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="document('')/*/psxctl:ControlMeta[@name='rx_LinkLookup']/psxctl:ParamList/psxctl:Param[@name='inlineSlot']/psxctl:DefaultValue"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="name">
<xsl:value-of select="@paramName"/>
</xsl:variable>
<a href="#">
<xsl:attribute name="onclick">
<xsl:value-of select="concat('launchLinkSearchBox(document.',$formname,'.',$name,',',$apos,$InlineImageSlot,$apos,');')"/>
</xsl:attribute>
<xsl:text>Search</xsl:text>
</a>
<xsl:if test="string-length(Value) > 0">
<xsl:text disable-output-escaping="yes"> </xsl:text>
<a href="#">
<xsl:attribute name="onclick">
<xsl:value-of select="concat('document.',$formname,'.',$name,'.value=',$apos,$apos)"/>
<xsl:text>;jQuery(this).siblings('.rx_LinkLookup_preview').html('None');</xsl:text>
</xsl:attribute>
<xsl:text>Clear</xsl:text>
</a>
</xsl:if>
<div class="rx_LinkLookup_preview" style="margin:5px;">
<xsl:choose>
<xsl:when test="(string-length(Value) = 0)">None</xsl:when>
<xsl:otherwise>
<script type="text/javascript">jQuery(function(){displayLinkPreview(jQuery(<xsl:value-of select="concat('document.',$formname,'.',$name)"/>).siblings('.rx_LinkLookup_preview'),'<xsl:value-of select="Value"/>');});</script>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:template>