1 | //+----------------------------------------------------------------------------- |
---|
2 | //+ Isidorus |
---|
3 | //+ (c) 2008-2009 Marc Kuester, Christoph Ludwig, Lukas Giessmann |
---|
4 | //+ |
---|
5 | //+ Isidorus is freely distributable under the LGPL license. |
---|
6 | //+ This ajax module uses the frameworks PrototypeJs and Scriptaculous, both |
---|
7 | //+ are distributed under the MIT license. |
---|
8 | //+ You can find a detailed description in trunk/docs/LGPL-LICENSE.txt and |
---|
9 | //+ in trunk/src/ajax/javascripts/external/MIT-LICENSE.txt. |
---|
10 | //+----------------------------------------------------------------------------- |
---|
11 | |
---|
12 | |
---|
13 | function makeHome() |
---|
14 | { |
---|
15 | var content = new Element("div", {"class" : CLASSES.content()}); |
---|
16 | var header = new Element("h1").update("Topic Maps Overview"); |
---|
17 | content.insert({"bottom" : header}); |
---|
18 | $(CLASSES.subPage()).insert({"bottom" : content}); |
---|
19 | |
---|
20 | function successFun(xhr){ |
---|
21 | var json = null; |
---|
22 | try{ |
---|
23 | json = xhr.responseText.evalJSON(); |
---|
24 | } |
---|
25 | catch(innrErr){} |
---|
26 | |
---|
27 | try{ |
---|
28 | if(json === null) { |
---|
29 | alert("The server's response does not contain any topics!"); |
---|
30 | } |
---|
31 | else { |
---|
32 | var treeView = new TreeViewC(json); |
---|
33 | content.insert({"bottom" : treeView.getFrame()}); |
---|
34 | } |
---|
35 | } |
---|
36 | catch(err) { |
---|
37 | alert("Could not create a Topic Map overview: " + err); |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | requestTreeView(successFun, null); |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | // --- Represents a list of trees. |
---|
46 | var TreeViewC = Class.create({"initialize" : function(contents){ |
---|
47 | if(!contents) throw "From NodeC(): content must be set!"; |
---|
48 | try { |
---|
49 | this.__frame__ = new Element("ul", {"class" : CLASSES.treeView()}); |
---|
50 | for(var i = 0; i !== contents.length; ++i){ |
---|
51 | var tLi = new Element("li").update(new TreeC(contents[i]).getFrame()); |
---|
52 | this.__frame__.insert({"bottom" : tLi}); |
---|
53 | } |
---|
54 | } |
---|
55 | catch(err){ |
---|
56 | throw "From TreeC(): The following exception was thrown:\n" + err; |
---|
57 | } |
---|
58 | }, |
---|
59 | "getFrame" : function(){ |
---|
60 | return this.__frame__; |
---|
61 | }}); |
---|
62 | |
---|
63 | |
---|
64 | // --- Represents the root of a tree of nodes and contain all tree's nodes. |
---|
65 | var TreeC = Class.create({"initialize" : function(content){ |
---|
66 | if(!content) throw "From NodeC(): content must be set!"; |
---|
67 | try { |
---|
68 | this.__frame__ = new Element("ul", {"class" : CLASSES.tree()}); |
---|
69 | this.__frame__.update(new NodeC(content).getFrame()); |
---|
70 | } |
---|
71 | catch(err){ |
---|
72 | throw "From TreeC(): The following exception was thrown:\n" + err; |
---|
73 | } |
---|
74 | }, |
---|
75 | "getFrame" : function(){ |
---|
76 | return this.__frame__; |
---|
77 | }}); |
---|
78 | |
---|
79 | |
---|
80 | // --- Represents a tree node with a topic as a list of psis, |
---|
81 | // --- an edit and a create button. Furter the node can contain |
---|
82 | // --- more nodes as listings of instances and subtypes of the |
---|
83 | // --- current node's topic. |
---|
84 | var NodeC = Class.create({"initialize" : function(content){ |
---|
85 | if(!content) throw "From NodeC(): content must be set!"; |
---|
86 | try { |
---|
87 | this.__frame__ = new Element("li", {"class" : CLASSES.node()}); |
---|
88 | this.__isMinimized__ = false; |
---|
89 | |
---|
90 | function setClickHandler(myself){ |
---|
91 | myself.__frame__.observe("click", function(event){ |
---|
92 | if(myself.__isMinimized__ === false){ |
---|
93 | if(myself.__instances__) myself.__instances__.hide(); |
---|
94 | if(myself.__subtypes__) myself.__subtypes__.hide(); |
---|
95 | myself.__frame__.setStyle({"color" : "#ff7f00"}); |
---|
96 | myself.__isMinimized__ = true; |
---|
97 | } |
---|
98 | else { |
---|
99 | if(myself.__instances__) myself.__instances__.show(); |
---|
100 | if(myself.__subtypes__) myself.__subtypes__.show(); |
---|
101 | myself.__frame__.setStyle({"color" : "inherit"}); |
---|
102 | myself.__isMinimized__ = false; |
---|
103 | } |
---|
104 | Event.stop(event); |
---|
105 | }); |
---|
106 | } |
---|
107 | setClickHandler(this); |
---|
108 | |
---|
109 | if((content.instances && content.instances.length !== 0) || (content.subtypes && content.subtypes.length !== 0)) { |
---|
110 | this.getFrame().setStyle({"cursor" : "pointer"}); |
---|
111 | } |
---|
112 | else { |
---|
113 | this.getFrame().setStyle({"cursor" : "text"}); |
---|
114 | } |
---|
115 | |
---|
116 | this.__topic__ = new Element("ul", {"class" : CLASSES.topicPsis()}); |
---|
117 | this.__frame__.insert({"bottom" : this.__topic__}); |
---|
118 | for(var i = 0; content.topic && i !== content.topic.length; ++i){ |
---|
119 | var tLi = new Element("li").update(content.topic[i]); |
---|
120 | this.__topic__.insert({"bottom" : tLi}); |
---|
121 | } |
---|
122 | |
---|
123 | this.__edit__ = new Element("span", {"class" : CLASSES.clickable()}).update("edit"); |
---|
124 | this.__create__ = new Element("span", {"class" : CLASSES.clickable()}).update("create"); |
---|
125 | if(content.isType !== true){ |
---|
126 | this.__create__.writeAttribute({"class" : CLASSES.disabled()}); |
---|
127 | } |
---|
128 | else { |
---|
129 | this.__create__.observe("click", function(event){ |
---|
130 | setNaviClasses($(PAGES.create)); |
---|
131 | makePage(PAGES.create, content.topic[0]); |
---|
132 | Event.stop(event); |
---|
133 | }); |
---|
134 | } |
---|
135 | |
---|
136 | if(content.isInstance !== true){ |
---|
137 | this.__edit__.writeAttribute({"class" : CLASSES.disabled()}); |
---|
138 | } |
---|
139 | else { |
---|
140 | this.__edit__.observe("click", function(event){ |
---|
141 | setNaviClasses($(PAGES.edit)); |
---|
142 | makePage(PAGES.edit, content.topic[0]); |
---|
143 | Event.stop(event); |
---|
144 | }); |
---|
145 | } |
---|
146 | this.__frame__.insert({"bottom" : this.__edit__}); |
---|
147 | this.__frame__.insert({"bottom" : "<span>|</span>"}); |
---|
148 | this.__frame__.insert({"bottom" : this.__create__}); |
---|
149 | for(var i = 1; content.topic && i < content.topic.length; ++i) this.__frame__.insert({"bottom" : "<br/><span> </span>"}); |
---|
150 | |
---|
151 | this.__instances__ = null; |
---|
152 | this.__subtypes__ = null; |
---|
153 | |
---|
154 | if(content.instances && content.instances.length !== 0) { |
---|
155 | this.__instances__ = new Element("ul", {"class" : CLASSES.instances()}); |
---|
156 | for(var i = 0; i !== content.instances.length; ++i){ |
---|
157 | var entry = new NodeC(content.instances[i]); |
---|
158 | this.__instances__.insert({"bottom" : entry.getFrame()}); |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | if(content.subtypes && content.subtypes.length !== 0) { |
---|
163 | this.__subtypes__ = new Element("ul", {"class" : CLASSES.subtypes()}); |
---|
164 | for(var i = 0; i !== content.subtypes.length; ++i){ |
---|
165 | var entry = new NodeC(content.subtypes[i]); |
---|
166 | this.__subtypes__.insert({"bottom" : entry.getFrame()}); |
---|
167 | } |
---|
168 | } |
---|
169 | |
---|
170 | if(this.__instances__) this.__frame__.insert({"bottom" : this.__instances__}); |
---|
171 | if(this.__subtypes__) this.__frame__.insert({"bottom" : this.__subtypes__}); |
---|
172 | } |
---|
173 | catch(err){ |
---|
174 | throw "From NodeC(): The following exception was thrown:\n" + err; |
---|
175 | } |
---|
176 | }, |
---|
177 | "getFrame" : function(){ |
---|
178 | return this.__frame__; |
---|
179 | }}); |
---|