Retrieve All Structure Names on Your System and Store them on a Drop Down List Custom Field

Description

This custom field retrieves all structures in your system and display their names and identifiers on a drop down.

You can then use the name of the structure for content pulls or anything you need.

 

 

Code

<script type="text/javascript" src="/js/jQuery.1.5.2.min.js"></script>

${esc.hash}set (${esc.dollar}_dummy = ${esc.dollar}render.eval("\${esc.hash}set (${esc.dollar}CustomFieldValue = ${esc.dollar}${esc.dollar}{field.velocityVarName})"))
${esc.hash}set (${esc.dollar}defaultValue = "")


<script type="text/javascript">
 jQuery.noConflict();
</script>


<script type="text/javascript">
  
jQuery(document).ready(function() {
 refreshContents("${esc.dollar}CustomFieldValue");
 jQuery('${esc.dollar}{esc.h}structureDropDown').change(function(){
    updateStructrue();
});
});
  function updateStructrue() {
	document.getElementById("${esc.dollar}{field.velocityVarName}").value = document.getElementById("structureDropDown").value;

jQuery('${esc.dollar}{esc.h}delPanel').html("");

jQuery('${esc.dollar}{esc.h}contentToChoose').val("");
        
refreshContents(document.getElementById("structureDropDown").value)

  }
 function refreshContents(stucture) {


        var stuctureQ = '';
        if(stucture&& stucture.length > 0) {
            stuctureQ = stucture;
        }
      jQuery.ajax({
            url: '/JSONContent/',
            data: 'type=json&limit=1000&orderBy='+stucture+'.urlTitle&q=%2BstructureName:' + stuctureQ,
            dataType: 'json',
            success: function(data) {
            jQuery('${esc.dollar}{esc.h}contentDropDown').find('option').remove();
               
                jQuery.each(data.contentlets, function(i, contentlet) {
                 var value = "";
                 if(typeof(contentlet.title)=='undefined'||typeof(contentlet.title)==null||contentlet.title=='undefined')
{
if(typeof(contentlet.name)=='undefined'||typeof(contentlet.name)==null||contentlet.name=='undefined')
{
alert("error Structure");
return;
}
else{
value=contentlet.name;
}
   }          
else{
 value=contentlet.title;
}				 
				  
jQuery('${esc.dollar}{esc.h}contentDropDown').append('<option value = '+contentlet.identifier +'>' + value+ '</option>');
                });
            }
        });
        };


</script>




${esc.hash}set(${esc.dollar}structureList=${esc.dollar}structures.findStructures(true))

<select id="structureDropDown" >
${esc.hash}foreach(${esc.dollar}structure in ${esc.dollar}structureList )

${esc.hash}if(!${esc.dollar}structure.isWidget())
${esc.hash}set(${esc.dollar}select="")
${esc.hash}if(${esc.dollar}structure.name==${esc.dollar}CustomFieldValue)
${esc.hash}set(${esc.dollar}select="SELECTED")
${esc.hash}end
<option value="${esc.dollar}UtilMethods.encodeURL(${esc.dollar}structure.velocityVarName)" ${esc.dollar}select>${esc.dollar}structure.name</option>
${esc.hash}end
${esc.hash}end

</select >