Back

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

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

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


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


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

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

jQuery('${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.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.h}contentDropDown').append('<option value = '+contentlet.identifier +'>' + value+ '</option>');
                });
            }
        });
        };


</script>




#set($structureList=$structures.findStructures(true))

<select id="structureDropDown" >
#foreach($structure in $structureList )

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

</select >