forked from ericabouaf/wireit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
guide.html
1153 lines (784 loc) · 39.1 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="doc/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%;">
<!-- 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>
<h1>Index</h1>
<div id="index"></div>
<div id='book'>
<ol class="topLevel">
<li>
<a href="#overview"><span>Overview</span></a>
<ol class="secondLevel">
<li><a href="#presentation">Presentation</a></li>
<li><a href="#components">Components/Widgets</a></li>
<li><a href="#WireItApplication">WireIt applications</a></li>
<li><a href="#directoryStructure">Directory structure</a></li>
</ol>
</li>
<li>
<a href="#GettingStarted"><span>Getting Started</span></a>
<ol class="secondLevel">
<li><a href="#installation">Installation</a></li>
<li><a href="#WiringEditorInstallation">WiringEditor installation</a></li>
<li><a href="#firstApp">Create Your First WireIt Application</a></li>
</ol>
</li>
<li>
<a href="#visualLanguage"><span>Create your visual language</span></a>
<ol class="secondLevel">
<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>
</ol>
</li>
<li>
<a href="#adapters"><span>Adapters - Connecting to another database or backend</span></a>
<ol 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>
</ol>
</li>
<li>
<a href="#advancedTopics"><span>Advanced Topics</span></a>
<ol class="secondLevel">
<li><a href="#outputFormat">WiringEditor ouput format</a></li>
<li><a href="#stylingContainers">Styling containers</a></li>
<li><a href="#autoload">WiringEditor autoload feature</a></li>
<li><a href="#mouseEvents">Handling Wire mouse events</a></li>
<li><a href="#createContainers">Creating new Containers / Extending existing containers</a></li>
<li><a href="#production">notes on production</a></li>
</ol>
</li>
<li>
<a href="#moreInformation"><span>More information</span></a>
<ol 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>
<li><a href="#contribute">Contribute</a></li>
<li><a href="#roadmap">Roadmap</a></li>
</ol>
</li>
</ol>
</div>
<a name="overview"><h1>Overview</h1></a>
<a name="presentation"><h2>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> (2.8.0r4) for DOM and events manipulation, 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 <a href="license.txt">MIT license</a>.</p>
<a name="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 <a href="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>
<a name="WireItApplication"><h2>WireIt applications</h2>
<p>WireIt provides another useful component: the <b>WiringEditor</b>, a single-page editor for your <i>visual language</i>.</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>
<a name="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>
<a name="GettingStarted"><h1>Getting Started</h1></a>
<a name="installation"><h2>Installation</h2></a>
<p>WireIt is mostly a bunch of static javascript, css, and image files, so you can just <a href="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 <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="WiringEditorInstallation"><h3>WiringEditor installation</h3></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="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>Launch the index.html file in your browser. You're ready to create your <a href="#visualLanguage">visual language</a>.</p>
<a name="visualLanguage"><h1>Create your visual language</h1></a>
<a name="visualLanguageDefinition"><h2>Visual Language Definition</h2></a>
<p>The visual language is defined in a JSON format :</p>
<pre class="brush:js">
var myLanguage = {
// Set a unique name for the language
languageName: "myLanguage",
modules: [
// List of module type definitions
]
};
</pre>
<a name="moduleDefinition"><h2>Module Definition</h2></a>
<p>Here is the skeleton of a module definition :</p>
<pre class="brush:js">
{
"name": "moduleName",
"container": {
// which container class to use
"xtype":"WireIt.InOutContainer",
// Depends of the container
"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="#customContainer">custom container</a>.</p>
<a name="BaseContainer"><h2>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": "../../res/icons/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>
<a name="InOutContainer"><h2>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>Using FormContainer</h2></a>
<p>Set "xtype": "WireIt.FormContainer". Additional parameters are all those used in inputEx.Group. (see <a href="http://javascript.neyric.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", "inputParams": {"label": "Title", "name": "title", "selectValues": ["Mr","Mrs","Mme"] } },
{"inputParams": {"label": "Firstname", "name": "firstname", "required": true } },
{"inputParams": {"label": "Lastname", "name": "lastname", "value":"Dupont"} },
{"type":"email", "inputParams": {"label": "Email", "name": "email", "required": true, "wirable": true}},
{"type":"boolean", "inputParams": {"label": "Happy to be there ?", "name": "happy"}},
{"type":"url", "inputParams": {"label": "Website", "name":"website", "size": 25}}
],
"legend": "Tell us about yourself..."
}
}
</pre>
<a name="ImageContainer"><h2>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>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://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>
<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", inputParams: {"name": "name", label: "Title", typeInvite: "Enter a title" } },
{"type": "text", inputParams: {"name": "description", label: "Description", cols: 30} },
// Additional fields
{"type": "boolean", inputParams: {"name": "isTest", value: true, label: "Test"}},
{"type": "select", inputParams: {"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="adapters"><h2>Adapters - Connecting to another database or backend</h2></a>
<a name="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>
<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>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>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>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>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="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>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>
<a name="advancedTopics"><h1>Advanced Topics</h1></a>
<a name="outputFormat"><h2>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],
"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>
<p class="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>
<a name="stylingContainers"><h2>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>
<a name="autoload"><h2>WiringEditor autoload feature</h2></a>
<p>The WiringEditor has an option called <i>autoload</i>. <br />
This is a parameter passed in the URL that tells the WiringEditor which <i>wiring</i> to open when the editor is displayed.</p>
<pre>
http://myhost.com/editor/?autoload=myWiring
</pre>
<p>For example, here is a direct link to the "guideAutoloadDemo" wiring of the WiringEditor example :<br />
<a href="examples/WiringEditor/?autoload=guideAutoloadDemo">examples/WiringEditor/?autoload=guideAutoloadDemo</a></p>
<a name="mouseEvents"><h2>Handling Wire mouse events</h2></a>
<p>There are two methods to handle wire mouse events :</p>
<ul>
<li>
<p>Listen to wire events (recommanded)</p>
<pre class="brush:js">
wire.eventMouseIn.subscribe(wireRed, wire, true);
wire.eventMouseOut.subscribe(wireBlue, wire, true);
wire.eventMouseClick.subscribe(wireClick, wire, true);
</pre>
</li>
<li>
<p>Override Wire.prototype methods</p>
<pre class="brush:js">
Wire.prototype.onWireIn = function(x,y) {
};
Wire.prototype.onWireOut = function(x,y) {
};
Wire.prototype.onWireClick = function(x,y) {
};
</pre>
</li>
</ul>
<p>Here is an example to create a random layer and lister for wire events :</p>
<pre class="brush:js">
// Functions executed with the scope of a wire
var wireRed = function() {
this.options.color = 'rgb(255, 0, 0)';
this.redraw();
},
wireBlue = function() {
this.options.color = 'rgb(173, 216, 230)';
this.redraw();
},
wireClick = function() {
alert("Hoho ! you clicked !");
};
// Generate a random layer
var layer = new WireIt.Layer({});
for(var i = 0 ; i < 5 ; i++) {
layer.addContainer({
terminals: [ {direction: [0,1], offsetPosition: {bottom: -13, left: 25} }],
title: "Block #"+i,
position: [ Math.floor(Math.random()*800)+30, Math.floor(Math.random()*300)+30 ]
});
}
for(var i = 0 ; i < 7 ; i++) {
var w = layer.addWire({
src: {moduleId: Math.floor(Math.random()*5), terminalId: 0},
tgt: {moduleId: Math.floor(Math.random()*5), terminalId: 0}
});
// Subscribe methods to mouse events for all wires
w.eventMouseIn.subscribe(wireRed, w, true);
w.eventMouseOut.subscribe(wireBlue, w, true);
w.eventMouseClick.subscribe(wireClick, w, true);
}
</pre>
<a name="createContainers"><h2>Creating new Containers / Extending existing containers</h2></a>
<p>The general way to create a new <i>Container</i> class is to extend the WireIt.Container class. We do this YUI-style :</p>
<pre class="brush:js">
WireIt.MyContainer = function(options, layer) {
WireIt.MyContainer.superclass.constructor.call(this, options, layer);
};
YAHOO.lang.extend(WireIt.MyContainer, WireIt.Container, {
// override methods or new methods
});
</pre>
<p>You can extend from WireIt.Container, WireIt.InOutContainer, WireIt.ImageContainer, WireIt.FormContainer.</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>
<pre class="brush:js">
WireIt.ImageContainer.prototype.myMethod = function () {
// new code
};
</pre>
<p>To use your new Container in a language definition go to <a href="#moduleDefinition">Module Definition</a>.</p>
<a name="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>
<pre class="brush:html">
<script type="text/javascript" src="lib/wireit/build/wireit-min.js"></script>
</pre>
<p>or</p>
<pre class="brush:html">
<script type="text/javascript" src="lib/wireit/build/wiring-editor-min.js"></script>
</pre>
<p><u>Warning :</u>The rollup files <b>don't</b> include the excanvas.js library <b>required by Internet Explorer</b>, because this file is conditionally loaded using the "if IE" hack :</p>
<pre class="brush:html">
<!--[if IE]><script type="text/javascript" src="../../lib/excanvas.js"></script><![endif]-->
</pre>
<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>
<p class="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>
<p class="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>
<pre>
wireit/
- build/
- css/
- images/
- js/
- lib/
</pre>
<a name="moreInformation"><h1>More information</h2></a>
<a name="examples"><h2>All examples</h2></a>
<ul>
<li><a href="examples/presentation.html">Interactive presentation</a></li>
<li><a href="examples/creating_terminals.html">Creating terminals and wires</a></li>
<li><a href="examples/changing_directions.html">Changing terminal direction</a></li>
<li><a href="examples/wires_and_terminals.html">Wire and Terminals configuration</a></li>
<li><a href="examples/dd_and_animation.html">Using animation</a></li>
<li><a href="examples/planarGame/planarGame.html">Planar game</a></li>
<li><a href="examples/inputex/">FormContainers</a></li>
</ul>
<p>WiringEditor :</p>
<ul>
<li><a href="examples/WiringEditor/">WiringEditor demo</a></li>
<li><a href="examples/jsBox/jsBox.html">jsBox</a></li>
<li><a href="examples/logicGates/index.html">Logic Gates demo</a></li>
<li><a href="examples/ajaxAdapter/">Ajax Adapter</a></li>
<li><a href="examples/gearsAdapter/">Gears Adapter</a></li>
</ul>