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