ruote-kit 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +0 -0
- data/.gitignore +8 -0
- data/Gemfile +10 -0
- data/README.rdoc +132 -0
- data/Rakefile +57 -0
- data/config.ru +21 -0
- data/lib/ruote-kit/application.rb +50 -0
- data/lib/ruote-kit/configuration.rb +52 -0
- data/lib/ruote-kit/helpers/engine_helpers.rb +24 -0
- data/lib/ruote-kit/helpers/form_helpers.rb +11 -0
- data/lib/ruote-kit/helpers/launch_item_parser.rb +59 -0
- data/lib/ruote-kit/helpers/navigation_helpers.rb +54 -0
- data/lib/ruote-kit/helpers/render_helpers.rb +103 -0
- data/lib/ruote-kit/helpers.rb +9 -0
- data/lib/ruote-kit/public/_ruote/images/bg.gif +0 -0
- data/lib/ruote-kit/public/_ruote/images/bg_button_left.gif +0 -0
- data/lib/ruote-kit/public/_ruote/images/bg_button_left_cancel.gif +0 -0
- data/lib/ruote-kit/public/_ruote/images/bg_button_left_submit.gif +0 -0
- data/lib/ruote-kit/public/_ruote/images/bg_button_right.gif +0 -0
- data/lib/ruote-kit/public/_ruote/javascripts/SimplyButtons.js +191 -0
- data/lib/ruote-kit/public/_ruote/javascripts/fluo-can.js +1111 -0
- data/lib/ruote-kit/public/_ruote/javascripts/fluo-dial.js +149 -0
- data/lib/ruote-kit/public/_ruote/javascripts/fluo-json.js +183 -0
- data/lib/ruote-kit/public/_ruote/javascripts/fluo-tred.js +515 -0
- data/lib/ruote-kit/public/_ruote/stylesheets/SimplyButtons.css +226 -0
- data/lib/ruote-kit/public/_ruote/stylesheets/base.css +336 -0
- data/lib/ruote-kit/public/_ruote/stylesheets/rk.css +30 -0
- data/lib/ruote-kit/public/_ruote/stylesheets/style.css +393 -0
- data/lib/ruote-kit/resources/expressions.rb +55 -0
- data/lib/ruote-kit/resources/processes.rb +52 -0
- data/lib/ruote-kit/resources/workitems.rb +64 -0
- data/lib/ruote-kit/spec/ruote_helpers.rb +47 -0
- data/lib/ruote-kit/vendor/sinatra-respond_to/LICENSE +21 -0
- data/lib/ruote-kit/vendor/sinatra-respond_to/README.markdown +102 -0
- data/lib/ruote-kit/vendor/sinatra-respond_to/Rakefile +30 -0
- data/lib/ruote-kit/vendor/sinatra-respond_to/VERSION.yml +4 -0
- data/lib/ruote-kit/vendor/sinatra-respond_to/lib/sinatra/respond_to.rb +206 -0
- data/lib/ruote-kit/vendor/sinatra-respond_to/sinatra-respond_to.gemspec +56 -0
- data/lib/ruote-kit/vendor/sinatra-respond_to/spec/app/public/static folder/.keep +0 -0
- data/lib/ruote-kit/vendor/sinatra-respond_to/spec/app/public/static.txt +1 -0
- data/lib/ruote-kit/vendor/sinatra-respond_to/spec/app/test_app.rb +53 -0
- data/lib/ruote-kit/vendor/sinatra-respond_to/spec/app/unreachable_static.txt +1 -0
- data/lib/ruote-kit/vendor/sinatra-respond_to/spec/app/views/layout.html.haml +2 -0
- data/lib/ruote-kit/vendor/sinatra-respond_to/spec/app/views/resource.html.haml +1 -0
- data/lib/ruote-kit/vendor/sinatra-respond_to/spec/app/views/resource.js.erb +3 -0
- data/lib/ruote-kit/vendor/sinatra-respond_to/spec/app/views/resource.xml.builder +3 -0
- data/lib/ruote-kit/vendor/sinatra-respond_to/spec/extension_spec.rb +403 -0
- data/lib/ruote-kit/vendor/sinatra-respond_to/spec/spec_helper.rb +18 -0
- data/lib/ruote-kit/views/expression.html.haml +38 -0
- data/lib/ruote-kit/views/expressions.html.haml +30 -0
- data/lib/ruote-kit/views/index.html.haml +1 -0
- data/lib/ruote-kit/views/launch_process.html.haml +19 -0
- data/lib/ruote-kit/views/layout.html.haml +46 -0
- data/lib/ruote-kit/views/process.html.haml +55 -0
- data/lib/ruote-kit/views/processes.html.haml +27 -0
- data/lib/ruote-kit/views/resource_not_found.html.haml +7 -0
- data/lib/ruote-kit/views/workitem.html.haml +39 -0
- data/lib/ruote-kit/views/workitems.html.haml +23 -0
- data/lib/ruote-kit.rb +105 -0
- data/ruote-kit.gemspec +136 -0
- data/spec/helpers/render_helpers_spec.rb +211 -0
- data/spec/resources/expressions_spec.rb +179 -0
- data/spec/resources/index_spec.rb +46 -0
- data/spec/resources/processes_spec.rb +259 -0
- data/spec/resources/workitems_spec.rb +308 -0
- data/spec/ruote-kit_spec.rb +4 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +152 -0
- data/spec/views/launch_process.html.haml_spec.rb +21 -0
- data/spec/views/process.html.haml_spec.rb +16 -0
- data/spec/views/processes.html.haml_spec.rb +30 -0
- data/spec/views/workitems.html.haml_spec.rb +68 -0
- metadata +185 -0
@@ -0,0 +1,515 @@
|
|
1
|
+
|
2
|
+
/*
|
3
|
+
* Ruote - open source ruby workflow engine
|
4
|
+
* (c) 2005-2009 John Mettraux
|
5
|
+
*
|
6
|
+
* Ruote is freely distributable under the terms
|
7
|
+
* of a BSD-style license.
|
8
|
+
* For details, see the OpenWFEru web site: http://openwferu.rubyforge.org
|
9
|
+
*
|
10
|
+
* This piece of hack was created during the RubyKaigi2008,
|
11
|
+
* between Tsukuba and Akihabara.
|
12
|
+
*/
|
13
|
+
|
14
|
+
//var flow = [ 'process-definition', { 'name': 'toto', 'revision': '1.0' }, [
|
15
|
+
// [ 'sequence', {}, [
|
16
|
+
// [ 'participant', { 'ref': 'alpha' }, [] ],
|
17
|
+
// [ 'bravo', {}, [] ]
|
18
|
+
// ]]
|
19
|
+
// ]
|
20
|
+
//]
|
21
|
+
|
22
|
+
try {
|
23
|
+
HTMLElement.prototype.firstChildOfClass = function (className) {
|
24
|
+
for (var i=0; i < this.childNodes.length; i++) {
|
25
|
+
var c = this.childNodes[i];
|
26
|
+
if (c.className == className) return c;
|
27
|
+
}
|
28
|
+
return null;
|
29
|
+
}
|
30
|
+
} catch (e) {
|
31
|
+
// probably testing via Rhino
|
32
|
+
}
|
33
|
+
|
34
|
+
String.prototype.tstrip = function () {
|
35
|
+
var s = this;
|
36
|
+
while (s.charAt(0) == ' ') s = s.substring(1);
|
37
|
+
while (s.charAt(s.length - 1) == ' ') s = s.substring(0, s.length - 1);
|
38
|
+
return s;
|
39
|
+
}
|
40
|
+
String.prototype.qstrip = function () {
|
41
|
+
var s = this;
|
42
|
+
if (s.match(/".*"/)) s = s.substring(1, s.length - 1);
|
43
|
+
return s;
|
44
|
+
}
|
45
|
+
String.prototype.tqstrip = function () {
|
46
|
+
return this.tstrip().qstrip();
|
47
|
+
}
|
48
|
+
|
49
|
+
var FluoTred = function () {
|
50
|
+
|
51
|
+
//
|
52
|
+
// it's easy to override this var to let FluoTred point to another root
|
53
|
+
//
|
54
|
+
// FluoTred.imageRoot = 'http://my.image.server.exmaple.com/img'
|
55
|
+
//
|
56
|
+
var imageRoot = '/images';
|
57
|
+
|
58
|
+
var ExpressionHead = function () {
|
59
|
+
|
60
|
+
function createButton (imgsrc, tooltip, callback) {
|
61
|
+
|
62
|
+
var i = document.createElement("img");
|
63
|
+
i.callback = callback;
|
64
|
+
i.className = "tred_button";
|
65
|
+
i.setAttribute('src', imgsrc);
|
66
|
+
i.setAttribute('title', tooltip);
|
67
|
+
i.setAttribute("onclick", "this.callback()");
|
68
|
+
return i;
|
69
|
+
}
|
70
|
+
|
71
|
+
function addHeadButtons (expdiv) {
|
72
|
+
|
73
|
+
var outOpacity = 0.0;
|
74
|
+
|
75
|
+
var buttons = document.createElement('span');
|
76
|
+
buttons.style.opacity = outOpacity;
|
77
|
+
|
78
|
+
var root = findTredRoot(expdiv);
|
79
|
+
|
80
|
+
expdiv.onmouseover = function () {
|
81
|
+
buttons.style.opacity = 1.0;
|
82
|
+
//var root = findTredRoot(expdiv);
|
83
|
+
if (root.onOver) root.onOver(computeExpId(expdiv.parentNode));
|
84
|
+
};
|
85
|
+
expdiv.onmouseout = function () {
|
86
|
+
buttons.style.opacity = outOpacity;
|
87
|
+
//var root = findTredRoot(expdiv);
|
88
|
+
if (root.onOver) root.onOver(null);
|
89
|
+
};
|
90
|
+
|
91
|
+
buttons.appendChild(createButton(
|
92
|
+
FluoTred.imageRoot+'/btn-add.gif',
|
93
|
+
'add a child expression',
|
94
|
+
function () {
|
95
|
+
FluoTred.addExpression(expdiv.parentNode, [ '---', {}, [] ]);
|
96
|
+
}));
|
97
|
+
|
98
|
+
if (expdiv.parentNode.parentNode != root) {
|
99
|
+
|
100
|
+
buttons.appendChild(createButton(
|
101
|
+
FluoTred.imageRoot+'/btn-cut.gif',
|
102
|
+
'cut expression',
|
103
|
+
function () {
|
104
|
+
FluoTred.removeExpression(expdiv.parentNode);
|
105
|
+
}));
|
106
|
+
buttons.appendChild(createButton(
|
107
|
+
FluoTred.imageRoot+'/btn-moveup.gif',
|
108
|
+
'move expression up',
|
109
|
+
function () {
|
110
|
+
FluoTred.moveExpression(expdiv.parentNode, -1);
|
111
|
+
buttons.style.opacity = outOpacity;
|
112
|
+
}));
|
113
|
+
buttons.appendChild(createButton(
|
114
|
+
FluoTred.imageRoot+'/btn-movedown.gif',
|
115
|
+
'move expression down',
|
116
|
+
function () {
|
117
|
+
FluoTred.moveExpression(expdiv.parentNode, +1);
|
118
|
+
buttons.style.opacity = outOpacity;
|
119
|
+
}));
|
120
|
+
buttons.appendChild(createButton(
|
121
|
+
FluoTred.imageRoot+'/btn-paste.gif',
|
122
|
+
'paste expression here',
|
123
|
+
function () {
|
124
|
+
var clip = document._tred_clipboard;
|
125
|
+
if (clip) FluoTred.insertExpression(expdiv.parentNode, clip);
|
126
|
+
}));
|
127
|
+
}
|
128
|
+
|
129
|
+
expdiv.appendChild(buttons);
|
130
|
+
}
|
131
|
+
|
132
|
+
var headPattern = /^(\S*)( [.]*[^:]*)?( .*)?$/;
|
133
|
+
var keyPattern = /([^ :]+|".*") *:/;
|
134
|
+
|
135
|
+
function quoteKeys (s) {
|
136
|
+
var ss = '';
|
137
|
+
while (s) {
|
138
|
+
var m = s.match(keyPattern);
|
139
|
+
if ( ! m) {
|
140
|
+
ss += s;
|
141
|
+
break;
|
142
|
+
}
|
143
|
+
ss += s.substring(0, m.index - 1);
|
144
|
+
var m1 = m[1].tstrip();
|
145
|
+
if (m1.match(/^".*"$/)) ss += m1;
|
146
|
+
else ss += ('"' + m1 + '"');
|
147
|
+
ss += ':';
|
148
|
+
s = s.substring(m.index + m[0].length);
|
149
|
+
}
|
150
|
+
return ss;
|
151
|
+
}
|
152
|
+
|
153
|
+
function renderAttributes (h) {
|
154
|
+
s = '';
|
155
|
+
for (var k in h) {
|
156
|
+
s += ('' + k + ': ' + fluoToJson(h[k]) + ', ');
|
157
|
+
}
|
158
|
+
if (s.length > 1) s = s.substring(0, s.length - 2);
|
159
|
+
return s;
|
160
|
+
}
|
161
|
+
|
162
|
+
return {
|
163
|
+
|
164
|
+
render: function (node, exp) {
|
165
|
+
|
166
|
+
var expname = exp[0];
|
167
|
+
|
168
|
+
var text = '';
|
169
|
+
if ((typeof exp[2][0]) == 'string') text = exp[2].shift();
|
170
|
+
|
171
|
+
//var atts = fluoToJson(exp[1]);
|
172
|
+
//atts = atts.substring(1, atts.length - 1);
|
173
|
+
var atts = renderAttributes(exp[1]);
|
174
|
+
|
175
|
+
var d = document.createElement('div');
|
176
|
+
d.setAttribute('class', 'tred_exp');
|
177
|
+
node.appendChild(d);
|
178
|
+
|
179
|
+
var sen = document.createElement('span');
|
180
|
+
sen.setAttribute('class', 'tred_exp_span tred_expression_name');
|
181
|
+
sen.appendChild(document.createTextNode(expname));
|
182
|
+
d.appendChild(sen);
|
183
|
+
|
184
|
+
var ses = document.createElement('span');
|
185
|
+
ses.setAttribute('class', 'tred_exp_span tred_expression_string');
|
186
|
+
var t = text;
|
187
|
+
if (t != '') t = ' ' + t;
|
188
|
+
ses.appendChild(document.createTextNode(t));
|
189
|
+
d.appendChild(ses);
|
190
|
+
|
191
|
+
var sea = document.createElement('span');
|
192
|
+
sea.setAttribute('class', 'tred_exp_span tred_expression_atts');
|
193
|
+
sea.appendChild(document.createTextNode(' ' + atts));
|
194
|
+
d.appendChild(sea);
|
195
|
+
|
196
|
+
addHeadButtons(d);
|
197
|
+
|
198
|
+
var onblur = function () {
|
199
|
+
|
200
|
+
var p = d.parentNode;
|
201
|
+
var d2 = ExpressionHead.render(p, ExpressionHead.parse(this.value));
|
202
|
+
p.replaceChild(d2, d);
|
203
|
+
|
204
|
+
triggerChange(p); // trigger onChange()...
|
205
|
+
};
|
206
|
+
|
207
|
+
var onkeyup = function (evt) {
|
208
|
+
|
209
|
+
var e = evt || window.event;
|
210
|
+
var c = e.charCode || e.keyCode;
|
211
|
+
if (c == 13) this.blur();
|
212
|
+
|
213
|
+
return false;
|
214
|
+
}
|
215
|
+
|
216
|
+
var onclick = function () {
|
217
|
+
d.removeChild(sen);
|
218
|
+
d.removeChild(ses);
|
219
|
+
var input = document.createElement('input');
|
220
|
+
input.setAttribute('type', 'text');
|
221
|
+
input.value = expname + ' ' + atts;
|
222
|
+
if (text != '') input.value = expname + ' ' + text + ' ' + atts;
|
223
|
+
d.replaceChild(input, sea);
|
224
|
+
input.onblur = onblur;
|
225
|
+
input.onkeyup = onkeyup;
|
226
|
+
input.focus();
|
227
|
+
};
|
228
|
+
|
229
|
+
sen.onclick = onclick;
|
230
|
+
ses.onclick = onclick;
|
231
|
+
sea.onclick = onclick;
|
232
|
+
|
233
|
+
return d;
|
234
|
+
},
|
235
|
+
|
236
|
+
parseAttributes: function (s) {
|
237
|
+
return fluoFromJson("{" + quoteKeys(s) + "}");
|
238
|
+
},
|
239
|
+
|
240
|
+
parse: function (s) {
|
241
|
+
|
242
|
+
var m = s.match(headPattern);
|
243
|
+
|
244
|
+
if (m == null) return [ '---', {}, [] ];
|
245
|
+
|
246
|
+
var expname = m[1];
|
247
|
+
|
248
|
+
var children = [];
|
249
|
+
if (m[2]) {
|
250
|
+
var t = m[2].tstrip();
|
251
|
+
if (t.match(/".*"/)) t = t.substring(1, t.length - 1);
|
252
|
+
if (t != '') children.push(t);
|
253
|
+
}
|
254
|
+
|
255
|
+
atts = ExpressionHead.parseAttributes(m[3]);
|
256
|
+
|
257
|
+
return [ expname, atts, children ];
|
258
|
+
},
|
259
|
+
|
260
|
+
toExp: function (node) {
|
261
|
+
|
262
|
+
node = node.firstChild;
|
263
|
+
|
264
|
+
var name = node.childNodes[0].firstChild.nodeValue;
|
265
|
+
var text = node.childNodes[1].firstChild.nodeValue;
|
266
|
+
var atts = node.childNodes[2].firstChild.nodeValue;
|
267
|
+
|
268
|
+
atts = ExpressionHead.parseAttributes(atts);
|
269
|
+
|
270
|
+
var children = [];
|
271
|
+
if (text != '') children.push(text.tstrip());
|
272
|
+
// child is just a string...
|
273
|
+
|
274
|
+
return [ name, atts, children ];
|
275
|
+
}
|
276
|
+
};
|
277
|
+
}();
|
278
|
+
|
279
|
+
function asJson (node) {
|
280
|
+
|
281
|
+
if ((typeof node) == 'string')
|
282
|
+
node = document.getElementById(node);
|
283
|
+
|
284
|
+
return fluoToJson(toTree(node));
|
285
|
+
}
|
286
|
+
|
287
|
+
function renderEnding (node, exp) {
|
288
|
+
|
289
|
+
var ending = document.createElement('div');
|
290
|
+
ending.className = 'tred_text';
|
291
|
+
if (exp[2].length > 0) ending.appendChild(document.createTextNode('end'));
|
292
|
+
node.appendChild(ending);
|
293
|
+
}
|
294
|
+
|
295
|
+
function renderExpressionString (node, s) {
|
296
|
+
|
297
|
+
var opening = document.createElement('div');
|
298
|
+
|
299
|
+
var sname = document.createElement('span');
|
300
|
+
sname.appendChild(document.createTextNode(s));
|
301
|
+
sname.setAttribute('onclick', 'EditableSpan.toInput(this);');
|
302
|
+
sname.className = 'tred_expression_string';
|
303
|
+
opening.appendChild(sname);
|
304
|
+
|
305
|
+
node.appendChild(opening);
|
306
|
+
}
|
307
|
+
|
308
|
+
function addExpression (parentExpNode, exp) {
|
309
|
+
|
310
|
+
var end = parentExpNode.lastChild;
|
311
|
+
var node = renderExpression(parentExpNode, exp);
|
312
|
+
parentExpNode.replaceChild(node, end);
|
313
|
+
parentExpNode.appendChild(end);
|
314
|
+
|
315
|
+
if (end.childNodes.length == 0)
|
316
|
+
end.appendChild(document.createTextNode('end'));
|
317
|
+
|
318
|
+
triggerChange(parentExpNode);
|
319
|
+
}
|
320
|
+
|
321
|
+
function removeExpression (expNode) {
|
322
|
+
|
323
|
+
var p = expNode.parentNode;
|
324
|
+
p.removeChild(expNode);
|
325
|
+
|
326
|
+
if (p.childNodes.length == 2)
|
327
|
+
p.lastChild.removeChild(p.lastChild.firstChild);
|
328
|
+
|
329
|
+
document._tred_clipboard = toTree(expNode);
|
330
|
+
|
331
|
+
triggerChange(p);
|
332
|
+
}
|
333
|
+
|
334
|
+
function renderExpression (parentNode, exp, isRootExp) {
|
335
|
+
|
336
|
+
//
|
337
|
+
// draw expression
|
338
|
+
|
339
|
+
var node = document.createElement('div');
|
340
|
+
node.className = 'tred_expression';
|
341
|
+
|
342
|
+
if ( ! isRootExp)
|
343
|
+
node.setAttribute('style', 'margin-left: 14px;');
|
344
|
+
|
345
|
+
parentNode.appendChild(node);
|
346
|
+
|
347
|
+
if ( ! (exp instanceof Array)) {
|
348
|
+
renderExpressionString(node, exp.toString());
|
349
|
+
return;
|
350
|
+
}
|
351
|
+
|
352
|
+
ExpressionHead.render(node, exp);
|
353
|
+
|
354
|
+
//
|
355
|
+
// draw children
|
356
|
+
|
357
|
+
for (var i=0; i < exp[2].length; i++) renderExpression(node, exp[2][i]);
|
358
|
+
|
359
|
+
//
|
360
|
+
// over
|
361
|
+
|
362
|
+
renderEnding(node, exp);
|
363
|
+
|
364
|
+
return node;
|
365
|
+
}
|
366
|
+
|
367
|
+
function renderFlow (parentNode, flow) {
|
368
|
+
|
369
|
+
parentNode.className = 'tred_root';
|
370
|
+
|
371
|
+
renderExpression(parentNode, flow, true);
|
372
|
+
|
373
|
+
parentNode.stack = []; // the undo stack
|
374
|
+
parentNode.currentTree = flow;
|
375
|
+
}
|
376
|
+
|
377
|
+
function moveExpression (elt, delta) {
|
378
|
+
|
379
|
+
var p = elt.parentNode;
|
380
|
+
|
381
|
+
if (delta == -1) { // move up
|
382
|
+
if (elt.previousSibling.className != 'tred_expression') return;
|
383
|
+
p.insertBefore(elt, elt.previousSibling);
|
384
|
+
}
|
385
|
+
else { // move down
|
386
|
+
if (elt.nextSibling.className != 'tred_expression') return;
|
387
|
+
p.insertBefore(elt, elt.nextSibling.nextSibling);
|
388
|
+
}
|
389
|
+
|
390
|
+
FluoTred.triggerChange(p);
|
391
|
+
}
|
392
|
+
|
393
|
+
function insertExpression (before, exp) {
|
394
|
+
|
395
|
+
var newNode = renderExpression(before.parentNode, exp);
|
396
|
+
|
397
|
+
before.parentNode.insertBefore(newNode, before);
|
398
|
+
|
399
|
+
FluoTred.triggerChange(before.parentNode);
|
400
|
+
}
|
401
|
+
|
402
|
+
function triggerChange (elt) {
|
403
|
+
|
404
|
+
var tredRoot = findTredRoot(elt);
|
405
|
+
var tree = toTree(tredRoot);
|
406
|
+
|
407
|
+
stack(tredRoot, tree);
|
408
|
+
|
409
|
+
//FluoTred.onChange(tree);
|
410
|
+
if (tredRoot.onChange) tredRoot.onChange(tree);
|
411
|
+
}
|
412
|
+
|
413
|
+
function stack(root, tree) {
|
414
|
+
root.stack.push(root.currentTree);
|
415
|
+
root.currentTree = tree;
|
416
|
+
}
|
417
|
+
|
418
|
+
function undo (root) {
|
419
|
+
|
420
|
+
if ((typeof root) == 'string') root = document.getElementById(root);
|
421
|
+
if (root.stack.length < 1) return;
|
422
|
+
|
423
|
+
while (root.firstChild != null) root.removeChild(root.firstChild);
|
424
|
+
|
425
|
+
var tree = root.stack.pop();
|
426
|
+
|
427
|
+
root.currentTree = tree;
|
428
|
+
renderExpression(root, tree, true);
|
429
|
+
|
430
|
+
if (root.onChange) root.onChange(tree);
|
431
|
+
}
|
432
|
+
|
433
|
+
function findTredRoot (node) {
|
434
|
+
|
435
|
+
if (node.className == 'tred_root') return node;
|
436
|
+
return findTredRoot(node.parentNode);
|
437
|
+
}
|
438
|
+
|
439
|
+
function computeExpId (node, from, expid) {
|
440
|
+
|
441
|
+
if (from == null) {
|
442
|
+
from = findTredRoot(node);
|
443
|
+
expid = '';
|
444
|
+
}
|
445
|
+
if (from == node) return expid.substring(1, expid.length);
|
446
|
+
|
447
|
+
var divs = from.childNodes;
|
448
|
+
var childid = -1;
|
449
|
+
|
450
|
+
for (var i=0; i<divs.length; i++) {
|
451
|
+
var e = divs[i];
|
452
|
+
if (e.nodeType != 1) continue;
|
453
|
+
if (e.className != 'tred_expression') continue;
|
454
|
+
childid += 1;
|
455
|
+
var ei = computeExpId(node, e, expid + '.' + childid);
|
456
|
+
if (ei != null) return ei;
|
457
|
+
}
|
458
|
+
|
459
|
+
return null;
|
460
|
+
}
|
461
|
+
|
462
|
+
function toTree (node) {
|
463
|
+
|
464
|
+
node.focus();
|
465
|
+
//
|
466
|
+
// making sure all the input boxes get blurred...
|
467
|
+
|
468
|
+
if (node.className != 'tred_expression') {
|
469
|
+
node = node.firstChildOfClass('tred_expression');
|
470
|
+
}
|
471
|
+
|
472
|
+
//
|
473
|
+
// expression itself
|
474
|
+
|
475
|
+
var exp = ExpressionHead.toExp(node);
|
476
|
+
|
477
|
+
//
|
478
|
+
// children
|
479
|
+
|
480
|
+
var divs = node.childNodes;
|
481
|
+
|
482
|
+
var children = exp[2];
|
483
|
+
|
484
|
+
for (var i=0; i<divs.length; i++) {
|
485
|
+
var e = divs[i];
|
486
|
+
if (e.nodeType != 1) continue;
|
487
|
+
if (e.className != 'tred_expression') continue;
|
488
|
+
children.push(toTree(e));
|
489
|
+
}
|
490
|
+
|
491
|
+
//
|
492
|
+
// done
|
493
|
+
|
494
|
+
return exp;
|
495
|
+
}
|
496
|
+
|
497
|
+
//
|
498
|
+
// public methods
|
499
|
+
//
|
500
|
+
return {
|
501
|
+
|
502
|
+
ExpressionHead: ExpressionHead, // for testing purposes
|
503
|
+
|
504
|
+
renderFlow: renderFlow,
|
505
|
+
addExpression: addExpression,
|
506
|
+
removeExpression: removeExpression,
|
507
|
+
moveExpression: moveExpression,
|
508
|
+
insertExpression: insertExpression,
|
509
|
+
triggerChange: triggerChange,
|
510
|
+
undo: undo,
|
511
|
+
asJson: asJson,
|
512
|
+
imageRoot: imageRoot
|
513
|
+
};
|
514
|
+
}();
|
515
|
+
|