This topics covers the basic knowledge of widgets, like what files are used by a widget, what functions are commonly used, etc.
Be sure to have read and understood the following topic before moving on : Widget
Here’s the file structure of the sample widget.
[your_geoprisma_root_directory]/src/client/widgets/sample : MySampleClass.js Sample.css Sample.js sample.php Sample.rst Sample.xslt
Widgets are not limited to a single directory structure. You can create an infinite architecture of sub-directories in which to put your widgets. This comes in handy when similar widgets have to share common files of classes or simply to group them. For examples, here’s the structure of the editfeature directory from the widgets directory :
editfeature ./create ./Create.js ./create.php ./Create.txt ./Create.xslt ./delete ./DeleteFeature.js ./delete.php ./Delete.xslt ./Delete.js ./Delete.txt ./update ./Update.js ./update.php ./Update.txt ./Update.xslt ./EditFeature.js
In the config, widgets using a sub-directories structure are defined a bit differently. They must have their whole path as type, with slashes ‘/’ replaces by ‘_’, like this :
<editfeature_create> <name>MyEditFeatureCreateWidget</name> <options> <geometrytype>LineString</geometrytype> <featurepanel>MyFeaturePanelWidget</featurepanel> </options> </editfeature_create>
Here, you have a choice of using either one or even both, it’s completely up to you. The drawWidgets method is much more user-friendly though. Nevertheless, we’ll see both methods and what they do and imply.
drawWidget
Designed to draw one widget only, by giving the widget’s name from the config as the argument. This requires to manually loop through the widgets in the template file. Here’s an example :
drawWidget function from the Widget.xslt file :
<xsl:template name="sample:drawWidget"> <xsl:param name="pWidgetName" /> objGPWidget<xsl:value-of select="$pWidgetName" /> </xsl:template>drawWidget call from the Template.xslt file :
<xsl:for-each select="/geoprisma/widgets/widget[./type = 'sample']"> oWestPanel.items.push( <xsl:call-template name="sample:drawWidget"> <xsl:with-param name="pWidgetName" select="./name" /> </xsl:call-template>); </xsl:for-each>
drawWidgets
Designed to draw all widgets of a given type. To be able to do so, each widget must be added (done in the printWidgetExecution) to some kind of container (defined in the printWidgetSource). This method is easier to use in the template file. Here’s an example :
drawWidgets function from the Widget.xslt file :
<xsl:template name="sample:drawWidgets"> <xsl:param name="pContainer" /> <xsl:variable name="WidgetType"> <xsl:text>sample</xsl:text> </xsl:variable> if (typeof(objGPWidget<xsl:value-of select="$WidgetType" />Container) != 'undefined' && typeof(<xsl:value-of select="$pContainer" />) != 'undefined') { if(<xsl:value-of select="$pContainer" />['ctype']){ <xsl:value-of select="$pContainer" />.add( objGPWidget<xsl:value-of select="$WidgetType" />Container ); } else { <xsl:value-of select="$pContainer" />.items.push( objGPWidget<xsl:value-of select="$WidgetType" />Container ) } } </xsl:template>drawWidgets call from the Template.xslt file :
<xsl:call-template name="shortcut:drawWidgets"> <xsl:with-param name="pContainer"> <xsl:text>oWestPanel</xsl:text> </xsl:with-param> </xsl:call-template>
See the existing widgets to know more about theses methods.