Graphical components is an extension of regular components on which we add lots of features in order to handle a graphical representation inserted in the DOM.
These components brings the Model View Controller architecture to Archetype. We assume that the Model is binged from the Ajax Framework you use, the Controller is your component and the View is the template assiociated to your component.
First, take a look at the structure of a graphical component:
$C.Extend(["Archetype.component.graphicalComponent"], {
name: "<name of the component>",
setup:{
dependencies: {
components: {
<componentKey>: <componentName>,
<...>
},
lib: [
<libraryName>,
<...>
],
css: [
<cssFileName>,
<...>
],
html: {
<templateKey>: <templateName>,
<...>
}
},
template: <template engine>
},
initialize: <initialization method>,
<first method name>: function() {/*your code!*/},
<second method name>: function() {/*your code again!*/},
...
});
$C.Extend : Extend a generic graphical component (located at the module name Archetype.component.graphicalComponent) for defining our component.
$C.Extend allows you to create components with inheritance of one or multiple other components already defined. The default graphical component is a core component include in the framework.
There is four kinds of dependency you can configure for a basic component: components and libraries as for normal components and two newer: css and templates.
Inside your methods, templates you declare as needed can be called by using this.templates :
$C.Extend(["Archetype.component.graphicalComponent"], {
name: "MyApp.components.aComponent",
setup:{
dependencies: {
templates: {
myTemplate: "MyApp.templates.myTemplate"
}
}
},
initialize: function() {
var myData = {
foo: "bar"
}
//Evaluate the template
Logger.debug(this.templates.myTemplate.evaluate(myData));
}
});
For more documentation of using templates, see the the template chapter .
The purpose of inherit of graphical component is to allow you to use the render method which add the component view in the DOM (in the page). Lets take a look to the complete API:
There is an example of graphical component which use default renderViewAsString and the default afterRender method:
$C.Extend(["Archetype.component.graphicalComponent"], {
name: "Slidy.components.container",
setup: {
dependencies: {
components: {
slideManager: "Slidy.components.slideManager",
slideChangeHandler: "Slidy.components.slideChangeHandler",
slideCounter: "Slidy.components.slideCounter"
},
lib: ["Slidy.libs.shjs.sh_main", "Slidy.libs.shjs.sh_javascript", "Slidy.libs.shjs.sh_html"],
css: ["Slidy.css.slidy", "Slidy.css.w3c-blue", "Slidy.libs.shjs.sh_typical"],
html: {
main: "Slidy.templates.container"
}
}
},
initialize: function(){
//Insert in the main template evaluation into the element mached by the selector
this.render($$("#bodyContent")[0]);
new this.components.slideChangeHandler();
new this.components.slideCounter();
new this.components.slideManager();
}
});