Emerald Hand Wiki

Back to tutorials section


Edit

Intrudoction

This tutorial shows how to easy it can be to create a simple atomic type. We are going to write a type to store a person name. Its obvious use is to capture contacts, but there's more to it. Just like Atomic Html this type has a broad array of uses. It could be used to for business related information, but more likely initially it will be used for collections (movies, books, games, etc.)

By now you should know how to create types. If you haven't read New Type and Atomic Html tutorials you should before continuing. I'm going to keep this tutorial short, only explaining unique points not covered previously.

Edit

Analysis

We are going to create a new type for the following reasons:
  1. Data reuse - Person name is used often and we will need it to create other, more complex types.
  2. Abstract type object use - I have covered some of the base type class methods in ../Html. This time we'll take a deeper look to see how they can help.

Edit

Structure prototype


<document>
<first>John</first>
<middle></middle> - middle name omitted
<last>Doe</last>
</document>

Edit

Descriptior

Go ahead and create a new type. Use the following data for it:
  • id - Generate new GUID for the type
  • name - PersonName
  • friendlyName - Person name
  • version - 0.5.0.0
  • category - embedded
  • prefix - name

Edit

Schema

Schema is going to be straight forward. To keep things simple all name parts are direct children of the document wrapper.

<xs:redefine schemaLocation="sider">
<xs:complexType name="DocumentContentType">
<xs:complexContent>
<xs:extension base="siderPN:DocumentContentType">
<xs:sequence>
<xs:element name="first" type="xs:string"/>
<xs:element name="middle" type="xs:string" />
<xs:element name="last" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:redefine>

Edit

Constructor

Writing a new document constructor is going to be even simpler than writing its schema. We can reuse prototype from analysis with minor modifications.

<xsl:template match="/*">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<name:first>FirstName</name:first>
<name:middle></name:middle>
<name:last>LastName</name:last>
</xsl:copy>
</xsl:template>

Edit

Script

Type script is going to be really simple as well. All types derive from sider.types.AbstractType, which provide some generic methods.

The most useful methods are getValue and setValue. They make document access generic, making you implement only type specific logic. Both methods need path to the document and field name (or its xpath), and generate path to the element in the document. Consult Sider component documentation for more details.

These methods will allow us to keep script as simple as:

dojo.require( "sider.exceptions" );
dojo.require( "sider.types" );
sider.types.addType( null,
{
});

To get first name or last name a view can do something like {sider.types.name.getValue( "//contact5", "first" )}.

Edit

Conclusion

This tutorial is really small and aims to show how easy it is to create simple data types. Making types is usually easy, writing good and interactive views can be much harder.

Copyright © 2006-2008 Emerald Hand, Inc. All rights reserved.
Powered by ScrewTurn Wiki version 2.0.34. Some of the icons created by FamFamFam.