Tip storing and managing images

Managing images is very simple with Version 7. Two points have to be considered:
* The storage of the images in the database.
* The display of the images on a page.

Storage in the database

Two ways are possible to handle the database storage:

Manage the image in the user interface

Two choices for the UI behavior

Managing an image can be done in two ways in the user interface:

The second way where the type is constant

An example of the second way is given here. The best way to do it is on the 'AREAD_AFTER' event. This will handle the '$detail' facet. But if the icon must also appear on a query facet, you must call it in the 'AQUERY_TRANS_AFTER' event.

Let's imagine that we have a 'MYPICTURE' property in the representation, that is always in **jpeg** format. The code to be written will then be the following:
$METHODSCase ACTIONWhen "AREAD_AFTER","AQUERY_TRANS_AFTER" : Gosub AREAD_AFTER...EndcaseReturn$AREAD_AFTER[L]ASTATUS = Fmet this.ASETATTRIBUTE("MYPICTURE","$contentType","image")Return

How the supervisor handles variable types

What happens if the document type is variable, and if you want to display the right icon in the browser and open the most relevant widget to display the document when clicking on it?
You will need to set the relevant $contentType attribute. This can of course be done with a most complex piece of code that will test the type of document to apply the right content type. To avoid to have to write this kind of code, the supervisor provides a very simple feature that is based on the following principles:

Let's give an example:

To handle this variable type of document, in the 'SALESORDER' class:

An that's all !

Of course, you will find in the content type a huge number of standard data ready to be used. But you can also add your own content types in this table to handle dedicated formats of document, if they can be for instance recognized by a browser thanks to additional viewer plug-ins.

The code you have avoided to write

Let's imagine the supervisor function is not used. This might be because you don't have a column with the right data type or because you want to manage the data type determination with another algorithm.

Let's see an example where a class stores a document that might have various formats in 'MYDOCUMENT' property. Let's suppose a 'DOCTYPE' char value defines the most frequent formats by their extension : pdf, doc, docx, xls, xlsx, ppt, txt, htm...

This could be handled that way:

$METHODSCase ACTIONWhen "AREAD_AFTER" : Gosub AREAD_AFTER...EndcaseReturn$AREAD_AFTERCase this.DOCTYPEWhen "pdf" : [L]ASTATUS = Fmet this.ASETATTRIBUTE("MYDOCUMENT","$contentType","application/pdf")When "doc" : [L]ASTATUS = Fmet this.ASETATTRIBUTE("MYDOCUMENT","$contentType","application/msword")When "docx" : [L]ASTATUS = Fmet this.ASETATTRIBUTE("MYDOCUMENT","$contentType","application/vnd.ms-word.document.12")When "xls" : [L]ASTATUS = Fmet this.ASETATTRIBUTE("MYDOCUMENT","$contentType","application/vnd.ms-excel")When "xlsx" : [L]ASTATUS = Fmet this.ASETATTRIBUTE("MYDOCUMENT","$contentType","application/vnd.ms-excel.12")When "jpg","jpeg" : [L]ASTATUS = Fmet this.ASETATTRIBUTE("MYDOCUMENT","$contentType","image/jpeg")When "htm","html" : [L]ASTATUS = Fmet this.ASETATTRIBUTE("MYDOCUMENT","$contentType","text/html")When "txt" : [L]ASTATUS = Fmet this.ASETATTRIBUTE("MYDOCUMENT","$contentType","text/plain")....EndcaseReturn

This last example is a little bit complicated... You probably don't know all the content types that might exist, and by the way, if you check your document type for "xlsx", the official one is "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet". So, using the supervisor management is much simpler.