Displaying Images in Custom Searches
From C3 Wiki
[edit] Summary
By utilizing the ability of Calling Entity Methods in Custom Searches, it's possible to build up html for display, including images. You can build up the image path either from a static location or from a property of type document content.
[edit] Examples
Note: some images paths reference external urls for ease of replication. Do not use references to external urls in production environments.
Example 1: Use an icon as an indicator of protocol status. Entity method on _Protocol.
function showStatusIcon()
{
try {
//Display an icon for the protocol depending on its current status
//If it's approved, show a checkmark
//Otherwise, show an X
var html;
if (this.status.ID == "Active"){
html = "<img src='https://careerservices.brocku.ca/imgs/check_mark.png'>";
}else{
html = "<img src='http://profitsincluded.com/asd/red-x.gif'>";
}
return html;
}
catch (e) {
wom.log("EXCEPTION _Protocol.showStatusIcon: " + e.description);
throw(e);
}
}
Example 2: Calculate turaround time from receipt to approval and show an icon indicating whether or not it has met the turnaround time goal. Entity method on _Protocol. (See Calling Entity Methods in Custom Searches for the method calcDaysFromReceivedToApproved )
function showTurnaroundTimeIcon()
{
try {
//Display an icon for the protocol depending on its turnaround time
//If it's under 21 days, show a checkmark
//Otherwise, show an X
var turnaroundTime = calcDaysFromReceivedToApproved();
var html;
if (turnaroundTime <= 21){
html = "<img src='https://careerservices.brocku.ca/imgs/check_mark.png'>";
}else{
html = "<img src='http://profitsincluded.com/asd/red-x.gif'>";
}
return html
}
catch (e) {
wom.log("EXCEPTION _Protocol.showTurnaroundTimeIcon: " + e.description);
throw(e);
}
}
Example 3: Access images stored as document content on a selection CDT. Entity method on _IACUC-Species. This function will show the picture associated with each defined species of animal.
function showPicture()
{
try {
var image = this.getQualifiedAttribute("customAttributes.defaultImage");
var html = "";
if(image){
image = image.getRelativeUrl();
html = "<img src='"+ image +"'>";
}
return html;
}
catch (e) {
wom.log("EXCEPTION _IACUC-Species.showPicture: " + e.description);
throw(e);
}
}
Example 4: Access images stored as document content on type Person. Entity method on Person. Create a property of type document content called photo on the Person object and use it to upload a profile picture. If no picture exists, a silhouette image will be rendered.
function showPhoto()
{
try {
var image = this.getQualifiedAttribute("customAttributes.Photo");
var html = "";
if(image){
image = image.getRelativeUrl();
}else{
image = "http://static.ak.fbcdn.net/pics/s_silhouette.jpg"
}
html = "<img src='"+ image +"'>";
return html;
}
catch (e) {
wom.log("EXCEPTION Person.SEMshowPhoto: " + e.description);
throw(e);
}
}
Wake Forest
