sgsML tutorial: Part 4

Examples (continued)


To make the description field more usable we change simple_type from textarea to htmlarea:

simple_type="htmlarea"

Hit refresh and you have a complete HTML editor!

Another way to avoid overloading of the display view is using simple_tabs.

So we define two tabs, one for general information, the other one for the details (both displayed with the translation from the language file):

<tab name="general" displayname="{t}General{/t}" />
<tab name="details" displayname="{t}Details{/t}" />

The difference between "views" and "tabs" is the time when the information is loaded. With views, only the information for the current view is loaded. Using tabs all the information is loaded, but hided using Javascript until you hit the tab. Switching between tabs is much faster because you have already loaded all the information in your browser, but loading the page takes longer at the beginning.

The same example using tabs instead of views looks like this:

myaddresses.xml:

<table modulename="{t}My Addresses{/t}" default_view="display" orderby="lastname" order="asc" limit="20" enable_new="true" enable_edit="true" enable_delete="true" enable_empty="true">
<view name="display" displayname="{t}Display{/t}" />
<tab name="general" displayname="{t}General{/t}" />
<tab name="details" displayname="{t}Details{/t}" />
<field name="id" simple_type="id" displayname="{t}Id{/t}" simple_tab="details" />
<field name="lastname" displayname="{t}Last name{/t}" simple_type="text" required="true" />
<field name="firstname" displayname="{t}First name{/t}" simple_type="text" required="true" />
<field name="description" displayname="{t}Description{/t}" simple_type="htmlarea" simple_size="4" simple_tab="details" />
<field name="street" displayname="{t}Street{/t}" simple_type="text" />
<field name="zipcode" displayname="{t}Zipcode{/t}" db_size="6" simple_type="text">
<validate function="numeric" />
</field>
<field name="city" displayname="{t}City{/t}" simple_type="text" />
</table>

To add a gender selectbox with the values male, female, use:

<field name="gender" displayname="{t}Gender{/t}" db_size="10" simple_type="select" simple_size="1" simple_tab="details">
<data values="{t}male{/t}|{t}female{/t}"/>
</field>

The field gender has a maximum of 10 characters, is displayed as a selectbox (simple_type select) and the user can select 1 item (instead of multiple items).

Since every address has relations to other addresses we finally add a field to store these relationships:

<field name="isrelatedto" displayname="{t}Is related to{/t}" simple_type="select" simple_size="3" is_linked="simple_myaddresses|details|lastname" multiple="&lt;br&gt;" simple_tab="details" allow_custom="true">
<data function="dbselect|simple_myaddresses|lastname,lastname||lastname asc|10"/>
</field>

The field isrelatedto is displayed with the translation of {t}Is related to{/t}. The simple_type is a selectbox with a height of 3 lines, allowing the user to select multiple items. In the display these items are separated by "<br>" (= new line). The user can also type in his own items which is declared by allow_custom=true. To get the data from the selectbox we use the select_dbselect function which does something like "select lastname from simple_myaddresses order by lastname asc limit 10". If there are more than 10 items, the user can select them by using a search box. This field is also shown in the details tab. Furthermore when displaying the items of this field we want these items to be links. When a user clicks them the referenced address should be displayed. This behavior is achieved by using the "is_linked" attribute. The first parameter names the table, the second the view we want to see in the popup and the third defines the field to choose from.


The complete code of the example


myaddresses.xml:

<table modulename="{t}My Addresses{/t}" default_view="display" orderby="lastname" order="asc" limit="20" enable_new="true" enable_edit="true" enable_delete="true" enable_empty="true">
<view name="display" displayname="{t}Display{/t}" />
<tab name="general" displayname="{t}General{/t}" />
<tab name="details" displayname="{t}Details{/t}" />
<field name="id" simple_type="id" displayname="{t}Id{/t}" simple_tab="details" />
<field name="gender" displayname="{t}Gender{/t}" db_size="10" simple_type="select" simple_size="1" simple_tab="details">
<data values="{t}male{/t}|{t}female{/t}"/>
</field>
<field name="lastname" displayname="{t}Last name{/t}" simple_type="text" required="true" />
<field name="firstname" displayname="{t}First name{/t}" simple_type="text" required="true" />
<field name="description" displayname="{t}Description{/t}" simple_type="htmlarea" simple_size="4" simple_tab="details" />
<field name="street" displayname="{t}Street{/t}" simple_type="text" />
<field name="zipcode" displayname="{t}Zipcode{/t}" db_size="6" simple_type="text">
<validate function="numeric"/>
</field>
<field name="city" displayname="{t}City{/t}" simple_type="text" />
<field name="isrelatedto" displayname="{t}Is related to{/t}" simple_type="select" simple_size="3" is_linked="simple_myaddresses|details|lastname" multiple="&lt;br&gt;" simple_tab="details" allow_custom="true">
<data function="dbselect|simple_myaddresses|lastname,lastname||lastname asc|10"/>
</field>
</table>

Note: Using translations normally takes more time, so it is on you to use them or not.


Screenshots of myaddresses.xml



Search functionality


All your data will automatically be searchable. If simple_type is files, each file will be indexed using the binary tools (catdoc, xlhtml, ImageMagick, Xpdf, UnZip, gzip, tar). These tools are included as windows binaries, if using Linux/Unix you need to install these packages from your distribution (see Installation).


Summary


To demonstrate the efficiency of Simple Groupware and sgsML:

  • We have written a complete web application including 9 fields with only 26 lines of code.
  • You can create / edit / delete assets. With the built-in tree of Simple Groupware you can create different folders for special groups of addresses.
  • All your changes are logged in the history.
  • And maybe the most important benefit all the values are already searchable via the global search function. (You can even try using phonetic searches!)

I hope you got a first introduction into the world of sgsML and already understood most parts of it.
For more examples, see the "src/modules/schema" directory (including examples using files, dates, codeareas, wikiareas etc.).
To go deeper into sgsML there is "src/modules/schema_sys" (containing the Simple Groupware system modules and handlers for external data sources).
This is only a small tutorial describing the basic ideas and elements behind sgsML. If you write your own modules, and there is something not working or not clear, feel free to mail me.

Enjoy Simple Groupware!



sgsML: Part 1 - sgsML: Part 2 - sgsML: Part 3 - sgsML: Part 4