Reliable method to display/hide web client label image

Forum to discuss the Web client version of Servoy.

Reliable method to display/hide web client label image

Postby alan.bourke » Tue Oct 08, 2013 5:30 pm

I have a form with a table view on it. The underlying records have a text field containing a path to a PDF file. This file may or may not exist. If it does exist, I want to display a little PDF icon for that record. If it doesn't exist, I want a blank space.

In 6.0.x this used to work in the onRender() event of the button/label:

Code: Select all
      
/** @type {JSRecord<{attachmentpath:String}>} */
var eventRec = JSRecord;
var currAttachpath = '';
   
eventRec = event.getRecord();
currAttachpath = eventRec.attachmentpath;
   
/** @type {JSLabel} */
var thisButton = event.getRenderable();
   
// -- Return icon depending on whether attachment file actually exists.
var attachmentFile = plugins.file.convertToJSFile(currAttachpath);
if (attachmentFile.exists())
{
    imageURL = 'media:///pdficon_small.gif';
}
else
    imageURL = 'media:///attachment_transparent.gif';
      
thisButton.imageURL = imageURL;   


However that stopped working in 7.x, as the imageURL property is not available via getRenderable().

I have changed it to this (common code omitted):

Code: Select all
   
thisButton.visible = (attachmentFile.exists()) ? true : false;


... however that is giving inconsistent results. Is there *any* reliable way to do this in web client?
alan.bourke
 
Posts: 30
Joined: Thu Sep 05, 2013 2:08 pm

Re: Reliable method to display/hide web client label image

Postby alan.bourke » Wed Oct 09, 2013 12:11 pm

OK seems I managed to do it by using a HTML Area instead. This has a calculation that returns a HTML string as its dataprovider, like this:

Code: Select all

function haspdf()
{
   var ret = '<html><img src="media:///attachment_transparent.gif"></html>'
   var currAttachpath = attachmentpath;
   
   if (currAttachpath)
   {
      var attachmentFile = plugins.file.convertToJSFile(currAttachpath);
      if (attachmentFile.exists())      
         ret = '<html><img src="media:///pdficon_small.gif"></html>'
   }
   
   return ret;
}

alan.bourke
 
Posts: 30
Joined: Thu Sep 05, 2013 2:08 pm


Return to Servoy Web Client

Who is online

Users browsing this forum: No registered users and 5 guests