1 | //+----------------------------------------------------------------------------- |
---|
2 | //+ Isidorus |
---|
3 | //+ (c) 2008-2009 Marc Kuester, Christoph Ludwig, Lukas Giessmann |
---|
4 | //+ |
---|
5 | //+ Isidorus is freely distributable under the LGPL license. |
---|
6 | //+ This ajax module uses the frameworks PrototypeJs and Scriptaculous, both |
---|
7 | //+ are distributed under the MIT license. |
---|
8 | //+ You can find a detailed description in trunk/docs/LGPL-LICENSE.txt and |
---|
9 | //+ in trunk/src/ajax/javascripts/external/MIT-LICENSE.txt. |
---|
10 | //+----------------------------------------------------------------------------- |
---|
11 | |
---|
12 | // --- The base class of all Frames defined in this file. |
---|
13 | var FrameC = Class.create({"initialize" : function(content, owner, min, max){ |
---|
14 | if(!owner) throw "From FrameC(): owner must be set but is null"; |
---|
15 | if(max !== -1 && (min > max || max === 0))throw "From FrameC(): min must be > max(" + max + ") and > 0 but is " + min; |
---|
16 | if(!owner.__frames__) owner.__frames__ = new Array(); |
---|
17 | owner.__frames__.push(this); |
---|
18 | |
---|
19 | this.__frame__ = new Element("div"); |
---|
20 | this.__remove__ = new Element("span", {"class" : CLASSES.clickable()}).update("-"); |
---|
21 | this.__add__ = new Element("span", {"class" : CLASSES.clickable()}).update("+"); |
---|
22 | |
---|
23 | checkRemoveAddButtons(owner, min, max, null); |
---|
24 | |
---|
25 | this.__error__ = new Element("div", {"class" : CLASSES.error()}); |
---|
26 | this.__error__.hide(); |
---|
27 | this.__content__ = new Element("span").update(content); |
---|
28 | |
---|
29 | this.__frame__.insert({"bottom" : this.__remove__}); |
---|
30 | this.__frame__.insert({"bottom" : this.__content__}); |
---|
31 | this.__frame__.insert({"bottom" : this.__add__}); |
---|
32 | this.__frame__.insert({"bottom" : this.__error__}); |
---|
33 | this.__disabled__ = false; |
---|
34 | |
---|
35 | setRemoveAddHandler(this, true, owner, min, max, function(){ |
---|
36 | return new FrameC("", owner, min, max); |
---|
37 | }); |
---|
38 | }, |
---|
39 | "getFrame" : function(){ |
---|
40 | return this.__frame__; |
---|
41 | }, |
---|
42 | "remove" : function(){ |
---|
43 | return this.getFrame().remove(); |
---|
44 | }, |
---|
45 | "hide" : function(){ |
---|
46 | this.getFrame().hide(); |
---|
47 | }, |
---|
48 | "show" : function(){ |
---|
49 | this.getFrame().show(); |
---|
50 | }, |
---|
51 | "getContent" : function(){ |
---|
52 | return this.__content__.textContent; |
---|
53 | }, |
---|
54 | "toJSON" : function(){ |
---|
55 | return this.getContent().toJSON(); |
---|
56 | }, |
---|
57 | "showError" : function(message){ |
---|
58 | this.__error__.update(message); |
---|
59 | this.__error__.show(); |
---|
60 | }, |
---|
61 | "hideError" : function(){ |
---|
62 | this.__error__.hide(); |
---|
63 | }, |
---|
64 | "hideRemoveButton" : function(){ |
---|
65 | this.__remove__.hide(); |
---|
66 | }, |
---|
67 | "showRemoveButton" : function(){ |
---|
68 | this.__remove__.show(); |
---|
69 | }, |
---|
70 | "hideAddButton" : function(){ |
---|
71 | this.__add__.hide(); |
---|
72 | }, |
---|
73 | "showAddButton" : function(){ |
---|
74 | this.__add__.show(); |
---|
75 | }, |
---|
76 | "append" : function(elem){ |
---|
77 | return this.getFrame().insert({"after" : elem}); |
---|
78 | }, |
---|
79 | "isUsed" : function(){ |
---|
80 | return !this.__disabled__; |
---|
81 | }}); |
---|
82 | |
---|
83 | |
---|
84 | // --- This class represents a textrow with the functionality of FrameC plus the method isValid |
---|
85 | // --- which returns a boolean value depending on the instance's value and the given regular expression. |
---|
86 | var TextrowC = Class.create(FrameC, {"initialize" : function($super, content, regexp, owner, min, max, cssTitle, dblClickHandler){ |
---|
87 | $super(content, owner, min, max); |
---|
88 | owner.__frames__.pop(); |
---|
89 | owner.__frames__.push(this); |
---|
90 | this.__owner__ = owner; |
---|
91 | this.__min__ = min; |
---|
92 | this.__max__ = max; |
---|
93 | |
---|
94 | this.__regexp__ = new RegExp(regexp); |
---|
95 | this.__regExpString__ = regexp; |
---|
96 | this.__frame__.writeAttribute({"class" : CLASSES.textrowWithRemoveButton()}); |
---|
97 | this.__content__.remove(); |
---|
98 | this.__content__ = new Element("input", {"type" : "text", "value" : content, "size" : 48}); |
---|
99 | this.__dblClickHandler__ = dblClickHandler; |
---|
100 | if(cssTitle && cssTitle.length){ |
---|
101 | this.__content__.writeAttribute({"title" : cssTitle}); |
---|
102 | } |
---|
103 | this.__remove__.insert({"after" : this.__content__}); |
---|
104 | |
---|
105 | checkRemoveAddButtons(owner, min, max, null); |
---|
106 | var myself = this; |
---|
107 | setRemoveAddHandler(this, true, owner, min, max, function(){ |
---|
108 | return new TextrowC("", regexp, owner, min, max, cssTitle, this.__dblClickHandler__); |
---|
109 | }); |
---|
110 | |
---|
111 | if(this.__dblClickHandler__){ |
---|
112 | this.getFrame().observe("dblclick", function(event){ |
---|
113 | myself.__dblClickHandler__(owner, event); |
---|
114 | }); |
---|
115 | } |
---|
116 | }, |
---|
117 | "dblClick" : function(){ |
---|
118 | if(this.__dblClickHandler__) this.__dblClickHandler__(this.__owner__); |
---|
119 | }, |
---|
120 | "getContent" : function(){ |
---|
121 | return this.__content__.value; |
---|
122 | }, |
---|
123 | "isValid" : function(){ |
---|
124 | return this.__regexp__.match(this.getContent()); |
---|
125 | }, |
---|
126 | "showRemoveButton" : function($super){ |
---|
127 | this.__remove__.show(); |
---|
128 | this.getFrame().writeAttribute({"class" : CLASSES.textrowWithRemoveButton()}); |
---|
129 | }, |
---|
130 | "hideRemoveButton" : function(){ |
---|
131 | this.__remove__.hide(); |
---|
132 | this.getFrame().writeAttribute({"class" : CLASSES.textrowWithoutRemoveButton()}); |
---|
133 | }, |
---|
134 | "disable" : function(){ |
---|
135 | this.hideError(); |
---|
136 | this.__content__.writeAttribute({"readonly" : "readonly"}); |
---|
137 | this.hideRemoveButton(); |
---|
138 | this.hideAddButton(); |
---|
139 | this.__disabled__ = true; |
---|
140 | }, |
---|
141 | "enable" : function(){ |
---|
142 | this.__content__.removeAttribute("readonly"); |
---|
143 | checkRemoveAddButtons(this.__owner__, this.__min__, this.__max__, null); |
---|
144 | this.__disabled__ = false; |
---|
145 | }, |
---|
146 | "getRegexp" : function(){ |
---|
147 | return this.__regExpString__; |
---|
148 | }}); |
---|
149 | |
---|
150 | |
---|
151 | // --- This class represents a selectrow with the functionality of FrameC. |
---|
152 | var SelectrowC = Class.create(FrameC, {"initialize" : function($super, contents, owner, min, max){ |
---|
153 | if(!contents || !contents.length)throw "From SelectrowC(): contents must be a non-empty array!"; |
---|
154 | $super(contents, owner, min, max); |
---|
155 | owner.__frames__.pop(); |
---|
156 | owner.__frames__.push(this); |
---|
157 | |
---|
158 | this.__frame__.writeAttribute({"class" : CLASSES.selectrowWithRemoveButton()}); |
---|
159 | this.__content__.remove(); |
---|
160 | this.__content__ = new Element("select"); |
---|
161 | for(var i = 0; i != contents.length; ++i){ |
---|
162 | // --- the attribute value must be set for IE |
---|
163 | var opt = new Element("option", {"value" : contents[i]}).update(contents[i]); |
---|
164 | this.__content__.insert({"bottom" : opt}); |
---|
165 | if(i === 0) opt.writeAttribute({"selected" : "selected"}); |
---|
166 | } |
---|
167 | this.__remove__.insert({"after" : this.__content__}); |
---|
168 | |
---|
169 | checkRemoveAddButtons(owner, min, max, null); |
---|
170 | setRemoveAddHandler(this, true, owner, min, max, function(){ |
---|
171 | return new SelectrowC(contents, owner, min, max); |
---|
172 | }); |
---|
173 | }, |
---|
174 | "getContent" : function(){ |
---|
175 | return this.__content__.value; |
---|
176 | }, |
---|
177 | "showRemoveButton" : function(){ |
---|
178 | this.__remove__.show(); |
---|
179 | this.getFrame().writeAttribute({"class" : CLASSES.selectrowWithRemoveButton()}); |
---|
180 | }, |
---|
181 | "hideRemoveButton" : function(){ |
---|
182 | this.__remove__.hide(); |
---|
183 | this.getFrame().writeAttribute({"class" : CLASSES.selectrowWithoutRemoveButton()}); |
---|
184 | }, |
---|
185 | "disable" : function(){ |
---|
186 | this.hideError(); |
---|
187 | this.__content__.writeAttribute({"disabled" : "disables"}); |
---|
188 | this.__disabled__ = true; |
---|
189 | }, |
---|
190 | "enable" : function(){ |
---|
191 | this.__content__.removeAttribute("disabled"); |
---|
192 | this.__disabled__ = false; |
---|
193 | }, |
---|
194 | "select" : function(value){ |
---|
195 | var opts = this.__content__.select("option"); |
---|
196 | for(var i = 0; i !== opts.length; ++i){ |
---|
197 | try{ |
---|
198 | if(opts[i].value === value){ |
---|
199 | opts[i].writeAttribute({"selected" : "selected"}); |
---|
200 | this.__content__.insert({"top" : opts[i]}); |
---|
201 | } |
---|
202 | else opts[i].removeAttribute("selected"); |
---|
203 | }catch(err){ alert("err [" + i + "]" + err); } |
---|
204 | } |
---|
205 | }}); |
---|
206 | |
---|
207 | |
---|
208 | // --- The base Class for alomost all frames which contains other frames like names, occurrences, ... |
---|
209 | var ContainerC = Class.create({"initialize" : function(){ |
---|
210 | this.__frame__ = new Element("div"); |
---|
211 | this.__error__ = new Element("div", {"class" : CLASSES.error()}); |
---|
212 | this.__error__.hide(); |
---|
213 | this.__frame__.insert({"bottom" : this.__error__}); |
---|
214 | this.__disabled__ = false; |
---|
215 | }, |
---|
216 | "hide" : function(){ |
---|
217 | this.__frame__.hide(); |
---|
218 | }, |
---|
219 | "show" : function(){ |
---|
220 | this.__frame__.show(); |
---|
221 | }, |
---|
222 | "getFrame" : function(){ |
---|
223 | return this.__frame__; |
---|
224 | }, |
---|
225 | "getContent" : function(unique, removeNull){ |
---|
226 | return ""; |
---|
227 | }, |
---|
228 | "toJSON" : function(unique, removeNull){ |
---|
229 | return this.getContent(unique, removeNull).toJSON(); |
---|
230 | }, |
---|
231 | "showError" : function(message){ |
---|
232 | this.__error__.update(message); |
---|
233 | this.__error__.show(); |
---|
234 | }, |
---|
235 | "hideError" : function(){ |
---|
236 | this.__error__.hide(); |
---|
237 | }, |
---|
238 | "append" : function(newElem){ |
---|
239 | this.getFrame().insert({"after" : newElem}); |
---|
240 | }, |
---|
241 | "remove" : function(){ |
---|
242 | this.getFrame().remove(); |
---|
243 | }, |
---|
244 | "showRemoveButton" : function(){ |
---|
245 | try{ this.__remove__.show(); } catch(err) {} |
---|
246 | }, |
---|
247 | "hideRemoveButton" : function(){ |
---|
248 | try{ this.__remove__.hide(); } catch(err) {} |
---|
249 | }, |
---|
250 | "showAddButton" : function(){ |
---|
251 | try{ this.__add__.show(); } catch(err) {} |
---|
252 | }, |
---|
253 | "hideAddButton" : function(){ |
---|
254 | try{ this.__add__.hide(); } catch(err) {} |
---|
255 | }, |
---|
256 | "isUsed" : function(){ |
---|
257 | return !this.__disabled__; |
---|
258 | }}); |
---|
259 | |
---|
260 | |
---|
261 | // --- Representation of a |
---|
262 | var EditC = Class.create(ContainerC, {"initialize" : function($super, contents, successFun, psi){ |
---|
263 | $super(); |
---|
264 | this.__frame__.writeAttribute({"class" : CLASSES.editFrame()}); |
---|
265 | this.__container__ = new Object(); |
---|
266 | try{ |
---|
267 | var row = new SelectrowC(contents, this.__container__, 1, 1); |
---|
268 | if(psi && psi.length !== 0) row.select(psi); |
---|
269 | this.__error__.insert({"before" : row.getFrame()}); |
---|
270 | } |
---|
271 | catch(err){ |
---|
272 | throw "From EditC(): The following exception was thrown:\n" + err; |
---|
273 | this.__container__ = null; |
---|
274 | } |
---|
275 | this.__commit__ = new Element("input", {"type" : "button", "value" : "generate fragment"}); |
---|
276 | |
---|
277 | function setHandler(myself){ |
---|
278 | function onSuccessHandler(xhr){ |
---|
279 | var json = null; |
---|
280 | try{ |
---|
281 | json = xhr.responseText.evalJSON(); |
---|
282 | } |
---|
283 | catch(err){ |
---|
284 | alert("Got bad JSON data from " + xhr.request.url + "!\n\n" + err); |
---|
285 | } |
---|
286 | successFun(new Array(myself.getContent()), json); |
---|
287 | } |
---|
288 | |
---|
289 | myself.__commit__.observe("click", function(event){ |
---|
290 | myself.hideError(); |
---|
291 | clearFragment(); |
---|
292 | requestConstraints("[" + myself.toJSON() + "]", onSuccessHandler, null) |
---|
293 | }); |
---|
294 | |
---|
295 | if(psi && psi.length !== 0) { |
---|
296 | myself.hideError(); |
---|
297 | clearFragment(); |
---|
298 | requestConstraints("[" + myself.toJSON() + "]", onSuccessHandler, null); |
---|
299 | } |
---|
300 | } |
---|
301 | setHandler(this); |
---|
302 | |
---|
303 | this.__error__.insert({"before" : this.__commit__}); |
---|
304 | }, |
---|
305 | "getContent" : function(){ |
---|
306 | return this.__container__.__frames__[0].getContent(); |
---|
307 | }, |
---|
308 | "toJSON" : function(){ |
---|
309 | return this.getContent().toJSON(); |
---|
310 | }}); |
---|
311 | |
---|
312 | |
---|
313 | // --- Represents a container for all instanceOf-Psis of a fragment's topic |
---|
314 | var InstanceOfC = Class.create(ContainerC, {"initialize" : function($super, contents, successFun, psi){ |
---|
315 | $super(); |
---|
316 | this.__frame__.writeAttribute({"class" : CLASSES.instanceOfFrame()}); |
---|
317 | this.__container__ = new Object(); |
---|
318 | try{ |
---|
319 | var row = new SelectrowC(contents, this.__container__, 1, -1); |
---|
320 | if(psi && psi.length !== 0) row.select(psi); |
---|
321 | this.__error__.insert({"before" : row.getFrame()}); |
---|
322 | } |
---|
323 | catch(err){ |
---|
324 | throw "From InstanceOfC(): The following exception was thrown:\n" + err; |
---|
325 | this.__container__ = null; |
---|
326 | } |
---|
327 | this.__commit__ = new Element("input", {"type" : "button", "value" : "generate fragment"}); |
---|
328 | |
---|
329 | function setHandler(myself){ |
---|
330 | function onSuccessHandler(xhr){ |
---|
331 | var json = null; |
---|
332 | try{ |
---|
333 | json = xhr.responseText.evalJSON(); |
---|
334 | } |
---|
335 | catch(err){ |
---|
336 | alert("Got bad JSON data from " + xhr.request.url + "!\n\n" + err); |
---|
337 | } |
---|
338 | |
---|
339 | var ret = checkExclusiveInstances(json, myself.getContent(true)); |
---|
340 | if(ret){ |
---|
341 | var str = "Some topics own exclusive-instance-constraints, please deselect the corresponding topics!<br/>"; |
---|
342 | for(var i = 0; i != ret.length; ++i){ |
---|
343 | for(var j = 0; j != ret[i].length; ++j){ |
---|
344 | if(j === 0){ |
---|
345 | str += "<br/>" + ret[i][j]; |
---|
346 | } |
---|
347 | else { |
---|
348 | str += " " + ret[i][j]; |
---|
349 | } |
---|
350 | str += "<br/>"; |
---|
351 | } |
---|
352 | } |
---|
353 | clearFragment(); |
---|
354 | myself.showError(str); |
---|
355 | } |
---|
356 | else { |
---|
357 | successFun(myself.getContent(true, true), json); |
---|
358 | } |
---|
359 | } |
---|
360 | |
---|
361 | myself.__commit__.observe("click", function(event){ |
---|
362 | myself.hideError(); |
---|
363 | clearFragment(); |
---|
364 | requestConstraints(myself.toJSON(true), onSuccessHandler, null, true); |
---|
365 | }); |
---|
366 | |
---|
367 | if(psi && psi.length !== 0) { |
---|
368 | myself.hideError(); |
---|
369 | clearFragment(); |
---|
370 | requestConstraints(myself.toJSON(true), onSuccessHandler, null, true); |
---|
371 | } |
---|
372 | } |
---|
373 | setHandler(this); |
---|
374 | |
---|
375 | this.__error__.insert({"before" : this.__commit__}); |
---|
376 | }, |
---|
377 | "getContent" : function(unique, removeNull){ |
---|
378 | var values = new Array(); |
---|
379 | for(var i = 0; i != this.__container__.__frames__.length; ++i){ |
---|
380 | if(unique === true && values.indexOf(this.__container__.__frames__[i].getContent()) !== -1) continue; |
---|
381 | if(removeNull === true && this.__container__.__frames__[i].getContent().strip().length === 0) continue; |
---|
382 | values.push(this.__container__.__frames__[i].getContent().strip()); |
---|
383 | } |
---|
384 | return values; |
---|
385 | }}); |
---|
386 | |
---|
387 | |
---|
388 | // --- Representation of a itemIdentity frame. |
---|
389 | var ItemIdentityC = Class.create(ContainerC, {"initialize" : function($super, contents, parent){ |
---|
390 | $super(); |
---|
391 | this.__frame__.writeAttribute({"class" : CLASSES.itemIdentityFrame()}); |
---|
392 | this.__container__ = new Object(); |
---|
393 | |
---|
394 | try{ |
---|
395 | for(var i = 0; i != contents.length; ++i){ |
---|
396 | new TextrowC(decodeURI(contents[i]), ".*", this.__container__, 1, -1, null); |
---|
397 | this.__error__.insert({"before" : this.__container__.__frames__[i].getFrame()}); |
---|
398 | } |
---|
399 | } |
---|
400 | catch(err){ |
---|
401 | this.__container__ = new Object(); |
---|
402 | new TextrowC("", ".*", this.__container__, 1, -1, null); |
---|
403 | this.__error__.insert({"before" : this.__container__.__frames__[i].getFrame()}); |
---|
404 | } |
---|
405 | finally { |
---|
406 | function setDeactivateHandler(myself){ |
---|
407 | myself.__frame__.observe("dblclick", function(event){ |
---|
408 | if(myself.__container__.__frames__.length === 1){ |
---|
409 | if(myself.isUsed() === true){ |
---|
410 | myself.disable(); |
---|
411 | Event.stop(event); |
---|
412 | } |
---|
413 | else { |
---|
414 | myself.enable(); |
---|
415 | if(parent.isUsed() === true) Event.stop(event); |
---|
416 | } |
---|
417 | } |
---|
418 | }); |
---|
419 | } |
---|
420 | setDeactivateHandler(this); |
---|
421 | |
---|
422 | if(!contents || contents.length === 0) this.disable(); |
---|
423 | } |
---|
424 | }, |
---|
425 | "getContent" : function(unique, removeNull){ |
---|
426 | var values = new Array(); |
---|
427 | for(var i = 0; i != this.__container__.__frames__.length; ++i){ |
---|
428 | if(unique === true && values.indexOf(this.__container__.__frames__[i].getContent()) !== -1) continue; |
---|
429 | if(removeNull === true && this.__container__.__frames__[i].getContent().strip().length === 0) continue; |
---|
430 | values.push(this.__container__.__frames__[i].getContent().strip()); |
---|
431 | } |
---|
432 | for(var i = 0; i !== values.length; ++i)values[i] = encodeURI(values[i]); |
---|
433 | return values; |
---|
434 | }, |
---|
435 | "toJSON" : function(unique, removeNull){ |
---|
436 | var content = this.getContent(unique, removeNull); |
---|
437 | return content.length === 0 ? "null" : content.toJSON(); |
---|
438 | }, |
---|
439 | "disable" : function(){ |
---|
440 | this.hideError(); |
---|
441 | if(this.__container__.__frames__){ |
---|
442 | for(var i = 0; i !== this.__container__.__frames__.length; ++i){ |
---|
443 | this.__container__.__frames__[i].disable(); |
---|
444 | } |
---|
445 | } |
---|
446 | this.__disabled__ = true; |
---|
447 | }, |
---|
448 | "enable" : function(){ |
---|
449 | if(this.__container__.__frames__){ |
---|
450 | for(var i = 0; i !== this.__container__.__frames__.length; ++i){ |
---|
451 | this.__container__.__frames__[i].enable(); |
---|
452 | } |
---|
453 | } |
---|
454 | this.__disabled__ = false; |
---|
455 | }}); |
---|
456 | |
---|
457 | |
---|
458 | // --- Representation of a subjectLocator and subjectIdentifier frame. |
---|
459 | var IdentifierC = Class.create(ContainerC, {"initialize" : function($super, contents, constraints, cssClass){ |
---|
460 | $super(); |
---|
461 | this.__frame__.writeAttribute({"class" : cssClass}); |
---|
462 | this.__containers__ = new Array(); |
---|
463 | this.__constraints__ = constraints; |
---|
464 | |
---|
465 | try{ |
---|
466 | if(constraints && constraints.length > 0){ |
---|
467 | var cContents = new Array(); |
---|
468 | if(contents) cContents = contents.clone(); |
---|
469 | |
---|
470 | var ret = makeConstraintsAndContents(cContents, constraints, null); |
---|
471 | var constraintsAndContents = ret.constraintsAndContents; |
---|
472 | cContents = ret.contents; |
---|
473 | |
---|
474 | // --- creates all rows |
---|
475 | for(var i = 0; i != constraints.length; ++i){ |
---|
476 | this.__containers__.push(new Object()); |
---|
477 | var min = parseInt(constraints[i].cardMin); |
---|
478 | var max = constraints[i].cardMax !== MAX_INT ? parseInt(constraints[i].cardMax) : MMAX_INT; |
---|
479 | var regexp = constraints[i].regexp; |
---|
480 | var _contents = null; |
---|
481 | for(var j = 0; j !== constraintsAndContents.length; ++j){ |
---|
482 | if(constraintsAndContents[j].constraint === constraints[i]){ |
---|
483 | _contents = constraintsAndContents[j].contents; |
---|
484 | break; |
---|
485 | } |
---|
486 | } |
---|
487 | var _c_ = ""; |
---|
488 | for(var x = 0; x !== _contents.length; ++x) _c_ += "[" + x + "/" + _contents.length + "]: " + _contents[x] + "\n"; |
---|
489 | if(max !== 0 || _contents && _contents.length){ |
---|
490 | // -- creates the roles |
---|
491 | var cssTitle = "min: " + min + " max: " + max + " regular expression: " + constraints[i].regexp; |
---|
492 | var endIdx = (min === 0 ? 1 : min); |
---|
493 | endIdx = _contents && _contents.length > endIdx ? _contents.length : endIdx; |
---|
494 | for(var j = 0; j != endIdx; ++j){ |
---|
495 | var dblClickHandler = null; |
---|
496 | if(min === 0) dblClickHandler = dblClickHandlerF; |
---|
497 | var _content = ""; |
---|
498 | if(_contents && _contents.length > j) _content = _contents[j]; |
---|
499 | |
---|
500 | var row = new TextrowC(_content, constraints[i].regexp, this.__containers__[i], min === 0 ? 1 : min, max === MMAX_INT ? -1 : max, cssTitle, dblClickHandler); |
---|
501 | if(!_content) row.dblClick(); |
---|
502 | this.__error__.insert({"before" : row.getFrame()}); |
---|
503 | } |
---|
504 | } |
---|
505 | } |
---|
506 | // --- not used contents |
---|
507 | if(cContents.length !== 0){ |
---|
508 | this.__containers__.push(new Object()); |
---|
509 | for(var i = 0; i !== cContents.length; ++i){ |
---|
510 | var owner = this.__containers__[this.__containers__.length - 1]; |
---|
511 | var cssTitle = "No constraint found for this identifier!"; |
---|
512 | var row = new TextrowC(cContents[i], "^.+$", owner, 0, 1, cssTitle, null); |
---|
513 | this.__error__.insert({"before" : row.getFrame()}); |
---|
514 | } |
---|
515 | } |
---|
516 | |
---|
517 | } |
---|
518 | else if(contents && contents.length !== 0){ |
---|
519 | this.__containers__.push(new Object()); |
---|
520 | var cssTitle = "No constraint found for this identifier"; |
---|
521 | for(var i = 0; i !== contents.length; ++i){ |
---|
522 | var row = new TextrowC(contents[i], null, this.__containers__[0], 0, 1, cssTitle, null); |
---|
523 | this.__error__.insert({"before" : row.getFrame()}); |
---|
524 | } |
---|
525 | } |
---|
526 | } |
---|
527 | catch(err){ |
---|
528 | alert("From IdentifierC(): " + err); |
---|
529 | } |
---|
530 | }, |
---|
531 | "getContent" : function(unique, removeNull){ |
---|
532 | var values = new Array(); |
---|
533 | try{ |
---|
534 | for(var i = 0; i != this.__containers__.length; ++i){ |
---|
535 | for(var j = 0; j != this.__containers__[i].__frames__.length; ++j){ |
---|
536 | if(unique === true && values.indexOf(this.__containers__[i].__frames__[j].getContent()) !== -1) continue; |
---|
537 | if(removeNull === true && this.__containers__[i].__frames__[j].getContent().strip().length === 0) continue; |
---|
538 | values.push(this.__containers__[i].__frames__[j].getContent().strip()); |
---|
539 | } |
---|
540 | } |
---|
541 | } |
---|
542 | catch(err){ |
---|
543 | for(var i = 0; i !== values.length; ++i) values[i] = encodeURI(values[i]); |
---|
544 | return values; |
---|
545 | } |
---|
546 | for(var i = 0; i !== values.length; ++i) values[i] = encodeURI(values[i]); |
---|
547 | return values; |
---|
548 | }, |
---|
549 | "toJSON" : function(unique, removeNull){ |
---|
550 | var content = this.getContent(unique, removeNull); |
---|
551 | return content.length === 0 ? "null" : content.toJSON(); |
---|
552 | }, |
---|
553 | "isValid" : function(){ |
---|
554 | var allIdentifiers = new Array(); |
---|
555 | var errorStr = ""; |
---|
556 | var ret = true; |
---|
557 | |
---|
558 | // --- checks if there are any constraints |
---|
559 | if((!this.__constraints__ || this.__constraints__.length === 0) && this.__containers__.length !== 0){ |
---|
560 | for(var i = 0; i !== this.__containers__.length; ++i){ |
---|
561 | for(var j = 0; this.__containers__[i].__frames__ && j !== this.__containers__[i].__frames__.length; ++j){ |
---|
562 | this.__containers__[i].__frames__[j].showError("No constraints found for this identifier!"); |
---|
563 | } |
---|
564 | } |
---|
565 | return false; |
---|
566 | } |
---|
567 | else if(!this.__constraints__ || this.__constraints__.length === 0) return true; |
---|
568 | |
---|
569 | // --- collects all non-empty identifiers |
---|
570 | for(var i = 0; i !== this.__containers__.length; ++i){ |
---|
571 | for(var j = 0; this.__containers__[i].__frames__ && j !== this.__containers__[i].__frames__.length; ++j){ |
---|
572 | var row = this.__containers__[i].__frames__[j]; |
---|
573 | row.hideError(); |
---|
574 | if(row.isUsed() === true && row.getContent().strip().length !== 0) allIdentifiers.push(row); |
---|
575 | } |
---|
576 | } |
---|
577 | |
---|
578 | var checkedIdentifiers = new Array(); |
---|
579 | for(var i = 0; i !== this.__constraints__.length; ++i){ |
---|
580 | var regexp = new RegExp(this.__constraints__[i].regexp); |
---|
581 | var cardMin = parseInt(this.__constraints__[i].cardMin); |
---|
582 | var cardMax = this.__constraints__[i].cardMax === MAX_INT ? MMAX_INT : parseInt(this.__constraints__[i].cardMax); |
---|
583 | var currentIdentifiers = new Array(); |
---|
584 | for(var j = 0; j !== allIdentifiers.length; ++j){ |
---|
585 | if(regexp.match(allIdentifiers[j].getContent()) === true) currentIdentifiers.push(allIdentifiers[j]); |
---|
586 | } |
---|
587 | checkedIdentifiers = checkedIdentifiers.concat(currentIdentifiers); |
---|
588 | |
---|
589 | // --- checks card-min and card-max for the current constraint |
---|
590 | if(cardMin > currentIdentifiers.length){ |
---|
591 | if(errorStr.length !== 0) errorStr += "<br/><br/>"; |
---|
592 | errorStr += "card-min of the constraint regexp: \"" + this.__constraints__[i].regexp + "\" card-min: " + cardMin + " card-max: " + cardMax + " is not satisfied (" + currentIdentifiers.length + ")!"; |
---|
593 | ret = false; |
---|
594 | } |
---|
595 | if(cardMax !== MMAX_INT && cardMax < currentIdentifiers.length){ |
---|
596 | if(errorStr.length !== 0) errorStr += "<br/><br/>"; |
---|
597 | errorStr += "card-max of the constraint regexp: \"" + this.__constraints__[i].regexp + "\" card-min: " + cardMin + " card-max: " + cardMax + " is not satisfied (" + currentIdentifiers.length + ")!"; |
---|
598 | ret = false; |
---|
599 | } |
---|
600 | } |
---|
601 | |
---|
602 | // --- checks if there are some identifiers which don't satisfies any constraint |
---|
603 | checkedIdentifiers = checkedIdentifiers.uniq(); |
---|
604 | if(checkedIdentifiers.length < allIdentifiers.length){ |
---|
605 | ret = false; |
---|
606 | for(var i = 0; i !== allIdentifiers.length; ++i){ |
---|
607 | if(checkedIdentifiers.indexOf(allIdentifiers[i]) === -1) allIdentifiers[i].showError("This Identifier does not satisfie any constraint!"); |
---|
608 | } |
---|
609 | } |
---|
610 | |
---|
611 | if(ret === true) this.hideError(); |
---|
612 | else this.showError(errorStr); |
---|
613 | return ret; |
---|
614 | }}); |
---|
615 | |
---|
616 | |
---|
617 | // --- Represantation of a scope frame, doesn't contain SelectrowCs, because the values must be unique! |
---|
618 | // --- So this class uses another implementation. |
---|
619 | var ScopeC = Class.create(ContainerC, {"initialize" : function($super, contents, selectedContents, min, max){ |
---|
620 | $super(); |
---|
621 | this.__frame__.writeAttribute({"class" : CLASSES.scopeFrame()}); |
---|
622 | this.__error__ = this.__error__.remove(); |
---|
623 | |
---|
624 | this.__container__ = null; |
---|
625 | this.__contents__ = contents; |
---|
626 | this.resetRows(this.__contents__, min, max, selectedContents); |
---|
627 | }, |
---|
628 | "resetRows" : function(contents, min, max, selectedContents){ |
---|
629 | try{ |
---|
630 | for(var i = 0; i != this.__container__.__frames__.length; ++i){ |
---|
631 | this.__container__.__frames__[i].remove(); |
---|
632 | } |
---|
633 | this.__container__ = new Object(); |
---|
634 | } |
---|
635 | catch(err){ |
---|
636 | this.__container__ = new Object(); |
---|
637 | }; |
---|
638 | |
---|
639 | this.__contents__ = contents; |
---|
640 | if(!contents || contents.length < min) throw "From ScopeC.resetRows(): contents.length (" + |
---|
641 | (contents ? contents.length : "null") + ") must be > min (" + min + ")!"; |
---|
642 | if(max !== -1 && min > max)throw "From FrameC(): min must be > max(" + max + ") and > 0 but is " + min; |
---|
643 | this.__min__ = min; |
---|
644 | this.__max__ = max; |
---|
645 | |
---|
646 | // --- creates an empty div element |
---|
647 | if(max === 0){ |
---|
648 | this.getFrame().update(""); |
---|
649 | var div = new Element("div", {"class" : CLASSES.selectrowWithoutRemoveButton()}); |
---|
650 | div.insert({"top" : select}); |
---|
651 | this.getFrame().insert({"bottom" : div}); |
---|
652 | return; |
---|
653 | } |
---|
654 | |
---|
655 | // --- creates an array with all available psis |
---|
656 | var options = new Array(); |
---|
657 | for(var i = 0; i != contents.length; ++i){ |
---|
658 | var topicPsis = new Array(); |
---|
659 | for(var j = 0; j != contents[i].length; ++j){ |
---|
660 | for(var k = 0; k != contents[i][j].length; ++k){ |
---|
661 | topicPsis.push(contents[i][j][k]); |
---|
662 | } |
---|
663 | } |
---|
664 | options.push(topicPsis); |
---|
665 | } |
---|
666 | |
---|
667 | function checkValues(myself){ |
---|
668 | var rows = myself.getFrame().select("div"); |
---|
669 | var selectedItems = new Array(); |
---|
670 | |
---|
671 | // --- collects all old selected values and removes the elements |
---|
672 | for(var i = 0; i != rows.length; ++i){ |
---|
673 | var selects = rows[i].select("select"); |
---|
674 | if(selects[0].value.strip().length !== 0) selectedItems.push(selects[0].value); |
---|
675 | selects[0].update(""); |
---|
676 | } |
---|
677 | |
---|
678 | // --- recreates the original values |
---|
679 | var values = options.clone(); |
---|
680 | for(var i = 0; i != rows.length && i != selectedItems.length; ++i){ |
---|
681 | var select = rows[i].select("select")[0]; |
---|
682 | var selectedIdx = new Array(); |
---|
683 | for(var j = 0; j != values.length; ++j){ |
---|
684 | if(values[j].indexOf(selectedItems[i]) !== -1){ |
---|
685 | for(var k = 0; k != values[j].length; ++k){ |
---|
686 | var opt = new Element("option", {"value" : values[j][k]}).update(values[j][k]); |
---|
687 | select.insert({"bottom" : opt}); |
---|
688 | if(values[j][k] === selectedItems[i]) opt.writeAttribute({"selected" : "selected"}); |
---|
689 | selectedIdx.push(j); |
---|
690 | } |
---|
691 | break; |
---|
692 | } |
---|
693 | } |
---|
694 | var cleanedValues = new Array(); |
---|
695 | for(var k = 0; k != values.length; ++k){ |
---|
696 | if(selectedIdx.indexOf(k) === -1){ |
---|
697 | cleanedValues.push(values[k]); |
---|
698 | } |
---|
699 | } |
---|
700 | values = cleanedValues; |
---|
701 | } |
---|
702 | |
---|
703 | // --- if there is an empty value "" (if cardMin == 0), this value should be the last |
---|
704 | // --- in the array (only when there is another value selected) |
---|
705 | for(var h = 0; h != rows.length; ++h){ |
---|
706 | var select = rows[h].select("select")[0].value; |
---|
707 | if(select !== ""){ |
---|
708 | for(var i = 0; i != values.length; ++i){ |
---|
709 | for(var j = 0; j != values[i].length; ++j){ |
---|
710 | if(values[i][j].length === 0){ |
---|
711 | values[i] = values[values.length - 1]; |
---|
712 | values[values.length - 1] = new Array(""); |
---|
713 | } |
---|
714 | } |
---|
715 | } |
---|
716 | break; |
---|
717 | } |
---|
718 | } |
---|
719 | |
---|
720 | // --- fills all empty select elements |
---|
721 | for(var i = 0; i != rows.length; ++i){ |
---|
722 | var select = rows[i].select("select")[0]; |
---|
723 | if(select.childElements().length === 0 && values.length !== 0){ |
---|
724 | for(var j = 0; j != values[0].length; ++j){ |
---|
725 | select.insert({"bottom" : new Element("option", {"value" : values[0][j]}).update(values[0][j])}); |
---|
726 | } |
---|
727 | values.shift(); |
---|
728 | } |
---|
729 | } |
---|
730 | |
---|
731 | // --- adds the values which wasn't distributed |
---|
732 | for(var i = 0; i != rows.length; ++i){ |
---|
733 | var select = rows[i].select("select")[0]; |
---|
734 | for(var j = 0; j != values.length; ++j){ |
---|
735 | for(var k = 0; k != values[j].length; ++k){ |
---|
736 | select.insert({"bottom" : new Element("option" , {"value" :values[j][k]}).update(values[j][k])}); |
---|
737 | } |
---|
738 | } |
---|
739 | } |
---|
740 | }// checkValues |
---|
741 | |
---|
742 | |
---|
743 | function addHandlers(myself){ |
---|
744 | var rows = myself.getFrame().select("div"); |
---|
745 | checkValues(myself); |
---|
746 | |
---|
747 | function addHandler(event){ |
---|
748 | var div = new Element("div", {"class" : CLASSES.selectrowWithRemoveButton()}); |
---|
749 | myself.getFrame().insert({"bottom" : div}); |
---|
750 | var select = new Element("select"); |
---|
751 | div.insert({"top" : select}); |
---|
752 | addHandlers(myself); |
---|
753 | } |
---|
754 | |
---|
755 | function removeHandler(event){ |
---|
756 | event.element().up().remove(); |
---|
757 | addHandlers(myself); |
---|
758 | } |
---|
759 | |
---|
760 | function changeHandler(event){ |
---|
761 | try{ |
---|
762 | var eventOwner = event.element(); |
---|
763 | var newValue = eventOwner.value; |
---|
764 | var oldValue = null; |
---|
765 | var allValues = new Array(); |
---|
766 | var allOpts = myself.getFrame().select("option"); |
---|
767 | var allOwnOpts = eventOwner.select("option"); |
---|
768 | for(var i = 0; i !== allOwnOpts.length; ++i) allOpts = allOpts.without(allOwnOpts[i]); |
---|
769 | |
---|
770 | // --- collects all selected values |
---|
771 | for(var i = 0; i !== allOpts.length; ++i) allValues.push(allOpts[i].value); |
---|
772 | allValues = allValues.uniq(); |
---|
773 | var foundContent = new Array(); |
---|
774 | for(var i = 0; i !== allValues.length; ++i){ |
---|
775 | for(var j = 0; contents && j !== contents.length; ++j){ |
---|
776 | for(var k = 0; k !== contents[j].length; ++k){ |
---|
777 | if(contents[j][k].indexOf(allValues[i]) !== -1) foundContent.push(contents[j]); |
---|
778 | if(contents[j][k].indexOf(newValue) !== -1) foundContent.push(contents[j]); |
---|
779 | } |
---|
780 | } |
---|
781 | } |
---|
782 | foundContent = foundContent.uniq(); |
---|
783 | // --- searches for the content to be removed from all other select elements |
---|
784 | // --- and for the values to be inserted to all other elements |
---|
785 | var contentToAdd = null; |
---|
786 | var contentToRemove = null; |
---|
787 | if(contents && contents.length !== 0){ |
---|
788 | for(var i = 0; i !== contents.length; ++i){ |
---|
789 | if(foundContent.indexOf(contents[i]) === -1) contentToAdd = contents[i]; |
---|
790 | if(!contentToRemove){ |
---|
791 | for(var j = 0; j !== contents[i].length; ++j){ |
---|
792 | if(contentToRemove) break; |
---|
793 | for(var k = 0; k !== contents[i][j].length; ++k){ |
---|
794 | if(contents[i][j][k].indexOf(newValue) !== -1){ |
---|
795 | contentToRemove = contents[i]; |
---|
796 | break; |
---|
797 | } |
---|
798 | } |
---|
799 | } |
---|
800 | } |
---|
801 | } |
---|
802 | } |
---|
803 | |
---|
804 | // --- iterates through all select elements and adds/removes the found values |
---|
805 | var selects = myself.getFrame().select("select"); |
---|
806 | selects = selects.without(eventOwner); |
---|
807 | if(contentToAdd) contentToAdd = contentToAdd.flatten(); |
---|
808 | if(contentToRemove) contentToRemove = contentToRemove.flatten(); |
---|
809 | for(var i = 0; i !== selects.length; ++i){ |
---|
810 | var opts = selects[i].select("option"); |
---|
811 | var val = selects[i].value; |
---|
812 | for(var j = 0; j !== opts.length; ++j){ |
---|
813 | if(contentToRemove.indexOf(opts[j].value) !== -1) opts[j].remove(); |
---|
814 | } |
---|
815 | |
---|
816 | if(contentToAdd){ |
---|
817 | var selectOpts = new Array(); |
---|
818 | for(var j = 0; j !== opts.length; ++j) selectOpts.push(opts[j].value); |
---|
819 | var iter = 0; |
---|
820 | for( ; iter !== contentToAdd.length; ++iter){ |
---|
821 | if(selectOpts.indexOf(contentToAdd[iter]) !== -1) break; |
---|
822 | } |
---|
823 | if(iter === contentToAdd.length){ |
---|
824 | for(var j = 0; j !== contentToAdd.length; ++j){ |
---|
825 | selects[i].insert({"bottom" : new Element("option", {"value" : contentToAdd[j]}).update(contentToAdd[j])}); |
---|
826 | } |
---|
827 | } |
---|
828 | } |
---|
829 | } |
---|
830 | }catch(err){ alert("ch: " + err);} |
---|
831 | } // changeHandler |
---|
832 | |
---|
833 | for(var i = 0; i != rows.length; ++i){ |
---|
834 | var selectE = rows[i].select("select"); |
---|
835 | var spans = rows[i].select("span." + CLASSES.clickable()); |
---|
836 | var removeS = null; |
---|
837 | var addS = null; |
---|
838 | if(spans.length === 0){ |
---|
839 | removeS = new Element("span", {"class" : CLASSES.clickable()}).update("-"); |
---|
840 | removeS.observe("click", removeHandler); |
---|
841 | addS = new Element("span", {"class" : CLASSES.clickable()}).update("+"); |
---|
842 | addS.observe("click", addHandler); |
---|
843 | rows[i].insert({"top" : removeS}); |
---|
844 | rows[i].insert({"bottom" : addS}); |
---|
845 | } |
---|
846 | else { |
---|
847 | removeS = spans[0]; |
---|
848 | addS = spans[1]; |
---|
849 | } |
---|
850 | |
---|
851 | if(max === -1 || max > rows.length){ |
---|
852 | addS.show() |
---|
853 | } |
---|
854 | else { |
---|
855 | addS.hide(); |
---|
856 | } |
---|
857 | |
---|
858 | if(min !== -1 || min < rows.length){ |
---|
859 | removeS.show() |
---|
860 | rows[i].writeAttribute({"class" : CLASSES.selectrowWithRemoveButton()}); |
---|
861 | } |
---|
862 | else { |
---|
863 | removeS.hide(); |
---|
864 | rows[i].writeAttribute({"class" : CLASSES.selectrowWithoutRemoveButton()}); |
---|
865 | } |
---|
866 | if(i == 0 && rows.length === 1 && max > 1){ |
---|
867 | rows[i].writeAttribute({"class" : CLASSES.selectrowWithoutRemoveButton()}); |
---|
868 | removeS.hide(); |
---|
869 | } |
---|
870 | if(selectE.length !== 0){ |
---|
871 | selectE[0].stopObserving("change"); |
---|
872 | selectE[0].observe("change", changeHandler); |
---|
873 | } |
---|
874 | } |
---|
875 | } // addHandlers |
---|
876 | |
---|
877 | |
---|
878 | var endIdx = (min === -1 ? 1 : min); |
---|
879 | if(selectedContents && selectedContents.length > endIdx) endIdx = selectedContents.length; |
---|
880 | if(endIdx > options.length) throw "From ScopeC(): not enough scope-topics(" + options.length + ") to satisfie card-min(" + min + ")!"; |
---|
881 | for(var i = 0; i != endIdx; ++i){ |
---|
882 | var currentScope = null; |
---|
883 | if(selectedContents && selectedContents.length > i) currentScope = selectedContents[i]; |
---|
884 | var currentOptions = options.clone(); |
---|
885 | |
---|
886 | var optionsToRemove = new Array(); |
---|
887 | for(var j = 0; selectedContents && j !== selectedContents.length; ++j){ |
---|
888 | for(var k = 0; k !== selectedContents[j].length; ++k){ |
---|
889 | for(var l = 0; l !== currentOptions.length; ++l){ |
---|
890 | if(currentOptions[l].indexOf(selectedContents[j][k]) !== -1) optionsToRemove.push(currentOptions[l]); |
---|
891 | } |
---|
892 | } |
---|
893 | } |
---|
894 | |
---|
895 | optionsToRemove = optionsToRemove.uniq(); |
---|
896 | for(var j = 0; j !== optionsToRemove.length; ++j) currentOptions = currentOptions.without(optionsToRemove[j]); |
---|
897 | if(currentScope) currentOptions.unshift(currentScope); |
---|
898 | var div = new Element("div", {"class" : CLASSES.selectrowWithoutRemoveButton()}); |
---|
899 | var select = new Element("select"); |
---|
900 | for(var j = 0; j != currentOptions.length; ++j){ |
---|
901 | for(var k = 0; k != currentOptions[j].length; ++k){ |
---|
902 | select.insert({"bottom" : new Element("option", {"value" : currentOptions[j][k]}).update(currentOptions[j][k])}); |
---|
903 | } |
---|
904 | } |
---|
905 | |
---|
906 | div.insert({"top" : select}); |
---|
907 | this.getFrame().insert({"bottom" : div}); |
---|
908 | addHandlers(this); |
---|
909 | } |
---|
910 | }, |
---|
911 | "isUsed" : function(){ |
---|
912 | return this.getContent(true, true).length !== 0 && !this.__disabled__; |
---|
913 | }, |
---|
914 | "getContent" : function(unique, removeNull){ |
---|
915 | var values = new Array(); |
---|
916 | try{ |
---|
917 | var rows = this.getFrame().select("div"); |
---|
918 | for(var i = 0; i != rows.length; ++i){ |
---|
919 | var select = rows[i].select("select")[0].value; |
---|
920 | if(unique === true && values.indexOf(select) !== -1) continue; |
---|
921 | if(removeNull === true && select.length === 0) continue; |
---|
922 | values.push(select); |
---|
923 | } |
---|
924 | } |
---|
925 | catch(err){ |
---|
926 | return new Array(); |
---|
927 | } |
---|
928 | |
---|
929 | for(var i = 0; i !== values.length; ++i) |
---|
930 | values[i] = new Array(values[i]); |
---|
931 | return values; |
---|
932 | }, |
---|
933 | "disable" : function(){ |
---|
934 | this.hideError(); |
---|
935 | var rows = this.getFrame().select("div"); |
---|
936 | for(var i = 0; i != rows.length; ++i){ |
---|
937 | rows[i].select("select")[0].disable(); |
---|
938 | var buttons = rows[i].select("span." + CLASSES.clickable()); |
---|
939 | buttons[0].hide(); |
---|
940 | buttons[1].hide(); |
---|
941 | } |
---|
942 | this.__disabled__ = true; |
---|
943 | }, |
---|
944 | "enable" : function(){ |
---|
945 | var rows = this.getFrame().select("div"); |
---|
946 | for(var i = 0; i != rows.length; ++i){ |
---|
947 | rows[i].select("select")[0].enable(); |
---|
948 | var buttons = rows[i].select("span." + CLASSES.clickable()); |
---|
949 | if(this.__min__ < rows.length && rows.length !== 1) buttons[0].show(); |
---|
950 | if(this.__max__ === -1 || this.__max__ > rows.length) buttons[1].show(); |
---|
951 | } |
---|
952 | this.__disabled__ = false; |
---|
953 | }}); |
---|
954 | |
---|
955 | |
---|
956 | |
---|
957 | // --- Contains all scope frames of an element (there can be more than one scope constraint) |
---|
958 | var ScopeContainerC = Class.create(ContainerC, {"initialize" : function($super, contents, constraints){ |
---|
959 | $super(); |
---|
960 | this.__frame__.writeAttribute({"class" : CLASSES.scopeContainer()}); |
---|
961 | this.__container__ = new Array(); |
---|
962 | this.resetValues(contents, constraints); |
---|
963 | this.__constraints__ = constraints; |
---|
964 | |
---|
965 | }, |
---|
966 | "resetValues" : function(contents, constraints){ |
---|
967 | try{ |
---|
968 | for(var i = 0; i != this.__container__.length; ++i){ |
---|
969 | this.__container__[i].remove(); |
---|
970 | } |
---|
971 | this.__container__ = new Array(); |
---|
972 | } |
---|
973 | catch(err){ |
---|
974 | this.__container__ = new Array(); |
---|
975 | } |
---|
976 | |
---|
977 | this.__constraints__ = constraints; |
---|
978 | |
---|
979 | // --- sets contents corresponding to the passed constraints |
---|
980 | if(constraints && constraints.length){ |
---|
981 | var cContents = contents ? contents.clone() : null; |
---|
982 | var foundContents = new Array(); |
---|
983 | for(var i = 0; i != constraints.length; ++i){ |
---|
984 | var scopeTypes = constraints[i].scopeTypes; |
---|
985 | var min = parseInt(constraints[i].cardMin); |
---|
986 | var max = constraints[i].cardMax !== MAX_INT ? parseInt(constraints[i].cardMax) : MMAX_INT; |
---|
987 | |
---|
988 | // --- checks already existing scopes with the given scope-constraints |
---|
989 | var currentFoundContents = new Array(); |
---|
990 | if(cContents && cContents.length !== 0){ |
---|
991 | var allCurrentTypes = scopeTypes ? scopeTypes.flatten() : new Array(); |
---|
992 | for(var j = 0; j !== cContents.length; ++j){ |
---|
993 | for(var k = 0; k !== allCurrentTypes.length; ++k){ |
---|
994 | if(cContents[j].indexOf(allCurrentTypes[k]) !== -1){ |
---|
995 | foundContents.push(cContents[j]); |
---|
996 | currentFoundContents.push(cContents[j]); |
---|
997 | break; |
---|
998 | } |
---|
999 | } |
---|
1000 | } |
---|
1001 | foundContents = foundContents.uniq(); |
---|
1002 | } |
---|
1003 | |
---|
1004 | // --- if min === 0 adds an empty option |
---|
1005 | if(min === 0){ |
---|
1006 | scopeTypes.unshift(new Array(new Array(""))); // [[""]] |
---|
1007 | } |
---|
1008 | |
---|
1009 | var scp = new ScopeC(scopeTypes, currentFoundContents, min === 0 ? 1 : min, max === MMAX_INT ? -1 : max); |
---|
1010 | this.__container__.push(scp); |
---|
1011 | this.__error__.insert({"before" : scp.getFrame()}); |
---|
1012 | } |
---|
1013 | |
---|
1014 | // --- removes contents that are already used |
---|
1015 | if(cContents && cContents.length !== 0){ |
---|
1016 | for(var i = 0; i !== foundContents.length; ++i) cContents = cContents.without(foundContents[i]); |
---|
1017 | |
---|
1018 | // --- inserts all contents that doesn't correspond with any constraint |
---|
1019 | for(var i = 0; i !== cContents.length; ++i) cContents[i] = new Array(cContents[i]); |
---|
1020 | var cmax = cContents.length; |
---|
1021 | for(var i = 0; i !== cContents.length; ++i){ |
---|
1022 | var scp = new ScopeC(new Array(cContents[i]), null, 1, 1); |
---|
1023 | this.__container__.push(scp); |
---|
1024 | this.__error__.insert({"before" : scp.getFrame()}); |
---|
1025 | } |
---|
1026 | } |
---|
1027 | } |
---|
1028 | else if(contents && contents.length){ |
---|
1029 | for(var i = 0; i !== contents.length; ++i){ |
---|
1030 | var scp = new ScopeC(new Array(new Array(contents[i])), null, 1, 1); |
---|
1031 | this.__container__.push(scp); |
---|
1032 | this.__error__.insert({"before" : scp.getFrame()}); |
---|
1033 | } |
---|
1034 | } |
---|
1035 | else { |
---|
1036 | this.getFrame().insert({"top" : new Element("div", {"class" : CLASSES.selectrowWithoutRemoveButton()})}); |
---|
1037 | } |
---|
1038 | }, |
---|
1039 | "isUsed" : function(){ |
---|
1040 | if(this.__disabled__ === true) return false; |
---|
1041 | for(var i = 0; i != this.__container__.length; ++i){ |
---|
1042 | if(this.__container__[i].isUsed() === true) return true; |
---|
1043 | } |
---|
1044 | return false; |
---|
1045 | }, |
---|
1046 | "isValid" : function(){ |
---|
1047 | var errorStr = ""; |
---|
1048 | var ret = true; |
---|
1049 | var allContent = this.getContent(); |
---|
1050 | if(!allContent) allContent = new Array(); |
---|
1051 | var allFoundContent = new Array(); |
---|
1052 | if(allContent) allContent = allContent.flatten(); |
---|
1053 | if((!this.__constraints__ || this.__constraints__length === 0) && allContent.length !== 0){ |
---|
1054 | this.showError("No constraints found for the existing scopes!"); |
---|
1055 | return false; |
---|
1056 | } |
---|
1057 | for(var i = 0; this.__constraints__ && i !== this.__constraints__.length; ++i){ |
---|
1058 | var min = parseInt(this.__constraints__[i].cardMin); |
---|
1059 | var max = this.__constraints__[i].cardMax === MAX_INT ? MMAX_INT : parseInt(this.__constraints__[i].cardMax); |
---|
1060 | var scopes = this.__constraints__[i].scopeTypes; |
---|
1061 | if(scopes) scopes = scopes.flatten(); |
---|
1062 | else scopes = new Array(); |
---|
1063 | |
---|
1064 | // --- checks all available types for the current constraint |
---|
1065 | var currentFoundContent = new Array(); |
---|
1066 | for(var j = 0; j !== allContent.length; ++j){ |
---|
1067 | if(scopes.indexOf(allContent[j]) !== -1){ |
---|
1068 | currentFoundContent.push(allContent[j]); |
---|
1069 | allFoundContent.push(allContent[j]); |
---|
1070 | } |
---|
1071 | } |
---|
1072 | currentFoundContent = currentFoundContent.uniq(); |
---|
1073 | allFoundContent = allFoundContent.uniq(); |
---|
1074 | |
---|
1075 | // --- find topics for the found psis |
---|
1076 | var foundScopes = 0; |
---|
1077 | var _scopes = this.__constraints__[i].scopeTypes; |
---|
1078 | for(var j = 0; _scopes && j !== _scopes.length; ++j){ |
---|
1079 | for(var k = 0; k !== _scopes[j].length; ++k){ |
---|
1080 | for(var l = 0; l !== currentFoundContent.length; ++l){ |
---|
1081 | if(_scopes[j][k].indexOf(currentFoundContent[l]) !== -1){ |
---|
1082 | ++foundScopes; |
---|
1083 | break; |
---|
1084 | } |
---|
1085 | } |
---|
1086 | } |
---|
1087 | } |
---|
1088 | // --- checks card-min/card-max |
---|
1089 | var scStr = ""; |
---|
1090 | for(var j = 0; j !== scopes.length; ++j){ |
---|
1091 | if(scopes[j].length !== 0) scStr += "<br/> *" + scopes[j]; |
---|
1092 | } |
---|
1093 | |
---|
1094 | if(min > foundScopes){ |
---|
1095 | if(errorStr.length !== 0) errorStr += "<br/><br/>"; |
---|
1096 | errorStr += "card-min(" + min + ") of the scope-constraint with the available scopes" + scStr + "<br/>is not satisfied(" + foundScopes + ")!" |
---|
1097 | ret = false; |
---|
1098 | } |
---|
1099 | if(max !== MMAX_INT && max < foundScopes){ |
---|
1100 | if(errorStr.length !== 0) errorStr += "<br/><br/>"; |
---|
1101 | errorStr += "card-max(" + max + ") of the scope-constraint with the available scopes" + scStr + "<br/>is not satisfied(" + foundScopes + ")!" |
---|
1102 | ret = false; |
---|
1103 | } |
---|
1104 | } |
---|
1105 | |
---|
1106 | // --- removes all checked contents |
---|
1107 | for(var i = 0; i !== allFoundContent.length; ++i) allContent = allContent.without(allFoundContent[i]); |
---|
1108 | if(allContent && allContent.length !== 0){ |
---|
1109 | allContent = allContent.flatten(); |
---|
1110 | scStr = ""; |
---|
1111 | for(var j = 0; j !== allContent.length; ++j){ |
---|
1112 | if(allContent[j].length !== 0) scStr += "<br/> *" + allContent[j]; |
---|
1113 | } |
---|
1114 | if(errorStr.length !== 0) errorStr += "<br/><br/>"; |
---|
1115 | errorStr += "No constraint found for the scopes \"" + scStr + "\"!"; |
---|
1116 | ret = false; |
---|
1117 | } |
---|
1118 | |
---|
1119 | if(ret === true) this.hideError(); |
---|
1120 | else if(errorStr.length !== 0)this.showError(errorStr); |
---|
1121 | return ret; |
---|
1122 | }, |
---|
1123 | "getContent" : function(){ |
---|
1124 | var values = new Array(); |
---|
1125 | try{ |
---|
1126 | for(var i = 0; i != this.__container__.length; ++i){ |
---|
1127 | var cValues = this.__container__[i].getContent(true, true); |
---|
1128 | for(var j = 0; j != cValues.length; ++j){ |
---|
1129 | if(values.indexOf(cValues[j]) !== -1) continue; |
---|
1130 | values.push(cValues[j][0]); |
---|
1131 | } |
---|
1132 | } |
---|
1133 | }catch(err){ |
---|
1134 | return new Array(); |
---|
1135 | } |
---|
1136 | if(values.length === 0) return null; |
---|
1137 | values = values.uniq(); |
---|
1138 | for(var i = 0; i !== values.length; ++i) values[i] = new Array(values[i]); |
---|
1139 | return values; |
---|
1140 | }, |
---|
1141 | "toJSON" : function(){ |
---|
1142 | if(!this.getContent() || this.getContent().length === 0) return "null"; |
---|
1143 | return this.getContent().toJSON(); |
---|
1144 | }, |
---|
1145 | "disable" : function(){ |
---|
1146 | this.hideError(); |
---|
1147 | for(var i = 0; i !== this.__container__.length; ++i) this.__container__[i].disable(); |
---|
1148 | this.__disabled__ = true; |
---|
1149 | }, |
---|
1150 | "enable" : function(){ |
---|
1151 | for(var i = 0; i !== this.__container__.length; ++i) this.__container__[i].enable(); |
---|
1152 | this.__disabled__ = false; |
---|
1153 | }}); |
---|
1154 | |
---|
1155 | |
---|
1156 | // --- Representation of a variant element |
---|
1157 | var VariantC = Class.create(ContainerC, {"initialize" : function($super, contents, owner, dblClickHandler, parent){ |
---|
1158 | $super(); |
---|
1159 | if(!owner.__frames__) owner.__frames__ = new Array(); |
---|
1160 | owner.__frames__.push(this); |
---|
1161 | this.__frame__.writeAttribute({"class" : CLASSES.variantFrame()}); |
---|
1162 | this.__table__ = new Element("table", {"class" : CLASSES.variantFrame()}); |
---|
1163 | this.__frame__.insert({"top" : this.__table__}); |
---|
1164 | this.__owner__ = owner; |
---|
1165 | this.__dblClickHandler__ = dblClickHandler; |
---|
1166 | this.__isMinimized__ = false; |
---|
1167 | |
---|
1168 | try{ |
---|
1169 | var itemIdentityContent = null; |
---|
1170 | var scopesContent = null; |
---|
1171 | if(contents){ |
---|
1172 | itemIdentityContent = contents.itemIdentities; |
---|
1173 | scopesContent = contents.scopes; |
---|
1174 | } |
---|
1175 | |
---|
1176 | // --- control row + itemIdentity |
---|
1177 | makeControlRow(this, 4, itemIdentityContent); |
---|
1178 | checkRemoveAddButtons(owner, 1, -1, null); |
---|
1179 | setRemoveAddHandler(this, true, owner, 1, -1, function(){ |
---|
1180 | return new VariantC(null, owner, dblClickHandler, parent); |
---|
1181 | }); |
---|
1182 | |
---|
1183 | // --- scopes |
---|
1184 | this.__scopes__ = null; |
---|
1185 | //TODO: implement -> also in the server |
---|
1186 | this.__table__.insert({"bottom" : newRow(CLASSES.scopeContainer(), "Scope", new Element("div"))}); |
---|
1187 | |
---|
1188 | // --- resource value and datatype |
---|
1189 | makeResource(this, contents, null, null, null, {"rows" : 3, "cols" : 55}); |
---|
1190 | |
---|
1191 | this.getFrame().observe("dblclick", function(event){ |
---|
1192 | dblClickHandler(owner, event); |
---|
1193 | if(parent.isUsed() === true)Event.stop(event); |
---|
1194 | }); |
---|
1195 | } |
---|
1196 | catch(err){ |
---|
1197 | alert("From VariantC(): " + err); |
---|
1198 | } |
---|
1199 | }, |
---|
1200 | "getContent" : function(){ |
---|
1201 | var resourceRef = null; |
---|
1202 | var resourceData = null; |
---|
1203 | if(this.__datatype__.__frames__[0].getContent() === ANY_URI){ |
---|
1204 | resourceRef = this.__value__.textContent.strip(); |
---|
1205 | } |
---|
1206 | else { |
---|
1207 | var datatype = STRING; |
---|
1208 | if(this.__datatype__.__frames__[0].getContent().strip() !== "") |
---|
1209 | datatype = this.__datatype__.__frames__[0].getContent().strip(); |
---|
1210 | resoureceData = {"datatype" : datatype, "value" : this.__value__.textContent.strip()}; |
---|
1211 | } |
---|
1212 | |
---|
1213 | // TODO: scopes |
---|
1214 | if(this.__itemIdentity__.getContent(true, true).length === 0 && |
---|
1215 | resourceRef === null && resourceData === null) return null; |
---|
1216 | return {"itemIdentities" : this.__itemIdentity__.getContent(true, true), |
---|
1217 | "scopes" : null, |
---|
1218 | "resourceRef" : resourceRef, |
---|
1219 | "resourceData" : resourceData}; |
---|
1220 | |
---|
1221 | }, |
---|
1222 | "toJSON" : function(){ |
---|
1223 | var resourceRef = null; |
---|
1224 | var resourceData = null; |
---|
1225 | if(this.__datatype__.__frames__[0].getContent() === ANY_URI){ |
---|
1226 | resourceRef = this.__value__.value.strip().toJSON(); |
---|
1227 | } |
---|
1228 | else { |
---|
1229 | var datatype = STRING.toJSON(); |
---|
1230 | if(this.__datatype__.__frames__[0].getContent().strip() !== "") |
---|
1231 | datatype = this.__datatype__.__frames__[0].getContent().strip().toJSON(); |
---|
1232 | resourceData = "{\"datatype\":" + datatype + ",\"value\":" + this.__value__.value.strip().toJSON() + "}"; |
---|
1233 | } |
---|
1234 | |
---|
1235 | // TODO: scopes |
---|
1236 | return "{\"itemIdentities\":" + this.__itemIdentity__.toJSON(true, true) + |
---|
1237 | ",\"scopes\":null,\"resourceRef\":" + resourceRef + ",\"resourceData\":" + resourceData + "}"; |
---|
1238 | |
---|
1239 | }, |
---|
1240 | "isEmpty" : function(){ |
---|
1241 | return this.__value__.value.length === 0; |
---|
1242 | }, |
---|
1243 | "isValid" : function(){ |
---|
1244 | if(this.__value__.value.strip() === ""){ |
---|
1245 | this.showError("Resource Value must be set!"); |
---|
1246 | return false; |
---|
1247 | } |
---|
1248 | else { |
---|
1249 | this.hideError(); |
---|
1250 | return true; |
---|
1251 | } |
---|
1252 | }, |
---|
1253 | "isUsed" : function(){ |
---|
1254 | return !this.__disabled__; |
---|
1255 | }, |
---|
1256 | "disable" : function(){ |
---|
1257 | this.hideError(); |
---|
1258 | this.__itemIdentity__.disable(); |
---|
1259 | // TODO: scope |
---|
1260 | this.__value__.writeAttribute({"readonly" : "readonly"}); |
---|
1261 | this.__datatype__.__frames__[0].disable(); |
---|
1262 | this.hideRemoveButton(); |
---|
1263 | this.hideAddButton(); |
---|
1264 | this.getFrame().writeAttribute({"class" : CLASSES.disabled()}); |
---|
1265 | this.__disabled__ = true; |
---|
1266 | }, |
---|
1267 | "enable" : function(){ |
---|
1268 | this.getFrame().select("tr." + CLASSES.showHiddenRows())[0].hide(); |
---|
1269 | this.__itemIdentity__.enable(); |
---|
1270 | // TODO: scope |
---|
1271 | this.__value__.removeAttribute("readonly") |
---|
1272 | this.__datatype__.__frames__[0].enable(); |
---|
1273 | if(this.__owner__.__frames__.length > 1) this.showRemoveButton(); |
---|
1274 | this.showAddButton(); |
---|
1275 | this.getFrame().removeAttribute("style"); |
---|
1276 | this.getFrame().writeAttribute({"class" : CLASSES.variantFrame()}); |
---|
1277 | this.__disabled__ = false; |
---|
1278 | }, |
---|
1279 | "minimize" : function(){ |
---|
1280 | if(this.__isMinimized__ === false) { |
---|
1281 | this.getFrame().select("tr." + CLASSES.showHiddenRows())[0].show(); |
---|
1282 | this.getFrame().select("tr." + CLASSES.itemIdentityFrame())[0].hide(); |
---|
1283 | this.getFrame().select("tr." + CLASSES.scopeContainer())[0].hide(); |
---|
1284 | this.getFrame().select("tr." + CLASSES.valueFrame())[0].hide(); |
---|
1285 | this.getFrame().select("tr." + CLASSES.datatypeFrame())[0].hide(); |
---|
1286 | this.__isMinimized__ = true; |
---|
1287 | } |
---|
1288 | else { |
---|
1289 | this.getFrame().select("tr." + CLASSES.showHiddenRows())[0].hide(); |
---|
1290 | this.getFrame().select("tr." + CLASSES.itemIdentityFrame())[0].show(); |
---|
1291 | this.getFrame().select("tr." + CLASSES.scopeContainer())[0].show(); |
---|
1292 | this.getFrame().select("tr." + CLASSES.valueFrame())[0].show(); |
---|
1293 | this.getFrame().select("tr." + CLASSES.datatypeFrame())[0].show(); |
---|
1294 | this.__isMinimized__ = false; |
---|
1295 | } |
---|
1296 | }}); |
---|
1297 | |
---|
1298 | |
---|
1299 | // --- contains all variants of a name element |
---|
1300 | var VariantContainerC = Class.create(ContainerC, {"initialize" : function($super, contents, parent){ |
---|
1301 | $super(); |
---|
1302 | this.__frame__.writeAttribute({"class" : CLASSES.variantContainer()}); |
---|
1303 | this.__container__ = new Object(); |
---|
1304 | |
---|
1305 | if(contents && contents.length != 0){ |
---|
1306 | for(var i = 0; i != contents.length; ++i){ |
---|
1307 | var variant = new VariantC(contents[i], this.__container__, dblClickHandlerF, parent); |
---|
1308 | this.__frame__.insert({"bottom" : variant.getFrame()}); |
---|
1309 | variant.minimize(); |
---|
1310 | } |
---|
1311 | } |
---|
1312 | else { |
---|
1313 | var variant = new VariantC(null, this.__container__, dblClickHandlerF, parent); |
---|
1314 | this.__frame__.insert({"bottom" : variant.getFrame()}); |
---|
1315 | variant.minimize(); |
---|
1316 | variant.disable(); |
---|
1317 | } |
---|
1318 | }, |
---|
1319 | "getContent" : function(){ |
---|
1320 | var values = new Array(); |
---|
1321 | for(var i = 0; i != this.__container__.__frames__.length; ++i){ |
---|
1322 | if(this.__container__.__frames__[i].isUsed() === true && this.__container__.__frames__[i].isEmpty() === false){ |
---|
1323 | values.push(this.__container__.__frames__[i].getContent()); |
---|
1324 | } |
---|
1325 | } |
---|
1326 | return values; |
---|
1327 | }, |
---|
1328 | "isValid" : function(){ |
---|
1329 | var ret = true; |
---|
1330 | for(var i = 0; i != this.__container__.__frames__.length; ++i){ |
---|
1331 | if(this.__container__.__frames__[i].isUsed() === true && |
---|
1332 | this.__container__.__frames__[i].isValid() === false) ret = false;; |
---|
1333 | } |
---|
1334 | return ret; |
---|
1335 | }, |
---|
1336 | "toJSON" : function(){ |
---|
1337 | var str = "["; |
---|
1338 | for(var i = 0; i != this.__container__.__frames__.length; ++i){ |
---|
1339 | if(this.__container__.__frames__[i].isUsed() === true && this.__container__.__frames__[i].isEmpty() === false){ |
---|
1340 | str += this.__container__.__frames__[i].toJSON() + ","; |
---|
1341 | } |
---|
1342 | } |
---|
1343 | str = str.substring(0, str.length - 1) + "]" |
---|
1344 | return str === "]" ? null : str; |
---|
1345 | }, |
---|
1346 | "isUsed" : function(){ |
---|
1347 | return !this.__disabled__; |
---|
1348 | }, |
---|
1349 | "disable" : function(){ |
---|
1350 | this.hideError(); |
---|
1351 | if(this.__container__.__frames__){ |
---|
1352 | for(var i = 0; i !== this.__container__.__frames__.length; ++i) |
---|
1353 | this.__container__.__frames__[i].disable(); |
---|
1354 | } |
---|
1355 | this.__disabled__ = true; |
---|
1356 | }, |
---|
1357 | "enable" : function(){ |
---|
1358 | if(this.__container__.__frames__){ |
---|
1359 | for(var i = 0; i !== this.__container__.__frames__.length; ++i) |
---|
1360 | this.__container__.__frames__[i].enable(); |
---|
1361 | } |
---|
1362 | this.__disabled__ = false; |
---|
1363 | }}); |
---|
1364 | |
---|
1365 | |
---|
1366 | // --- representation of a name element |
---|
1367 | var NameC = Class.create(ContainerC, {"initialize" : function($super, contents, nametypescopes, simpleConstraint, owner, min, max, dblClickHandler){ |
---|
1368 | $super(); |
---|
1369 | if(!owner) throw "From NameC(): owner must be set but is null"; |
---|
1370 | if(max !== -1 && (min > max || max === 0))throw "From FrameC(): min must be > max(" + max + ") and > 0 but is " + min; |
---|
1371 | if(!owner.__frames__) owner.__frames__ = new Array(); |
---|
1372 | owner.__frames__.push(this); |
---|
1373 | |
---|
1374 | this.__frame__.writeAttribute({"class" : CLASSES.nameFrame()}); |
---|
1375 | this.__table__ = new Element("table", {"class" : CLASSES.nameFrame()}); |
---|
1376 | this.__frame__.insert({"top" : this.__table__}); |
---|
1377 | this.__max__ = max; |
---|
1378 | this.__owner__ = owner; |
---|
1379 | this.__dblClickHandler__ = dblClickHandler; |
---|
1380 | this.__constraint__ = simpleConstraint; |
---|
1381 | this.__isMinimized__ = false; |
---|
1382 | |
---|
1383 | try{ |
---|
1384 | var itemIdentityContent = null; |
---|
1385 | var typeContent = null; |
---|
1386 | var scopesContent = null; |
---|
1387 | var valueContent = ""; |
---|
1388 | var variantsContent = null; |
---|
1389 | if(contents){ |
---|
1390 | itemIdentityContent = contents.itemIdentities; |
---|
1391 | typeContent = contents.type; |
---|
1392 | scopesContent = contents.scopes; |
---|
1393 | valueContent = contents.value; |
---|
1394 | variantsContent = contents.variants; |
---|
1395 | } |
---|
1396 | |
---|
1397 | // --- control row + ItemIdentity |
---|
1398 | makeControlRow(this, 5, itemIdentityContent); |
---|
1399 | checkRemoveAddButtons(owner, min, max, this); |
---|
1400 | setRemoveAddHandler(this, this.__constraint__, owner, min, max, function(){ |
---|
1401 | return new NameC(null, nametypescopes, simpleConstraint, owner, min, max, dblClickHandler); |
---|
1402 | }); |
---|
1403 | |
---|
1404 | // --- type |
---|
1405 | var types = makeTypes(this, typeContent, nametypescopes); |
---|
1406 | |
---|
1407 | // --- scopes |
---|
1408 | this.__scope__ = new ScopeContainerC(scopesContent, nametypescopes && nametypescopes[0].scopeConstraints ? nametypescopes[0].scopeConstraints : null); |
---|
1409 | this.__table__.insert({"bottom" : newRow(CLASSES.scopeContainer(), "Scope", this.__scope__.getFrame())}); |
---|
1410 | onTypeChangeScope(this, contents ? contents.scopes : null, nametypescopes, "name"); |
---|
1411 | |
---|
1412 | // --- value |
---|
1413 | var noConstraint = false; |
---|
1414 | if(!simpleConstraint){ |
---|
1415 | simpleConstraint = {"regexp" : ".*", "cardMin" : 0, "cardMax" : MAX_INT}; |
---|
1416 | noConstraint = true; |
---|
1417 | } |
---|
1418 | this.__value__ = new Object(); |
---|
1419 | var _min = parseInt(simpleConstraint.cardMin); |
---|
1420 | var _max = simpleConstraint.cardMax !== MAX_INT ? parseInt(simpleConstraint.cardMax) : MMAX_INT; |
---|
1421 | var cssTitle = "No constraint found for this name"; |
---|
1422 | if(noConstraint === false){ |
---|
1423 | cssTitle = "min: " + _min + " max: " + _max + " regular expression: " + (simpleConstraint ? simpleConstraint.regexp : ".*"); |
---|
1424 | } |
---|
1425 | this.__cssTitle__ = cssTitle; |
---|
1426 | new TextrowC(valueContent, (simpleConstraint ? simpleConstraint.regexp : ".*"), this.__value__, 1, 1, cssTitle); |
---|
1427 | this.__table__.insert({"bottom" : newRow(CLASSES.valueFrame(), "Value", this.__value__.__frames__[0].getFrame())}); |
---|
1428 | |
---|
1429 | // --- variants |
---|
1430 | this.__variants__ = new VariantContainerC(variantsContent, this); |
---|
1431 | this.__table__.insert({"bottom" : newRow(CLASSES.variantContainer(), "Variants", this.__variants__.getFrame())}); |
---|
1432 | |
---|
1433 | // --- adds a second show handler, so the variants will be hidden, when the entire |
---|
1434 | // --- name element will be shown |
---|
1435 | function addSecondShowHandler(myself){ |
---|
1436 | myself.__table__.select("tr")[0].observe("click", function(event){ |
---|
1437 | for(var i = 0; i != myself.__variants__.__container__.__frames__.length; ++i){ |
---|
1438 | myself.__variants__.__container__.__frames__[i].minimize(); |
---|
1439 | } |
---|
1440 | }); |
---|
1441 | } |
---|
1442 | |
---|
1443 | addSecondShowHandler(this); |
---|
1444 | |
---|
1445 | if(dblClickHandler){ |
---|
1446 | this.getFrame().observe("dblclick", function(event){ |
---|
1447 | dblClickHandler(owner, event); |
---|
1448 | }); |
---|
1449 | } |
---|
1450 | } |
---|
1451 | catch(err){ |
---|
1452 | alert("From NameC(): " + err); |
---|
1453 | } |
---|
1454 | }, |
---|
1455 | "isEmpty" : function(){ |
---|
1456 | return this.__value__.__frames__[0].getContent().length === 0; |
---|
1457 | }, |
---|
1458 | "getContent" : function(){ |
---|
1459 | if(this.isUsed() === false) return null; |
---|
1460 | var type = this.__type__.__frames__[0].getContent(); |
---|
1461 | return {"itemIdentities" : this.__itemIdentity__.getContent(true, true), |
---|
1462 | "type" : type ? new Array(type) : null, |
---|
1463 | "scopes" : this.__scope__.getContent(), |
---|
1464 | "value" : this.__value__.__frames__[0].getContent(), |
---|
1465 | "variants" : this.__variants__.getContent()}; |
---|
1466 | }, |
---|
1467 | "toJSON" : function(){ |
---|
1468 | if(this.isUsed() === false) return "null"; |
---|
1469 | return "{\"itemIdentities\":" + this.__itemIdentity__.toJSON(true, true) + |
---|
1470 | ",\"type\":[" + this.__type__.__frames__[0].toJSON() + |
---|
1471 | "],\"scopes\":" + this.__scope__.toJSON() + |
---|
1472 | ",\"value\":" + this.__value__.__frames__[0].toJSON() + |
---|
1473 | ",\"variants\":" + this.__variants__.toJSON() + "}"; |
---|
1474 | }, |
---|
1475 | "isValid" : function(){ |
---|
1476 | var valueValid = this.__value__.__frames__[0].isValid(); |
---|
1477 | if(valueValid === false) this.showError("The name-value \"" + this.__value__.__frames__[0].getContent() + "\" doesn't matches the constraint \"" + this.__value__.__frames__[0].getRegexp() + "\"!"); |
---|
1478 | else this.hideError(); |
---|
1479 | var variantsValid = this.__variants__.isValid(); |
---|
1480 | var scopeValid = this.scopeIsValid(); |
---|
1481 | return valueValid && variantsValid && scopeValid; |
---|
1482 | }, |
---|
1483 | "scopeIsValid" : function(){ |
---|
1484 | return this.__scope__.isValid(); |
---|
1485 | }, |
---|
1486 | "minimize" : function(){ |
---|
1487 | if(this.__isMinimized__ === false){ |
---|
1488 | this.getFrame().select("tr." + CLASSES.showHiddenRows())[0].show(); |
---|
1489 | this.getFrame().select("tr." + CLASSES.itemIdentityFrame())[0].hide(); |
---|
1490 | this.getFrame().select("tr." + CLASSES.typeFrame())[0].hide(); |
---|
1491 | this.getFrame().select("tr." + CLASSES.scopeContainer())[0].hide(); |
---|
1492 | this.getFrame().select("tr." + CLASSES.valueFrame())[0].hide(); |
---|
1493 | this.getFrame().select("tr." + CLASSES.variantContainer())[0].hide(); |
---|
1494 | this.__isMinimized__ = true; |
---|
1495 | } |
---|
1496 | else { |
---|
1497 | this.getFrame().select("tr." + CLASSES.showHiddenRows())[0].hide(); |
---|
1498 | this.getFrame().select("tr." + CLASSES.itemIdentityFrame())[0].show(); |
---|
1499 | this.getFrame().select("tr." + CLASSES.typeFrame())[0].show(); |
---|
1500 | this.getFrame().select("tr." + CLASSES.scopeContainer())[0].show(); |
---|
1501 | this.getFrame().select("tr." + CLASSES.valueFrame())[0].show(); |
---|
1502 | this.getFrame().select("tr." + CLASSES.variantContainer())[0].show(); |
---|
1503 | this.__isMinimized__ = false; |
---|
1504 | } |
---|
1505 | }, |
---|
1506 | "disable" : function(){ |
---|
1507 | this.hideError(); |
---|
1508 | this.__itemIdentity__.disable(); |
---|
1509 | this.__type__.__frames__[0].disable(); |
---|
1510 | this.__scope__.disable(); |
---|
1511 | this.__value__.__frames__[0].disable(); |
---|
1512 | this.__variants__.disable(); |
---|
1513 | this.getFrame().writeAttribute({"class" : CLASSES.disabled()}); |
---|
1514 | this.getFrame().writeAttribute({"title" : this.__cssTitle__}); |
---|
1515 | this.hideAddButton(); |
---|
1516 | this.__disabled__ = true; |
---|
1517 | }, |
---|
1518 | "enable" : function(){ |
---|
1519 | this.__itemIdentity__.enable(); |
---|
1520 | this.__type__.__frames__[0].enable(); |
---|
1521 | this.__scope__.enable(); |
---|
1522 | this.__value__.__frames__[0].enable(); |
---|
1523 | this.__variants__.enable(); |
---|
1524 | this.getFrame().writeAttribute({"class" : CLASSES.nameFrame()}); |
---|
1525 | this.getFrame().removeAttribute("title"); |
---|
1526 | checkRemoveAddButtons(this.__owner__, 1, this.__max__, this); |
---|
1527 | this.__disabled__ = false; |
---|
1528 | }}); |
---|
1529 | |
---|
1530 | |
---|
1531 | |
---|
1532 | // --- contains all names of a topic |
---|
1533 | var NameContainerC = Class.create(ContainerC, {"initialize" : function($super, contents, constraints){ |
---|
1534 | $super(); |
---|
1535 | this.__frame__.writeAttribute({"class" : CLASSES.nameContainer()}); |
---|
1536 | this.__containers__ = new Array(); |
---|
1537 | this.__constraints__ = constraints; |
---|
1538 | |
---|
1539 | try{ |
---|
1540 | if(constraints && constraints.length > 0){ |
---|
1541 | var cContents = new Array(); |
---|
1542 | if(contents) cContents = contents.clone(); |
---|
1543 | for(var i = 0; i != constraints.length; ++i){ |
---|
1544 | var simpleConstraints = constraints[i].constraints; |
---|
1545 | |
---|
1546 | var allTypes = new Array(); |
---|
1547 | for(var k = 0; k !== constraints[i].nametypescopes.length; ++k){ |
---|
1548 | allTypes = allTypes.concat(constraints[i].nametypescopes[k].nameType); |
---|
1549 | } |
---|
1550 | allTypes = allTypes.flatten().uniq(); |
---|
1551 | |
---|
1552 | var ret = makeConstraintsAndContents(cContents, simpleConstraints, allTypes); |
---|
1553 | var constraintsAndContents = ret.constraintsAndContents; |
---|
1554 | cContents = ret.contents; |
---|
1555 | |
---|
1556 | // --- creation of the frames with the found contents |
---|
1557 | this.__containers__.push(new Array()); |
---|
1558 | for(var j = 0; j != constraints[i].constraints.length; ++j){ |
---|
1559 | this.__containers__[i].push(new Object()); |
---|
1560 | var min = parseInt(constraints[i].constraints[j].cardMin); |
---|
1561 | var max = constraints[i].constraints[j].cardMax !== MAX_INT ? parseInt(constraints[i].constraints[j].cardMax) : MMAX_INT; |
---|
1562 | var _contents = null; |
---|
1563 | for(var k = 0; k !== constraintsAndContents.length; ++k){ |
---|
1564 | if(constraintsAndContents[k].constraint === constraints[i].constraints[j]){ |
---|
1565 | _contents = constraintsAndContents[k].contents; |
---|
1566 | break; |
---|
1567 | } |
---|
1568 | } |
---|
1569 | var endIdx = (min === 0 ? 1 : min); |
---|
1570 | endIdx = _contents && _contents.length > endIdx ? _contents.length : endIdx; |
---|
1571 | var regexp = constraints[i].constraints[j].regexp; |
---|
1572 | if(max !== 0 || _contents && _contents.length){ |
---|
1573 | var dblClickHandler = null; |
---|
1574 | if(min === 0) dblClickHandler = dblClickHandlerF; |
---|
1575 | for(var k = 0; k !== endIdx; ++k){ |
---|
1576 | var _content = null; |
---|
1577 | if(_contents && _contents.length > k) _content = _contents[k]; |
---|
1578 | var name = new NameC(_content, constraints[i].nametypescopes, constraints[i].constraints[j], this.__containers__[i][j], min === 0 ? 1 : min, max === MMAX_INT ? -1 : max, dblClickHandler); |
---|
1579 | if(min === 0)name.disable(); |
---|
1580 | this.__error__.insert({"before" : name.getFrame()}); |
---|
1581 | if(min === 0)name.minimize(); |
---|
1582 | } |
---|
1583 | } |
---|
1584 | } |
---|
1585 | } |
---|
1586 | // --- inserts not used contents |
---|
1587 | if(cContents.length !== 0){ |
---|
1588 | this.__containers__.push(new Array(new Object())); |
---|
1589 | var owner = this.__containers__[0][0]; |
---|
1590 | var cssTitle = "No constraint found for this name"; |
---|
1591 | for(var i = 0; i !== cContents.length; ++i){ |
---|
1592 | var name = new NameC(cContents[i], null, null, owner, 0, 1, null); |
---|
1593 | this.__error__.insert({"before" : name.getFrame()}); |
---|
1594 | } |
---|
1595 | } |
---|
1596 | } |
---|
1597 | else if(contents && contents.length !== 0){ |
---|
1598 | this.__containers__.push(new Array(new Object())); |
---|
1599 | var owner = this.__containers__[0][0]; |
---|
1600 | var cssTitle = "No constraint found for this name"; |
---|
1601 | for(var i = 0; i !== contents.length; ++i){ |
---|
1602 | var name = new NameC(contents[i], null, null, owner, 0, 1, null); |
---|
1603 | this.__error__.insert({"before" : name.getFrame()}); |
---|
1604 | } |
---|
1605 | } |
---|
1606 | } |
---|
1607 | catch(err){ |
---|
1608 | alert("From NameContainerC(): " + err); |
---|
1609 | } |
---|
1610 | }, |
---|
1611 | "getContent" : function(){ |
---|
1612 | var values = new Array(); |
---|
1613 | try{ |
---|
1614 | for(var i = 0; i != this.__containers__.length; ++i){ |
---|
1615 | for(var j = 0; j != this.__containers__[i].length; ++j){ |
---|
1616 | for(var k = 0; k != this.__containers__[i][j].__frames__.length; ++k){ |
---|
1617 | if(this.__containers__[i][j].__frames__[k].isUsed() === true && this.__containers__[i][j].__frames__[k].isEmpty() === false){ |
---|
1618 | values.push(this.__containers__[i][j].__frames__[k].getContent()); |
---|
1619 | } |
---|
1620 | } |
---|
1621 | } |
---|
1622 | } |
---|
1623 | return values; |
---|
1624 | } |
---|
1625 | catch(err){ |
---|
1626 | return values; |
---|
1627 | } |
---|
1628 | }, |
---|
1629 | "toJSON" : function(){ |
---|
1630 | try{ |
---|
1631 | var str = "["; |
---|
1632 | for(var i = 0; i != this.__containers__.length; ++i){ |
---|
1633 | for(var j = 0; j != this.__containers__[i].length; ++j){ |
---|
1634 | for(var k = 0; k != this.__containers__[i][j].__frames__.length; ++k){ |
---|
1635 | if(this.__containers__[i][j].__frames__[k].isUsed() === true && this.__containers__[i][j].__frames__[k].isEmpty() === false){ |
---|
1636 | str += this.__containers__[i][j].__frames__[k].toJSON() + ","; |
---|
1637 | } |
---|
1638 | } |
---|
1639 | } |
---|
1640 | } |
---|
1641 | if(str.endsWith(",")) str = str.slice(0, str.length - 1); |
---|
1642 | str += "]"; |
---|
1643 | return str === "[]" ? null : str; |
---|
1644 | } |
---|
1645 | catch(err){ |
---|
1646 | return "null"; |
---|
1647 | } |
---|
1648 | }, |
---|
1649 | "isValid" : function(){ |
---|
1650 | var ret = true; |
---|
1651 | var errorStr = ""; |
---|
1652 | |
---|
1653 | // --- checks if there are any constraints |
---|
1654 | if((!this.__constraints__ || this.__constraints__.length === 0) && this.__containers__.length !== 0){ |
---|
1655 | var nameTypes = new Array(); |
---|
1656 | for(var i = 0; i !== this.__containers__.length; ++i){ |
---|
1657 | for(var j = 0; j !== this.__containers__[i].length; ++j){ |
---|
1658 | for(var k = 0; k !== this.__containers__[i][j].__frames__.length; ++k){ |
---|
1659 | this.__containers__[i][j].__frames__[k].hideError(); |
---|
1660 | if(this.__containers__[i][j].__frames__[k].isUsed() === true){ |
---|
1661 | this.__containers__[i][j].__frames__[k].showError("No constraints found for this name!"); |
---|
1662 | } |
---|
1663 | } |
---|
1664 | } |
---|
1665 | } |
---|
1666 | return false; |
---|
1667 | } |
---|
1668 | else if(!this.__constraints__ || this.__constraints__.length === 0) return true; |
---|
1669 | |
---|
1670 | // --- summarizes all names |
---|
1671 | var allNames = new Array(); |
---|
1672 | for(var i = 0; i !== this.__containers__.length; ++i){ |
---|
1673 | for(var j = 0; j !== this.__containers__[i].length; ++j){ |
---|
1674 | for(var k = 0; k !== this.__containers__[i][j].__frames__.length; ++k){ |
---|
1675 | this.__containers__[i][j].__frames__[k].hideError(); |
---|
1676 | if(this.__containers__[i][j].__frames__[k].scopeIsValid() === false) ret = false; |
---|
1677 | if(this.__containers__[i][j].__frames__[k].isUsed() === true && this.__containers__[i][j].__frames__[k].isEmpty() === false){ |
---|
1678 | allNames.push(this.__containers__[i][j].__frames__[k]); |
---|
1679 | } |
---|
1680 | } |
---|
1681 | } |
---|
1682 | } |
---|
1683 | |
---|
1684 | // --- checks every constraint and the existing names corresponding to the constraint |
---|
1685 | for(var i = 0; i !== this.__constraints__.length; ++i){ |
---|
1686 | var currentConstraintTypes = new Array(); |
---|
1687 | for(var j = 0; j !== this.__constraints__[i].nametypescopes.length; ++j){ |
---|
1688 | currentConstraintTypes = currentConstraintTypes.concat(this.__constraints__[i].nametypescopes[j].nameType); |
---|
1689 | } |
---|
1690 | currentConstraintTypes = currentConstraintTypes.uniq(); |
---|
1691 | |
---|
1692 | // --- collects all names to the current constraint |
---|
1693 | var currentNames = new Array(); |
---|
1694 | for(var j = 0; j !== allNames.length; ++j){ |
---|
1695 | var type = allNames[j].getContent().type; |
---|
1696 | if(type && currentConstraintTypes.indexOf(type[0]) !== -1) currentNames.push(allNames[j]); |
---|
1697 | |
---|
1698 | } |
---|
1699 | // --- removes all current found names from "allNames" |
---|
1700 | for(var j = 0; j !== currentNames.length; ++j) allNames = allNames.without(currentNames[j]); |
---|
1701 | // --- removes empty names (for constraints that have a subset of regexp) |
---|
1702 | |
---|
1703 | // --- checks the regExp, card-min and card-max for the found types |
---|
1704 | var satisfiedNames = new Array(); |
---|
1705 | for(var j = 0; j !== this.__constraints__[i].constraints.length; ++j){ |
---|
1706 | var regexp = new RegExp(this.__constraints__[i].constraints[j].regexp); |
---|
1707 | var cardMin = parseInt(this.__constraints__[i].constraints[j].cardMin); |
---|
1708 | var cardMax = this.__constraints__[i].constraints[j].cardMax === MAX_INT ? MMAX_INT : parseInt(this.__constraints__[i].constraints[j].cardMax); |
---|
1709 | var matchedNames = 0; |
---|
1710 | for(var k = 0; k !== currentNames.length; ++k){ |
---|
1711 | if(regexp.match(currentNames[k].getContent().value) === true){ |
---|
1712 | ++matchedNames; |
---|
1713 | satisfiedNames.push(currentNames[k]); |
---|
1714 | } |
---|
1715 | } |
---|
1716 | if(matchedNames < cardMin){ |
---|
1717 | ret = false; |
---|
1718 | if(errorStr.length !== 0) errorStr += "<br/><br/>"; |
---|
1719 | errorStr += "card-min of the constraint regexp: \"" + this.__constraints__[i].constraints[j].regexp + "\" card-min: " + cardMin + " card-max: " + cardMax + " for the nametype \"" + currentConstraintTypes + " is not satisfied (" + matchedNames + ")!"; |
---|
1720 | } |
---|
1721 | if(cardMax !== MMAX_INT && matchedNames > cardMax){ |
---|
1722 | ret = false; |
---|
1723 | if(errorStr.length !== 0) errorStr += "<br/><br/>"; |
---|
1724 | errorStr += "card-max of the constraint regexp: \"" + this.__constraints__[i].constraints[j].regexp + "\" card-min: " + cardMin + " card-max: " + cardMax + " for the nametype \"" + currentConstraintTypes + " is not satisfied (" + matchedNames + ")!"; |
---|
1725 | } |
---|
1726 | } |
---|
1727 | |
---|
1728 | // --- checks if there are names which wasn't checked --> bad value |
---|
1729 | satisfiedNames = satisfiedNames.uniq(); |
---|
1730 | for(var j = 0; j !== satisfiedNames.length; ++j)currentNames = currentNames.without(satisfiedNames[j]); |
---|
1731 | if(currentNames.length !== 0){ |
---|
1732 | ret = false; |
---|
1733 | for(var j = 0; j !== currentNames.length; ++j) |
---|
1734 | currentNames[j].showError("This name does not satisfie any constraint!"); |
---|
1735 | } |
---|
1736 | } |
---|
1737 | |
---|
1738 | // --- all names are valid -> hide the error-div-element |
---|
1739 | if(ret === true) this.hideError(); |
---|
1740 | else this.showError(errorStr); |
---|
1741 | return ret; |
---|
1742 | }}); |
---|
1743 | |
---|
1744 | |
---|
1745 | // --- represenation of an occurrence element |
---|
1746 | var OccurrenceC = Class.create(ContainerC, {"initialize" : function($super, contents, occurrenceTypes, constraint, uniqueConstraints, owner, min, max, cssTitle, dblClickHandler){ |
---|
1747 | $super(); |
---|
1748 | if(!owner.__frames__) owner.__frames__ = new Array(); |
---|
1749 | owner.__frames__.push(this); |
---|
1750 | this.__frame__.writeAttribute({"class" : CLASSES.occurrenceFrame()}); |
---|
1751 | this.__table__ = new Element("table", {"class" : CLASSES.occurrenceFrame()}); |
---|
1752 | this.__frame__.insert({"top" : this.__table__}); |
---|
1753 | this.__max__ = max; |
---|
1754 | this.__constraint__ = constraint; |
---|
1755 | this.__owner__ = owner; |
---|
1756 | this.__dblClickHandler__ = dblClickHandler; |
---|
1757 | this.__isMinimized__ = false; |
---|
1758 | |
---|
1759 | try{ |
---|
1760 | var itemIdentityContent = null; |
---|
1761 | var typeContent = null; |
---|
1762 | var scopesContent = null; |
---|
1763 | if(contents){ |
---|
1764 | itemIdentityContent = contents.itemIdentities; |
---|
1765 | typeContent = contents.type; |
---|
1766 | scopesContent = contents.scopes; |
---|
1767 | } |
---|
1768 | |
---|
1769 | // --- control row + itemIdentity |
---|
1770 | makeControlRow(this, 5, itemIdentityContent); |
---|
1771 | checkRemoveAddButtons(owner, 1, max, this); |
---|
1772 | setRemoveAddHandler(this, this.__constraint__, owner, 1, max, function(){ |
---|
1773 | return new OccurrenceC(null, occurrenceTypes, constraint, uniqueConstraints, owner, min, max, cssTitle, dblClickHandler); |
---|
1774 | }); |
---|
1775 | |
---|
1776 | // --- type |
---|
1777 | var types = makeTypes(this, typeContent, occurrenceTypes); |
---|
1778 | |
---|
1779 | // --- scopes |
---|
1780 | var scopes = null; |
---|
1781 | if(contents){ |
---|
1782 | if(typeContent){ |
---|
1783 | for(var i = 0; occurrenceTypes && i !== occurrenceTypes.length; ++i){ |
---|
1784 | if(scopes) break; |
---|
1785 | for(var j = 0; j !== occurrenceTypes[i].occurrenceType.length; ++j){ |
---|
1786 | if(typeContent.indexOf(occurrenceTypes[i].occurrenceType[j]) !== -1){ |
---|
1787 | scopes = occurrenceTypes[i].scopeConstraints; |
---|
1788 | break; |
---|
1789 | } |
---|
1790 | } |
---|
1791 | } |
---|
1792 | } |
---|
1793 | } |
---|
1794 | else if(occurrenceTypes && occurrenceTypes[0].scopeConstraints){ |
---|
1795 | scopes = occurrenceTypes[0].scopeConstraints; |
---|
1796 | } |
---|
1797 | this.__scope__ = new ScopeContainerC(scopesContent, scopes); |
---|
1798 | this.__table__.insert({"bottom" : newRow(CLASSES.scopeContainer(), "Scope", this.__scope__.getFrame())}); |
---|
1799 | onTypeChangeScope(this, contents && contents.scopes ? contents.scopes : null, occurrenceTypes, "occurrence"); |
---|
1800 | |
---|
1801 | // --- resource value and datatype |
---|
1802 | var noConstraint = false; |
---|
1803 | if(!constraint){ |
---|
1804 | constraint = {"regexp" : ".*", "cardMin" : 0, "cardMax" : MAX_INT}; |
---|
1805 | noConstraint = true; |
---|
1806 | } |
---|
1807 | var _min = parseInt(constraint.cardMin); |
---|
1808 | var _max = constraint.cardMax !== MAX_INT ? parseInt(constraint.cardMax) : MMAX_INT; |
---|
1809 | var cssTitle = "No constraint found for this occurrence"; |
---|
1810 | if(noConstraint === false) cssTitle = "min: " + _min + " max: " + _max + " regular expression: " + constraint.regexp; |
---|
1811 | this.__cssTitle__ = cssTitle; |
---|
1812 | |
---|
1813 | var dataType = null; |
---|
1814 | if(types && types.length !== 0){ |
---|
1815 | for(var i = 0; occurrenceTypes && i !== occurrenceTypes.length; ++i){ |
---|
1816 | if(occurrenceTypes[i].occurrenceType.indexOf(types[0]) !== -1){ |
---|
1817 | dataType = occurrenceTypes[i].datatypeConstraint; |
---|
1818 | break; |
---|
1819 | } |
---|
1820 | } |
---|
1821 | } |
---|
1822 | makeResource(this, contents, constraint, dataType, cssTitle, {"rows" : 5, "cols" : 70}); |
---|
1823 | |
---|
1824 | if(dblClickHandler){ |
---|
1825 | this.getFrame().observe("dblclick", function(event){ |
---|
1826 | dblClickHandler(owner, event); |
---|
1827 | }); |
---|
1828 | } |
---|
1829 | } |
---|
1830 | catch(err){ |
---|
1831 | alert("From OccurrenceC(): " + err); |
---|
1832 | } |
---|
1833 | }, |
---|
1834 | "getContent" : function(){ |
---|
1835 | if(this.isUsed() === true){ |
---|
1836 | var resourceRef = null; |
---|
1837 | var resourceData = null; |
---|
1838 | if(this.__datatype__.__frames__[0].getContent() === ANY_URI){ |
---|
1839 | resourceRef = this.__value__.value; |
---|
1840 | } |
---|
1841 | else { |
---|
1842 | resourceData = {"datatype" : this.__datatype__.__frames__[0].getContent(), |
---|
1843 | "value" : this.__value__.value}; |
---|
1844 | } |
---|
1845 | return {"itemIdentities" : this.__itemIdentity__.getContent(true, true), |
---|
1846 | "type" : new Array(this.__type__.__frames__[0].getContent()), |
---|
1847 | "scopes" : this.__scope__.getContent(), |
---|
1848 | "resourceRef" : resourceRef, |
---|
1849 | "resourceData" : resourceData}; |
---|
1850 | } |
---|
1851 | else { |
---|
1852 | return null; |
---|
1853 | } |
---|
1854 | }, |
---|
1855 | "toJSON" : function(){ |
---|
1856 | if(this.isUsed() === true){ |
---|
1857 | var resourceRef = "null"; |
---|
1858 | var resourceData = "null"; |
---|
1859 | if(this.__datatype__.__frames__[0].getContent() === ANY_URI){ |
---|
1860 | resourceRef = this.__value__.value.toJSON(); |
---|
1861 | } |
---|
1862 | else { |
---|
1863 | resourceData = "{\"datatype\":" + this.__datatype__.__frames__[0].toJSON() + |
---|
1864 | ",\"value\":" + this.__value__.value.toJSON() + "}"; |
---|
1865 | } |
---|
1866 | return "{\"itemIdentities\":" + this.__itemIdentity__.toJSON(true, true) + |
---|
1867 | ",\"type\":[" + this.__type__.__frames__[0].toJSON() + |
---|
1868 | "],\"scopes\":" + this.__scope__.toJSON() + |
---|
1869 | ",\"resourceRef\":" + resourceRef + |
---|
1870 | ",\"resourceData\":" + resourceData + "}"; |
---|
1871 | } |
---|
1872 | else { |
---|
1873 | return "null"; |
---|
1874 | } |
---|
1875 | }, |
---|
1876 | "isEmpty" : function(){ |
---|
1877 | return this.__value__.value.length === 0; |
---|
1878 | }, |
---|
1879 | "isValid" : function(){ |
---|
1880 | var regexp = new RegExp(this.__constraint__.regexp); |
---|
1881 | // TODO: validate the data via the given datatype |
---|
1882 | // TODO: validate the uniqeuoccurrence-constraint |
---|
1883 | var scopeValid = this.scopeIsValid(); |
---|
1884 | return regexp.match(this.__value__.value) && scopeValid; |
---|
1885 | }, |
---|
1886 | "scopeIsValid" : function(){ |
---|
1887 | return this.__scope__.isValid(); |
---|
1888 | }, |
---|
1889 | "minimize" : function(){ |
---|
1890 | if(this.__isMinimized__ === false){ |
---|
1891 | this.getFrame().select("tr." + CLASSES.showHiddenRows())[0].show(); |
---|
1892 | this.getFrame().select("tr." + CLASSES.itemIdentityFrame())[0].hide(); |
---|
1893 | this.getFrame().select("tr." + CLASSES.typeFrame())[0].hide(); |
---|
1894 | this.getFrame().select("tr." + CLASSES.scopeContainer())[0].hide(); |
---|
1895 | this.getFrame().select("tr." + CLASSES.valueFrame())[0].hide(); |
---|
1896 | this.getFrame().select("tr." + CLASSES.datatypeFrame())[0].hide(); |
---|
1897 | this.__isMinimized__ = true; |
---|
1898 | } |
---|
1899 | else { |
---|
1900 | this.getFrame().select("tr." + CLASSES.showHiddenRows())[0].hide(); |
---|
1901 | this.getFrame().select("tr." + CLASSES.itemIdentityFrame())[0].show(); |
---|
1902 | this.getFrame().select("tr." + CLASSES.typeFrame())[0].show(); |
---|
1903 | this.getFrame().select("tr." + CLASSES.scopeContainer())[0].show(); |
---|
1904 | this.getFrame().select("tr." + CLASSES.valueFrame())[0].show(); |
---|
1905 | this.getFrame().select("tr." + CLASSES.datatypeFrame())[0].show(); |
---|
1906 | this.__isMinimized__ = false; |
---|
1907 | } |
---|
1908 | }, |
---|
1909 | "disable" : function(){ |
---|
1910 | this.hideError(); |
---|
1911 | this.__itemIdentity__.disable(); |
---|
1912 | this.__type__.__frames__[0].disable(); |
---|
1913 | this.__scope__.disable(); |
---|
1914 | this.__value__.writeAttribute({"readonly" : "readonly"}); |
---|
1915 | this.__datatype__.__frames__[0].disable(); |
---|
1916 | this.getFrame().writeAttribute({"class" : CLASSES.disabled()}); |
---|
1917 | this.getFrame().writeAttribute({"title" : this.__cssTitle__}); |
---|
1918 | this.hideAddButton(); |
---|
1919 | this.__disabled__ = true; |
---|
1920 | }, |
---|
1921 | "enable" : function(){ |
---|
1922 | this.__itemIdentity__.enable(); |
---|
1923 | this.__type__.__frames__[0].enable(); |
---|
1924 | this.__scope__.enable(); |
---|
1925 | this.__value__.removeAttribute("readonly"); |
---|
1926 | if(this.__datatypeIsSet__ === false) this.__datatype__.__frames__[0].enable(); |
---|
1927 | this.getFrame().writeAttribute({"class" : CLASSES.occurrenceFrame()}); |
---|
1928 | this.getFrame().removeAttribute("style"); |
---|
1929 | this.getFrame().removeAttribute("title"); |
---|
1930 | checkRemoveAddButtons(this.__owner__, 1, this.__max__, this); |
---|
1931 | this.__disabled__ = false; |
---|
1932 | }}); |
---|
1933 | |
---|
1934 | |
---|
1935 | // --- contains all occurrences of an topic element |
---|
1936 | var OccurrenceContainerC = Class.create(ContainerC, {"initialize" : function($super, contents, constraints){ |
---|
1937 | $super(); |
---|
1938 | this.__containers__ = new Array(); |
---|
1939 | this.__frame__.writeAttribute({"class" : CLASSES.occurrenceContainer()}); |
---|
1940 | this.__constraints__ = constraints; |
---|
1941 | |
---|
1942 | try{ |
---|
1943 | if(constraints && constraints.length > 0){ |
---|
1944 | var cContents = new Array(); |
---|
1945 | if(contents) cContents = contents.clone(); |
---|
1946 | |
---|
1947 | for(var i = 0; i != constraints.length; ++i){ |
---|
1948 | var simpleConstraints = constraints[i].constraints; |
---|
1949 | |
---|
1950 | var allTypes = new Array(); |
---|
1951 | for(var k = 0; k !== constraints[i].occurrenceTypes.length; ++k){ |
---|
1952 | allTypes = allTypes.concat(constraints[i].occurrenceTypes[k].occurrenceType); |
---|
1953 | } |
---|
1954 | allTypes = allTypes.flatten().uniq(); |
---|
1955 | |
---|
1956 | var ret = makeConstraintsAndContents(cContents, simpleConstraints, allTypes); |
---|
1957 | var constraintsAndContents = ret.constraintsAndContents; |
---|
1958 | cContents = ret.contents; |
---|
1959 | |
---|
1960 | var _c_ = ""; |
---|
1961 | for(var j = 0; j !== constraintsAndContents.length; ++j){ |
---|
1962 | for(var k = 0; k !== constraintsAndContents[j].contents.length; ++k){ |
---|
1963 | var val = constraintsAndContents[j].contents[k].resourceRef; |
---|
1964 | if(!val){ |
---|
1965 | if(constraintsAndContents[j].contents[k].resourceData) |
---|
1966 | val = constraintsAndContents[j].contents[k].resourceData.value; |
---|
1967 | } |
---|
1968 | _c_ += val + "\n"; |
---|
1969 | } |
---|
1970 | } |
---|
1971 | |
---|
1972 | this.__containers__.push(new Array()); |
---|
1973 | for(var j = 0; j != constraints[i].constraints.length; ++j){ |
---|
1974 | this.__containers__[i].push(new Object()); |
---|
1975 | var min = parseInt(constraints[i].constraints[j].cardMin); |
---|
1976 | var max = constraints[i].constraints[j].cardMax !== MAX_INT ? parseInt(constraints[i].constraints[j].cardMax) : MMAX_INT; |
---|
1977 | var _contents = null; |
---|
1978 | for(var k = 0; k !== constraintsAndContents.length; ++k){ |
---|
1979 | if(constraintsAndContents[k].constraint === constraints[i].constraints[j]){ |
---|
1980 | _contents = constraintsAndContents[k].contents; |
---|
1981 | break; |
---|
1982 | } |
---|
1983 | } |
---|
1984 | var endIdx = (min === 0 ? 1 : min); |
---|
1985 | endIdx = _contents && _contents.length > endIdx ? _contents.length : endIdx; |
---|
1986 | var regexp = constraints[i].constraints[j].regexp; |
---|
1987 | if(max !== 0 || (_contents && contents.length)){ |
---|
1988 | var dblClickHandler = null; |
---|
1989 | if(min === 0) dblClickHandler = dblClickHandlerF; |
---|
1990 | var title = "min: " + min + " max: " + max + " regular expression: " + regexp; |
---|
1991 | for(var k = 0; k !== endIdx; ++k){ |
---|
1992 | var _content = null; |
---|
1993 | if(_contents && _contents.length > k) _content = _contents[k]; |
---|
1994 | var occurrence = new OccurrenceC(_content, constraints[i].occurrenceTypes, constraints[i].constraints[j], constraints[i].uniqueConstraints, this.__containers__[i][j], min === 0 ? 1 : min, max === MMAX_INT ? -1 : max, title, dblClickHandler); |
---|
1995 | if(min === 0 && !_content){ |
---|
1996 | occurrence.disable(); |
---|
1997 | occurrence.minimize(); |
---|
1998 | } |
---|
1999 | this.__error__.insert({"before" : occurrence.getFrame()}); |
---|
2000 | } |
---|
2001 | } |
---|
2002 | } |
---|
2003 | } |
---|
2004 | // --- inserts not used contents |
---|
2005 | if(cContents.length !== 0){ |
---|
2006 | this.__containers__.push(new Array(new Object())); |
---|
2007 | var owner = this.__containers__[0][0]; |
---|
2008 | var cssTitle = "No constraint found for this occurrence"; |
---|
2009 | for(var i = 0; i !== cContents.length; ++i){ |
---|
2010 | var occurrence = new OccurrenceC(cContents[i], null, null, null, owner, 0, 1, cssTitle, null); |
---|
2011 | this.__error__.insert({"before" : occurrence.getFrame()}); |
---|
2012 | } |
---|
2013 | } |
---|
2014 | } |
---|
2015 | else if(contents && contents.length !== 0){ |
---|
2016 | this.__containers__.push(new Array(new Object())); |
---|
2017 | var owner = this.__containers__[0][0]; |
---|
2018 | var cssTitle = "No constraint found for this occurrence"; |
---|
2019 | for(var i = 0; i !== contents.length; ++i){ |
---|
2020 | var occurrence = new OccurrenceC(contents[i], null, null, null, owner, 0, 1, null); |
---|
2021 | this.__error__.insert({"before" : occurrence.getFrame()}); |
---|
2022 | } |
---|
2023 | } |
---|
2024 | } |
---|
2025 | catch(err){ |
---|
2026 | alert("From OccurrenceContainerC(): " + err); |
---|
2027 | } |
---|
2028 | }, |
---|
2029 | "isValid" : function(){ |
---|
2030 | var ret = true; |
---|
2031 | var errorStr = ""; |
---|
2032 | |
---|
2033 | // --- checks if there are any constraints |
---|
2034 | if((!this.__constraints__ || this.__constraints__.length === 0) && this.__containers__.length !== 0){ |
---|
2035 | for(var i = 0; i !== this.__containers__.length; ++i){ |
---|
2036 | for(var j = 0; j !== this.__containers__[i].length; ++j){ |
---|
2037 | for(var k = 0; k !== this.__containers__[i][j].__frames__.length; ++k){ |
---|
2038 | this.__containers__[i][j].__frames__[k].hideError(); |
---|
2039 | if(this.__containers__[i][j].__frames__[k].isUsed() === true){ |
---|
2040 | var type = this.__containers__[i][j].__frames__[k].showError("No constraints found for this occurrence!"); |
---|
2041 | } |
---|
2042 | } |
---|
2043 | } |
---|
2044 | } |
---|
2045 | return false; |
---|
2046 | } |
---|
2047 | else if(!this.__constraints__ || this.__constraints__.length === 0) return true; |
---|
2048 | |
---|
2049 | // --- summarizes all occurrences |
---|
2050 | var allOccurrences = new Array(); |
---|
2051 | for(var i = 0; i !== this.__containers__.length; ++i){ |
---|
2052 | for(var j = 0; j !== this.__containers__[i].length; ++j){ |
---|
2053 | for(var k = 0; k !== this.__containers__[i][j].__frames__.length; ++k){ |
---|
2054 | if(this.__containers__[i][j].__frames__[k].isUsed() === true && this.__containers__[i][j].__frames__[k].isEmpty() === false){ |
---|
2055 | allOccurrences.push(this.__containers__[i][j].__frames__[k]); |
---|
2056 | } |
---|
2057 | this.__containers__[i][j].__frames__[k].hideError(); |
---|
2058 | if(this.__containers__[i][j].__frames__[k].scopeIsValid() === false) ret = false; |
---|
2059 | } |
---|
2060 | } |
---|
2061 | } |
---|
2062 | |
---|
2063 | // --- checks every constraint and the existing occurrences corresponding to the current constraint |
---|
2064 | for(var i = 0; i !== this.__constraints__.length; ++i){ |
---|
2065 | var currentConstraintTypes = new Array(); |
---|
2066 | for(var j = 0; j !== this.__constraints__[i].occurrenceTypes.length; ++j){ |
---|
2067 | currentConstraintTypes = currentConstraintTypes.concat(this.__constraints__[i].occurrenceTypes[j].occurrenceType); |
---|
2068 | } |
---|
2069 | currentConstraintTypes = currentConstraintTypes.uniq(); |
---|
2070 | |
---|
2071 | // --- collects all occurrences to the current constraint |
---|
2072 | var currentOccurrences = new Array(); |
---|
2073 | for(var j = 0; j !== allOccurrences.length; ++j){ |
---|
2074 | var type = allOccurrences[j].getContent().type; |
---|
2075 | if(type && currentConstraintTypes.indexOf(type[0]) !== -1) currentOccurrences.push(allOccurrences[j]); |
---|
2076 | } |
---|
2077 | // --- removes all current found occurrences from "allOccurrences" |
---|
2078 | for(var j = 0; j !== currentOccurrences.length; ++j) allOccurrences = allOccurrences.without(currentOccurrences[j]); |
---|
2079 | // --- checks the regExp, card-min and card-max for the found types |
---|
2080 | var satisfiedOccurrences = new Array(); |
---|
2081 | for(var j = 0; j !== this.__constraints__[i].constraints.length; ++j){ |
---|
2082 | var regexp = new RegExp(this.__constraints__[i].constraints[j].regexp); |
---|
2083 | var cardMin = parseInt(this.__constraints__[i].constraints[j].cardMin); |
---|
2084 | var cardMax = this.__constraints__[i].constraints[j].cardMax === MAX_INT ? MMAX_INT : parseInt(this.__constraints__[i].constraints[j].cardMax); |
---|
2085 | var matchedOccurrences = 0; |
---|
2086 | for(var k = 0; k !== currentOccurrences.length; ++k){ |
---|
2087 | var value = currentOccurrences[k].getContent().resourceRef; |
---|
2088 | if(!value) value = currentOccurrences[k].getContent().resourceData.value; |
---|
2089 | if(regexp.match(value) === true){ |
---|
2090 | ++matchedOccurrences; |
---|
2091 | satisfiedOccurrences.push(currentOccurrences[k]); |
---|
2092 | } |
---|
2093 | } |
---|
2094 | // TODO: check the unique-occurrence |
---|
2095 | // TODO: check the occurrence's datatype and its content |
---|
2096 | if(matchedOccurrences < cardMin){ |
---|
2097 | ret = false; |
---|
2098 | if(errorStr.length !== 0) errorStr += "<br/><br/>"; |
---|
2099 | errorStr += "card-min of the constraint regexp: \"" + this.__constraints__[i].constraints[j].regexp + "\" card-min: " + cardMin + " card-max: " + cardMax + " for the occurrencetype \"" + currentConstraintTypes + " is not satisfied (" + matchedOccurrences + ")!"; |
---|
2100 | } |
---|
2101 | if(cardMax !== MMAX_INT && matchedOccurrences > cardMax){ |
---|
2102 | ret = false; |
---|
2103 | if(errorStr.length !== 0) errorStr += "<br/><br/>"; |
---|
2104 | errorStr += "card-max of the constraint regexp: \"" + this.__constraints__[i].constraints[j].regexp + "\" card-min: " + cardMin + " card-max: " + cardMax + " for the occurrencetype \"" + currentConstraintTypes + " is not satisfied (" + matchedOccurrences + ")!"; |
---|
2105 | } |
---|
2106 | } |
---|
2107 | |
---|
2108 | // --- checks if there are any occurrences which wasn't checked --> bad value |
---|
2109 | satisfiedOccurrences = satisfiedOccurrences.uniq(); |
---|
2110 | for(var j = 0; j !== satisfiedOccurrences.length; ++j) |
---|
2111 | currentOccurrences = currentOccurrences.without(satisfiedOccurrences[j]); |
---|
2112 | if(currentOccurrences.length !== 0){ |
---|
2113 | ret = false; |
---|
2114 | for(var j = 0; j !== currentOccurrences.length; ++j) |
---|
2115 | currentOccurrences[j].showError("This occurrence does not satisfie any constraint!"); |
---|
2116 | } |
---|
2117 | } |
---|
2118 | |
---|
2119 | if(ret === true) this.hideError(); |
---|
2120 | else this.showError(errorStr); |
---|
2121 | return ret; |
---|
2122 | }, |
---|
2123 | "getContent" : function(){ |
---|
2124 | var values = new Array(); |
---|
2125 | try{ |
---|
2126 | for(var i = 0; i != this.__containers__.length; ++i){ |
---|
2127 | for(var j = 0; j != this.__containers__[i].length; ++j){ |
---|
2128 | for(var k = 0; k != this.__containers__[i][j].__frames__.length; ++k){ |
---|
2129 | if(this.__containers__[i][j].__frames__[k].isUsed() === true){ |
---|
2130 | values.push(this.__containers__[i][j].__frames__[k].getContent()); |
---|
2131 | } |
---|
2132 | } |
---|
2133 | } |
---|
2134 | } |
---|
2135 | return values; |
---|
2136 | } |
---|
2137 | catch(err){ |
---|
2138 | return values; |
---|
2139 | } |
---|
2140 | }, |
---|
2141 | "toJSON" : function(){ |
---|
2142 | try{ |
---|
2143 | var str = "["; |
---|
2144 | for(var i = 0; i != this.__containers__.length; ++i){ |
---|
2145 | for(var j = 0; j != this.__containers__[i].length; ++j){ |
---|
2146 | for(var k = 0; k != this.__containers__[i][j].__frames__.length; ++k){ |
---|
2147 | if(this.__containers__[i][j].__frames__[k].isUsed() === true){ |
---|
2148 | str += this.__containers__[i][j].__frames__[k].toJSON() + ","; |
---|
2149 | } |
---|
2150 | } |
---|
2151 | } |
---|
2152 | } |
---|
2153 | if(str.endsWith(",")) str = str.slice(0, str.length - 1); |
---|
2154 | str += "]"; |
---|
2155 | return str === "[]" ? null : str; |
---|
2156 | } |
---|
2157 | catch(err){ |
---|
2158 | return "null"; |
---|
2159 | } |
---|
2160 | }}); |
---|
2161 | |
---|
2162 | |
---|
2163 | // --- representation of a topic element. |
---|
2164 | var TopicC = Class.create(ContainerC, {"initialize" : function($super, content, constraints, instanceOfs){ |
---|
2165 | $super(); |
---|
2166 | this.__minimized__ = false; |
---|
2167 | this.__instanceOfs__ = (!instanceOfs || instanceOfs.length === 0 ? null : instanceOfs); |
---|
2168 | |
---|
2169 | try{ |
---|
2170 | var topicidContent = null; |
---|
2171 | var itemIdentityContent = null; |
---|
2172 | var subjectLocatorContent = null; |
---|
2173 | var subjectIdentifierContent = null; |
---|
2174 | var namesContent = null; |
---|
2175 | var occurrencesContent = null; |
---|
2176 | if(content){ |
---|
2177 | topicidContent = content.id |
---|
2178 | itemIdentityContent = content.itemIdentities |
---|
2179 | subjectLocatorContent = content.subjectLocators; |
---|
2180 | subjectIdentifierContent = content.subjectIdentifiers; |
---|
2181 | namesContent = content.names; |
---|
2182 | occurrencesContent = content.occurrences; |
---|
2183 | } |
---|
2184 | this.__frame__ .writeAttribute({"class" : CLASSES.topicFrame()}); |
---|
2185 | this.__table__ = new Element("table", {"class" : CLASSES.topicFrame()}); |
---|
2186 | this.__frame__.insert({"top" : this.__table__}); |
---|
2187 | this.__caption__ = new Element("caption", {"class" : CLASSES.clickable()}).update("Topic"); |
---|
2188 | this.__table__.insert({"top" : this.__caption__}); |
---|
2189 | |
---|
2190 | function setMinimizeHandler(myself){ |
---|
2191 | myself.__caption__.observe("click", function(event){ |
---|
2192 | myself.minimize(); |
---|
2193 | }); |
---|
2194 | } |
---|
2195 | setMinimizeHandler(this); |
---|
2196 | |
---|
2197 | // --- topic id |
---|
2198 | this.__topicid__ = new Object(); |
---|
2199 | new TextrowC(topicidContent, ".*", this.__topicid__, 1, 1, null); |
---|
2200 | this.__table__.insert({"bottom" : newRow(CLASSES.topicIdFrame(), "Topic ID", this.__topicid__.__frames__[0].getFrame())}); |
---|
2201 | |
---|
2202 | // --- itemIdentity |
---|
2203 | this.__itemIdentity__ = new ItemIdentityC(itemIdentityContent, this); |
---|
2204 | this.__table__.insert({"bottom" : newRow(CLASSES.itemIdentityFrame(), "ItemIdentity", this.__itemIdentity__.getFrame())}); |
---|
2205 | |
---|
2206 | // --- subjectLocator |
---|
2207 | var _constraints = (constraints ? constraints.subjectLocatorConstraints : null); |
---|
2208 | this.__subjectLocator__ = new IdentifierC(subjectLocatorContent, _constraints, CLASSES.subjectLocatorFrame()); |
---|
2209 | this.__table__.insert({"bottom" : newRow(CLASSES.subjectLocatorFrame(), "SubjectLocator", this.__subjectLocator__.getFrame())}); |
---|
2210 | |
---|
2211 | // --- subjectIdentifier |
---|
2212 | _constraints = (constraints ? constraints.subjectIdentifierConstraints : null); |
---|
2213 | this.__subjectIdentifier__ = new IdentifierC(subjectIdentifierContent, _constraints, CLASSES.subjectIdentifierFrame()); |
---|
2214 | this.__table__.insert({"bottom" : newRow(CLASSES.subjectIdentifierFrame(), "SubjectIdentifier", this.__subjectIdentifier__.getFrame())}); |
---|
2215 | |
---|
2216 | // --- names |
---|
2217 | _constraints = (constraints ? constraints.topicNameConstraints : null); |
---|
2218 | this.__name__ = new NameContainerC(namesContent, _constraints); |
---|
2219 | this.__table__.insert({"bottom" : newRow(CLASSES.nameContainer(), "Names", this.__name__.getFrame())}); |
---|
2220 | |
---|
2221 | // --- occurrences |
---|
2222 | _constraints = (constraints ? constraints.topicOccurrenceConstraints : null); |
---|
2223 | this.__occurrence__ = new OccurrenceContainerC(occurrencesContent, _constraints); |
---|
2224 | this.__table__.insert({"bottom" : newRow(CLASSES.occurrenceContainer(), "Occurrences", this.__occurrence__.getFrame())}); |
---|
2225 | }catch(err){ |
---|
2226 | alert("From TopciC(): " + err); |
---|
2227 | } |
---|
2228 | }, |
---|
2229 | "getContent" : function(){ |
---|
2230 | try{ |
---|
2231 | return {"id" : this.__topicid__.__frames__[0].getContent().strip(), |
---|
2232 | "itemIdentities" : this.__itemIdentity__.getContent(true, true), |
---|
2233 | "subjectLocators" : this.__subjectLocator__.getContent(true, true), |
---|
2234 | "subjectIdentifiers" : this.__subjectIdentifier__.getContent(true, true), |
---|
2235 | "instanceOfs" : this.__instanceOfs__, |
---|
2236 | "names" : this.__name__.getContent(), |
---|
2237 | "occurrences" : this.__occurrence__.getContent()}; |
---|
2238 | } |
---|
2239 | catch(err){ |
---|
2240 | return null; |
---|
2241 | } |
---|
2242 | }, |
---|
2243 | "toJSON" : function(){ |
---|
2244 | try{ |
---|
2245 | return "{\"id\":" + this.__topicid__.__frames__[0].getContent().strip().toJSON() + |
---|
2246 | ",\"itemIdentities\":" + this.__itemIdentity__.toJSON(true, true) + |
---|
2247 | ",\"subjectLocators\":" + this.__subjectLocator__.toJSON(true, true) + |
---|
2248 | ",\"subjectIdentifiers\":" + this.__subjectIdentifier__.toJSON(true, true) + |
---|
2249 | ",\"instanceOfs\":" + (!this.__instanceOfs__ ? "null" : this.__instanceOfs__.toJSON()) + |
---|
2250 | ",\"names\":" + this.__name__.toJSON() + |
---|
2251 | ",\"occurrences\":" + this.__occurrence__.toJSON() + "}"; |
---|
2252 | } |
---|
2253 | catch(err){ |
---|
2254 | return "null"; |
---|
2255 | } |
---|
2256 | }, |
---|
2257 | "minimize" : function(){ |
---|
2258 | var rows = new Array(); |
---|
2259 | rows.push(this.getFrame().select("tr." + CLASSES.topicIdFrame())[0], |
---|
2260 | this.getFrame().select("tr." + CLASSES.itemIdentityFrame())[0], |
---|
2261 | this.getFrame().select("tr." + CLASSES.subjectLocatorFrame())[0], |
---|
2262 | this.getFrame().select("tr." + CLASSES.subjectIdentifierFrame())[0], |
---|
2263 | this.getFrame().select("tr." + CLASSES.nameContainer())[0], |
---|
2264 | this.getFrame().select("tr." + CLASSES.occurrenceContainer())[0]); |
---|
2265 | for(var i = 0; i != rows.length; ++i){ |
---|
2266 | if(this.__minimized__ === false) rows[i].hide(); |
---|
2267 | else rows[i].show(); |
---|
2268 | } |
---|
2269 | this.__minimized__ = !this.__minimized__; |
---|
2270 | }, |
---|
2271 | "hasPsi" : function(){ |
---|
2272 | return this.__subjectIdentifier__.getContent(true, true).length !== 0; |
---|
2273 | }, |
---|
2274 | "isValid" : function(){ |
---|
2275 | var ret = true; |
---|
2276 | if(this.__topicid__.__frames__[0].getContent().strip().length === 0){ |
---|
2277 | ret = false; |
---|
2278 | this.__topicid__.__frames__[0].showError("The topic must contain a topic ID!"); |
---|
2279 | } |
---|
2280 | else { |
---|
2281 | this.__topicid__.__frames__[0].hideError(); |
---|
2282 | } |
---|
2283 | if(this.__subjectIdentifier__.getContent().length === 0){ |
---|
2284 | ret = false; |
---|
2285 | this.showError("The topic must contain at least one SubjectIdentifier!<br/>If it is not possible to insert one - please create a subjectidentifier-constraint for this topic (-type)!"); |
---|
2286 | } |
---|
2287 | else if(ret === true){ |
---|
2288 | this.hideError(); |
---|
2289 | } |
---|
2290 | |
---|
2291 | if(this.__subjectLocator__.isValid() === false) ret = false; |
---|
2292 | if(this.__subjectIdentifier__.isValid() === false) ret = false; |
---|
2293 | if(this.__name__.isValid() === false) ret = false; |
---|
2294 | if(this.__occurrence__.isValid() === false) ret = false; |
---|
2295 | |
---|
2296 | return ret; |
---|
2297 | }, |
---|
2298 | "getReferencedTopics" : function(){ |
---|
2299 | var referencedTopics = new Array(); |
---|
2300 | var names = this.getContent().names; |
---|
2301 | if(names){ |
---|
2302 | for(var i = 0; i !== names.length; ++i){ |
---|
2303 | // TODO: variant (-scope topicStubs) |
---|
2304 | var type = names[i].type; |
---|
2305 | if(type){ |
---|
2306 | if(referencedTopics.indexOf(type[0]) === -1) referencedTopics.push(type[0]); |
---|
2307 | } |
---|
2308 | var scopes = names[i].scopes; |
---|
2309 | if(scopes){ |
---|
2310 | for(var j = 0; j !== scopes.length; ++j){ |
---|
2311 | if(referencedTopics.indexOf(scopes[j][0]) === -1) referencedTopics.push(scopes[j][0]); |
---|
2312 | } |
---|
2313 | } |
---|
2314 | } |
---|
2315 | } |
---|
2316 | |
---|
2317 | var occurrences = this.getContent().occurrences; |
---|
2318 | if(occurrences){ |
---|
2319 | for(var i = 0; i !== occurrences.length; ++i){ |
---|
2320 | var type = occurrences[i].type; |
---|
2321 | if(type){ |
---|
2322 | if(referencedTopics.indexOf(type[0]) === -1) referencedTopics.push(type[0]); |
---|
2323 | } |
---|
2324 | var scopes = occurrences[i].scopes; |
---|
2325 | if(scopes){ |
---|
2326 | for(var j = 0; j !== scopes.length; ++j){ |
---|
2327 | if(referencedTopics.indexOf(scopes[j][0]) === -1) referencedTopics.push(scopes[j][0]); |
---|
2328 | } |
---|
2329 | } |
---|
2330 | } |
---|
2331 | } |
---|
2332 | |
---|
2333 | if(this.__instanceOfs__){ |
---|
2334 | for(var i = 0; i !== this.__instanceOfs__.length; ++i){ |
---|
2335 | if(referencedTopics.indexOf(this.__instanceOfs__[i][0]) === -1) referencedTopics.push(this.__instanceOfs__[i][0]); |
---|
2336 | } |
---|
2337 | } |
---|
2338 | return referencedTopics; |
---|
2339 | }}); |
---|
2340 | |
---|
2341 | |
---|
2342 | // --- representation of a role element. |
---|
2343 | var RoleC = Class.create(ContainerC, {"initialize" : function($super, itemIdentities, roleTypes, rolePlayers, owner, typeMin, parent){ |
---|
2344 | $super(); |
---|
2345 | if(!owner.__frames__) owner.__frames__ = new Array(); |
---|
2346 | if(!roleTypes || roleTypes.length === 0) throw "From RoleC(): roleTypes must be set!"; |
---|
2347 | if(!rolePlayers || rolePlayers.length === 0) throw "From RoleC(): rolePlayers must be set"; |
---|
2348 | owner.__frames__.push(this); |
---|
2349 | this.__frame__.writeAttribute({"class" : CLASSES.roleFrame()}); |
---|
2350 | this.__table__ = new Element("table", {"class" : CLASSES.roleFrame()}); |
---|
2351 | this.__frame__.insert({"top" : this.__table__}); |
---|
2352 | this.__roleTypes__ = roleTypes; |
---|
2353 | this.__rolePlayers__ = rolePlayers; |
---|
2354 | this.__owner__ = owner; |
---|
2355 | this.__typeMin__ = typeMin; |
---|
2356 | this.__parentElem__ = parent; |
---|
2357 | this.__constraint__ = true; // is needed for checkAddRemoveButtons |
---|
2358 | this.__isMinimized__ = false; |
---|
2359 | |
---|
2360 | try{ |
---|
2361 | // --- control row + itemIdentity |
---|
2362 | makeControlRow(this, 3, itemIdentities); // make control row have to be changed to a separate control row for roles |
---|
2363 | checkRemoveAddButtons(owner, 1, -1, this); |
---|
2364 | setRemoveAddHandler(this, this.__constraint__, owner, 1, -1, function(){ /*do nothing*/ }); |
---|
2365 | // --- gets the add and remove button |
---|
2366 | var cTd = this.__table__.select("tr." + CLASSES.itemIdentityFrame())[0].select("td." + CLASSES.controlColumn())[0].select("span." + CLASSES.clickable()); |
---|
2367 | this.__removeButton__ = cTd[1]; |
---|
2368 | this.__addButton__ = cTd[2]; |
---|
2369 | |
---|
2370 | // --- type |
---|
2371 | var types = this.__roleTypes__.flatten(); |
---|
2372 | this.__type__ = new Object(); |
---|
2373 | var tr = newRow(CLASSES.typeFrame(), "Type", new SelectrowC(types, this.__type__, 1, 1).getFrame()); |
---|
2374 | this.__table__.insert({"bottom" : tr}); |
---|
2375 | |
---|
2376 | // --- player |
---|
2377 | var players = this.__rolePlayers__.flatten(); |
---|
2378 | this.__player__ = new Object(); |
---|
2379 | tr = newRow(CLASSES.playerFrame(), "Player", new SelectrowC(players, this.__player__, 1, 1).getFrame()); |
---|
2380 | this.__table__.insert({"bottom" : tr}); |
---|
2381 | |
---|
2382 | function setDblClickHandler(myself){ |
---|
2383 | myself.getFrame().observe("dblclick", function(event){ |
---|
2384 | if(myself.__typeMin__ === 0){ |
---|
2385 | var roles = new Array(); |
---|
2386 | for(var i = 0; i !== owner.__frames__.length; ++i){ |
---|
2387 | if(roleTypes.flatten().indexOf(owner.__frames__[i].getType()) !== -1) |
---|
2388 | roles.push(owner.__frames__[i]); |
---|
2389 | } |
---|
2390 | |
---|
2391 | if(roles.length === 1 && roles[0].isUsed() === true){ |
---|
2392 | roles[0].disable(); |
---|
2393 | } |
---|
2394 | else if(roles.length === 1 && roles[0].isUsed() === false){ |
---|
2395 | roles[0].enable(); |
---|
2396 | } |
---|
2397 | if(parent.isUsed() === true)Event.stop(event); |
---|
2398 | } |
---|
2399 | }); |
---|
2400 | } |
---|
2401 | setDblClickHandler(this); |
---|
2402 | |
---|
2403 | } |
---|
2404 | catch(err){ |
---|
2405 | alert("From RoleC(): " + err); |
---|
2406 | } |
---|
2407 | }, |
---|
2408 | "addItemIdentities" : function(additionalItemIdentities){ |
---|
2409 | if(!additionalItemIdentities || additionalItemIdentities.length === 0) return; |
---|
2410 | |
---|
2411 | var con = this.getContent(); |
---|
2412 | if(!con) con = new Array(); |
---|
2413 | else con = con.itemIdentities; |
---|
2414 | |
---|
2415 | con = con.concat(additionalItemIdentities); |
---|
2416 | var td = this.__itemIdentity__.getFrame().parentNode; |
---|
2417 | this.__itemIdentity__.remove(); |
---|
2418 | |
---|
2419 | this.__itemIdentity__ = new ItemIdentityC(con.uniq(), this); |
---|
2420 | td.update(this.__itemIdentity__.getFrame()); |
---|
2421 | }, |
---|
2422 | "selectPlayer" : function(playerPsi){ |
---|
2423 | if(this.getPlayer() === playerPsi) return; |
---|
2424 | var opts = this.__player__.__frames__[0].getFrame().select("select")[0].select("option"); |
---|
2425 | for(var i = 0; i !== opts.length; ++i){ |
---|
2426 | if(opts[i].value !== playerPsi) opts[i].removeAttribute("selected"); |
---|
2427 | else { |
---|
2428 | opts[i].writeAttribute({"selected" : "selected"}); |
---|
2429 | this.__player__.__frames__[0].getFrame().select("select")[0].insert({"top" : opts[i]}); |
---|
2430 | } |
---|
2431 | } |
---|
2432 | }, |
---|
2433 | "selectType" : function(typePsi){ |
---|
2434 | if(this.getType() === typePsi) return; |
---|
2435 | var opts = this.__type__.__frames__[0].getFrame().select("select")[0].select("option"); |
---|
2436 | for(var i = 0; i !== opts.length; ++i){ |
---|
2437 | if(opts[i].value !== typePsi) opts[i].removeAttribute("selected"); |
---|
2438 | else { |
---|
2439 | opts[i].writeAttribute({"selected" : "selected"}); |
---|
2440 | this.__type__.__frames__[0].getFrame().select("select")[0].insert({"top" : opts[i]}); |
---|
2441 | } |
---|
2442 | } |
---|
2443 | }, |
---|
2444 | "getAllPlayers" : function(){ |
---|
2445 | if(!this.__rolePlayers__ || this.__rolePlayers__.length === 0) return new Array(); |
---|
2446 | return this.__rolePlayers__.clone(); |
---|
2447 | }, |
---|
2448 | "getAllTypes" : function(){ |
---|
2449 | if(!this.__roleTypes__ || this.__roleTypes__.length === 0) return new Array(); |
---|
2450 | return this.__roleTypes__; |
---|
2451 | }, |
---|
2452 | "setAddHandler" : function(handler){ |
---|
2453 | if(!handler) return; |
---|
2454 | this.__addButton__.stopObserving(); |
---|
2455 | var addButton = this.__addButton__; |
---|
2456 | function addHandler(myself){ |
---|
2457 | addButton.observe("click", function(event){ handler(myself); }); |
---|
2458 | } |
---|
2459 | addHandler(this); |
---|
2460 | }, |
---|
2461 | "setRemoveHandler" : function(handler){ |
---|
2462 | if(!handler) return; |
---|
2463 | this.__removeButton__.stopObserving(); |
---|
2464 | var removeButton = this.__removeButton__; |
---|
2465 | function addHandler(myself){ |
---|
2466 | removeButton.observe("click", function(event){ handler(myself); }); |
---|
2467 | } |
---|
2468 | addHandler(this); |
---|
2469 | }, |
---|
2470 | "addPlayer" : function(player){ |
---|
2471 | if(!player || player.length === 0) return; |
---|
2472 | var selected = this.getPlayer(); |
---|
2473 | var select = this.__player__.__frames__[0].getFrame().select("select")[0]; |
---|
2474 | select.update(""); |
---|
2475 | if(this.__rolePlayers__){ |
---|
2476 | var j = 0; |
---|
2477 | for(var i = 0; i !== player.length; ++i){ |
---|
2478 | j = 0; |
---|
2479 | for( ; j !== this.__rolePlayers__.length; ++j){ |
---|
2480 | if(this.__rolePlayers__[j].indexOf(player[i]) !== -1) break; |
---|
2481 | } |
---|
2482 | if(j !== this.__rolePlayers__.length){ |
---|
2483 | this.__rolePlayers__[j] = player; |
---|
2484 | break; |
---|
2485 | } |
---|
2486 | } |
---|
2487 | if(j === this.__rolePlayers__.length)this.__rolePlayers__.push(player); |
---|
2488 | } |
---|
2489 | else { |
---|
2490 | this.__rolePlayers__ = new Array(player); |
---|
2491 | } |
---|
2492 | for(var i = 0; i !== this.__rolePlayers__.length; ++i){ |
---|
2493 | for(var j = 0; j !== this.__rolePlayers__[i].length; ++j){ |
---|
2494 | var opt = new Element("option", {"value" : this.__rolePlayers__[i][j]}).update(this.__rolePlayers__[i][j]); |
---|
2495 | if(this.__rolePlayers__[i][j] !== selected){ |
---|
2496 | select.insert({"bottom" : opt}); |
---|
2497 | } |
---|
2498 | else { |
---|
2499 | opt.writeAttribute({"selected" : "selected"}); |
---|
2500 | select.insert({"top" : opt}); |
---|
2501 | } |
---|
2502 | } |
---|
2503 | } |
---|
2504 | }, |
---|
2505 | "removePlayer" : function(player){ |
---|
2506 | if(!player || player.length === 0 || !this.__rolePlayers__ || this.__rolePlayers__.length === 0) return; |
---|
2507 | var selected = this.getPlayer(); |
---|
2508 | var select = this.__player__.__frames__[0].getFrame().select("select")[0]; |
---|
2509 | select.update(""); |
---|
2510 | var j = 0; |
---|
2511 | for(var i = 0; i !== player.length; ++i){ |
---|
2512 | j = 0; |
---|
2513 | for( ; j !== this.__rolePlayers__.length; ++j){ |
---|
2514 | if(this.__rolePlayers__[j].indexOf(player[i]) !== -1) break; |
---|
2515 | } |
---|
2516 | if(j !== this.__rolePlayers__.length) break; |
---|
2517 | } |
---|
2518 | this.__rolePlayers__ = this.__rolePlayers__.slice(0, j).concat(this.__rolePlayers__.slice(j + 1, this.__rolePlayers__.length)); |
---|
2519 | for(var i = 0; i !== this.__rolePlayers__.length; ++i){ |
---|
2520 | for(var j = 0; j !== this.__rolePlayers__[i].length; ++j){ |
---|
2521 | var opt = new Element("option", {"value" : this.__rolePlayers__[i][j]}).update(this.__rolePlayers__[i][j]); |
---|
2522 | if(this.__rolePlayers__[i][j] !== selected){ |
---|
2523 | select.insert({"bottom" : opt}); |
---|
2524 | } |
---|
2525 | else { |
---|
2526 | opt.writeAttribute({"selected" : "selected"}); |
---|
2527 | select.insert({"top" : opt}); |
---|
2528 | } |
---|
2529 | } |
---|
2530 | } |
---|
2531 | }, |
---|
2532 | "getType" : function(){ |
---|
2533 | return this.__type__.__frames__[0].getContent(); |
---|
2534 | }, |
---|
2535 | "getPlayer" : function(){ |
---|
2536 | return this.__player__.__frames__[0].getContent(); |
---|
2537 | }, |
---|
2538 | "getContent" : function(){ |
---|
2539 | if(this.isUsed()){ |
---|
2540 | return {"itemIdentities" : this.__itemIdentity__.getContent(true, true), |
---|
2541 | "type" : new Array(this.getType()), |
---|
2542 | "topicRef" : new Array(this.getPlayer())}; |
---|
2543 | } |
---|
2544 | |
---|
2545 | return null; |
---|
2546 | }, |
---|
2547 | "toJSON" : function(){ |
---|
2548 | if(this.isUsed()){ |
---|
2549 | return "{\"itemIdentities\":" + this.__itemIdentity__.toJSON(true, true) + |
---|
2550 | ",\"type\":[" + this.getType().toJSON() + "]" + |
---|
2551 | ",\"topicRef\":[" + this.getPlayer().toJSON() + "]}"; |
---|
2552 | } |
---|
2553 | |
---|
2554 | return "null"; |
---|
2555 | }, |
---|
2556 | "isUsed" : function(){ |
---|
2557 | return !this.__disabled__; |
---|
2558 | }, |
---|
2559 | "disable" : function(){ |
---|
2560 | this.hideError(); |
---|
2561 | this.__itemIdentity__.disable() |
---|
2562 | this.__type__.__frames__[0].disable(); |
---|
2563 | this.__player__.__frames__[0].disable(); |
---|
2564 | this.getFrame().writeAttribute({"class" : CLASSES.disabled()}); |
---|
2565 | this.__disabled__ = true; |
---|
2566 | }, |
---|
2567 | "enable" : function(){ |
---|
2568 | this.__itemIdentity__.enable() |
---|
2569 | this.__type__.__frames__[0].enable(); |
---|
2570 | this.__player__.__frames__[0].enable(); |
---|
2571 | this.getFrame().writeAttribute({"class" : CLASSES.roleFrame()}); |
---|
2572 | this.__disabled__ = false; |
---|
2573 | }, |
---|
2574 | "minimize" : function(){ |
---|
2575 | if(this.__isMinimized__ === false) { |
---|
2576 | this.getFrame().select("tr." + CLASSES.showHiddenRows())[0].show(); |
---|
2577 | this.getFrame().select("tr." + CLASSES.itemIdentityFrame())[0].hide(); |
---|
2578 | this.getFrame().select("tr." + CLASSES.typeFrame())[0].hide(); |
---|
2579 | this.getFrame().select("tr." + CLASSES.playerFrame())[0].hide(); |
---|
2580 | this.__isMinimized__ = true; |
---|
2581 | } |
---|
2582 | else { |
---|
2583 | this.getFrame().select("tr." + CLASSES.showHiddenRows())[0].hide(); |
---|
2584 | this.getFrame().select("tr." + CLASSES.itemIdentityFrame())[0].show(); |
---|
2585 | this.getFrame().select("tr." + CLASSES.typeFrame())[0].show(); |
---|
2586 | this.getFrame().select("tr." + CLASSES.playerFrame())[0].show(); |
---|
2587 | this.__isMinimized__ = false; |
---|
2588 | } |
---|
2589 | }}); |
---|
2590 | |
---|
2591 | |
---|
2592 | // --- contains all roles of an association |
---|
2593 | var RoleContainerC = Class.create(ContainerC, {"initialize" : function($super, contents, associationRoleConstraints, rolePlayerConstraints, otherRoleConstraints, parent){ |
---|
2594 | $super(); |
---|
2595 | this.__frame__.writeAttribute({"class" : CLASSES.roleContainer()}); |
---|
2596 | this.__arContainer__ = new Object(); this.__arContainer__.__frames__ = new Array(); |
---|
2597 | this.__orContainer__ = new Object(); this.__orContainer__.__frames__ = new Array(); |
---|
2598 | this.__associationRoleConstraints__ = associationRoleConstraints; |
---|
2599 | this.__otherRoleConstraints__ = otherRoleConstraints; |
---|
2600 | this.__rolePlayerConstraints__ = rolePlayerConstraints; |
---|
2601 | this.__parentElem__ = parent; |
---|
2602 | |
---|
2603 | try{ |
---|
2604 | this.resetValues(associationRoleConstraints, rolePlayerConstraints, otherRoleConstraints, contents); |
---|
2605 | this.__createFromContent__(contents); |
---|
2606 | } |
---|
2607 | catch(err){ |
---|
2608 | alert("From RoleContainerC(): " + err); |
---|
2609 | } |
---|
2610 | }, |
---|
2611 | "__orderContentsToRoles__" : function(contents, roleContainer, usedContents, alreadyUsedRoles){ |
---|
2612 | if(!roleContainer || roleContainer.length === 0){ |
---|
2613 | return {"usedContents" : usedContents, "contents" : contents, "alreadyUsedRoles" : alreadyUsedRoles}; |
---|
2614 | } |
---|
2615 | |
---|
2616 | for(var i = 0; i !== contents.length; ++i){ |
---|
2617 | var rType = contents[i].type; |
---|
2618 | var player = contents[i].topicRef; |
---|
2619 | var itemIdentities = contents[i].itemIdentities; |
---|
2620 | |
---|
2621 | // --- searches existing roles in the role-container |
---|
2622 | for(var j = 0; j !== roleContainer.length; ++j){ |
---|
2623 | var role = roleContainer[j]; |
---|
2624 | if(alreadyUsedRoles.indexOf(role) !== -1) continue; |
---|
2625 | |
---|
2626 | var typesOfRole = role.getAllTypes().flatten(); |
---|
2627 | var playersOfRole = role.getAllPlayers().flatten(); |
---|
2628 | var iter = 0; |
---|
2629 | for( ; iter !== rType.length; ++iter){ |
---|
2630 | if(typesOfRole.indexOf(rType[iter]) !== -1) break; |
---|
2631 | } |
---|
2632 | if(iter === rType.length) continue; |
---|
2633 | for(iter = 0; iter !== player.length; ++iter){ |
---|
2634 | if(playersOfRole.indexOf(player[iter]) !== -1) break; |
---|
2635 | } |
---|
2636 | if(iter === player.length) continue; |
---|
2637 | |
---|
2638 | alreadyUsedRoles.push(role); |
---|
2639 | usedContents.push(contents[i]); |
---|
2640 | |
---|
2641 | // --- inserts the deselected player of all other roles of this type |
---|
2642 | var oldPlayer = new Array(role.getPlayer()); |
---|
2643 | var _tmp = role.getAllPlayers(); |
---|
2644 | for(var i = 0; i !== _tmp.length; ++i){ |
---|
2645 | if(_tmp[i].indexOf(oldPlayer[0]) !== -1){ |
---|
2646 | oldPlayer = _tmp[i]; |
---|
2647 | break; |
---|
2648 | } |
---|
2649 | } |
---|
2650 | |
---|
2651 | for(var k = 0; k !== roleContainer.length; ++k){ |
---|
2652 | if(roleContainer[k] === role) continue; |
---|
2653 | roleContainer[k].addPlayer(oldPlayer); |
---|
2654 | } |
---|
2655 | |
---|
2656 | // --- removes the current player from all other roles with this type |
---|
2657 | for(var k = 0; k !== roleContainer.length; ++k){ |
---|
2658 | if(roleContainer[k] === role) continue; |
---|
2659 | roleContainer[k].removePlayer(player); |
---|
2660 | } |
---|
2661 | |
---|
2662 | // --- selects the currentPlayer/type |
---|
2663 | role.selectPlayer(player[0]); |
---|
2664 | |
---|
2665 | // --- selects the current roletype |
---|
2666 | role.selectType(rType[0]); |
---|
2667 | |
---|
2668 | // --- creates itemIdentities for the current role |
---|
2669 | role.addItemIdentities(itemIdentities); |
---|
2670 | break; |
---|
2671 | } |
---|
2672 | } |
---|
2673 | // --- removes all used contents from contents |
---|
2674 | for(var i = 0; i !== usedContents.length; ++i) contents = contents.without(usedContents[i]); |
---|
2675 | |
---|
2676 | return {"usedContents" : usedContents, "contents" : contents, "alreadyUsedRoles" : alreadyUsedRoles}; |
---|
2677 | }, |
---|
2678 | "__createAdditionalRolesFromContents__" : function(contents,usedContents, alreadyUsedRoles, isARC){ |
---|
2679 | var roleContainer = this.__orContainer__.__frames__; |
---|
2680 | if(isARC === true) roleContainer = this.__arContainer__.__frames__; |
---|
2681 | |
---|
2682 | if(roleContainer && roleContainer.length !== 0){ |
---|
2683 | var currentUsedContents = new Array(); |
---|
2684 | for(var i = 0; i !== contents.length; ++i){ |
---|
2685 | var rType = contents[i].type; |
---|
2686 | var player = contents[i].topicRef; |
---|
2687 | var itemIdentities = contents[i].itemIdentities; |
---|
2688 | |
---|
2689 | // --- gets all existing roles corresponding to the current content |
---|
2690 | var existingRoles = new Array(); |
---|
2691 | for(var j = 0; j !== roleContainer.length; ++j){ |
---|
2692 | var iTypes = roleContainer[j].getAllTypes().flatten(); |
---|
2693 | var iPlayers = roleContainer[j].getAllPlayers().flatten(); |
---|
2694 | var iter = 0; |
---|
2695 | for( ; iter !== rType.length; ++iter) if(iTypes.indexOf(rType[iter]) !== -1) break; |
---|
2696 | if(iter === rType.length) continue; |
---|
2697 | for(iter = 0; iter !== player.length; ++iter) if(iPlayers.indexOf(player[iter]) !== -1) break; |
---|
2698 | if(iter === player.length) continue; |
---|
2699 | |
---|
2700 | existingRoles.push(roleContainer[j]); |
---|
2701 | } |
---|
2702 | |
---|
2703 | // --- collects the selected players |
---|
2704 | if(existingRoles && existingRoles.length > 0){ |
---|
2705 | var selectedPlayers = new Array(); |
---|
2706 | for(var j = 0; j !== existingRoles.length; ++j){ |
---|
2707 | var _tmp = existingRoles[j].getAllPlayers(); |
---|
2708 | for(var k = 0; k !== _tmp.length; ++k){ |
---|
2709 | if(_tmp[k].indexOf(existingRoles[j].getPlayer()) !== -1){ |
---|
2710 | selectedPlayers.push(_tmp[k]); |
---|
2711 | break; |
---|
2712 | } |
---|
2713 | } |
---|
2714 | } |
---|
2715 | selectedPlayers = selectedPlayers.flatten(); |
---|
2716 | var allPlayers = existingRoles[0].getAllPlayers(); |
---|
2717 | var playersToRemove = new Array(); |
---|
2718 | for(var j = 0; j !== allPlayers.length; ++j){ |
---|
2719 | for(var k = 0; k !== selectedPlayers.length; ++k){ |
---|
2720 | if(allPlayers[j].indexOf(selectedPlayers[k]) !== -1){ |
---|
2721 | playersToRemove.push(allPlayers[j]); |
---|
2722 | break; |
---|
2723 | } |
---|
2724 | } |
---|
2725 | } |
---|
2726 | for(var j = 0; j !== playersToRemove.length; ++j) allPlayers = allPlayers.without(playersToRemove[j]); |
---|
2727 | var newTypes = existingRoles[0].getAllTypes(); |
---|
2728 | var min = 0; |
---|
2729 | var arc = null; |
---|
2730 | var orc = null; |
---|
2731 | if(isARC === true){ |
---|
2732 | for(var j = 0; this.__associationRoleConstraints__ && j !== this.__associationRoleConstraints__.length; ++j){ |
---|
2733 | if(arc) break; |
---|
2734 | var arcTypes = this.__associationRoleConstraints__[j].roleType; |
---|
2735 | if(arcTypes) arcTypes = arcTypes.flatten(); |
---|
2736 | var nTs = newTypes.flatten(); |
---|
2737 | for(var k = 0; k !== nTs.length; ++k){ |
---|
2738 | if(arcTypes.indexOf(nTs[k]) !== -1){ |
---|
2739 | arc = this.__associationRoleConstraints__[j]; |
---|
2740 | min = parseInt(arc.cardMin); |
---|
2741 | break; |
---|
2742 | } |
---|
2743 | } |
---|
2744 | } |
---|
2745 | } |
---|
2746 | else { |
---|
2747 | for(var j = 0; this.__otherRoleConstraints__ && j !== this.__otherRoleConstraints__.length; ++j){ |
---|
2748 | if(orc) break; |
---|
2749 | var oPlayers = this.__otherRoleConstraints__[j].otherPlayers; |
---|
2750 | if(oPlayers) oPlayers = oPlayers.flatten(); |
---|
2751 | var oTypes = this.__otherRoleConstraints__[j].otherRoleType; |
---|
2752 | if(oTypes) oTypes = oTypes.flatten(); |
---|
2753 | |
---|
2754 | for(var k = 0; k !== rType.length; ++k){ |
---|
2755 | if(orc) break; |
---|
2756 | if(oTypes.indexOf(rType[k]) !== -1){ |
---|
2757 | for(var l = 0; l !== player.length; ++l){ |
---|
2758 | if(oPlayers.indexOf(player[l]) !== -1){ |
---|
2759 | orc = this.__otherRoleConstraints__[j]; |
---|
2760 | min = parseInt(orc.cardMin); |
---|
2761 | break; |
---|
2762 | } |
---|
2763 | } |
---|
2764 | } |
---|
2765 | } |
---|
2766 | } |
---|
2767 | } |
---|
2768 | var role = null; |
---|
2769 | if(isARC === true) role = new RoleC(null, newTypes, allPlayers, this.__arContainer__, min, this.__parentElem__); |
---|
2770 | else role = new RoleC(null, newTypes, allPlayers, this.__orContainer__, min, this.__parentElem__); |
---|
2771 | for(var j = 0; j !== roleContainer.length; ++j){ |
---|
2772 | if(roleContainer[j] !== role) roleContainer[j].removePlayer(player); |
---|
2773 | } |
---|
2774 | role.selectPlayer(player[0]); |
---|
2775 | role.selectType(rType[0]); |
---|
2776 | |
---|
2777 | if(isARC === true){ |
---|
2778 | var rpcs = getRolePlayerConstraintsForRole(newTypes, this.__rolePlayerConstraints__); |
---|
2779 | var allAvailablePlayers = extractPlayersOfConstraints(rpcs); |
---|
2780 | var allRolesToCheck = existingRoles; |
---|
2781 | allRolesToCheck.push(role); |
---|
2782 | this.__checkARCButtons__(allRolesToCheck, allAvailablePlayers, arc); |
---|
2783 | this.__setARCAddHandler__(role, allAvailablePlayers, arc); |
---|
2784 | this.__setARCRemoveHandler__(role, arc); |
---|
2785 | this.__setRoleChangePlayerHandler__(role, this.__arContainer__.__frames__, rpcs, null); |
---|
2786 | } |
---|
2787 | else { |
---|
2788 | var orpcs = new Array(); |
---|
2789 | var ac = this.__arContainer__.__frames__; |
---|
2790 | for(var j = 0; ac && j !== ac.length; ++j){ |
---|
2791 | var fType = new Array(ac[j].getType()); |
---|
2792 | var fPlayer = new Array(ac[j].getPlayer()); |
---|
2793 | orpcs = orpcs.concat(getOtherRoleConstraintsForRole(fType, fPlayer, this.__otherRoleConstraints__)); |
---|
2794 | } |
---|
2795 | var _orpcs = new Array(); |
---|
2796 | for(var j = 0; j !== orpcs.length; ++j){ |
---|
2797 | var players = orpcs[j].otherPlayers; |
---|
2798 | if(players) players = players.flatten(); |
---|
2799 | var types = orpcs[j].otherRoleType; |
---|
2800 | if(types) types = types.flatten(); |
---|
2801 | if(!types || !players) continue; |
---|
2802 | for(var k = 0; k !== rType.length; ++k){ |
---|
2803 | if(types.indexOf(rType[k]) !== -1){ |
---|
2804 | for(var l = 0; l !== player.length; ++l){ |
---|
2805 | if(players.indexOf(player[l]) !== -1) _orpcs.push(orpcs[j]); |
---|
2806 | } |
---|
2807 | } |
---|
2808 | } |
---|
2809 | } |
---|
2810 | |
---|
2811 | orpcs = _orpcs.uniq(); |
---|
2812 | this.__checkORCButtons__(role, orc); |
---|
2813 | this.__setRoleChangePlayerHandler__(role, this.__orContainer__.__frames__, null, orpcs); |
---|
2814 | this.__setORCAddHandler__(role, orc, orpcs); |
---|
2815 | this.__setORCRemoveHandler__(role, orc, orpcs); |
---|
2816 | } |
---|
2817 | // --- adds itemIdentities |
---|
2818 | role.addItemIdentities(itemIdentities); |
---|
2819 | |
---|
2820 | var lastRole = roleContainer[roleContainer.length -2]; |
---|
2821 | lastRole.getFrame().insert({"after" : role.getFrame()}); |
---|
2822 | currentUsedContents.push(contents[i]); |
---|
2823 | } |
---|
2824 | } |
---|
2825 | |
---|
2826 | // --- removes all used contents from contents |
---|
2827 | if(!usedContents) usedContents = new Array(); |
---|
2828 | usedContents = usedContents.concat(currentUsedContents).uniq(); |
---|
2829 | for(var i = 0; i !== usedContents.length; ++i) contents = contents.without(usedContents[i]); |
---|
2830 | } |
---|
2831 | return {"usedContents" : usedContents, "contents" : contents, "alreadyUsedRoles" : alreadyUsedRoles}; |
---|
2832 | }, |
---|
2833 | "__createNewRolesFromContents__" : function(contents){ |
---|
2834 | if(!contents || contents.length === 0) return; |
---|
2835 | |
---|
2836 | for(var i = 0; i !== contents.length; ++i){ |
---|
2837 | var rType = contents[i].type; |
---|
2838 | if(!rType) rType = new Array(""); |
---|
2839 | rType = new Array(rType); |
---|
2840 | var rPlayer = contents[i].topicRef; |
---|
2841 | if(!rPlayer) rPlayer = new Array(""); |
---|
2842 | rPlayer = new Array(rPlayer); |
---|
2843 | var itemIdentities = contents[i].itemIdentities; |
---|
2844 | |
---|
2845 | // itemIdentities, roleTypes, rolePlayers, owner, typeMin, parent){ |
---|
2846 | var role = new RoleC(itemIdentities, rType, rPlayer, this.__arContainer__, 0, this.__parentElem__); |
---|
2847 | if(this.__arContainer__.__frames__ && this.__arContainer__.__frames__.length > 1){ |
---|
2848 | var insertPoint = this.__arContainer__.__frames__[this.__arContainer__.__frames__.length - 2]; |
---|
2849 | insertPoint.getFrame().insert({"after" : role.getFrame()}); |
---|
2850 | } |
---|
2851 | else { |
---|
2852 | this.__error__.insert({"before" : role.getFrame()}) |
---|
2853 | } |
---|
2854 | role.hideAddButton(); |
---|
2855 | } |
---|
2856 | }, |
---|
2857 | "__createFromContent__" : function(contents){ |
---|
2858 | if(!contents || contents.length === 0) return; |
---|
2859 | |
---|
2860 | var cContents = contents; |
---|
2861 | var usedContents = new Array(); |
---|
2862 | var alreadyUsedRoles = new Array(); |
---|
2863 | |
---|
2864 | // --- searches for associaitonrole-constraints and roleplayer-constraints |
---|
2865 | var ret = this.__orderContentsToRoles__(cContents, this.__arContainer__.__frames__, usedContents, alreadyUsedRoles); |
---|
2866 | cContents = ret.contents; |
---|
2867 | usedContents = ret.usedContents; |
---|
2868 | alreadyUsedRoles = ret.alreadyUsedRoles; |
---|
2869 | |
---|
2870 | // --- searches for otherrole-constraints |
---|
2871 | ret = this.__orderContentsToRoles__(cContents, this.__orContainer__.__frames__, usedContents, alreadyUsedRoles); |
---|
2872 | cContents = ret.contents; |
---|
2873 | usedContents = ret.usedContents; |
---|
2874 | alreadyUsedRoles = ret.alreadyUsedRoles; |
---|
2875 | |
---|
2876 | // --- creates additional roles (associationrole-constraints) |
---|
2877 | ret = this.__createAdditionalRolesFromContents__(cContents, usedContents, alreadyUsedRoles, true); |
---|
2878 | cContents = ret.contents; |
---|
2879 | usedContents = ret.usedContents; |
---|
2880 | alreadyUsedRoles = ret.alreadyUsedRoles; |
---|
2881 | |
---|
2882 | // --- creates additional roles (associationrole-constraints) |
---|
2883 | ret = this.__createAdditionalRolesFromContents__(cContents, usedContents, alreadyUsedRoles, false); |
---|
2884 | cContents = ret.contents; |
---|
2885 | usedContents = ret.usedContents; |
---|
2886 | alreadyUsedRoles = ret.alreadyUsedRoles; |
---|
2887 | |
---|
2888 | this.__createNewRolesFromContents__(cContents); |
---|
2889 | }, |
---|
2890 | "resetValues" : function(associationRoleConstraints, rolePlayerConstraints, otherRoleConstraints){ |
---|
2891 | this.__associationRoleConstraints__ = associationRoleConstraints; |
---|
2892 | this.__rolePlayerConstraints__ = rolePlayerConstraints; |
---|
2893 | this.__otherRoleConstraints__ = otherRoleConstraints; |
---|
2894 | |
---|
2895 | try{ |
---|
2896 | for(var i = 0; this.__arContainer__.__frames__ && i !== this.__arContainer__.__frames__.length; ++i){ |
---|
2897 | this.__arContainer__.__frames__[i].remove(); |
---|
2898 | } |
---|
2899 | this.__arContainer__ = new Object(); |
---|
2900 | } |
---|
2901 | catch(err){ |
---|
2902 | this.__arContainer__ = new Object(); |
---|
2903 | } |
---|
2904 | try{ |
---|
2905 | for(var i = 0; this.__orContainer__.__frames__ && i !== this.__orContainer__.__frames__.length; ++i){ |
---|
2906 | this.__orContainer__.__frames__[i].remove(); |
---|
2907 | } |
---|
2908 | this.__orContainer__ = new Object(); |
---|
2909 | } |
---|
2910 | catch(err){ |
---|
2911 | this.__orContainer__ = new Object(); |
---|
2912 | } |
---|
2913 | |
---|
2914 | // --- creates all roles from existing associationroleconstraints and roleplayerConstraints |
---|
2915 | for(var i = 0; this.__associationRoleConstraints__ && i !== this.__associationRoleConstraints__.length; ++i){ |
---|
2916 | var arc = this.__associationRoleConstraints__[i]; |
---|
2917 | var foundRpcs = getRolePlayerConstraintsForRole(arc.roleType, this.__rolePlayerConstraints__); |
---|
2918 | this.__makeRolesFromARC__(arc, foundRpcs); |
---|
2919 | } |
---|
2920 | // --- creates roles from otherrole-constraints |
---|
2921 | for(var i = 0; this.__arContainer__.__frames__ && i !== this.__arContainer__.__frames__.length; ++i){ |
---|
2922 | this.__makeRolesFromORC__(this.__arContainer__.__frames__[i].getType(), this.__arContainer__.__frames__[i].getPlayer()); |
---|
2923 | } |
---|
2924 | }, |
---|
2925 | "__makeRolesFromARC__" : function(associationRoleConstraint, rolePlayerConstraints){ |
---|
2926 | if(!associationRoleConstraint || !rolePlayerConstraints || rolePlayerConstraints.length === 0) return; |
---|
2927 | checkCardinalitiesARC_RPC(associationRoleConstraint, rolePlayerConstraints); |
---|
2928 | |
---|
2929 | // --- creates all roles with all needed players |
---|
2930 | var currentRoles = new Array(); |
---|
2931 | var rolesCreated = 0; |
---|
2932 | var allAvailablePlayers = extractPlayersOfConstraints(rolePlayerConstraints); |
---|
2933 | var roleType = associationRoleConstraint.roleType; |
---|
2934 | var roleMin = associationRoleConstraint.cardMin === 0 ? 1 : parseInt(associationRoleConstraint.cardMin); |
---|
2935 | var roleMinOrg = parseInt(associationRoleConstraint.cardMin); |
---|
2936 | for(var i = 0; i !== rolePlayerConstraints.length; ++i){ |
---|
2937 | var playerMin = rolePlayerConstraints[i].cardMin === 0 ? 1 : parseInt(rolePlayerConstraints[i].cardMin); |
---|
2938 | if(rolePlayerConstraints[i].players.length < playerMin) throw "From __makeRolesFromARC__(): not enough players(=" + rolePlayerConstraints[i].players.length + ") to reach card-min(=" + playerMin + ") of roletype\"" + roleType.flatten()[0] + "\"!"; |
---|
2939 | for(var k = 0; k !== playerMin; ++k){ |
---|
2940 | // --- creates a new role |
---|
2941 | var selectedPlayers = new Array(); |
---|
2942 | for(var j = 0; j !== currentRoles.length; ++j) selectedPlayers.push(currentRoles[j].getPlayer()); |
---|
2943 | var currentPlayers = cleanPlayers(rolePlayerConstraints[i].players, selectedPlayers) |
---|
2944 | var cleanedPlayers = cleanPlayers(allAvailablePlayers, selectedPlayers); |
---|
2945 | cleanedPlayers = cleanPlayers(cleanedPlayers, currentPlayers); |
---|
2946 | cleanedPlayers = currentPlayers.concat(cleanedPlayers); |
---|
2947 | var role = new RoleC(null, roleType, cleanedPlayers, this.__arContainer__, roleMinOrg, this.__parentElem__); |
---|
2948 | this.__setRoleChangePlayerHandler__(role, this.__arContainer__.__frames__, rolePlayerConstraints, null); |
---|
2949 | this.__error__.insert({"before" : role.getFrame()}); |
---|
2950 | // --- removes the new role's selected item from all other existing roles |
---|
2951 | for(var j = 0; j !== currentRoles.length; ++j){ |
---|
2952 | currentRoles[j].removePlayer(new Array(role.getPlayer())); |
---|
2953 | } |
---|
2954 | ++rolesCreated; |
---|
2955 | currentRoles.push(role); |
---|
2956 | } |
---|
2957 | } |
---|
2958 | |
---|
2959 | // --- creates all further needed roles with players that owns a card-max > existing players |
---|
2960 | while(rolesCreated < roleMin){ |
---|
2961 | var currentlyCreated = 0; |
---|
2962 | for(var i= 0; i !== rolePlayerConstraints.length; ++i){ |
---|
2963 | // existing roles --> all roles that owns a player which is selected of those listed in the roleplayer-constraint |
---|
2964 | var existingRoles = this.getExistingRoles(roleType, rolePlayerConstraints[i].players, this.__arContainer__.__frames__); |
---|
2965 | var availablePlayers = rolePlayerConstraints[i].players; |
---|
2966 | if(existingRoles.length < rolePlayerConstraints[i].cardMax && availablePlayers.length > existingRoles.length){ |
---|
2967 | var currentAvailablePlayers = rolePlayerConstraints[i].players; |
---|
2968 | var cleanedPlayers = cleanPlayers(allAvailablePlayers, currentAvailablePlayers); |
---|
2969 | |
---|
2970 | // --- adds players that are not selected yet |
---|
2971 | for(var j = 0; j !== currentAvailablePlayers.length; ++j){ |
---|
2972 | if(this.getExistingRoles(roleType, currentAvailablePlayers[j], this.__arContainer__.__frames__).length === 0){ |
---|
2973 | cleanedPlayers.push(currentAvailablePlayers[j]); |
---|
2974 | } |
---|
2975 | } |
---|
2976 | |
---|
2977 | // --- removes the player which will be seleted by the new created role of all other select-elements |
---|
2978 | for(var j = 0; j !== this.__arContainer__.__frames__.length; ++j){ |
---|
2979 | this.__arContainer__.__frames__[j].removePlayer(cleanedPlayers[0]); |
---|
2980 | } |
---|
2981 | |
---|
2982 | var role = new RoleC(null, roleType, cleanedPlayers, this.__arContainer__, roleMinOrg, this.__parentElem__); |
---|
2983 | currentRoles.push(role); |
---|
2984 | this.__setRoleChangePlayerHandler__(role, this.__arContainer__.__frames__, rolePlayerConstraints, null); |
---|
2985 | this.__error__.insert({"before" : role.getFrame()}); |
---|
2986 | ++rolesCreated; |
---|
2987 | ++currentlyCreated; |
---|
2988 | } |
---|
2989 | } |
---|
2990 | if(currentlyCreated === 0) throw "Not enough players to create all needed roles of the type \"" + roleType.flatten()[0] + "\"!"; |
---|
2991 | }; |
---|
2992 | this.__checkARCButtons__(currentRoles, allAvailablePlayers, associationRoleConstraint); |
---|
2993 | for(var i = 0; i !== currentRoles.length; ++i){ |
---|
2994 | this.__setARCAddHandler__(currentRoles[i], allAvailablePlayers, associationRoleConstraint); |
---|
2995 | this.__setARCRemoveHandler__(currentRoles[i], associationRoleConstraint); |
---|
2996 | } |
---|
2997 | }, |
---|
2998 | "__makeRolesFromORC__" : function(roleType, player){ |
---|
2999 | var orpcs = getOtherRoleConstraintsForRole(new Array(roleType), new Array(player), this.__otherRoleConstraints__); |
---|
3000 | for(var i = 0; i !== orpcs.length; ++i){ |
---|
3001 | var cPlayers = orpcs[i].players; |
---|
3002 | var cRoleType = orpcs[i].roleType; |
---|
3003 | var cOtherPlayers = orpcs[i].otherPlayers; |
---|
3004 | var cOtherRoleType = orpcs[i].otherRoleType; |
---|
3005 | var cMin = orpcs[i].cardMin === 0 ? 1 : parseInt(orpcs[i].cardMin); |
---|
3006 | var cMinOrg = parseInt(orpcs[i].cardMin); |
---|
3007 | if(!cOtherPlayers || cOtherPlayers.length < cMin) throw "from __makeRolesFromORC__(): not enough players(=" + cOtherPlayers.length + ") for roletype + \"" + cOtherRoleType.flatten()[0] + "\"!"; |
---|
3008 | var existingRoles = this.getExistingRoles(cOtherRoleType, cOtherPlayers, this.__orContainer__.__frames__); |
---|
3009 | for(var j = 0; j < cMin - existingRoles.length; ++j){ |
---|
3010 | // --- removes all players that are already selected from the |
---|
3011 | // --- current players list |
---|
3012 | var cleanedPlayers = new Array(); |
---|
3013 | for(var k = 0; k !== cOtherPlayers.length; ++k){ |
---|
3014 | if(this.getExistingRoles(cOtherRoleType, cOtherPlayers[k], this.__orContainer__.__frames__).length === 0){ |
---|
3015 | cleanedPlayers.push(cOtherPlayers[k]); |
---|
3016 | } |
---|
3017 | } |
---|
3018 | |
---|
3019 | // --- removes the player that will be selected in this role |
---|
3020 | // --- from all existing roles |
---|
3021 | for(var j = 0; this.__orContainer__.__frames__ && j !== this.__orContainer__.__frames__.length; ++j){ |
---|
3022 | this.__orContainer__.__frames__[j].removePlayer(cleanedPlayers[0]); |
---|
3023 | } |
---|
3024 | |
---|
3025 | var role = new RoleC(null, cOtherRoleType, cleanedPlayers, this.__orContainer__, cMinOrg, this.__parentElem__); |
---|
3026 | this.__checkORCButtons__(role, orpcs[i]); |
---|
3027 | this.__setRoleChangePlayerHandler__(role, this.__orContainer__.__frames__, null, orpcs); |
---|
3028 | this.__setORCAddHandler__(role, orpcs[i], orpcs); |
---|
3029 | this.__setORCRemoveHandler__(role, orpcs[i], orpcs); |
---|
3030 | this.__error__.insert({"before" : role.getFrame()}); |
---|
3031 | } |
---|
3032 | } |
---|
3033 | }, |
---|
3034 | "__checkORCButtons__" : function(role, constraint){ |
---|
3035 | if(!role || !constraint) return; |
---|
3036 | var cOtherPlayers = constraint.otherPlayers; |
---|
3037 | var cOtherRoleType = constraint.otherRoleType; |
---|
3038 | var cardMax = constraint.cardMax === MAX_INT ? MMAX_INT : parseInt(constraint.cardMax); |
---|
3039 | var cardMin = parseInt(constraint.cardMin); |
---|
3040 | var existingRoles = this.getExistingRoles(cOtherRoleType, cOtherPlayers, this.__orContainer__.__frames__); |
---|
3041 | var cleanedPlayers = new Array(); |
---|
3042 | for(var i = 0; i !== cOtherPlayers.length; ++i){ |
---|
3043 | if(this.getExistingRoles(cOtherRoleType, cOtherPlayers[i], this.__orContainer__.__frames__).length === 0){ |
---|
3044 | cleanedPlayers.push(cOtherPlayers[i]); |
---|
3045 | } |
---|
3046 | } |
---|
3047 | |
---|
3048 | // --- add button |
---|
3049 | if(cardMax > existingRoles.length && cleanedPlayers.length !== 0){ |
---|
3050 | for(var i = 0; i !== existingRoles.length; ++i) existingRoles[i].showAddButton(); |
---|
3051 | } |
---|
3052 | else { |
---|
3053 | for(var i = 0; i !== existingRoles.length; ++i) existingRoles[i].hideAddButton(); |
---|
3054 | } |
---|
3055 | |
---|
3056 | // --- remove button |
---|
3057 | if(cardMin >= existingRoles.length){ |
---|
3058 | for(var i = 0; i !== existingRoles.length; ++i) existingRoles[i].hideRemoveButton(); |
---|
3059 | } |
---|
3060 | else { |
---|
3061 | for(var i = 0; i !== existingRoles.length; ++i) existingRoles[i].showRemoveButton(); |
---|
3062 | } |
---|
3063 | }, |
---|
3064 | "__checkARCButtons__" : function(rolesToCheck, players, associationRoleConstraint){ |
---|
3065 | if(!rolesToCheck || !associationRoleConstraint) return; |
---|
3066 | var cardMin = associationRoleConstraint.cardMin === 0 ? 1 : parseInt(associationRoleConstraint.cardMin); |
---|
3067 | var cardMax = associationRoleConstraint.cardMax === MAX_INT ? MMAX_INT : parseInt(associationRoleConstraint.cardMax); |
---|
3068 | var lenPlayers = players ? players.length : 0; |
---|
3069 | if(cardMin < rolesToCheck.length) { |
---|
3070 | for(var i = 0; i !== rolesToCheck.length; ++i) rolesToCheck[i].showRemoveButton(); |
---|
3071 | } |
---|
3072 | else { |
---|
3073 | for(var i = 0; i !== rolesToCheck.length; ++i) rolesToCheck[i].hideRemoveButton(); |
---|
3074 | } |
---|
3075 | |
---|
3076 | if(cardMax === MMAX_INT || cardMax > rolesToCheck.length && rolesToCheck.length < lenPlayers){ |
---|
3077 | for(var i = 0; i !== rolesToCheck.length; ++i) rolesToCheck[i].showAddButton(); |
---|
3078 | } |
---|
3079 | else { |
---|
3080 | for(var i = 0; i !== rolesToCheck.length; ++i) rolesToCheck[i].hideAddButton(); |
---|
3081 | } |
---|
3082 | }, |
---|
3083 | "__setORCAddHandler__" : function(role, currentConstraint, constraints){ |
---|
3084 | if(!role || !currentConstraint || !constraints || constraints.length === 0) return; |
---|
3085 | |
---|
3086 | var roleContainer = this; |
---|
3087 | function addHandler(myself){ |
---|
3088 | var cOtherPlayers = currentConstraint.otherPlayers; |
---|
3089 | var cOtherRoleType = currentConstraint.otherRoleType; |
---|
3090 | var cardMax = currentConstraint.cardMax === MAX_INT ? MMAX_INT : parseInt(currentConstraint.cardMax); |
---|
3091 | var cardMin = currentConstraint.cardMin === 0 ? 1 : parseInt(currentConstraint.cardMin); |
---|
3092 | var cardMinOrg = parseInt(currentConstraint.cardMin);; |
---|
3093 | var existingRoles = roleContainer.getExistingRoles(cOtherRoleType, cOtherPlayers, roleContainer.__orContainer__.__frames__); |
---|
3094 | var cleanedPlayers = new Array(); |
---|
3095 | for(var i = 0; i !== cOtherPlayers.length; ++i){ |
---|
3096 | if(roleContainer.getExistingRoles(cOtherRoleType, cOtherPlayers[i], roleContainer.__orContainer__.__frames__).length === 0){ |
---|
3097 | cleanedPlayers.push(cOtherPlayers[i]); |
---|
3098 | } |
---|
3099 | } |
---|
3100 | |
---|
3101 | // --- creates new role |
---|
3102 | if(cleanedPlayers.length !== 0){ |
---|
3103 | var role = new RoleC(null, cOtherRoleType, cleanedPlayers, roleContainer.__orContainer__, cardMinOrg, this.__parentElem__); |
---|
3104 | roleContainer.__checkORCButtons__(role, currentConstraint); |
---|
3105 | roleContainer.__setRoleChangePlayerHandler__(role, roleContainer.__orContainer__.__frames__, null, constraints); |
---|
3106 | roleContainer.__setORCAddHandler__(role, currentConstraint, constraints); |
---|
3107 | roleContainer.__setORCRemoveHandler__(role, currentConstraint, constraints); |
---|
3108 | roleContainer.__error__.insert({"before" : role.getFrame()}); |
---|
3109 | // --- removes the selected player from all other roles |
---|
3110 | for(var i = 0; i !== existingRoles.length; ++i){ |
---|
3111 | existingRoles[i].removePlayer(new Array(role.getPlayer())); |
---|
3112 | } |
---|
3113 | var allRoles = existingRoles; |
---|
3114 | allRoles.push(role); |
---|
3115 | roleContainer.__innerCheckORCButtons__(allRoles, cardMin, cardMax); |
---|
3116 | } |
---|
3117 | } |
---|
3118 | |
---|
3119 | role.setAddHandler(addHandler); |
---|
3120 | }, |
---|
3121 | "__setORCRemoveHandler__" : function(role, currentConstraint, constraints){ |
---|
3122 | if(!role || !currentConstraint || !constraints) return; |
---|
3123 | |
---|
3124 | var roleContainer = this; |
---|
3125 | function removeHandler(myself){ |
---|
3126 | var cOtherPlayers = currentConstraint.otherPlayers; |
---|
3127 | var cOtherRoleType = currentConstraint.otherRoleType; |
---|
3128 | var cardMax = currentConstraint.cardMax === MAX_INT ? MMAX_INT : parseInt(currentConstraint.cardMax); |
---|
3129 | var cardMin = currentConstraint.cardMin === 0 ? 1 : parseInt(currentConstraint.cardMin); |
---|
3130 | var playerToAdd = null; |
---|
3131 | for(var i = 0; i !== cOtherPlayers.length; ++i){ |
---|
3132 | if(cOtherPlayers[i].indexOf(role.getPlayer()) !== -1){ |
---|
3133 | playerToAdd = cOtherPlayers[i]; |
---|
3134 | } |
---|
3135 | } |
---|
3136 | roleContainer.__orContainer__.__frames__ = roleContainer.__orContainer__.__frames__.without(role); |
---|
3137 | role.remove(); |
---|
3138 | var existingRoles = roleContainer.getExistingRoles(cOtherRoleType, cOtherPlayers, roleContainer.__orContainer__.__frames__); |
---|
3139 | for(var i = 0; i !== existingRoles.length; ++i){ |
---|
3140 | existingRoles[i].addPlayer(playerToAdd); |
---|
3141 | } |
---|
3142 | roleContainer.__innerCheckORCButtons__(existingRoles, cardMin, cardMax); |
---|
3143 | } |
---|
3144 | |
---|
3145 | role.setRemoveHandler(removeHandler); |
---|
3146 | }, |
---|
3147 | "__innerCheckORCButtons__" : function(existingRoles, cardMin, cardMax){ |
---|
3148 | if(!existingRoles) return; |
---|
3149 | |
---|
3150 | // --- checks all control buttons after an add or remove operation |
---|
3151 | if(cardMax !== MMAX_INT && existingRoles.length >= cardMax){ |
---|
3152 | for(var i = 0; i !== existingRoles.length; ++i){ |
---|
3153 | existingRoles[i].hideAddButton(); |
---|
3154 | } |
---|
3155 | } |
---|
3156 | else { |
---|
3157 | for(var i = 0; i !== existingRoles.length; ++i){ |
---|
3158 | existingRoles[i].showAddButton(); |
---|
3159 | } |
---|
3160 | } |
---|
3161 | |
---|
3162 | if(cardMin < existingRoles.length){ |
---|
3163 | for(var i = 0; i !== existingRoles.length; ++i){ |
---|
3164 | existingRoles[i].showRemoveButton(); |
---|
3165 | } |
---|
3166 | } |
---|
3167 | else { |
---|
3168 | for(var i = 0; i !== existingRoles.length; ++i){ |
---|
3169 | existingRoles[i].hideRemoveButton(); |
---|
3170 | } |
---|
3171 | } |
---|
3172 | }, |
---|
3173 | "__setARCAddHandler__" : function(role, players, associationRoleConstraint){ |
---|
3174 | if(!role || !associationRoleConstraint) return; |
---|
3175 | var lenPlayers = players ? players.length : 0; |
---|
3176 | |
---|
3177 | var roleContainer = this; |
---|
3178 | function addHandler(myself){ |
---|
3179 | var roleType = associationRoleConstraint.roleType.flatten(); |
---|
3180 | var rolesToCheck = new Array(); |
---|
3181 | for(var i = 0; i !== roleContainer.__arContainer__.__frames__.length; ++i){ |
---|
3182 | if(roleType.indexOf(roleContainer.__arContainer__.__frames__[i].getType()) !== -1) |
---|
3183 | rolesToCheck.push(roleContainer.__arContainer__.__frames__[i]); |
---|
3184 | } |
---|
3185 | |
---|
3186 | // --- creates a new role |
---|
3187 | var cardMax = associationRoleConstraint.cardMax === MAX_INT ? MMAX_INT : parseInt(associationRoleConstraint.cardMax); |
---|
3188 | var cardMin = parseInt(associationRoleConstraint.cardMin); |
---|
3189 | if(cardMax === MMAX_INT || cardMax > rolesToCheck.length){ |
---|
3190 | var usedPlayers = new Array(); |
---|
3191 | for(var i = 0; i !== rolesToCheck.length; ++i) usedPlayers.push(rolesToCheck[i].getPlayer()); |
---|
3192 | var cleanedPlayers = cleanPlayers(players ? players : new Array(), usedPlayers); |
---|
3193 | var role = new RoleC(null, roleType, cleanedPlayers, roleContainer.__arContainer__, cardMin, this.__parentElem__); |
---|
3194 | var foundRpcs = getRolePlayerConstraintsForRole(roleType, roleContainer.__rolePlayerConstraints__); |
---|
3195 | roleContainer.__setRoleChangePlayerHandler__(role, roleContainer.__arContainer__.__frames__, foundRpcs, null); |
---|
3196 | roleContainer.__setARCAddHandler__(role, players, associationRoleConstraint); |
---|
3197 | roleContainer.__setARCRemoveHandler__(role, associationRoleConstraint); |
---|
3198 | |
---|
3199 | // --- removes the new role's selected item from all other existing roles |
---|
3200 | for(var j = 0; j !== rolesToCheck.length; ++j){ |
---|
3201 | rolesToCheck[j].removePlayer(new Array(role.getPlayer())); |
---|
3202 | } |
---|
3203 | roleContainer.__arContainer__.__frames__[roleContainer.__arContainer__.__frames__.length - 2].getFrame().insert({"after" : role.getFrame()}); |
---|
3204 | rolesToCheck.push(role); |
---|
3205 | roleContainer.__checkORCRoles__(role); |
---|
3206 | } |
---|
3207 | |
---|
3208 | roleContainer.__checkARCButtons__(rolesToCheck, players, associationRoleConstraint); |
---|
3209 | } |
---|
3210 | |
---|
3211 | role.setAddHandler(addHandler); |
---|
3212 | }, |
---|
3213 | "__setARCRemoveHandler__" : function(role, associationRoleConstraint){ |
---|
3214 | if(!role || !associationRoleConstraint) return; |
---|
3215 | |
---|
3216 | var roleContainer = this; |
---|
3217 | function removeHandler(myself){ |
---|
3218 | var cardMin = associationRoleConstraint.cardMin === 0 ? 1 : parseInt(associationRoleConstraint.cardMin); |
---|
3219 | var roleType = associationRoleConstraint.roleType.flatten(); |
---|
3220 | var rolesToCheck = new Array(); |
---|
3221 | for(var i = 0; i !== roleContainer.__arContainer__.__frames__.length; ++i){ |
---|
3222 | if(roleType.indexOf(roleContainer.__arContainer__.__frames__[i].getType()) !== -1) |
---|
3223 | rolesToCheck.push(roleContainer.__arContainer__.__frames__[i]); |
---|
3224 | } |
---|
3225 | |
---|
3226 | // --- removes the role |
---|
3227 | if(cardMin < rolesToCheck.length){ |
---|
3228 | // --- gets the player which is selected by the role has to be removed |
---|
3229 | var player = null; |
---|
3230 | for(var i = 0; roleContainer.__rolePlayerConstraints__ && i !== roleContainer.__rolePlayerConstraints__.length; ++i){ |
---|
3231 | if(player !== null) break; |
---|
3232 | for(var j = 0; roleContainer.__rolePlayerConstraints__[i].players && j !== roleContainer.__rolePlayerConstraints__[i].players.length; ++j){ |
---|
3233 | if(roleContainer.__rolePlayerConstraints__[i].players[j].indexOf(role.getPlayer()) !== -1){ |
---|
3234 | player = roleContainer.__rolePlayerConstraints__[i].players[j]; |
---|
3235 | break; |
---|
3236 | } |
---|
3237 | } |
---|
3238 | } |
---|
3239 | rolesToCheck = rolesToCheck.without(role); |
---|
3240 | role.remove(); |
---|
3241 | roleContainer.__arContainer__.__frames__ = roleContainer.__arContainer__.__frames__.without(role); |
---|
3242 | |
---|
3243 | // --- adds the player which was selected by the removed role to all other |
---|
3244 | // --- existing roles of the same type |
---|
3245 | for(var i = 0; i !== rolesToCheck.length; ++i){ |
---|
3246 | rolesToCheck[i].addPlayer(player); |
---|
3247 | } |
---|
3248 | } |
---|
3249 | var foundRpcs = getRolePlayerConstraintsForRole(associationRoleConstraint.roleType, roleContainer.__rolePlayerConstraints__); |
---|
3250 | var players = extractPlayersOfConstraints(foundRpcs); |
---|
3251 | roleContainer.__checkARCButtons__(rolesToCheck, players, associationRoleConstraint); |
---|
3252 | roleContainer.__checkORCRoles__(null); |
---|
3253 | } |
---|
3254 | |
---|
3255 | role.setRemoveHandler(removeHandler); |
---|
3256 | }, |
---|
3257 | "getExistingRoles" : function(roleType, players, roles){ |
---|
3258 | var rolesFound = new Array(); |
---|
3259 | if(!roles || roles.length === 0) return rolesFound; |
---|
3260 | |
---|
3261 | var allTypes = roleType && roleType.length !== 0 ? roleType.flatten() : new Array(); |
---|
3262 | var allPlayers = players && players.length !== 0 ? players.flatten() : new Array(); |
---|
3263 | for(var i = 0; i !== roles.length; ++i){ |
---|
3264 | if(allTypes.indexOf(roles[i].getType()) !== -1 && allPlayers.indexOf(roles[i].getPlayer()) !== -1) rolesFound.push(roles[i]); |
---|
3265 | } |
---|
3266 | |
---|
3267 | return rolesFound; |
---|
3268 | }, |
---|
3269 | "__setRoleChangePlayerHandler__" : function(role, roleContainer, arConstraints, orConstraints){ |
---|
3270 | var constraints = null; |
---|
3271 | if(arConstraints && arConstraints.length !== 0) constraints = arConstraints; |
---|
3272 | else if(orConstraints && orConstraints.length !== 0) constraints = orConstraints; |
---|
3273 | else if(arConstraints && orConstraints && arConstraints.length !== 0 && orConstraints.length !== 0) throw "From __setRoleChangePlayerHandler__(): one of the parameters arConstraints or orConstraints must be set to null"; |
---|
3274 | role.__lastPlayer__ = new Array(role.getPlayer()); |
---|
3275 | var select = role.__table__.select("tr." + CLASSES.playerFrame())[0].select("td." + CLASSES.content())[0].select("select")[0]; |
---|
3276 | function setEvent(myself){ |
---|
3277 | select.observe("change", function(event){ |
---|
3278 | role.__lastPlayer__.push(role.getPlayer()); |
---|
3279 | if(role.__lastPlayer__.length > 2) role.__lastPlayer__.shift(); |
---|
3280 | if(!roleContainer || roleContainer.length < 2 || ! constraints || constraints.length === 0) return; |
---|
3281 | role.getLastPlayer = function(){ |
---|
3282 | return role.__lastPlayer__[role.__lastPlayer__.length - 2]; |
---|
3283 | } |
---|
3284 | // --- selects the players which have to be removed or added to |
---|
3285 | // --- the found roles |
---|
3286 | var playerToAdd = new Array(role.getLastPlayer()); |
---|
3287 | var playerToRemove = new Array(role.getPlayer()); |
---|
3288 | |
---|
3289 | // --- collects all roles depending on the same constraint as the passed role |
---|
3290 | var existingRoles = new Array(); |
---|
3291 | for(var i = 0; constraints && i !== constraints.length; ++i){ |
---|
3292 | var roleType = orConstraints ? constraints[i].otherRoleType : constraints[i].roleType; |
---|
3293 | var players = orConstraints ? constraints[i].otherPlayers : constraints[i].players; |
---|
3294 | |
---|
3295 | // --- adds new psi of the roles have to be added |
---|
3296 | for(var j = 0; j !== players.length; ++j){ |
---|
3297 | if(players[j].indexOf(playerToRemove[0]) !== -1){ |
---|
3298 | for(var l = 0; l !== players[j].length; ++l){ |
---|
3299 | if(players[j][l] !== playerToRemove[0]) playerToRemove.push(players[j][l]); |
---|
3300 | } |
---|
3301 | } |
---|
3302 | if(players[j].indexOf(playerToAdd[0]) !== -1){ |
---|
3303 | for(var l = 0; l !== players[j].length; ++l){ |
---|
3304 | if(players[j][l] !== playerToAdd[0]) playerToAdd.push(players[j][l]); |
---|
3305 | } |
---|
3306 | } |
---|
3307 | } |
---|
3308 | |
---|
3309 | var foundRoles = myself.getExistingRoles(roleType, players, roleContainer); |
---|
3310 | for(var j = 0; j !== foundRoles.length; ++j){ |
---|
3311 | existingRoles.push(foundRoles[j]); |
---|
3312 | } |
---|
3313 | } |
---|
3314 | existingRoles = existingRoles.without(role); |
---|
3315 | |
---|
3316 | // --- removes and adds the new selected psi-value |
---|
3317 | // --- and the old deselected psi if the player is another one |
---|
3318 | if(playerToRemove.indexOf(role.getLastPlayer()) === -1){ |
---|
3319 | for(var i = 0; i !== existingRoles.length; ++i){ |
---|
3320 | existingRoles[i].addPlayer(playerToAdd); |
---|
3321 | existingRoles[i].removePlayer(playerToRemove); |
---|
3322 | } |
---|
3323 | } |
---|
3324 | |
---|
3325 | // --- chekcs roles created from otherrole-contraints |
---|
3326 | myself.__checkORCRoles__(role); |
---|
3327 | }); |
---|
3328 | } |
---|
3329 | setEvent(this); |
---|
3330 | }, |
---|
3331 | "__checkORCRoles__" : function(changedRole){ |
---|
3332 | // --- removes all roles created from otherrole-constraints, which |
---|
3333 | // --- currently must not exist |
---|
3334 | var toRemove = new Array(); |
---|
3335 | for(var i = 0; i !== this.__orContainer__.__frames__.length; ++i){ |
---|
3336 | var oRole = this.__orContainer__.__frames__[i]; |
---|
3337 | var orcs = new Array(); // found orcs for the existing orc-roles |
---|
3338 | var checkedOrcs = new Array(); |
---|
3339 | for(var j = 0; this.__otherRoleConstraints__ && j !== this.__otherRoleConstraints__.length; ++j){ |
---|
3340 | var orc = this.__otherRoleConstraints__[j]; |
---|
3341 | if(orc.otherRoleType.flatten().indexOf(oRole.getType()) !== -1 && orc.otherPlayers.flatten().indexOf(oRole.getPlayer()) !== -1) orcs.push(orc); |
---|
3342 | } |
---|
3343 | |
---|
3344 | for(var j = 0; j !== orcs.length; ++j){ |
---|
3345 | for(var k = 0; this.__arContainer__.__frames__ && k !== this.__arContainer__.__frames__.length; ++k){ |
---|
3346 | var aRole = this.__arContainer__.__frames__[k]; |
---|
3347 | if(orcs[j].roleType.flatten().indexOf(aRole.getType()) !== -1 && orcs[j].players.flatten().indexOf(aRole.getPlayer()) !== -1){ |
---|
3348 | checkedOrcs.push(orcs[j]); |
---|
3349 | break; |
---|
3350 | } |
---|
3351 | } |
---|
3352 | } |
---|
3353 | |
---|
3354 | // --- no otherrole-constraints exist for this roles, so they have to be removed |
---|
3355 | if(checkedOrcs.length === 0) toRemove.push(oRole); |
---|
3356 | } |
---|
3357 | for(var i = 0; i !== toRemove.length; ++i){ |
---|
3358 | this.__orContainer__.__frames__ = this.__orContainer__.__frames__.without(toRemove[i]); |
---|
3359 | toRemove[i].remove(); |
---|
3360 | } |
---|
3361 | |
---|
3362 | // --- creates new roles from other role-constraints, which has to exist or are optional |
---|
3363 | if(changedRole) this.__makeRolesFromORC__(changedRole.getType(), changedRole.getPlayer()); |
---|
3364 | }, |
---|
3365 | "getContent" : function(){ |
---|
3366 | if((!this.__orContainer__.__frames__ && this.__orContainer__.frames__.length === 0) || (!this.__arContainer__.__frames__ && this.__arContainer__.__frames__.length === 0)) return null; |
---|
3367 | var roles = new Array(); |
---|
3368 | for(var i = 0; this.__arContainer__.__frames__ && i !== this.__arContainer__.__frames__.length; ++i){ |
---|
3369 | roles.push(this.__arContainer__.__frames__[i].getContent()); |
---|
3370 | } |
---|
3371 | for(var i = 0; this.__orContainer__.__frames__ && i !== this.__orContainer__.__frames__.length; ++i){ |
---|
3372 | roles.push(this.__orContainer__.__frames__[i].getContent()); |
---|
3373 | } |
---|
3374 | return roles; |
---|
3375 | }, |
---|
3376 | "toJSON" : function(){ |
---|
3377 | if((!this.__orContainer__.__frames__ && this.__orContainer__.frames__.length === 0) || (!this.__arContainer__.__frames__ && this.__arContainer__.__frames__.length === 0)) return "null"; |
---|
3378 | var roles = "["; |
---|
3379 | for(var i = 0; this.__arContainer__.__frames__ && i !== this.__arContainer__.__frames__.length; ++i){ |
---|
3380 | roles += this.__arContainer__.__frames__[i].toJSON() + ","; |
---|
3381 | } |
---|
3382 | for(var i = 0; this.__orContainer__.__frames__ && i !== this.__orContainer__.__frames__.length; ++i){ |
---|
3383 | roles += this.__orContainer__.__frames__[i].toJSON() + ","; |
---|
3384 | } |
---|
3385 | return roles.substring(0, roles.length - 1) + "]"; |
---|
3386 | }, |
---|
3387 | "disable" : function(){ |
---|
3388 | this.hideError(); |
---|
3389 | if(this.__orContainer__.__frames__){ |
---|
3390 | for(var i = 0; i !== this.__orContainer__.__frames__.length; ++i) this.__orContainer__.__frames__[i].disable(); |
---|
3391 | } |
---|
3392 | if(this.__arContainer__.__frames__){ |
---|
3393 | for(var i = 0; i !== this.__arContainer__.__frames__.length; ++i) this.__arContainer__.__frames__[i].disable(); |
---|
3394 | } |
---|
3395 | this.__disabled__ = true; |
---|
3396 | }, |
---|
3397 | "enable" : function(){ |
---|
3398 | if(this.__orContainer__.__frames__){ |
---|
3399 | for(var i = 0; i !== this.__orContainer__.__frames__.length; ++i) this.__orContainer__.__frames__[i].enable(); |
---|
3400 | } |
---|
3401 | if(this.__arContainer__.__frames__){ |
---|
3402 | for(var i = 0; i !== this.__arContainer__.__frames__.length; ++i) this.__arContainer__.__frames__[i].enable(); |
---|
3403 | } |
---|
3404 | this.__disable__ = false; |
---|
3405 | }, |
---|
3406 | "isValid" : function(){ |
---|
3407 | var ret = true; |
---|
3408 | var errorStr = ""; |
---|
3409 | |
---|
3410 | var arcs = this.__associationRoleConstraints__; |
---|
3411 | var orcs = this.__otherRoleConstraints__; |
---|
3412 | var rpcs = this.__rolePlayerConstraints__; |
---|
3413 | |
---|
3414 | // --- checks if there exist any constraints |
---|
3415 | if(!arcs || arcs.length === 0){ |
---|
3416 | this.showError("No association-constraints found for this association!"); |
---|
3417 | return false; |
---|
3418 | } |
---|
3419 | |
---|
3420 | if(!rpcs || rpcs.length === 0){ |
---|
3421 | this.showError("No roleplayer-constraints found for this association!"); |
---|
3422 | return false; |
---|
3423 | } |
---|
3424 | |
---|
3425 | // --- collects all used roles depending on associationrole-constraints |
---|
3426 | var allAroles = new Array(); |
---|
3427 | var allAroles2 = new Array(); |
---|
3428 | for(var i = 0; this.__arContainer__.__frames__ && i !== this.__arContainer__.__frames__.length; ++i){ |
---|
3429 | this.__arContainer__.__frames__[i].hideError(); |
---|
3430 | if(this.__arContainer__.__frames__[i].isUsed() === true){ |
---|
3431 | allAroles.push(this.__arContainer__.__frames__[i]); |
---|
3432 | allAroles2.push(this.__arContainer__.__frames__[i]); |
---|
3433 | } |
---|
3434 | } |
---|
3435 | |
---|
3436 | // --- collects all used roles depending on otherrole-constraints |
---|
3437 | var allOroles = new Array(); |
---|
3438 | for(var i = 0; i !== this.__orContainer__.__frames__.length; ++i){ |
---|
3439 | this.__orContainer__.__frames__[i].hideError(); |
---|
3440 | if(this.__orContainer__.__frames__[i].isUsed() === true) |
---|
3441 | allOroles.push(this.__orContainer__.__frames__[i]); |
---|
3442 | } |
---|
3443 | |
---|
3444 | // --- checks all associationrole-constraints |
---|
3445 | var checkedRoles = new Array(); |
---|
3446 | for(var i = 0; i !== arcs.length; ++i){ |
---|
3447 | var currentRoles = new Array(); |
---|
3448 | var rType = arcs[i].roleType.flatten(); |
---|
3449 | var cardMin = parseInt(arcs[i].cardMin); |
---|
3450 | var cardMax = arcs[i].cardMax === MAX_INT ? MMAX_INT : parseInt(arcs[i].cardMax); |
---|
3451 | |
---|
3452 | // --- collects all roles for the current constraint |
---|
3453 | for(var j = 0; j !== allAroles.length; ++j){ |
---|
3454 | if(rType.indexOf(allAroles[j].getType()) !== -1) currentRoles.push(allAroles[j]); |
---|
3455 | } |
---|
3456 | allAroles = allAroles.uniq(); |
---|
3457 | |
---|
3458 | if(cardMin > currentRoles.length){ |
---|
3459 | ret = false; |
---|
3460 | if(errorStr.length !== 0) errorStr += "<br/><br/>"; |
---|
3461 | errorStr += "card-min of the associationrole-constraint card-min: " + cardMin + " card-max: " + cardMax + " for the roletype \"" + rType + " is not satisfied (" + currentRoles.length + ")!"; |
---|
3462 | } |
---|
3463 | if(cardMax !== MMAX_INT && cardMax < currentRoles.length){ |
---|
3464 | ret = false; |
---|
3465 | if(errorStr.length !== 0) errorStr += "<br/><br/>"; |
---|
3466 | errorStr += "card-max of the associationrole-constraint card-min: " + cardMin + " card-max: " + cardMax + " for the roletype \"" + rType + " is not satisfied (" + currentRoles.length + ")!"; |
---|
3467 | } |
---|
3468 | |
---|
3469 | // --- checks roleplayer-constraints for the found roles |
---|
3470 | var currentRpcs = getRolePlayerConstraintsForRole(rType, rpcs); |
---|
3471 | if(currentRpcs.length === 0){ |
---|
3472 | ret = false; |
---|
3473 | for(var j = 0; j !== currentRoles.length; ++j) currentRoles[j].showError("This role does not satisfie any roleplayer-constraint!"); |
---|
3474 | } |
---|
3475 | for(var j = 0; j !== currentRpcs.length; ++j){ |
---|
3476 | var players = currentRpcs[i].players; |
---|
3477 | var pType = currentRpcs[i].playerType.flatten(); |
---|
3478 | cardMin = parseInt(currentRpcs[i].cardMin); |
---|
3479 | cardMax = currentRpcs[i].cardMax === MAX_INT ? MMAX_INT : parseInt(currentRpcs[i].cardMax); |
---|
3480 | var foundRoles = this.getExistingRoles(rType, players, currentRoles); |
---|
3481 | if(cardMin > foundRoles.length){ |
---|
3482 | ret = false; |
---|
3483 | if(errorStr.length !== 0) errorStr += "<br/><br/>"; |
---|
3484 | errorStr += "card-min of the roleplayer-constraint card-min: " + cardMin + " card-max: " + cardMax + " for the roletype \"" + rType + " and the playertype \"" + pType + "\" is not satisfied (" + foundRoles.length + ")!"; |
---|
3485 | } |
---|
3486 | if(cardMax !== MMAX_INT && cardMax < foundRoles.length){ |
---|
3487 | ret = false; |
---|
3488 | if(errorStr.length !== 0) errorStr += "<br/><br/>"; |
---|
3489 | errorStr += "card-max of the roleplayer-constraint card-min: " + cardMin + " card-max: " + cardMax + " for the roletype \"" + rType + " and the playertype \"" + pType + "\" is not satisfied (" + foundRoles.length + ")!"; |
---|
3490 | } |
---|
3491 | // --- marks all found roles from "allAroles" |
---|
3492 | for(var k = 0; k !== foundRoles.length; ++k) checkedRoles.push(foundRoles[k]); |
---|
3493 | } |
---|
3494 | } |
---|
3495 | |
---|
3496 | // --- checks roles that does not belong to any constraint |
---|
3497 | for(var i = 0; i !== checkedRoles.length; ++i) allAroles = allAroles.without(checkedRoles[i]); |
---|
3498 | |
---|
3499 | if(allAroles.length !== 0){ |
---|
3500 | for(var i = 0; i !== allAroles.length; ++i) allAroles[i].showError("This role does not satisfie any associationrole- or roleplayer-constraints!"); |
---|
3501 | } |
---|
3502 | |
---|
3503 | // --- checks otherrole-constraints |
---|
3504 | // --- collects all neede otherrole-constraints |
---|
3505 | var usedOrcs = new Array(); |
---|
3506 | allAroles = allAroles2; |
---|
3507 | for(var i = 0; i !== allAroles.length; ++i){ |
---|
3508 | usedOrcs = usedOrcs.concat(getOtherRoleConstraintsForRole(new Array(allAroles[i].getType()), new Array(allAroles[i].getPlayer()), orcs)); |
---|
3509 | } |
---|
3510 | |
---|
3511 | checkedRole = new Array(); |
---|
3512 | for(var i = 0; i !== usedOrcs.length; ++i){ |
---|
3513 | var players = usedOrcs[i].otherPlayers; |
---|
3514 | var pType = usedOrcs[i].otherPlayerType; |
---|
3515 | var rType = usedOrcs[i].otherRoleType; |
---|
3516 | var cardMin = parseInt(usedOrcs[i].cardMin); |
---|
3517 | var cardMax = usedOrcs[i].cardMax === MAX_INT ? MMAX_INT : parseInt(usedOrcs[i].cardMax); |
---|
3518 | var foundRoles = this.getExistingRoles(rType, players, allOroles); |
---|
3519 | checkedRoles = checkedRoles.concat(foundRoles); |
---|
3520 | if(cardMin > foundRoles.length){ |
---|
3521 | ret = false; |
---|
3522 | if(errorStr.length !== 0) errorStr += "<br/><br/>"; |
---|
3523 | errorStr += "card-min of the otherrole-constraint card-min: " + cardMin + " card-max: " + cardMax + " for the roletype \"" + rType + " and the playertype \"" + pType + "\" is not satisfied (" + foundRoles.length + ")!"; |
---|
3524 | } |
---|
3525 | if(cardMax !== MMAX_INT && cardMax < foundRoles.length){ |
---|
3526 | ret = false; |
---|
3527 | if(errorStr.length !== 0) errorStr += "<br/><br/>"; |
---|
3528 | errorStr += "card-max of the otherrole-constraint card-min: " + cardMin + " card-max: " + cardMax + " for the roletype \"" + rType + " and the playertype \"" + pType + "\" is not satisfied (" + foundRoles.length + ")!"; |
---|
3529 | } |
---|
3530 | } |
---|
3531 | |
---|
3532 | if(ret === false) this.showError(errorStr); |
---|
3533 | else this.hideError(); |
---|
3534 | return ret; |
---|
3535 | }}); |
---|
3536 | |
---|
3537 | |
---|
3538 | // --- representation of an association element |
---|
3539 | var AssociationC = Class.create(ContainerC, {"initialize" : function($super, contents, constraints, owner){ |
---|
3540 | $super(); |
---|
3541 | if(!owner) throw "From NameC(): owner must be set but is null"; |
---|
3542 | if(!owner.__frames__) owner.__frames__ = new Array(); |
---|
3543 | owner.__frames__.push(this); |
---|
3544 | this.__frame__.writeAttribute({"class" : CLASSES.associationFrame()}); |
---|
3545 | this.__table__ = new Element("table", {"class" : CLASSES.associationFrame()}); |
---|
3546 | this.__frame__.insert({"top" : this.__table__}); |
---|
3547 | this.__constraints__ = constraints; |
---|
3548 | this.__contents__ = contents; |
---|
3549 | this.__constraints__ = constraints; |
---|
3550 | this.__owner__ = owner; |
---|
3551 | this.__dblClickHandler__ = dblClickHandlerF; |
---|
3552 | this.__isMinimized__ = false; |
---|
3553 | |
---|
3554 | try{ |
---|
3555 | var itemIdentityContent = null; |
---|
3556 | var typeContent = null; |
---|
3557 | var scopesContent = null; |
---|
3558 | var rolesContent = null; |
---|
3559 | if(contents){ |
---|
3560 | itemIdentityContent = contents.itemIdentities; |
---|
3561 | typeContent = contents.type; |
---|
3562 | scopesContent = contents.scopes; |
---|
3563 | rolesContent = contents.roles; |
---|
3564 | } |
---|
3565 | |
---|
3566 | // --- control row + ItemIdentity |
---|
3567 | makeControlRow(this, 4, itemIdentityContent); |
---|
3568 | checkRemoveAddButtons(owner, 1, -1, this); |
---|
3569 | setRemoveAddHandler(this, this.__constraints__, owner, 1, -1, function(){ |
---|
3570 | return new AssociationC(null, constraints, owner); |
---|
3571 | }); |
---|
3572 | |
---|
3573 | // --- type |
---|
3574 | var types = makeTypes(this, typeContent, constraints); |
---|
3575 | if(types.flatten().length === 0 || types.flatten()[0].strip().length === 0 || !constraints || constraints.length === 0) this.hideAddButton(); |
---|
3576 | |
---|
3577 | // --- scopes |
---|
3578 | var currentConstraint = this.getCurrentConstraint(); |
---|
3579 | this.__scope__ = new ScopeContainerC(scopesContent, currentConstraint && currentConstraint.scopeConstraints ? currentConstraint.scopeConstraints : null); |
---|
3580 | this.__table__.insert({"bottom" : newRow(CLASSES.scopeContainer(), "Scope", this.__scope__.getFrame())}); |
---|
3581 | |
---|
3582 | // --- roles |
---|
3583 | var _roleConstraints = null; |
---|
3584 | var _playerConstraints = null; |
---|
3585 | var _otherRoleConstraints = null; |
---|
3586 | var cc = this.getCurrentConstraint(); |
---|
3587 | if(cc){ |
---|
3588 | _roleConstraints = cc.associationRoleConstraints; |
---|
3589 | _playerConstraints = cc.rolePlayerConstraints; |
---|
3590 | _otherRoleConstraints = cc.otherRoleConstraints; |
---|
3591 | } |
---|
3592 | |
---|
3593 | this.__roles__ = new RoleContainerC(rolesContent, _roleConstraints, _playerConstraints, _otherRoleConstraints, this); |
---|
3594 | this.__table__.insert({"bottom" : newRow(CLASSES.roleContainer(), "Roles", this.__roles__.getFrame())}); |
---|
3595 | |
---|
3596 | // --- registers the onChangeHandler of the Type-selectrow |
---|
3597 | onTypeChangeScope(this, null, null, "association"); |
---|
3598 | |
---|
3599 | function setDblClickHandler(myself){ |
---|
3600 | myself.getFrame().observe("dblclick", function(event){ |
---|
3601 | myself.__dblClickHandler__(owner, event); |
---|
3602 | }); |
---|
3603 | } |
---|
3604 | setDblClickHandler(this); |
---|
3605 | } |
---|
3606 | catch(err){ |
---|
3607 | alert("From AssociationC(): " + err); |
---|
3608 | } |
---|
3609 | }, |
---|
3610 | "resetValues" : function(){ |
---|
3611 | var cc = this.getCurrentConstraint(); |
---|
3612 | this.__scope__.resetValues(null, (cc ? cc.scopeConstraints : null)); |
---|
3613 | |
---|
3614 | var _roleConstraints = null; |
---|
3615 | var _playerConstraints = null; |
---|
3616 | var _otherRoleConstraints = null; |
---|
3617 | if(cc){ |
---|
3618 | _roleConstraints = cc.associationRoleConstraints; |
---|
3619 | _playerConstraints = cc.rolePlayerConstraints; |
---|
3620 | _otherRoleConstraints = cc.otherRoleConstraints; |
---|
3621 | } |
---|
3622 | this.__roles__.resetValues(_roleConstraints, _playerConstraints, _otherRoleConstraints); |
---|
3623 | }, |
---|
3624 | "getContent" : function(){ |
---|
3625 | if(!this.isUsed()) return null; |
---|
3626 | var type = this.__type__.__frames__[0].getContent(); |
---|
3627 | return {"itemIdentities" : this.__itemIdentity__.getContent(true, true), |
---|
3628 | "type" : type ? new Array(type) : null, |
---|
3629 | "scopes" : this.__scope__.getContent(), |
---|
3630 | "roles" : this.__roles__.getContent()}; |
---|
3631 | }, |
---|
3632 | "toJSON" : function(){ |
---|
3633 | if(!this.isUsed()) return "null"; |
---|
3634 | return "{\"itemIdentities\":" + this.__itemIdentity__.toJSON(true, true) + |
---|
3635 | ",\"type\":[" + this.__type__.__frames__[0].toJSON() + "]" + |
---|
3636 | ",\"scopes\":" + this.__scope__.toJSON() + |
---|
3637 | ",\"roles\":" + this.__roles__.toJSON() + "}"; |
---|
3638 | }, |
---|
3639 | "getCurrentConstraint" : function(){ |
---|
3640 | if(!this.__constraints__ || this.__constraints__.length === 0) return null; |
---|
3641 | var currentConstraint = null; |
---|
3642 | for(var i = 0; i !== this.__constraints__.length; ++i){ |
---|
3643 | var aType = this.__constraints__[i].associationType; |
---|
3644 | aType = aType.flatten(); |
---|
3645 | if(aType.indexOf(this.__type__.__frames__[0].getContent()) !== -1){ |
---|
3646 | currentConstraint = this.__constraints__[i]; |
---|
3647 | break; |
---|
3648 | } |
---|
3649 | } |
---|
3650 | |
---|
3651 | return currentConstraint; |
---|
3652 | }, |
---|
3653 | "isValid" : function(){ |
---|
3654 | if(!this.getCurrentConstraint()){ |
---|
3655 | this.showError("No constraints found for this association!"); |
---|
3656 | return false; |
---|
3657 | } |
---|
3658 | else { |
---|
3659 | this.hideError(); |
---|
3660 | } |
---|
3661 | |
---|
3662 | return this.__roles__.isValid() && this.__scope__.isValid(); |
---|
3663 | }, |
---|
3664 | "disable" : function(){ |
---|
3665 | this.hideError(); |
---|
3666 | this.__itemIdentity__.disable(); |
---|
3667 | this.__roles__.disable(); |
---|
3668 | this.__type__.__frames__[0].disable(); |
---|
3669 | this.__scope__.disable(); |
---|
3670 | this.hideRemoveButton(); |
---|
3671 | this.hideAddButton(); |
---|
3672 | this.getFrame().writeAttribute({"class" : CLASSES.disabled()}); |
---|
3673 | this.__disabled__ = true; |
---|
3674 | }, |
---|
3675 | "enable" : function(){ |
---|
3676 | this.__itemIdentity__.enable(); |
---|
3677 | this.__roles__.enable(); |
---|
3678 | this.__type__.__frames__[0].enable(); |
---|
3679 | this.__scope__.enable(); |
---|
3680 | if(this.__owner__.__frames__.length > 1 || !this.__constraints__ || this.__constraints__.length !== 0) this.showRemoveButton(); |
---|
3681 | if(this.__constraints__ && this.__constraints__.length !== 0) this.showAddButton(); |
---|
3682 | this.getFrame().writeAttribute({"class" : CLASSES.associationFrame()}); |
---|
3683 | this.__disabled__ = false; |
---|
3684 | }, |
---|
3685 | "minimize" : function(){ |
---|
3686 | if(this.__isMinimized__ === false) { |
---|
3687 | this.getFrame().select("tr." + CLASSES.showHiddenRows())[0].show(); |
---|
3688 | this.getFrame().select("tr." + CLASSES.itemIdentityFrame())[0].hide(); |
---|
3689 | this.getFrame().select("tr." + CLASSES.typeFrame())[0].hide(); |
---|
3690 | this.getFrame().select("tr." + CLASSES.scopeContainer())[0].hide(); |
---|
3691 | this.getFrame().select("tr." + CLASSES.roleContainer())[0].hide(); |
---|
3692 | this.__isMinimized__ = true; |
---|
3693 | } |
---|
3694 | else { |
---|
3695 | this.getFrame().select("tr." + CLASSES.showHiddenRows())[0].hide(); |
---|
3696 | this.getFrame().select("tr." + CLASSES.itemIdentityFrame())[0].show(); |
---|
3697 | this.getFrame().select("tr." + CLASSES.typeFrame())[0].show(); |
---|
3698 | this.getFrame().select("tr." + CLASSES.scopeContainer())[0].show(); |
---|
3699 | this.getFrame().select("tr." + CLASSES.roleContainer())[0].show(); |
---|
3700 | this.__isMinimized__ = false; |
---|
3701 | } |
---|
3702 | }}); |
---|
3703 | |
---|
3704 | |
---|
3705 | // --- contains all fragment's associations depending on the main topic |
---|
3706 | var AssociationContainerC = Class.create(ContainerC, {"initialize" : function($super, contents, constraints){ |
---|
3707 | $super(); |
---|
3708 | this.__minimized__ = false; |
---|
3709 | try{ |
---|
3710 | this.__frame__ .writeAttribute({"class" : CLASSES.associationContainer()}); |
---|
3711 | this.__table__ = new Element("table", {"class" : CLASSES.associationContainer()}); |
---|
3712 | this.__frame__.insert({"top" : this.__table__}); |
---|
3713 | this.__caption__ = new Element("caption", {"class" : CLASSES.clickable()}).update("Associations"); |
---|
3714 | this.__table__.insert({"top" : this.__caption__}) |
---|
3715 | this.__container__ = new Object(); |
---|
3716 | |
---|
3717 | for(var i = 0; contents && i != contents.length; ++i){ |
---|
3718 | var association = new AssociationC(contents[i], constraints, this.__container__); |
---|
3719 | var tr = new Element("tr", {"class" : CLASSES.associationFrame()}); |
---|
3720 | var td = new Element("td", {"class" : CLASSES.content()}); |
---|
3721 | td.update(association.getFrame()); |
---|
3722 | tr.update(td); |
---|
3723 | this.__table__.insert({"bottom" : tr}); |
---|
3724 | } |
---|
3725 | if(!constraints || constraints.length === 0){ |
---|
3726 | for(var i = 0; i !== this.__container__.__frames__.length; ++i){ |
---|
3727 | this.__container__.__frames__[i].hideAddButton(); |
---|
3728 | } |
---|
3729 | } |
---|
3730 | |
---|
3731 | if(!this.__container__.__frames__ && constraints && constraints.length !== 0){ |
---|
3732 | var association = new AssociationC(null, constraints, this.__container__); |
---|
3733 | var tr = new Element("tr", {"class" : CLASSES.associationFrame()}); |
---|
3734 | var td = new Element("td", {"class" : CLASSES.content()}); |
---|
3735 | td.update(association.getFrame()); |
---|
3736 | tr.update(td); |
---|
3737 | this.__table__.insert({"bottom" : tr}); |
---|
3738 | association.disable(); |
---|
3739 | } |
---|
3740 | function setMinimizeHandler(myself){ |
---|
3741 | myself.__caption__.observe("click", function(event){ |
---|
3742 | myself.minimize(); |
---|
3743 | }); |
---|
3744 | } |
---|
3745 | setMinimizeHandler(this); |
---|
3746 | } |
---|
3747 | catch(err){ |
---|
3748 | alert("From AssociationContainerC(): " + err); |
---|
3749 | } |
---|
3750 | }, |
---|
3751 | "getContent" : function(){ |
---|
3752 | var associations = new Array(); |
---|
3753 | for(var i = 0; this.__container__.__frames__ && i !== this.__container__.__frames__.length; ++i){ |
---|
3754 | if(this.__container__.__frames__[i].isUsed() === true) associations.push(this.__container__.__frames__[i].getContent()); |
---|
3755 | } |
---|
3756 | if(associations.length === 0) return null; |
---|
3757 | return associations; |
---|
3758 | }, |
---|
3759 | "toJSON" : function(){ |
---|
3760 | var associations = "["; |
---|
3761 | for(var i = 0; this.__container__.__frames__ && i !== this.__container__.__frames__.length; ++i){ |
---|
3762 | if(this.__container__.__frames__[i].isUsed() === true) associations += this.__container__.__frames__[i].toJSON() +","; |
---|
3763 | } |
---|
3764 | |
---|
3765 | if(associations === "[") return "null"; |
---|
3766 | return associations.substring(0, associations.length - 1) + "]"; |
---|
3767 | }, |
---|
3768 | "isValid" : function(){ |
---|
3769 | var ret = true; |
---|
3770 | for(var i = 0; i !== this.__container__.__frames__.length; ++i){ |
---|
3771 | if(this.__container__.__frames__[i].isUsed() === true && this.__container__.__frames__[i].isValid() === false) |
---|
3772 | ret = false; |
---|
3773 | } |
---|
3774 | |
---|
3775 | return ret; |
---|
3776 | }, |
---|
3777 | "minimize" : function(){ |
---|
3778 | var rows = this.__table__.select("tr." + CLASSES.associationFrame()); |
---|
3779 | for(var i = 0; i != rows.length; ++i){ |
---|
3780 | if(this.__minimized__ === false) rows[i].hide(); |
---|
3781 | else rows[i].show(); |
---|
3782 | } |
---|
3783 | this.__minimized__ = !this.__minimized__; |
---|
3784 | }, |
---|
3785 | "getReferencedTopics" : function(){ |
---|
3786 | var referencedTopics = new Array(); |
---|
3787 | var associations = this.getContent(); |
---|
3788 | if(associations){ |
---|
3789 | for(var i = 0; i !== associations.length; ++i){ |
---|
3790 | var assType = associations[i].type; |
---|
3791 | if(referencedTopics.indexOf(assType[0]) === -1) referencedTopics.push(assType[0]); |
---|
3792 | var scopes = associations[i].scopes; |
---|
3793 | if(scopes){ |
---|
3794 | for(var j = 0; j !== scopes.length; ++j){ |
---|
3795 | if(referencedTopics.indexOf(scopes[j][0]) === -1) referencedTopics.push(scopes[j][0]); |
---|
3796 | } |
---|
3797 | } |
---|
3798 | var roles = associations[i].roles; |
---|
3799 | if(roles){ |
---|
3800 | for(var j = 0; j !== roles.length; ++j){ |
---|
3801 | var roleType = roles[j].type; |
---|
3802 | if(roleType && referencedTopics.indexOf(roleType[0]) === -1) referencedTopics.push(roleType[0]); |
---|
3803 | var player = roles[j].topicRef; |
---|
3804 | if(player && referencedTopics.indexOf(player[0]) === -1) referencedTopics.push(player[0]); |
---|
3805 | } |
---|
3806 | } |
---|
3807 | } |
---|
3808 | } |
---|
3809 | return referencedTopics; |
---|
3810 | }}); |
---|
3811 | |
---|
3812 | |
---|
3813 | // --- Representation of a topic map if frame. |
---|
3814 | var TmIdC = Class.create(ContainerC, {"initialize" : function($super, contents){ |
---|
3815 | $super(); |
---|
3816 | try{ |
---|
3817 | this.__frame__.writeAttribute({"class" : CLASSES.itemIdentityFrame()}); |
---|
3818 | this.__container__ = new Object(); |
---|
3819 | this.__frame__.writeAttribute({"class" : CLASSES.tmIdFrame()}); |
---|
3820 | this.__table__ = new Element("table", {"class" : CLASSES.tmIdFrame()}); |
---|
3821 | this.__frame__.insert({"top" : this.__table__}); |
---|
3822 | this.__caption__ = new Element("caption", {"class" : CLASSES.clickable()}).update("Topic Map ID"); |
---|
3823 | this.__table__.update(this.__caption__); |
---|
3824 | var value = contents && contents.length !== 0 ? decodeURI(contents[0]) : ""; |
---|
3825 | this.__contentrow__ = new Element("input", {"type" : "text", "value" : value, "size" : 48}); |
---|
3826 | this.__tr__ = new Element("tr", {"class" : CLASSES.tmIdFrame()}); |
---|
3827 | var td =new Element("td", {"class" : CLASSES.content()}); |
---|
3828 | this.__tr__.update(td); |
---|
3829 | td.update(this.__contentrow__); |
---|
3830 | this.__table__.insert({"bottom" : this.__tr__}); |
---|
3831 | |
---|
3832 | this.__minimized__ = false; |
---|
3833 | function setMinimizeHandler(myself){ |
---|
3834 | myself.__caption__.observe("click", function(event){ |
---|
3835 | myself.minimize(); |
---|
3836 | }); |
---|
3837 | } |
---|
3838 | setMinimizeHandler(this); |
---|
3839 | } |
---|
3840 | catch(err){ |
---|
3841 | alert("From tmIdC(): " + err); |
---|
3842 | } |
---|
3843 | }, |
---|
3844 | "getContent" : function(){ |
---|
3845 | if(this.__contentrow__.value.strip().length === 0) return null; |
---|
3846 | return new Array(encodeURI(this.__contentrow__.value.strip())); |
---|
3847 | }, |
---|
3848 | "toJSON" : function(){ |
---|
3849 | return (this.getContent() === null ? "null" : this.getContent().toJSON()); |
---|
3850 | }, |
---|
3851 | "isValid" : function(){ |
---|
3852 | if(this.getContent() !== null){ |
---|
3853 | this.hideError(); |
---|
3854 | return true; |
---|
3855 | } |
---|
3856 | else { |
---|
3857 | this.showError("Please enter a Topic Map ID!"); |
---|
3858 | return false; |
---|
3859 | } |
---|
3860 | }, |
---|
3861 | "minimize": function(){ |
---|
3862 | if(this.__minimized__ === false) this.__tr__.hide(); |
---|
3863 | else this.__tr__.show(); |
---|
3864 | |
---|
3865 | this.__minimized__ = !this.__minimized__; |
---|
3866 | }}); |
---|
3867 | |
---|
3868 | |
---|
3869 | // --- A handler for the dblclick-event. So a frame can be disabled or enabled. |
---|
3870 | function dblClickHandlerF(owner, event) |
---|
3871 | { |
---|
3872 | if(owner.__frames__.length === 1){ |
---|
3873 | if(owner.__frames__[0].isUsed() === true){ |
---|
3874 | owner.__frames__[0].disable(); |
---|
3875 | } |
---|
3876 | else { |
---|
3877 | if(!owner.__frames__[0].__parentElem__ || owner.__frames__[0].__parentElem__.isUsed() === true) owner.__frames__[0].enable(); |
---|
3878 | } |
---|
3879 | } |
---|
3880 | } |
---|
3881 | |
---|
3882 | |
---|
3883 | // --- helper function to create a dom-fragment of the form |
---|
3884 | // --- <tr class="rowClass"><td class="description">description</td> |
---|
3885 | //---- <td class="content">content</td></tr> |
---|
3886 | function newRow(rowClass, description, content) |
---|
3887 | { |
---|
3888 | var tr = new Element("tr", {"class" : rowClass}); |
---|
3889 | tr.insert({"top" : new Element("td", {"class" : CLASSES.description()}).update(description)}); |
---|
3890 | tr.insert({"bottom" : new Element("td", {"class" : CLASSES.content()}).update(content)}); |
---|
3891 | return tr; |
---|
3892 | } |
---|
3893 | |
---|
3894 | |
---|
3895 | // --- Helper function for the constructors of all classes |
---|
3896 | // --- of the type FrameC. |
---|
3897 | // --- There will be set the remome and add handler. |
---|
3898 | function setRemoveAddHandler(myself, constraint, owner, min, max, call) |
---|
3899 | { |
---|
3900 | myself.__remove__.stopObserving(); |
---|
3901 | myself.__add__.stopObserving(); |
---|
3902 | myself.__remove__.observe("click", function(event){ |
---|
3903 | var disabled = false; |
---|
3904 | try{ disabled = myself.__disabled__; } catch(err){ }; |
---|
3905 | if(disabled === false){ |
---|
3906 | myself.remove(); |
---|
3907 | owner.__frames__ = owner.__frames__.without(myself); |
---|
3908 | if(min >= owner.__frames__.length && constraint){ |
---|
3909 | for(var i = 0; i != owner.__frames__.length; ++i){ |
---|
3910 | owner.__frames__[i].hideRemoveButton(); |
---|
3911 | } |
---|
3912 | } |
---|
3913 | if((max === -1 || max > owner.__frames__.length) && constraint){ |
---|
3914 | for(var i = 0; i != owner.__frames__.length; ++i){ |
---|
3915 | owner.__frames__[i].showAddButton(); |
---|
3916 | } |
---|
3917 | } |
---|
3918 | } |
---|
3919 | }); |
---|
3920 | |
---|
3921 | myself.__add__.observe("click", function(event){ |
---|
3922 | var disabled = false; |
---|
3923 | try{ disabled = myself.__disabled__; } catch(err){ }; |
---|
3924 | if(disabled === false){ |
---|
3925 | var newElem = call(); |
---|
3926 | myself.append(newElem.getFrame()); |
---|
3927 | if((myself.remove === true && min !== -1 && owner.__frames__.length > min) || !constraint){ |
---|
3928 | for(var i = 0; i != owner.__frames__.length; ++i){ |
---|
3929 | owner.__frames__[i].showRemoveButton(); |
---|
3930 | } |
---|
3931 | } |
---|
3932 | if((max > -1 && max <= owner.__frames__.length) || !constraint){ |
---|
3933 | for(var i = 0; i != owner.__frames__.length; ++i){ |
---|
3934 | owner.__frames__[i].hideAddButton(); |
---|
3935 | } |
---|
3936 | } |
---|
3937 | } |
---|
3938 | }); |
---|
3939 | } |
---|
3940 | |
---|
3941 | |
---|
3942 | // --- Helper function for the constructors of all classes |
---|
3943 | // --- of the type FrameC and some of the type ContainerC. |
---|
3944 | // --- There will be checked the visibility of the remove and |
---|
3945 | // --- add buttons. |
---|
3946 | function checkRemoveAddButtons(owner, min, max, myself) |
---|
3947 | { |
---|
3948 | var constraint = true; |
---|
3949 | if(myself && !myself.__constraint__ && (!myself.__constraints__ || myself.__constraints__.length === 0)) constraint = false; |
---|
3950 | |
---|
3951 | if(min >= owner.__frames__.length && constraint === true){ |
---|
3952 | for(var i = 0; i != owner.__frames__.length; ++i){ |
---|
3953 | owner.__frames__[i].hideRemoveButton(); |
---|
3954 | } |
---|
3955 | } |
---|
3956 | |
---|
3957 | if((min > -1 && min < owner.__frames__.length) || constraint === false){ |
---|
3958 | for(var i = 0; i != owner.__frames__.length; ++i){ |
---|
3959 | owner.__frames__[i].showRemoveButton(); |
---|
3960 | } |
---|
3961 | } |
---|
3962 | |
---|
3963 | if((max > -1 && max <= owner.__frames__.length) || constraint === false){ |
---|
3964 | for(var i = 0; i != owner.__frames__.length; ++i){ |
---|
3965 | owner.__frames__[i].hideAddButton(); |
---|
3966 | } |
---|
3967 | } |
---|
3968 | |
---|
3969 | if((max === -1 || max > owner.__frames__.length) && constraint === true){ |
---|
3970 | for(var i = 0; i != owner.__frames__.length; ++i){ |
---|
3971 | owner.__frames__[i].showAddButton(); |
---|
3972 | } |
---|
3973 | } |
---|
3974 | } |
---|
3975 | |
---|
3976 | |
---|
3977 | // --- creates a control row for NameC, OccurrenceC and VariantC with a nested ItemIdentity frame. |
---|
3978 | function makeControlRow(myself, rowspan, itemIdentities) |
---|
3979 | { |
---|
3980 | var tr = new Element("tr", {"class" : CLASSES.itemIdentityFrame()}); |
---|
3981 | var tdCtrl = new Element("td", {"class" : CLASSES.controlColumn(), "rowspan" : rowspan}); |
---|
3982 | tr.insert({"top" : tdCtrl}) |
---|
3983 | var tdDesc = new Element("td", {"class" : CLASSES.description()}).update("ItemIdentity"); |
---|
3984 | tr.insert({"bottom" : tdDesc}); |
---|
3985 | var min = new Element("span", {"class" : CLASSES.clickable()}).update("«"); |
---|
3986 | myself.__min__ = min; |
---|
3987 | myself.__remove__ = new Element("span", {"class" : CLASSES.clickable()}).update("-"); |
---|
3988 | myself.__add__ = new Element("span", {"class" : CLASSES.clickable()}).update("+"); |
---|
3989 | tdCtrl.insert({"top" : min}); |
---|
3990 | tdCtrl.insert({"bottom" : "<br/>"}); |
---|
3991 | tdCtrl.insert({"bottom" : myself.__remove__}); |
---|
3992 | tdCtrl.insert({"bottom" : "<br/>"}); |
---|
3993 | tdCtrl.insert({"bottom" : myself.__add__}); |
---|
3994 | var tdCont = new Element("td", {"class" : CLASSES.content()}); |
---|
3995 | tr.insert({"bottom" : tdCont}); |
---|
3996 | myself.__itemIdentity__ = new ItemIdentityC(itemIdentities, myself); |
---|
3997 | tdCont.insert({"top" : myself.__itemIdentity__.getFrame()}); |
---|
3998 | myself.__table__.insert({"bottom" : tr}); |
---|
3999 | |
---|
4000 | var trCtrl = new Element("tr", {"class" : CLASSES.showHiddenRows()}); |
---|
4001 | trCtrl.insert({"top" : new Element("td", {"class" : CLASSES.clickable()}).update("»")}); |
---|
4002 | myself.__table__.insert({"top" : trCtrl}); |
---|
4003 | trCtrl.hide(); |
---|
4004 | trCtrl.observe("click", function(){ |
---|
4005 | /*var trs = myself.__table__.select("tr"); |
---|
4006 | for(var i = 0; i != trs.length; ++i) trs[i].show(); |
---|
4007 | trCtrl.hide();*/ |
---|
4008 | try{myself.minimize();}catch(err){ alert("err: " + err); } |
---|
4009 | }); |
---|
4010 | |
---|
4011 | // --- min click-handler |
---|
4012 | min.observe("click", function(event){ |
---|
4013 | /* |
---|
4014 | var trs = myself.__table__.select("tr"); |
---|
4015 | for(var i = 0; i != trs.length; ++i){ |
---|
4016 | if(i === 0) trs[i].show(); |
---|
4017 | else trs[i].hide(); |
---|
4018 | } |
---|
4019 | */ |
---|
4020 | try{myself.minimize();}catch(err){ alert("err: " + err); } |
---|
4021 | }); |
---|
4022 | } |
---|
4023 | |
---|
4024 | |
---|
4025 | // --- This function adds a onchange handler to the type-selct-element |
---|
4026 | // --- of the instance passed through the variable myself. |
---|
4027 | // --- On changing there will be reset the scope frame to the corresponding |
---|
4028 | // --- type and when what is set to "occurrence" there will be set a corresponding |
---|
4029 | // --- datatype-value. |
---|
4030 | function onTypeChangeScope(myself, contents, constraints, what) |
---|
4031 | { |
---|
4032 | try{ |
---|
4033 | var select = myself.__table__.select("tr." + CLASSES.typeFrame())[0].select("td." + CLASSES.content())[0].select("select")[0]; |
---|
4034 | select.observe("change", function(event){ |
---|
4035 | var type = event.element().value; |
---|
4036 | |
---|
4037 | var foundIdx = -1; |
---|
4038 | if(what === "name"){ |
---|
4039 | for(var i = 0; constraints && i !== constraints.length; ++i){ |
---|
4040 | if(foundIdx !== -1) break; |
---|
4041 | for(var j = 0; j !== constraints[i].nameType.length; ++j){ |
---|
4042 | if(foundIdx !== -1) break; |
---|
4043 | if(constraints[i].nameType[j] === type){ |
---|
4044 | foundIdx = i; |
---|
4045 | break; |
---|
4046 | } |
---|
4047 | } |
---|
4048 | } |
---|
4049 | myself.__scope__.resetValues(contents, (foundIdx === -1 ? null : constraints[foundIdx].scopeConstraints)); |
---|
4050 | } |
---|
4051 | else if(what === "occurrence"){ |
---|
4052 | for(var i = 0; constraints && i !== constraints.length; ++i){ |
---|
4053 | if(foundIdx !== -1) break; |
---|
4054 | for(var j = 0; j !== constraints[i].occurrenceType.length; ++j){ |
---|
4055 | if(foundIdx !== -1) break; |
---|
4056 | if(constraints[i].occurrenceType[j] === type){ |
---|
4057 | foundIdx = i; |
---|
4058 | break; |
---|
4059 | } |
---|
4060 | } |
---|
4061 | } |
---|
4062 | if(foundIdx !== -1 && constraints[foundIdx].datatypeConstraint){ |
---|
4063 | var dc = constraints[foundIdx].datatypeConstraint; |
---|
4064 | myself.__datatype__.__frames__[0].getFrame().select("input")[0].writeAttribute({"readonly" : "readonly"}); |
---|
4065 | myself.__datatype__.__frames__[0].getFrame().select("input")[0].setValue(dc); |
---|
4066 | } |
---|
4067 | else { |
---|
4068 | myself.__datatype__.__frames__[0].getFrame().select("input")[0].writeAttribute({"value" : ""}); |
---|
4069 | myself.__datatype__.__frames__[0].getFrame().select("input")[0].removeAttribute("readonly"); |
---|
4070 | } |
---|
4071 | myself.__scope__.resetValues(contents, (foundIdx === -1 ? null : constraints[foundIdx].scopeConstraints)); |
---|
4072 | } |
---|
4073 | else if(what === "variant"){ |
---|
4074 | // do nothing all values will be stored |
---|
4075 | } |
---|
4076 | else if(what === "association"){ |
---|
4077 | myself.resetValues(); |
---|
4078 | } |
---|
4079 | }); |
---|
4080 | } |
---|
4081 | catch(err){} |
---|
4082 | } |
---|
4083 | |
---|
4084 | |
---|
4085 | // --- sets the resource value and datatype of names and occurrences |
---|
4086 | function makeResource(myself, content, constraints, datatypeConstraint, cssTitle, size) |
---|
4087 | { |
---|
4088 | if(!size) size = {"rows" : 3, "cols" : 60}; |
---|
4089 | var value = ""; |
---|
4090 | var datatype = ""; |
---|
4091 | if(content && content.resourceRef && content.resourceRef.length !== 0){ |
---|
4092 | value = content.resourceRef; |
---|
4093 | datatype = ANY_URI; |
---|
4094 | } |
---|
4095 | else if(content && content.resourceData){ |
---|
4096 | value = content.resourceData.value; |
---|
4097 | datatype = content.resourceData.datatype; |
---|
4098 | } |
---|
4099 | |
---|
4100 | try{ |
---|
4101 | this.__value__.remove(); |
---|
4102 | this.__value__ = null; |
---|
4103 | }catch(err){} |
---|
4104 | try{ |
---|
4105 | this.__datatype__.__frames__[0].remove(); |
---|
4106 | this.__datatype__ = new Object(); |
---|
4107 | }catch(err){} |
---|
4108 | myself.__value__ = new Element("textarea", size).setValue(value); |
---|
4109 | myself.__table__.insert({"bottom" : newRow(CLASSES.valueFrame(), "Resource Value", myself.__value__)}); |
---|
4110 | if(cssTitle && cssTitle.length !== 0) myself.__value__.writeAttribute({"title" : cssTitle}); |
---|
4111 | |
---|
4112 | // --- datatype |
---|
4113 | myself.__datatype__ = new Object(); |
---|
4114 | if((datatypeConstraint && datatypeConstraint.length !== 0) || datatype === ANY_URI){ |
---|
4115 | new TextrowC(datatypeConstraint, datatypeConstraint, myself.__datatype__, 1, 1, null); |
---|
4116 | myself.__datatype__.__frames__[0].getFrame().select("input")[0].writeAttribute({"readonly" : "readonly"}); |
---|
4117 | myself.__datatypeIsSet__ = true; |
---|
4118 | } |
---|
4119 | else { |
---|
4120 | new TextrowC(datatype, ".*", myself.__datatype__, 1, 1, null); |
---|
4121 | myself.__datatypeIsSet__ = false; |
---|
4122 | } |
---|
4123 | myself.__table__.insert({"bottom" : newRow(CLASSES.datatypeFrame(), "Datatype", myself.__datatype__.__frames__[0].getFrame())}); |
---|
4124 | } |
---|
4125 | |
---|
4126 | |
---|
4127 | // --- Orders the passed contents to a corresponding constraint. |
---|
4128 | // --- There will be searched for every content the constraint |
---|
4129 | // --- with the longest string.length of the regular expression. |
---|
4130 | // --- If there is a constraint invalidated by card-min |
---|
4131 | // --- there will be tried to move some contents to other constraint |
---|
4132 | // --- with a matching regular expression and a card-min/card-max that is |
---|
4133 | // --- not bad. |
---|
4134 | // --- If for types ist set to an array of a length > 0, the constraint |
---|
4135 | // --- and content type must be for a name or occurrence. |
---|
4136 | // --- The return value is an object of the form |
---|
4137 | // --- {"constraintsAndContents" : constraintsAndContents, "contents" : contents} |
---|
4138 | // --- constraintsAndContents contains all constraints with an array of contents |
---|
4139 | // --- belonging to the constraint, contents is an array of all contents |
---|
4140 | // --- which were passed to this function without the matched contents for found |
---|
4141 | // --- constraints. |
---|
4142 | function makeConstraintsAndContents(contents, simpleConstraints, forTypes) |
---|
4143 | { |
---|
4144 | var isForTypes = forTypes && forTypes.length !== 0; |
---|
4145 | |
---|
4146 | var constraintsAndContents = new Array(); |
---|
4147 | for(var j = 0; j !== contents.length; ++j){ |
---|
4148 | // --- searches only for contents that have the given type of the current constraint |
---|
4149 | if(isForTypes){ |
---|
4150 | var cContentIsInConstraint = false; |
---|
4151 | for(var k = 0; contents[j].type && k !== contents[j].type.length; ++k){ |
---|
4152 | if(forTypes.indexOf(contents[j].type[k]) !== -1){ |
---|
4153 | cContentIsInConstraint = true; |
---|
4154 | break; |
---|
4155 | } |
---|
4156 | } |
---|
4157 | // --- cContent's type is not in the current constraint |
---|
4158 | if(cContentIsInConstraint === false) continue; |
---|
4159 | } |
---|
4160 | |
---|
4161 | // --- searches a constraint for every existing content |
---|
4162 | var tmpConstraint = null; |
---|
4163 | for(var k = 0; k !== simpleConstraints.length; ++k){ |
---|
4164 | var rex = new RegExp(simpleConstraints[k].regexp); |
---|
4165 | var contentValue = (isForTypes === true ? contents[j].value : contents[j]); |
---|
4166 | if(!contentValue){ // must be an occurrence |
---|
4167 | if(contents[j].resourceRef) contentValue = contents[j].resourceRef; |
---|
4168 | else if(contents[j].resourceData) contentValue = contents[j].resourceData.value; |
---|
4169 | } |
---|
4170 | if(rex.match(contentValue) === true && (tmpConstraint === null || (tmpConstraint && (simpleConstraints[k].regexp.length > tmpConstraint.regexp.length)))){ |
---|
4171 | tmpConstraint = simpleConstraints[k]; |
---|
4172 | } |
---|
4173 | } |
---|
4174 | if(tmpConstraint){ |
---|
4175 | var found = false; |
---|
4176 | for(var k = 0; k !== constraintsAndContents.length; ++k){ |
---|
4177 | if(constraintsAndContents[k].constraint === tmpConstraint){ |
---|
4178 | constraintsAndContents[k].contents.push(contents[j]); |
---|
4179 | found = true; |
---|
4180 | break; |
---|
4181 | } |
---|
4182 | } |
---|
4183 | if(found === false){ |
---|
4184 | constraintsAndContents.push({"constraint" : tmpConstraint, "contents" : new Array(contents[j])}) |
---|
4185 | } |
---|
4186 | } |
---|
4187 | } |
---|
4188 | // --- removes all moved contents from contents |
---|
4189 | for(var j = 0; j !== constraintsAndContents.length; ++j){ |
---|
4190 | for(var k = 0; k !== constraintsAndContents[j].contents.length; ++k){ |
---|
4191 | contents = contents.without(constraintsAndContents[j].contents[k]); |
---|
4192 | } |
---|
4193 | } |
---|
4194 | |
---|
4195 | // --- adds all constraints to constraintsAndcontents that are not used now |
---|
4196 | // --- this is neccessary to find constraint with card-min > 0, but which has |
---|
4197 | // --- still no contents because the regular expression is too short, |
---|
4198 | for(var j = 0; j !== simpleConstraints.length; ++j){ |
---|
4199 | var k = 0; |
---|
4200 | for( ; k !== constraintsAndContents.length; ++k){ |
---|
4201 | if(constraintsAndContents[k].constraint === simpleConstraints[j]) break; |
---|
4202 | } |
---|
4203 | if(k === constraintsAndContents.length){ |
---|
4204 | constraintsAndContents.push({"constraint" : simpleConstraints[j], "contents" : new Array()}); |
---|
4205 | } |
---|
4206 | } |
---|
4207 | |
---|
4208 | // --- checks the card-min of all used constraints |
---|
4209 | for(var j = 0; j !== constraintsAndContents.length; ++j){ |
---|
4210 | var min = parseInt(constraintsAndContents[j].constraint.cardMin); |
---|
4211 | var len = constraintsAndContents[j].contents.length; |
---|
4212 | var rex = new RegExp(constraintsAndContents[j].constraint.regexp); |
---|
4213 | if(len < min){ |
---|
4214 | for(var k = 0; k !== constraintsAndContents.length; ++k){ |
---|
4215 | if(constraintsAndContents[j] === constraintsAndContents[k]) continue; |
---|
4216 | var _min = parseInt(constraintsAndContents[k].constraint.cardMin); |
---|
4217 | var _len = constraintsAndContents[k].contents.length; |
---|
4218 | var contentsToMove = new Array(); |
---|
4219 | for(var l = 0; l !== constraintsAndContents[k].contents.length; ++l){ |
---|
4220 | if(_min >= _len - contentsToMove.length || min <= len + contentsToMove.length) break; |
---|
4221 | var contentValue = (isForTypes === true ? constraintsAndContents[k].contents[l].value : constraintsAndContents[k].contents[l]); |
---|
4222 | if(!contentValue){ // must be an occurrence |
---|
4223 | if(constraintsAndContents[k].contents[l].resourceRef) contentValue = constraintsAndContents[k].contents[l].resourceRef; |
---|
4224 | else if(constraintsAndContents[k].contents[l].resourceData) contentValue = constraintsAndContents[k].contents[l].resourceData.value; |
---|
4225 | } |
---|
4226 | if(rex.match(contentValue) === true){ |
---|
4227 | contentsToMove.push(constraintsAndContents[k].contents[l]); |
---|
4228 | } |
---|
4229 | } |
---|
4230 | constraintsAndContents[j].contents = constraintsAndContents[j].contents.concat(contentsToMove); |
---|
4231 | // --- removes the moved contents from the source object |
---|
4232 | for(var l = 0; l !== contentsToMove.length; ++l){ |
---|
4233 | constraintsAndContents[k].contents = constraintsAndContents[k].contents.without(contentsToMove[l]); |
---|
4234 | } |
---|
4235 | if(constraintsAndContents[j].contents.length >= min) break; |
---|
4236 | } |
---|
4237 | } |
---|
4238 | } |
---|
4239 | |
---|
4240 | // --- to check card-max is not necessary, because if there is any constraint not satisfied the |
---|
4241 | // --- validation will fail anyway |
---|
4242 | |
---|
4243 | return {"constraintsAndContents" : constraintsAndContents, "contents" : contents}; |
---|
4244 | } |
---|
4245 | |
---|
4246 | |
---|
4247 | // --- creates a type frames for a name- or an occurrence- frame. |
---|
4248 | function makeTypes(myself, typeContent, xtypescopes) |
---|
4249 | { |
---|
4250 | var types = new Array(); |
---|
4251 | var matched = false; |
---|
4252 | for(var i = 0; xtypescopes && i !== xtypescopes.length; ++i){ |
---|
4253 | var xtype = xtypescopes[i].nameType; |
---|
4254 | if(!xtype) xtype = xtypescopes[i].occurrenceType; |
---|
4255 | if(!xtype) xtype = xtypescopes[i].associationType; |
---|
4256 | for(var j = 0; xtype && j != xtype.length; ++j){ |
---|
4257 | types.push(xtype[j]); |
---|
4258 | if(typeContent && typeContent[0] === xtype[j]){ |
---|
4259 | var selected = xtype[j]; |
---|
4260 | matched = true; |
---|
4261 | if(types.length !== 0) types[types.length - 1] = types[0]; |
---|
4262 | types[0] = selected; |
---|
4263 | } |
---|
4264 | } |
---|
4265 | } |
---|
4266 | if(matched === false && typeContent && typeContent.length !== 0) types.unshift(typeContent); |
---|
4267 | |
---|
4268 | if(types.length === 0 && typeContent && typeContent.length !== 0) types = typeContent; |
---|
4269 | if(!types || types.length === 0) types = new Array(""); |
---|
4270 | myself.__type__ = new Object(); |
---|
4271 | var tr = newRow(CLASSES.typeFrame(), "Type", new SelectrowC(types, myself.__type__, 1, 1).getFrame()); |
---|
4272 | myself.__table__.insert({"bottom" : tr}); |
---|
4273 | return types; |
---|
4274 | } |
---|