<p>This guide tries to centralize everything that has been written on WireIt. If you think something is missing or need better explanation, please contact us through the <ahref="http://groups.google.com/group/wireit/">forum</a>. Being written by a french, help in finding typos, technical errors, or poorly worded sentences is greatly appreciated.</p>

<p>WireIt is tested on all <ahref="http://developer.yahoo.com/yui/articles/gbs/">A-Grade Browsers</a>, although it might work with older versions of browsers and platforms. Please report your issues with specific browsers in <ahref="http://groups.google.com/group/wireit/">the forum</a>.</p>

<p>It uses the <ahref="http://developer.yahoo.com/yui/">YUI library</a> (2.8.0r4) for DOM and events manipulation, and <ahref="http://excanvas.sourceforge.net/">excanvas</a> for IE support of the canvas tag.</p>

<p>The code for Wireit is provided under a <ahref="license.txt">MIT license</a>.</p>

<aname="components"><h2>Components/Widgets</h2></a>

<p>Here are the main widget classes :</p>

<ul>

<li>Wire - create wires in browsers</li>

<li>Terminal - wire endpoints and edition widget</li>

<li>Container - general "box" containing one or more terminals</li>

<li>Layer - handle multiple containers and wires</li>

</ul>

<p>Different types of Container are provided :</p>

<ul>

<li>InOutContainer - simple module with named inputs and outputs</li>

<li>FormContainer - build form containers based on <ahref="http://javascript.neyric.com/inputex/">inputEx</a> forms</li>

<li>ImageContainer - use images as graph nodes</li>

</ul>

<p>You can create your own container by subclassing the base <i>Container</i> class, and still benefit from the drop-in use of the WiringEditor in your web application.</p>

<p>You create a simple html page, import WireIt widgets and WiringEditor, define your visual language using a JSON configuration and a full-page editor is built into the browser to use your language.</p>

<p>The WiringEditor requires a connection to a database to use save/load features. You can customize it using adapters. A default adapter is provided, which uses JSON-RPC through ajax calls, and a PHP/MySQL backend.</p>

<aname="directoryStructure"><h2>Directory structure</h2></a>

<table>

<thead>

<tr>

<th>file or directory</th>

<th></th>

</tr>

</thead>

<tbody>

<tr>

<td>backend/</td>

<td>Contains backend (server-side) code for the WiringEditor</td>

</tr>

<tr>

<td>build/</td>

<td>Contains the minified javascript and build scripts</td>

</tr>

<tr>

<td>css/</td>

<td>Contains the css WireIt components</td>

</tr>

<tr>

<td>doc/</td>

<td>Auto-generated API documentation</td>

</tr>

<tr>

<td>examples/</td>

<td>Examples or applications that are part of the library</td>

</tr>

<tr>

<td>images/</td>

<td>WireIt images</td>

</tr>

<tr>

<td>index.html</td>

<td>WireIt Home page</td>

</tr>

<tr>

<td>INSTALL.txt</td>

<td>Installation instructions</td>

</tr>

<tr>

<td>js/</td>

<td>javascript sources</td>

</tr>

<tr>

<td>lib/</td>

<td>Librairies required by WireIt</td>

</tr>

<tr>

<td>license.txt</td>

<td>Open-source license details</td>

</tr>

<tr>

<td>README.txt</td>

<td>This file</td>

</tr>

<tr>

<td>VERSION.txt</td>

<td>The change log</td>

</tr>

</tbody>

</table>

<aname="GettingStarted"><h1>Getting Started</h1></a>

<aname="installation"><h2>Installation</h2></a>

<p>WireIt is mostly a bunch of static javascript, css, and image files, so you can just <ahref="http://javascript.neyric.com/wireit">download the library</a> and put the files in your project library directory.</p>

<p>However, the WiringEditor requires a database connection to use the save/load features. (see <ahref="#WiringEditorInstallation">WiringEditor installation</a>)</p>

<pclass="advanced">You could also clone the <ahref="http://github.com/neyric/wireit/tree/master">development repository</a> to get the edge version.</p>

<pclass="advanced">In a production environment, documentation and examples are not necessary. More on this in <ahref="#production">production</a>.</p>

<p>The WiringEditor requires a database connection to use the save/load features. <br />

The database connection can be adapted to your project though <ahref="#adapters">adapters</a>.</p>

<p>Adapters themselves don't require any particular installation, however, they are connected to a <i>backend</i>, which often require a specific server environment.</p>

<p>Please refer to the <ahref="#adapters">adapters documentation</a> to install the associated backends.</p>

<pclass="advanced">You can <ahref="#adaptersCreation">create your own adapters</a>.</p>

<aname="firstApp"><h2>Create Your First WireIt Application</h2></a>

<p>Depending on which default adapter you decided to use, copy the examples/gearsAdapter/ or examples/WiringEditor/ files into your project directory.</p>

<p>Edit the index.html file you copied to check that the paths to javascript and css files are correct. (You might want to create your project directory directly in the examples/ folder so that the paths remain unchanged.)</p>

<p>To add properties to the <i>Wirings</i>, we configure the <i>propertiesFields</i> property of the language definition.<br />

This property defines the fields as they will appear in the "Properties" form on the right in the WiringEditor.</p>

<p>The form is created using the <ahref="http://javascript.neyric.com/inputex/">inputEx form library</a>. The <i>propertiesFields</i> array is directly used to instantiate a inputEx.Group class. Please refer to inputEx documentation to learn how to configure your fields.</p>

<p>When you use the save/load fetures of the WiringEditor, the form values are automatically saved within your <i>wirings</i> before being sent back to the server.</p>

