1 | |
---|
2 | class AssetTreeTagLib { |
---|
3 | static namespace = 'gnumims' |
---|
4 | |
---|
5 | def resources = { attrs -> |
---|
6 | ///@todo: should include our javascript and do setup here. |
---|
7 | } |
---|
8 | |
---|
9 | def assetTree = { attrs -> |
---|
10 | |
---|
11 | def sites = Site.list() |
---|
12 | |
---|
13 | def assetInstance = Asset.get(1) /// @todo: remove this. |
---|
14 | |
---|
15 | def divIdCount = 0 |
---|
16 | def divId = '' |
---|
17 | def nextDivId = { |
---|
18 | divIdCount++ |
---|
19 | divId = 'assetTreeBranch'+divIdCount |
---|
20 | } |
---|
21 | |
---|
22 | def mkp = new groovy.xml.MarkupBuilder(out) //this line will be unnecessary in versions of Grails after version 1.2 |
---|
23 | |
---|
24 | |
---|
25 | /// @todo: use a loop for the subItem levels. |
---|
26 | mkp.div(class: 'tree') { |
---|
27 | ul() { |
---|
28 | img(src: treeRootImg(), alt: 'TreeRoot') |
---|
29 | for(site in sites.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) { |
---|
30 | li() { |
---|
31 | if(site.sections) { |
---|
32 | a(href: toggleBranch(nextDivId()) ) { |
---|
33 | img( src: bulletTreePlusImg(), id: divId+'img' ) |
---|
34 | } |
---|
35 | } |
---|
36 | else |
---|
37 | img(src: dashImg(), class: 'emptynode') |
---|
38 | a( href: siteShowLink(site.id) ) { |
---|
39 | yieldUnescaped( site.encodeAsHTML() ) |
---|
40 | } |
---|
41 | a(href: sectionCreateLink(site.id)) { |
---|
42 | img(src: addImg(), alt: 'Add', title: 'Add Section') |
---|
43 | } |
---|
44 | } |
---|
45 | if(site.sections) { |
---|
46 | div(id: divId, style: 'display:none;') { |
---|
47 | ul() { |
---|
48 | for(section in site.sections.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) { |
---|
49 | li() { |
---|
50 | if(section.assets) { |
---|
51 | a(href: toggleBranch(nextDivId()) ) { |
---|
52 | img(src: bulletTreePlusImg(), id: divId+'img' ) |
---|
53 | } |
---|
54 | } |
---|
55 | else |
---|
56 | img(src: dashImg(), class: 'emptynode') |
---|
57 | a( href: sectionShowLink(section.id) ) { |
---|
58 | yieldUnescaped( section.encodeAsHTML() ) |
---|
59 | } |
---|
60 | a(href: assetCreateLink(section.id)) { |
---|
61 | img(src: addImg(), alt: 'Add', title: 'Add Asset') |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | if(section.assets) { |
---|
66 | div(id: divId, style: 'display:none;') { |
---|
67 | ul() { |
---|
68 | for(asset in section.assets.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) { |
---|
69 | li() { |
---|
70 | if(asset.assetSubItems) { |
---|
71 | a(href: toggleBranch(nextDivId()) ) { |
---|
72 | img(src: bulletTreePlusImg(), id: divId+'img' ) |
---|
73 | } |
---|
74 | } |
---|
75 | else |
---|
76 | img(src: dashImg(), class: 'emptynode') |
---|
77 | a( href: assetShowLink(asset.id) ) { |
---|
78 | yieldUnescaped( asset.encodeAsHTML() ) |
---|
79 | } |
---|
80 | a(href: assetSubItemCreateLink(asset.id)) { |
---|
81 | img(src: addImg(), alt: 'Add', title: 'Add Sub Item') |
---|
82 | } |
---|
83 | } // li |
---|
84 | |
---|
85 | if(asset.assetSubItems) { |
---|
86 | div(id: divId, style: 'display:none;') { |
---|
87 | ul() { |
---|
88 | for(assetSubItemL1 in asset.assetSubItems.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) { |
---|
89 | li() { |
---|
90 | if(assetSubItemL1.subItems) { |
---|
91 | a(href: toggleBranch(nextDivId()) ) { |
---|
92 | img(src: bulletTreePlusImg(), id: divId+'img' ) |
---|
93 | } |
---|
94 | } |
---|
95 | else |
---|
96 | img(src: dashImg(), class: 'emptynode') |
---|
97 | a( href: assetSubItemShowLink(assetSubItemL1.id) ) { |
---|
98 | yieldUnescaped( assetSubItemL1.encodeAsHTML() ) |
---|
99 | } |
---|
100 | a(href: assetSubItemCreateWithParentLink(assetSubItemL1.id)) { |
---|
101 | img(src: addImg(), alt: 'Add', title: 'Add Sub Item') |
---|
102 | } |
---|
103 | } // li |
---|
104 | |
---|
105 | if(assetSubItemL1.subItems) { |
---|
106 | div(id: divId, style: 'display:none;') { |
---|
107 | ul() { |
---|
108 | for(assetSubItemL2 in assetSubItemL1.subItems.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) { |
---|
109 | li() { |
---|
110 | if(assetSubItemL2.subItems) { |
---|
111 | a(href: toggleBranch(nextDivId()) ) { |
---|
112 | img( src: bulletTreePlusImg(), id: divId+'img' ) |
---|
113 | } |
---|
114 | } |
---|
115 | else |
---|
116 | img(src: dashImg(), class: 'emptynode') |
---|
117 | a( href: assetSubItemShowLink(assetSubItemL2.id) ) { |
---|
118 | yieldUnescaped( assetSubItemL2.encodeAsHTML() ) |
---|
119 | } |
---|
120 | a(href: assetSubItemCreateWithParentLink(assetSubItemL2.id)) { |
---|
121 | img(src: addImg(), alt: 'Add', title: 'Add Sub Item') |
---|
122 | } |
---|
123 | } // li |
---|
124 | |
---|
125 | if(assetSubItemL2.subItems) { |
---|
126 | div(id: divId, style: 'display:none;') { |
---|
127 | ul() { |
---|
128 | for(assetSubItemL3 in assetSubItemL2.subItems.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) { |
---|
129 | li() { |
---|
130 | if(assetSubItemL3.subItems) { |
---|
131 | a(href: toggleBranch(nextDivId()) ) { |
---|
132 | img( src: bulletTreePlusImg(), id: divId+'img' ) |
---|
133 | } |
---|
134 | } |
---|
135 | else |
---|
136 | img(src: dashImg(), class: 'emptynode') |
---|
137 | a( href: assetSubItemShowLink(assetSubItemL3.id) ) { |
---|
138 | yieldUnescaped( assetSubItemL3.encodeAsHTML() ) |
---|
139 | } |
---|
140 | a(href: assetSubItemCreateWithParentLink(assetSubItemL3.id)) { |
---|
141 | img(src: addImg(), alt: 'Add', title: 'Add Sub Item') |
---|
142 | } |
---|
143 | } // li |
---|
144 | |
---|
145 | if(assetSubItemL3.subItems) { |
---|
146 | div(id: divId, style: 'display:none;') { |
---|
147 | ul() { |
---|
148 | for(assetSubItemL4 in assetSubItemL3.subItems.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) { |
---|
149 | li() { |
---|
150 | // if(assetSubItemL4.subItems) { |
---|
151 | // a(href: toggleBranch(nextDivId()) ) { |
---|
152 | // img( src: bulletTreePlusImg(), id: divId+'img' ) |
---|
153 | // } |
---|
154 | // } |
---|
155 | // else |
---|
156 | img(src: dashImg(), class: 'emptynode') |
---|
157 | a( href: assetSubItemShowLink(assetSubItemL4.id) ) { |
---|
158 | yieldUnescaped( assetSubItemL4.encodeAsHTML() ) |
---|
159 | } |
---|
160 | // a(href: assetSubItemCreateWithParentLink(assetSubItemL4.id)) { |
---|
161 | // img(src: addImg(), alt: 'Add', title: 'Add Sub Item') |
---|
162 | // } |
---|
163 | } // li |
---|
164 | |
---|
165 | } // assetSubItemL4 |
---|
166 | } // ul |
---|
167 | } // div |
---|
168 | } // if(assetSubItemL3.subItems) |
---|
169 | |
---|
170 | |
---|
171 | } // assetSubItemL3 |
---|
172 | } // ul |
---|
173 | } // div |
---|
174 | } // if(assetSubItemL2.subItems) |
---|
175 | |
---|
176 | } // assetSubItemL2 |
---|
177 | } // ul |
---|
178 | } // div |
---|
179 | } // if(assetSubItemL1.subItems) |
---|
180 | |
---|
181 | } // assetSubItemL1 |
---|
182 | } // ul |
---|
183 | } // div |
---|
184 | } // if(asset.assetSubItems) |
---|
185 | |
---|
186 | } // assets |
---|
187 | } // ul |
---|
188 | } // div |
---|
189 | } // if(section.assets) |
---|
190 | |
---|
191 | } //sections |
---|
192 | } // ul |
---|
193 | } // div |
---|
194 | } // if(site.sections) |
---|
195 | } // sites |
---|
196 | } // ul |
---|
197 | } // mkp |
---|
198 | |
---|
199 | } // assetTree |
---|
200 | |
---|
201 | |
---|
202 | |
---|
203 | /** Imgs */ |
---|
204 | |
---|
205 | def treeRootImg() { |
---|
206 | resource(dir:'images/skin',file:'chart_organisation.png').toString() |
---|
207 | } |
---|
208 | def addImg() { |
---|
209 | resource(dir:'images/skin',file:'database_add.png').toString() |
---|
210 | } |
---|
211 | def copyImg() { |
---|
212 | resource(dir:'images/skin',file:'page_copy.png').toString() |
---|
213 | } |
---|
214 | def bulletTreePlusImg() { |
---|
215 | resource(dir:'images/skin',file:'bullet_tree_plus.png').toString() |
---|
216 | } |
---|
217 | // actually set in javascript function. |
---|
218 | def bulletTreeMinusImg() { |
---|
219 | resource(dir:'images/skin',file:'bullet_tree_minus.png').toString() |
---|
220 | } |
---|
221 | def dashImg() { |
---|
222 | resource(dir:'images/skin',file:'hline_short.png').toString() |
---|
223 | } |
---|
224 | |
---|
225 | /** js calls */ |
---|
226 | |
---|
227 | def toggleBranch(divId) { |
---|
228 | /// @todo: toggleBranch is in overlayPane.js and should be moved to tree.js |
---|
229 | 'javascript: toggleBranch(\"' + divId + '\", \"' + divId + 'img' + '\");' |
---|
230 | } |
---|
231 | |
---|
232 | /** Links */ |
---|
233 | |
---|
234 | def siteShowLink(id) { |
---|
235 | createLink(controller: 'siteDetailed', action: 'show', params: ['id': id] ).toString() |
---|
236 | } |
---|
237 | |
---|
238 | def siteEditLink(id) { |
---|
239 | createLink(controller: 'siteDetailed', action: 'edit', params: ['id': id] ).toString() |
---|
240 | } |
---|
241 | |
---|
242 | def sectionCreateLink(id) { |
---|
243 | createLink(controller: 'sectionDetailed', action: 'create', params: ['id': id] ).toString() |
---|
244 | } |
---|
245 | |
---|
246 | def sectionShowLink(id) { |
---|
247 | createLink(controller: 'sectionDetailed', action: 'show', params: ['id': id] ).toString() |
---|
248 | } |
---|
249 | |
---|
250 | def sectionEditLink(id) { |
---|
251 | createLink(controller: 'sectionDetailed', action: 'edit', params: ['id': id] ).toString() |
---|
252 | } |
---|
253 | |
---|
254 | def assetCreateLink(id) { |
---|
255 | createLink(controller: 'assetDetailed', action: 'create', params: ['id': id] ).toString() |
---|
256 | } |
---|
257 | |
---|
258 | def assetShowLink(id) { |
---|
259 | createLink(controller: 'assetDetailed', action: 'show', id: id ).toString() |
---|
260 | } |
---|
261 | |
---|
262 | def assetEditLink(id) { |
---|
263 | createLink(controller: 'assetDetailed', action: 'edit', id: id ).toString() |
---|
264 | } |
---|
265 | |
---|
266 | def assetCopyLink(id) { |
---|
267 | createLink(controller: 'assetDetailed', action: 'copy', params: ['asset.id': id] ).toString() |
---|
268 | } |
---|
269 | |
---|
270 | def assetSubItemCreateLink(id) { |
---|
271 | createLink(controller: 'assetSubItemDetailed', action: 'create', params: ['id': id] ).toString() |
---|
272 | } |
---|
273 | |
---|
274 | def assetSubItemCreateWithParentLink(parentItemId) { |
---|
275 | createLink(controller: 'assetSubItemDetailed', action: 'create', params: ['parentItem.id': parentItemId] ).toString() |
---|
276 | } |
---|
277 | |
---|
278 | def assetSubItemShowLink(id) { |
---|
279 | createLink(controller: 'assetSubItemDetailed', action: 'show', params: ['id': id] ).toString() |
---|
280 | } |
---|
281 | |
---|
282 | def assetSubItemEditLink(id) { |
---|
283 | createLink(controller: 'assetSubItemDetailed', action: 'edit', params: ['id': id] ).toString() |
---|
284 | } |
---|
285 | |
---|
286 | } // end class |
---|