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