<pclass="advanced">The HiddenField can be used to store additional wirings informations.</p>

<aname="adapters"><h2>Adapters - Connecting to another database or backend</h2></a>

<aname="adaptersIntroduction"><h2>Introduction</h2></a>

<p>Adapters are used by the WiringEditor to provide the loading/saving features. It makes it easy to "plug" the WiringEditor into your application. They usually connect to a database of some kind through Ajax calls to store the wirings and bring them back.</p>

<li>You probably use a framework to develop your website, which provides its own models (ex: Django,Rails,Symfony,...)</li>

<li>Convert the wirings into another workflow model. (ex: XProc XML)</li>

</ul>

<p>Here is the skeleton of an adapter :</p>

<preclass="brush:js">

WireIt.WiringEditor.adapters.MyAdapter = {

// adapter default options

config: {

// ...

},

// Initialization method called by the WiringEditor

init: function() {

},

/**

* save/list/delete asynchronous methods

*/

saveWiring: function(val, callbacks) {

// ...

// don't forget to call the callbacks !

},

deleteWiring: function(val, callbacks) {

// ...

// don't forget to call the callbacks !

},

listWirings: function(val, callbacks) {

// ...

// don't forget to call the callbacks !

}

// + private methods or properties

};

})();

</pre>

<p>The main three methods use asynchronous callbacks to push back the results to the WiringEditor. Here is the structure of the callbacks that are passed to these methods : </p>

<preclass="brush:js">

var callbacks = {

success: function() {

},

failure: function() {

},

scope: this

};

</pre>

<p>To call the callbacks, in a synchronous way, use something like :</p>

<preclass="brush:js">

function(val, callbacks) {

if(everythingGoesFine) {

callbacks.success.call(callbacks.scope, results);

}

else {

callbacks.failure.call(callbacks.scope, results);

}

}

</pre>

<p>The asynchronous pattern is particularly useful for ajax-based adapters. Here is an example with YUI :</p>

<preclass="brush:js">

function(val, callbacks) {

YAHOO.util.Connect.asyncRequest('POST', 'myUrl', {

success: function(r) {

//...

callbacks.success.call(callbacks.scope, results);

},

failure: function(r) {

callbacks.failure.call(callbacks.scope, error);

}

});

}

</pre>

<aname="advancedTopics"><h1>Advanced Topics</h1></a>

<aname="outputFormat"><h2>WiringEditor ouput format</h2></a>

<p>First, here is the JSON output of the WiringEditor :</p>

<preclass="brush:js">

var working = {

"modules":[

{

"config":{

"position":[166,195],

"xtype":"WireIt.ImageContainer"

},

"name":"AND gate",

"value":{}

},

{

"config":{

"position":[454,271],

"xtype":"WireIt.ImageContainer"

},

"name":"AND gate",

"value":{}

},

{

"config":{

"position":[149,403],

"xtype":"WireIt.ImageContainer"

},

"name":"AND gate",

"value":{}

}

],

"wires":[

{

"src":{"moduleId":0,"terminal":"_OUTPUT"},

"tgt":{"moduleId":1,"terminal":"_INPUT1"}

},

{

"src":{"moduleId":2,"terminal":"_OUTPUT"},

"tgt":{"moduleId":1,"terminal":"_INPUT2"}

}

],

"properties":{

"name":"demo",

"description":"",

"isTest":true,

"category":"Demo"

}

};

</pre>

<p>First comes the list of instantiated modules. The <i>name</i> is set to the module name, <i>config.xtype</i> indicates the container class, <i>config.position</i> is pretty self-explanatory, and <i>value</i> contains the exported value for this instance (in this case it is empty, but for a FormContainer, it will contain the form value.)</p>

<p>Secondly, the wires instances, composed of a <i>src</i> (source) terminal and a <i>tgt</i> (target) terminal.<br />

Each terminal is referenced by its moduleId (module index in the above definition) and its name (terminal).</p>

<p>Finally, the <i>properties</i> object contains the value of the "Properties" form on the right of the editor.</p>

<pclass="advanced">The examples store directly the JSON in a TEXT column in the database. Almost all programming languages provide built-in JSON stringify/parse methods, so you can parse this tree to convert to another format.</p>

<p>For more details with Container methods, please refer to the API Documentation.</p>

<p>To extend or modify the behavior of an existing Container.</p>

<preclass="brush:js">

WireIt.ImageContainer.prototype.myMethod = function () {

// new code

};

</pre>

<p>To use your new Container in a language definition go to <ahref="#moduleDefinition">Module Definition</a>.</p>

<aname="production"><h2>notes on production</h2></a>

<p>In a production environment, it is preferable to use rollup files: The javascript files are concatenated into a single javascript file (to reduce the number of HTTP requests) then compressed using the YUI compressor (to reduce file size).</p>

<p>Some rollup files are provided in the <i>wireit/build</i> directory :</p>

<p><u>Warning :</u>The wiring-editor-min.js file <b>doesn't</b> include any adapter, and only includes <b>some</b> fields of the inputEx library.</p>

<pclass="advanced">It is strongly recommended to build your custom rollup file for production. You can then include the adapter you use, the visual language definition, or even the YUI library dependencies. The script to build those files is available at build/rollups.sh (only in source, not in the zipped library)</p>

<pclass="advanced">The YUI library is included in the zip file, but the YUI files can be served from Yahoo or Google servers.</p>

<p>Moreover, the WireIt zip file contains example, guides, documentation, which are not necessary in a production environment. We recommend you to copy only the required files on your webserver :</p>