-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguide.html
1782 lines (1253 loc) · 61.4 KB
/
guide.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>WireIt Guide</title>
<meta name="author" content="Eric Abouaf" />
<meta name="copyright" content="Copyright 2009 Eric Abouaf" />
<meta name="keywords" content="wireit,javascript,library,pipes,visualization,yui,programming,canvas,wire,wires,framework,webdev,ajax,ui,web,graphics,graph,graphs,opensource,tools" />
<meta name="description" content="WireIt is an open-source javascript library to create web wirable interfaces for dataflow applications, visual programming languages or graphical modeling." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="alternate" type="application/rss+xml" title="WireIt blog" href="http://javascript.neyric.com/blog/feed/" />
<link rel="shortcut icon" type="images/x-icon" href="res/favicon.ico" />
<link rel="stylesheet" type="text/css" href="res/style.css" />
<link rel="stylesheet" type="text/css" href="res/guide.css" />
<link rel="stylesheet" type="text/css" href="res/SyntaxHighlighter/shCore.css" />
<link type="text/css" rel="stylesheet" href="res/SyntaxHighlighter/shThemeDefault.css" id="shTheme"/>
<script type="text/javascript" src="res/SyntaxHighlighter/shCore.js"></script>
<script type="text/javascript" src="res/SyntaxHighlighter/shBrushJScript.js"></script>
<script type="text/javascript" src="res/SyntaxHighlighter/shBrushXml.js"></script>
<script type="text/javascript" src="res/SyntaxHighlighter/shBrushCss.js"></script>
<script type="text/javascript">SyntaxHighlighter.config.clipboardSwf = 'res/SyntaxHighlighter/clipboard.swf';SyntaxHighlighter.all();</script>
</head>
<body>
<div id='headbar'>
<ul class="navigation" style=" position: absolute; margin: 6px 0 0 380px;">
<li><a href="index.html">Home</a></li>
<li><a href="http://github.com/neyric/wireit/">GitHub[Git]</a></li>
<li><a href="http://github.com/neyric/wireit/issues">Issues</a></li>
<li><a href="guide.html">Guide</a></li>
<li><a href="api/index.html">API Documentation</a></li>
<li><a href="http://javascript.neyric.com/blog/category/wireit/">Blog</a>
<a href="http://javascript.neyric.com/blog/feed/"><img src="doc/rss.png" border="0"/></a></li>
<li><a href="http://groups.google.com/group/wireit/">Forums</a></li>
</ul>
<div style="position: absolute; top: 80px; left: 750px; font-size: 90%; line-height: 30px;">
<img src='http://www.twitter.com/favicon.ico' alt="twitter" /> follow <a href="http://twitter.com/wireit">WireIt on Twitter</a><br />
<img src="http://delicious.com/favicon.ico"> bookmark on <a href="http://del.icio.us/url/651a56650c753830645ecf46fb036db6">Del.icio.us</a><br />
<img src='http://github.com/favicon.ico' alt="twitter" /> follow <a href="http://github.com/neyric/wireit/tree/master"> on GitHub</a>
</div>
</div>
<center>
<div style="text-align: left; width: 70%; position: relative;">
<!-- START OF THE GUIDE -->
<h1>WireIt Guide</h1>
<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 <a href="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>
<div id='index'>
<h2>Chapters</h2>
<ol class="topLevel">
<li>
<a href="#overview"><span>Overview</span></a>
<ul class="secondLevel">
<li><a href="#presentation">Presentation</a></li>
<li><a href="#terminology">Terminology</a></li>
<li><a href="#components">Core components and widgets</a></li>
<li><a href="#plugins">Plugins</a></li>
</ul>
</li>
<li>
<a href="#GettingStarted"><span>Getting Started</span></a>
<ul class="secondLevel">
<li><a href="#installation">Installation</a></li>
<li><a href="#directoryStructure">Directory structure</a></li>
<li><a href="#firstApp">Create Your First WireIt Application</a></li>
</ul>
</li>
<li>
<a href="#visualLanguage"><span>Create your visual language</span></a>
<ul class="secondLevel">
<li><a href="#xtypeConvention"><i>xtype</i> convention</a></li>
<li><a href="#customizingWiresAndTerminals">Customizing Wires and Terminals</a></li>
<li><a href="#visualLanguageDefinition">Visual Language Definition</a></li>
<li><a href="#moduleDefinition">Module Definition</a></li>
<li><a href="#BaseContainer">Using the basic Container</a></li>
<li><a href="#InOutContainer">Using InOutContainer</a></li>
<li><a href="#FormContainer">Using FormContainer</a></li>
<li><a href="#ImageContainer">Using ImageContainer</a></li>
<li><a href="#propertiesForm">Edit the "Properties" form</a></li>
<li><a href="#stylingContainers">Styling containers</a></li>
</ul>
</li>
<li>
<a href="#adapters"><span>Adapters - Connecting to another database or backend</span></a>
<ul class="secondLevel">
<li><a href="#adaptersIntroduction">Introduction</a></li>
<li><a href="#adaptersConfiguration">Configuring the adapter</a></li>
<li><a href="#ajaxAdapter">Ajax adapter</a></li>
<li><a href="#jsonRPCAdapter">Json-RPC Adapter</a></li>
<li><a href="#gearsAdapter">Gears adapter</a></li>
<li><a href="#adaptersCreation">Create an adapter</a></li>
</ul>
</li>
<li>
<a href="#wirings"><span>Working with Wirings</span></a>
<ul class="secondLevel">
<li><a href="#outputFormat">WiringEditor ouput format</a></li>
<li><a href="#convertFormat">Converting the format</a></li>
<li><a href="#storage">Storing wirings</a></li>
</ul>
</li>
<li>
<a href="#containers"><span>Creating custom Containers</span></a>
<ul class="secondLevel">
<li><a href="#yuiInheritance">YUI Inheritance</a></li>
<li><a href="#createContainers">Creating new Containers / Extending existing containers</a></li>
<li><a href="#logicgates">Example - Logic Gates</a></li>
</ul>
</li>
<li>
<a href="#composablePlugin"><span>The <i>Composable</i> plugin</span></a>
<ul class="secondLevel">
<li><a href="#composableIntro">Introduction</a></li>
<li><a href="#composableHow">How does it work</a></li>
</ul>
</li>
<li>
<a href="#advancedTopics"><span>Advanced Topics</span></a>
<ul class="secondLevel">
<li><a href="#autoload">WiringEditor autoload feature</a></li>
<li><a href="#mouseEvents">Handling Wire mouse events</a></li>
<li><a href="#production">notes on production</a></li>
</ul>
</li>
<li>
<a href="#contribute"><span>Contribute</span></a>
<ul class="secondLevel">
<li><a href="#issues">Reporting an Issue</a></li>
<li><a href="#documentation">Contributing to the Documentation</a></li>
<li><a href="#code">Contributing to the Code</a></li>
<li><a href="#contributors">Contributors</a></li>
<li><a href="#donate">Donate</a></li>
<li><a href="#roadmap">Roadmap</a></li>
</ul>
</li>
<li>
<a href="#moreInformation"><span>Other resources</span></a>
<ul class="secondLevel">
<li><a href="#examples">All examples</a></li>
<li><a href="#apiReferences">API References</a></li>
<li><a href="#otherResources">Other resources</a></li>
<li><a href="#projects">WireIt-based projects</a></li>
</ul>
</li>
</ol>
</div>
<br /><br />
<a name="overview"><h1>1 Overview</h1></a>
<a name="presentation"><h2>1.1 Presentation</h2></a>
<p>WireIt is an open-source javascript library to create <i>web wirable interfaces</i> for <b>dataflow applications</b>, <b>visual programming languages, graphical modeling,</b> or <b>graph editors</b>.</p>
<p>WireIt is tested on all <a href="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 <a href="http://groups.google.com/group/wireit/">the forum</a>.</p>
<p>It uses the <a href="http://developer.yahoo.com/yui/">YUI library</a>, the <a href="http://neyric.github.com/inputex/">inputEx library</a> for forms and fields, and <a href="http://excanvas.sourceforge.net/">excanvas</a> for IE support of the canvas tag.</p>
<p>The code for Wireit is provided under <a href="license.txt">MIT license</a>.</p>
<a name="terminology"><h2>1.2 Terminology</h2></a>
<p>This section defines some concepts that will be used throughout this guide.</p>
<h3>Wires and Terminals</h3>
<p><i>Wires</i> are pretty explicit. They connect two <i>Terminals</i> together :</p>
<img src="res/guide/wire_terminals.png" /><br />
<p><i>Terminals</i> are responsible for the graph edition :</p>
<ul>
<li>You can create a Wire by dragging a terminal to another one</li>
<li>You can destroy all the wires connected to a terminal by clicking on the scissors</li>
</ul>
<p><i>Terminals</i> have various configuration options, such as the number of wires that can be connected to them, wether they are editable or not, or style informations about the wires that are connected. <a href="examples/wires_and_terminals.html">Check out this example to see some of those properties in action.</a></p>
<p class="advanced" style="width: 50%">At this time, two <i>Terminals</i> can only be connected using one <i>Wire</i> only.</p>
<h3>Containers</h3>
<p><i>Containers</i> are "boxes", containing one or more <i>Terminals</i>. <i>Containers</i> are willingly generic, so that an application can easily create custom <i>Containers</i>.</p>
<p class="advanced" style="width: 50%">See the chapter <a href="#createContainers"><i>Creating new containers/Extending existing containers</i></a>.</p>
<h3>Layer</h3>
<p>A <i>Layer</i> handles multiple containers and connected wires. It keeps an internal representation of the whole graph and is responsible for <b>saving/loading a graph</b>.</p>
<br />
<a name="components"><h2>1.3 Core components and widgets</h2></a>
<p>WireIt is able to draw several types of wires :</p>
<ul>
<li>Straight - draws a straight line</li>
<li>Bezier - using bezier curves</li>
<li>Arrow - for directed directed graphs</li>
<li>BezierArrow - a mix of the two above</li>
<li>Step - using only horizontal and vertical lines</li>
</ul>
<p>Different types of Container are provided :</p>
<ul>
<li>InOutContainer - simple module with named inputs and outputs</li>
<li>ImageContainer - use images as graph nodes</li>
<li>FormContainer - displays a form with wirable inputs (optional). (requires the <i>inputEx plugin</i>)</li>
</ul>
<img src="res/guide/containers.png" /><br />
<p class="advanced" style="width: 70%">You can create your own <i>Containers</i> by subclassing the base <i>Container</i> class.<br />
See the chapter <a href="#createContainers"><i>Creating new containers/Extending existing containers</i></a>.</p>
<a name="plugins"><h2>1.4 Plugins</h2></a>
<p>Introduced in version 0.6.0, plugins are separated from the core components to build <i>à la carte</i> applications. <br />
All plugins are optional, although some of them have dependencies to others.</p>
<h3>1.4.1 The inputEx plugin</h3>
<p>The <a href="http://neyric.github.com/inputex/">inputEx library</a> and WireIt share the same creator, and their dependency to YUI. inputEx is an open-source javascript framework to build fields and forms. All the fields and forms are configured using JSON or created in Javascript. It provides a very efficient abstraction for building interactive web applications.</p>
<p>The inputEx plugin, besides containing the inputEx library, adds two major components :</p>
<ul>
<li>WirableField - replace the root inputEx.Field class to add a <i>Terminal</i>, to "wire" the field (optional)</li>
<li>FormContainer - build form containers based on <a href="http://neyric.github.com/inputex/">inputEx</a> forms</li>
</ul>
<h3>1.4.2 The editor plugin</h3>
<p>The editor plugin provides another very useful component: the <b>WiringEditor</b>.<br />
It provides the common features of most visual editors for <i>your visual language</i>.</p>
<center>
<img src="res/guide/editor2.png" />
<br /><br />
<img src="res/guide/editor.png" />
</center>
<p class="advanced">The WiringEditor requires a connection to a database or file system to use save/load features. You can customize it using <a href="#adapters">Adapters</a>.</p>
<h3>1.4.3 Other plugins</h3>
<ul>
<li>animations - utility to provide YUI Animations on any DOM element containing terminals</li>
<li>composable - extends the WiringEditor with composable wirings (a wiring can use other wirings)</li>
<li>grouping - extends the WiringEditor with module grouping feature (if you have large wirings)</li>
<li>layout - provide functions to layout the Layer</li>
</ul>
<p class="advanced">Read the README.md file of each plugin to learn more about them !</p>
<br /><br />
<a name="GettingStarted"><h1>2 Getting Started</h1></a>
<p>Most of this guide explain the usage and customization of the WiringEditor. If you are not using it, you will still learn about customizing/creating containers, and the Wires/Terminals options.</p>
<a name="installation"><h2>2.1 Installation</h2></a>
<p>WireIt is mostly a bunch of static javascript, css, and image files, so you can just <a href="http://github.com/neyric/wireit/downloads">download the latest version of 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 <a href="#WiringEditorInstallation">WiringEditor installation</a>)</p>
<p class="advanced">You could also clone the <a href="http://github.com/neyric/wireit/tree/master">development repository</a> to get the edge version.</p>
<p class="advanced">In a production environment, documentation and examples are not necessary. More on this in <a href="#production">production</a>.</p>
<a name="directoryStructure"><h2>2.2 Directory structure</h2></a>
<table>
<thead>
<tr>
<th>file or directory</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>api/</td>
<td>Auto-generated <a href="api/index.html">API documentation</a></td>
</tr>
<tr>
<td>assets/</td>
<td>Contains WireIt CSS and images</td>
</tr>
<tr>
<td>build/</td>
<td>Contains the minified javascript (More on this in <a href="#production">production</a>)</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>js/</td>
<td>javascript sources</td>
</tr>
<tr>
<td>lib/</td>
<td>librairies required by WireIt core</td>
</tr>
<tr>
<td>license.txt</td>
<td>MIT license details</td>
</tr>
<tr>
<td>plugins/</td>
<td>WireIt plugins directory</td>
</tr>
<tr>
<td>README.md</td>
<td>links for the GitHub page</td>
</tr>
<tr>
<td>res/</td>
<td>resources for WireIt website and documentation</td>
</tr>
<tr>
<td>scripts/</td>
<td>scripts to build rollup files and documentation</td>
</tr>
<tr>
<td>VERSION.txt</td>
<td>change log</td>
</tr>
</tbody>
</table>
<a name="firstApp"><h2>2.3 Create Your First WireIt Application</h2></a>
<p>The easiest way to start creating your visual language is to copy one of the editor example from the <i>plugins/editor/examples</i> directory.</p>
<p>Depending on which default adapter you decided to use, copy the examples/gearsAdapter/ or examples/WiringEditor/ files into your project directory. (more on <a href="#adapters">Adapters</a>)</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>Setup a webserver to serve your files and launch the index.html file in your browser. You're ready to create your <a href="#visualLanguage">visual language</a> !</p>
<p class="advanced">The <a href="#gearsAdapter">Gears Adapter</a> is handy for prototyping the interface since it doesn't require a backend. Make sure you have <a href="http://gears.google.com">Google Gears</a> installed.</p>
<br /><br />
<a name="visualLanguage"><h1>3 Create your visual language</h1></a>
<a name="xtypeConvention"><h2>3.1 <i>xtype</i> convention</h2></a>
<p>WireIt uses a convention to simplify extending widgets:<br />
<b style="font-size: 120%;">wires, terminals and containers are instantiated from the class specified by the <i>xtype</i> property</b>.</p>
<p>It lets you create specialized widgets by creating a subclass and using it simply from your language definition.</p>
<p class="advanced">This choice was made to transport the definition using JSON.</p>
<a name="customizingWiresAndTerminals"><h2>3.2 Customizing Wires and Terminals</h2></a>
<p>Many options are available to customize Wires and Terminals, but the general pattern is simple: you create a subclass of the Wire named <i>WeirdWire</i>, you use it using the xtype property :</p>
<pre class="brush:js">
Terminal.prototype.wireConfig = {"xtype":"WeirdWire", "weirdness": 7};
</pre>
<p>The code above overrides the default Wire configuration for <b>all</b> terminals on the page.</p>
<p>If you want to use this configuration only on specified wires, you can make it default for "some" terminals. You need to subclass the terminal to set your new config as default. An exemple is actually included in the library.</p>
<p>For a concrete example, let's see how the TerminalOutput works :</p>
<pre class="brush:js">
// use YUI2 class inheritance
WireIt.util.TerminalOutput = function(parentEl, options, container) {
WireIt.util.TerminalOutput.superclass.constructor.call(this,parentEl, options, container);
};
YAHOO.lang.extend(WireIt.util.TerminalOutput, WireIt.Terminal, {
xtype: "WireIt.TerminalOutput",
// override some options
direction: [0,1],
fakeDirection: [0,-1],
ddConfig: { type: "output", allowedTypes: ["input"] },
alwaysSrc: true
});</pre>
<p>Simple enough. What this says is: Create a TerminalOutput class which extends the Terminal widget, set the direction from top to bottom, and connect only to "input" terminals. The <i>alwaysSrc</i> option force this terminal as being the "source" terminal in the wire definition.</p>
<p><b>How do we handle the wire creation ? What are the options ?</b></p>
<p>The idea is to create a Drag'n Drop proxy element (we do not move the original Terminal, but a copy of it).</p>
<p>When we start dragging the proxy element, a <i>fake</i> terminal is created within, which we can move around. A wire is added between those two terminals.</p>
<p>You can change the default wiring config using the <i>editingWireConfig</i> property :</p>
<pre class="brush:js">
WeirdTerminal = function(parentEl, options, container) {
WeirdTerminal.superclass.constructor.call(this,parentEl, options, container);
};
YAHOO.lang.extend(WeirdTerminal, WireIt.Terminal, {
xtype: "WeirdTerminal",
wireConfig: {"xtype":"WeirdWire", "weirdness": 7},
editingWireConfig: {"xtype":"WeirdWire", "weirdness": 13},
direction: [1,1],
fakeDirection: [-1,-1]
});
</pre>
<p class="advanced">For a complete list of the properties, please refer to the API documentation for <a href="api/WireIt.Terminal.html">Terminal</a>, <a href="api/WireIt.Wire.html">Wire</a> or <a href="api/WireIt.Container.html">Container</a>.</p>
<a name="visualLanguageDefinition"><h2>3.3 Visual Language Definition</h2></a>
<p>Your visual language is defined by a JSON object :</p>
<pre class="brush:js">
var myLanguageDef = {
// Set a unique name for your language
languageName: "myLanguage",
// modules: list of module type definitions
modules: [
{
name: "module1",
container: {"xtype":"WireIt.InOutContainer", ...}
},
...
]
};
</pre>
<p>This language definition is passed to the WiringEditor constructor :</p>
<pre class="brush:js">
YAHOO.util.Event.onDOMReady( function() {
try {
logicGates = new WireIt.WiringEditor(myLanguageDef);
}catch(ex) {
alert(ex);
}
});
</pre>
<a name="moduleDefinition"><h2>3.4 Module Definition</h2></a>
<p>Here is the skeleton of a module definition :</p>
<pre class="brush:js">
{
"name": "moduleName",
// properties of the container
"container": {
// which container class to use
"xtype":"WireIt.InOutContainer",
// The options depends of the container class used in xtype
"inputs": ["text1", "text2", "option1"],
"outputs": ["result", "error"]
}
}
</pre>
<p>To declare a module using a different <i>Container</i> class, you'll have to set the container <i>xtype</i> property.</p>
<p class="advanced">The xtype property is a string representing the class. This had to be a string to remain JSON compliant.</p>
<p>Of course, you can use containers provided in WireIt (ImageContainer, FormContainer, InOutContainer), or a <a href="#containers">custom container</a>.</p>
<a name="BaseContainer"><h2>3.5 Using the basic Container</h2></a>
<p>Set "xtype": "WireIt.Container" (optional). The parameters are :</p>
<ul>
<li><i>icon</i> - url of the icon (relative or absolute)</li>
<li><i>terminals</i> - list of terminals configuration</li>
</ul>
<pre class="brush:js">
{
"name": "demoModule",
"container": {
"xtype":"WireIt.Container",
"icon": "../../assets/application_edit.png",
"terminals": [
{"name": "_INPUT1", "direction": [-1,0], "offsetPosition": {"left": -3, "top": 2 }},
{"name": "_INPUT2", "direction": [-1,0], "offsetPosition": {"left": -3, "top": 37 }},
{"name": "_OUTPUT", "direction": [1,0], "offsetPosition": {"left": 103, "top": 20 }}
]
}
}
</pre>
<p class="advanced">All other Container classes inherits from this base class, and therefore share the above options.</p>
<a name="InOutContainer"><h2>3.6 Using InOutContainer</h2></a>
<p>Set "xtype": "WireIt.InOutContainer". Additional parameters are :</p>
<ul>
<li><i>inputs</i> - list of inputs as strings</li>
<li><i>outputs</i> - list of outputs as strings</li>
</ul>
<p>Example: </p>
<pre class="brush:js">
{
"name": "InOut test",
"container": {
"xtype":"WireIt.InOutContainer",
"inputs": ["text1", "text2", "option1"],
"outputs": ["result", "error"]
}
}
</pre>
<a name="FormContainer"><h2>3.7 Using FormContainer</h2></a>
<p>Set "xtype": "WireIt.FormContainer". Additional parameters are all those used in inputEx.Group. (see <a href="http://neyric.github.com/inputex/">inputEx</a>)</p>
<pre class="brush:js">
{
"name": "MyModule",
"container": {
"xtype": "WireIt.FormContainer",
// inputEx options :
"title": "WireIt.FormContainer demo",
"collapsible": true,
"fields": [
{"type": "select", "label": "Title", "name": "title", "selectValues": ["Mr","Mrs","Mme"] },
{"type": "string", "label": "Firstname", "name": "firstname", "required": true },
{"type": "string", "label": "Lastname", "name": "lastname", "value":"Dupont"},
{"type":"email", "label": "Email", "name": "email", "required": true, "wirable": true },
{"type":"boolean", "label": "Happy to be there ?", "name": "happy" },
{"type":"url", "label": "Website", "name":"website", "size": 25 }
],
"legend": "Tell us about yourself..."
}
}
</pre>
<a name="ImageContainer"><h2>3.8 Using ImageContainer</h2></a>
<p>Set "xtype": "WireIt.ImageContainer". Additional parameters are :</p>
<ul>
<li><i>image</i> - url of the image (relative or absolute)</li>
</ul>
<pre class="brush:js">
{
"name": "AND gate",
"container": {
"xtype":"WireIt.ImageContainer",
"image": "../logicGates/images/gate_and.png",
"terminals": [
{"name": "_INPUT1", "direction": [-1,0], "offsetPosition": {"left": -3, "top": 2 }},
{"name": "_INPUT2", "direction": [-1,0], "offsetPosition": {"left": -3, "top": 37 }},
{"name": "_OUTPUT", "direction": [1,0], "offsetPosition": {"left": 103, "top": 20 }}
]
}
}
</pre>
<a name="propertiesForm"><h2>3.9 Edit the "Properties" form</h2></a>
<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 <a href="http://neyric.github.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>
<pre class="brush:js">
var demoLanguage = {
languageName: "meltingpotDemo",
// inputEx fields for pipes properties
propertiesFields: [
// default fields (the "name" field is required by the WiringEditor):
{"type": "string", "name": "name", label: "Title", typeInvite: "Enter a title" },
{"type": "text", "name": "description", label: "Description", cols: 30},
// Additional fields
{"type": "boolean", "name": "isTest", value: true, label: "Test"},
{"type": "select", "name": "category", label: "Category", selectValues: ["Demo", "Test", "Other"] }
],
modules: [
//...
]
};
</pre>
<p class="advanced">The HiddenField can be used to store additional wirings informations.</p>
<a name="stylingContainers"><h2>3.10 Styling containers</h2></a>
<p>The WiringEditor adds a CSS class for each module instance in your layer: <b>WiringEditor-module-<i>moduleName</i></b>.</p>
<p>You can therefore style all the descending structure using cascaded style sheets. <br />
Here is an exemple for the "comment" module of the <a href="examples/WiringEditor/">WiringEditor demo</a>.</p>
<pre class="brush:css">
/* Comment Module */
div.WireIt-Container.WiringEditor-module-comment {
width: 200px;
}
div.WireIt-Container.WiringEditor-module-comment div.body {
background-color: #EEEE66;
}
div.WireIt-Container.WiringEditor-module-comment div.body textarea {
background-color: transparent; font-weight: bold; border: 0;
}
</pre>
<br /><br />
<a name="adapters"><h1>4 Adapters - Connecting to another database or backend</h1></a>
<!--a name="WiringEditorInstallation"><h2>2.2 WiringEditor installation</h2></a>
<p>The WiringEditor requires a database connection to use the save/load features. <br />
The database connection can be adapted to your project though <a href="#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 <a href="#adapters">adapters documentation</a> to install the associated backends.</p>
<p class="advanced">You can <a href="#adaptersCreation">create your own adapters</a>.</p-->
<a name="adaptersIntroduction"><h2>4.1 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>
<p>WireIt provides default adapters to get you started :</p>
<ul>
<li><a href="#ajaxAdapter">Ajax Adapter (no backend provided)</a></li>
<li><a href="#jsonRPCAdapter">Json-RPC Adapter + a sample PHP/MySQL backend</a></li>
<li><a href="#gearsAdapter">Gears Adapter (no backend required)</a></li>
</ul>
<a name="adaptersConfiguration"><h2>4.2 Configuring the adapter</h2></a>
<pre class="brush:js">
// Override adapter default parameters
WireIt.WiringEditor.adapters.MyAdapter.config.configParam1 = value1;
// Instantiate the WiringEditor with a custom adapter
new WireIt.WiringEditor({
...
adapter: WireIt.WiringEditor.adapters.MyAdapter
...
})
</pre>
<a name="ajaxAdapter"><h2>4.3 Ajax Adapter</h2></a>
<p>This adapter is the general way to connect to a custom backend through Ajax (or XHR) calls. It uses a JSON representation.</p>
<p>You can use it to connect to a REST resource store or any HTTP-based RPC backend.</p>
<p>The <a href="examples/ajaxAdapter/">ajaxAdapter example</a> connects to a fake backend (the queried URLs are static files), but demonstrate how to configure the adapter :</p>
<pre class="brush:js">
WireIt.WiringEditor.adapters.Ajax.config = {
saveWiring: {
method: 'GET',
// The url can be hard-coded
url: 'fakeSaveDelete.json'
},
deleteWiring: {
method: 'GET',
/**
* 'url' can also be a function that returns the URL as a string.
* For exemple, to connect to a REST store, you might want to send a DELETE /resource/wirings/moduleName
* (moduleName is present in the "value" parameter)
*/
url: function(value) {
return "fakeSaveDelete.json";
}
},
listWirings: {
method: 'GET',
url: 'listWirings.json'
}
};
</pre>
<a name="jsonRPCAdapter"><h2>4.4 Json-RPC Adapter</h2></a>
<p>This adapter uses Ajax calls as the previous one, but wraps http requests in a JSON-RPC envelope.</p>
<p>This adapter is used in the <a href="examples/WiringEditor/">WiringEditor demo</a>.</p>
<p>It is connected to a sample PHP/MySQL backend, which requires the following installtion steps :</p>
<ul>
<li>copy the backend/php directory to your wireit directory</li>
<li>edit the script with your database access config (backend/php/WiringEditor.php)</li>
<li>make sure the backend files are accessible by your webserver and that the php module is loaded </li>
</ul>
<p>The JSON-RPC adapter configuration resides in the single service url :</p>
<pre class="brush:js">
WireIt.WiringEditor.adapters.JsonRpc.config.url = '/my/json-rpc/serviceUrl';
</pre>
<a name="gearsAdapter"><h2>4.5 Gears Adapter</h2></a>
<p>This adapter uses the <i>database</i> component of Google Gears to store the <i>wirings</i> in a SQLite table <b>client-side</b> (in the browser).</p>
<p>This adapter is very useful for prototyping your project, since it can be used without any server installation.</p>
<p>To use this adapter, you must install <a href="http://gears.google.com">google gears</a>.</p>
<p>A demo of this adapter is showed in the <a href="plugins/editor/examples/gearsAdapter/">gears adapter example</a>.</p>
<p>This adapter doesn't have any noticeable configuration except <i>WireIt.WiringEditor.adapters.Gears.config.dbName</i> which contains the gears database name (default is 'database-test').</p>
<p class="advanced">The gears adapter already includes gears-init.js</p>
<a name="adaptersCreation"><h2>4.6 Create an adapter</h2></a>
<p>Why would you build your own ?</p>
<ul>
<li>You use a different server-side language</li>
<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>
<pre class="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>
<pre class="brush:js">
var callbacks = {
success: function() {
},
failure: function() {
},
scope: this
};
</pre>
<p>To call the callbacks, in a synchronous way, use something like :</p>
<pre class="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>
<pre class="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>
<br /><br />
<a name="advancedTopics"><h1>5 Working with Wirings</h1></a>
<a name="outputFormat"><h2>5.1 WiringEditor ouput format</h2></a>
<p>First, here is the JSON output of the WiringEditor :</p>
<pre class="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],