[286] | 1 | /** |
---|
| 2 | * Asset Tree tags. |
---|
[308] | 3 | * Specific to gnuMims hence the namespace. |
---|
[286] | 4 | */ |
---|
[278] | 5 | class AssetTreeTagLib { |
---|
[306] | 6 | static namespace = 'gnuMims' |
---|
[278] | 7 | |
---|
| 8 | def resources = { attrs -> |
---|
| 9 | ///@todo: should include our javascript and do setup here. |
---|
| 10 | } |
---|
| 11 | |
---|
[306] | 12 | def assetTreeButton = { |
---|
| 13 | def mkp = new groovy.xml.MarkupBuilder(out) //this line will be unnecessary in versions of Grails after version 1.2 |
---|
| 14 | |
---|
| 15 | mkp.div(class: "tree_button") { |
---|
| 16 | a(href: showPane()) { |
---|
| 17 | img(src: treeRootImg()) |
---|
| 18 | } |
---|
| 19 | } |
---|
| 20 | } // mkp |
---|
| 21 | |
---|
[278] | 22 | def assetTree = { attrs -> |
---|
| 23 | |
---|
| 24 | def sites = Site.list() |
---|
| 25 | |
---|
[307] | 26 | def visibleBranches = session.assetTreeVisibleBranches ? session.assetTreeVisibleBranches.tokenize(',') : [] |
---|
| 27 | |
---|
| 28 | def branchStyle = { branchId -> |
---|
| 29 | if(visibleBranches.contains(branchId)) |
---|
| 30 | '' |
---|
| 31 | else |
---|
| 32 | 'display:none;' |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | def branchImg = { branchId -> |
---|
| 36 | if(visibleBranches.contains(branchId)) |
---|
| 37 | bulletTreeMinusImg() |
---|
| 38 | else |
---|
| 39 | bulletTreePlusImg() |
---|
| 40 | } |
---|
| 41 | |
---|
[278] | 42 | def divIdCount = 0 |
---|
| 43 | def divId = '' |
---|
| 44 | def nextDivId = { |
---|
| 45 | divIdCount++ |
---|
| 46 | divId = 'assetTreeBranch'+divIdCount |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | def mkp = new groovy.xml.MarkupBuilder(out) //this line will be unnecessary in versions of Grails after version 1.2 |
---|
| 50 | |
---|
[308] | 51 | // Offer a site create link if no sites are found. |
---|
| 52 | if(!sites) { |
---|
| 53 | mkp.div(class: 'overlayPane', id: 'assetTreePane', style: 'display:none;') { |
---|
| 54 | div(class: 'tree', id: 'assetTreeTable') { |
---|
| 55 | table() { |
---|
| 56 | tr() { |
---|
| 57 | td( valign: 'top', class: 'value') { |
---|
| 58 | ul() { |
---|
| 59 | img(src: treeRootImg(), alt: 'TreeRoot') |
---|
| 60 | li() { |
---|
| 61 | a(href: siteCreateLink()) { |
---|
| 62 | img(src: addImg(), alt: 'Add', title: 'Add Site') |
---|
| 63 | } |
---|
| 64 | } // li |
---|
| 65 | } // ul |
---|
| 66 | } // td |
---|
| 67 | } // tr |
---|
| 68 | } // table |
---|
| 69 | } // div |
---|
[278] | 70 | |
---|
[308] | 71 | div( class: 'buttons') { |
---|
| 72 | span(class: 'button') { |
---|
| 73 | input( type: 'button', value: 'Close', onclick: hideAssetTreePane() ) |
---|
| 74 | } |
---|
| 75 | } // button div |
---|
| 76 | } // mkp |
---|
| 77 | return |
---|
| 78 | } // if(!sites) |
---|
| 79 | |
---|
| 80 | |
---|
[278] | 81 | /// @todo: use a loop for the subItem levels. |
---|
[306] | 82 | mkp.div(class: 'overlayPane', id: 'assetTreePane', style: 'display:none;') { |
---|
[307] | 83 | div(class: 'tree', id: 'assetTreeTable') { |
---|
[306] | 84 | table() { |
---|
| 85 | tr() { |
---|
| 86 | td( valign: 'top', class: 'value') { |
---|
[278] | 87 | ul() { |
---|
[306] | 88 | img(src: treeRootImg(), alt: 'TreeRoot') |
---|
| 89 | for(site in sites.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) { |
---|
[278] | 90 | li() { |
---|
[306] | 91 | if(site.sections) { |
---|
[278] | 92 | a(href: toggleBranch(nextDivId()) ) { |
---|
[307] | 93 | img( src: branchImg(divId), id: divId+'img' ) |
---|
[278] | 94 | } |
---|
| 95 | } |
---|
| 96 | else |
---|
[282] | 97 | img(src: dashImg()) |
---|
[307] | 98 | a( href: siteShowLink(site.id), onclick: hideAssetTreePane() ) { |
---|
[306] | 99 | yieldUnescaped( site.encodeAsHTML() ) |
---|
[278] | 100 | } |
---|
[307] | 101 | a(href: sectionCreateLink(site.id), onclick: hideAssetTreePane()) { |
---|
[306] | 102 | img(src: addImg(), alt: 'Add', title: 'Add Section') |
---|
[278] | 103 | } |
---|
| 104 | } |
---|
[306] | 105 | if(site.sections) { |
---|
[307] | 106 | div( id: divId, style: branchStyle(divId) ) { |
---|
[278] | 107 | ul() { |
---|
[306] | 108 | for(section in site.sections.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) { |
---|
[278] | 109 | li() { |
---|
[306] | 110 | if(section.assets) { |
---|
[307] | 111 | a( href: toggleBranch(nextDivId()) ) { |
---|
| 112 | img(src: branchImg(divId), id: divId+'img' ) |
---|
[278] | 113 | } |
---|
| 114 | } |
---|
| 115 | else |
---|
[282] | 116 | img(src: dashImg()) |
---|
[307] | 117 | a( href: sectionShowLink(section.id), onclick: hideAssetTreePane() ) { |
---|
[306] | 118 | yieldUnescaped( section.encodeAsHTML() ) |
---|
[278] | 119 | } |
---|
[307] | 120 | a(href: assetCreateLink(section.id), onclick: hideAssetTreePane()) { |
---|
[306] | 121 | img(src: addImg(), alt: 'Add', title: 'Add Asset') |
---|
[278] | 122 | } |
---|
[306] | 123 | } |
---|
[278] | 124 | |
---|
[306] | 125 | if(section.assets) { |
---|
[307] | 126 | div( id: divId, style: branchStyle(divId) ) { |
---|
[278] | 127 | ul() { |
---|
[306] | 128 | for(asset in section.assets.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) { |
---|
[278] | 129 | li() { |
---|
[306] | 130 | if(asset.assetSubItems) { |
---|
[307] | 131 | a( href: toggleBranch(nextDivId()) ) { |
---|
| 132 | img(src: branchImg(divId), id: divId+'img' ) |
---|
[278] | 133 | } |
---|
| 134 | } |
---|
| 135 | else |
---|
[282] | 136 | img(src: dashImg()) |
---|
[307] | 137 | a( href: assetShowLink(asset.id), onclick: hideAssetTreePane() ) { |
---|
[306] | 138 | yieldUnescaped( asset.encodeAsHTML() ) |
---|
[278] | 139 | } |
---|
[307] | 140 | a(href: assetSubItemCreateLink(asset.id), onclick: hideAssetTreePane()) { |
---|
[278] | 141 | img(src: addImg(), alt: 'Add', title: 'Add Sub Item') |
---|
| 142 | } |
---|
[307] | 143 | a(href: assetCopyLink(asset.id), onclick: hideAssetTreePane()) { |
---|
[306] | 144 | img(src: copyImg(), alt: 'Add', title: 'Copy Asset') |
---|
| 145 | } |
---|
[278] | 146 | } // li |
---|
| 147 | |
---|
[306] | 148 | if(asset.assetSubItems) { |
---|
[307] | 149 | div( id: divId, style: branchStyle(divId) ) { |
---|
[278] | 150 | ul() { |
---|
[306] | 151 | for(assetSubItemL1 in asset.assetSubItems.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) { |
---|
[278] | 152 | li() { |
---|
[306] | 153 | if(assetSubItemL1.subItems) { |
---|
[307] | 154 | a( href: toggleBranch(nextDivId()) ) { |
---|
| 155 | img(src: branchImg(divId), id: divId+'img' ) |
---|
[278] | 156 | } |
---|
| 157 | } |
---|
| 158 | else |
---|
[282] | 159 | img(src: dashImg()) |
---|
[307] | 160 | a( href: assetSubItemShowLink(assetSubItemL1.id), onclick: hideAssetTreePane() ) { |
---|
[306] | 161 | yieldUnescaped( assetSubItemL1.encodeAsHTML() ) |
---|
[278] | 162 | } |
---|
[307] | 163 | a(href: assetSubItemCreateWithParentLink(assetSubItemL1.id), onclick: hideAssetTreePane()) { |
---|
[278] | 164 | img(src: addImg(), alt: 'Add', title: 'Add Sub Item') |
---|
| 165 | } |
---|
| 166 | } // li |
---|
| 167 | |
---|
[306] | 168 | if(assetSubItemL1.subItems) { |
---|
[307] | 169 | div( id: divId, style: branchStyle(divId) ) { |
---|
[278] | 170 | ul() { |
---|
[306] | 171 | for(assetSubItemL2 in assetSubItemL1.subItems.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) { |
---|
[278] | 172 | li() { |
---|
[306] | 173 | if(assetSubItemL2.subItems) { |
---|
[307] | 174 | a( href: toggleBranch(nextDivId()) ) { |
---|
| 175 | img( src: branchImg(divId), id: divId+'img' ) |
---|
[278] | 176 | } |
---|
| 177 | } |
---|
| 178 | else |
---|
[282] | 179 | img(src: dashImg()) |
---|
[307] | 180 | a( href: assetSubItemShowLink(assetSubItemL2.id), onclick: hideAssetTreePane() ) { |
---|
[306] | 181 | yieldUnescaped( assetSubItemL2.encodeAsHTML() ) |
---|
[278] | 182 | } |
---|
[307] | 183 | a(href: assetSubItemCreateWithParentLink(assetSubItemL2.id), onclick: hideAssetTreePane()) { |
---|
[278] | 184 | img(src: addImg(), alt: 'Add', title: 'Add Sub Item') |
---|
| 185 | } |
---|
| 186 | } // li |
---|
| 187 | |
---|
[306] | 188 | if(assetSubItemL2.subItems) { |
---|
[307] | 189 | div( id: divId, style: branchStyle(divId) ) { |
---|
[278] | 190 | ul() { |
---|
[306] | 191 | for(assetSubItemL3 in assetSubItemL2.subItems.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) { |
---|
[278] | 192 | li() { |
---|
[306] | 193 | if(assetSubItemL3.subItems) { |
---|
[307] | 194 | a( href: toggleBranch(nextDivId()) ) { |
---|
| 195 | img( src: branchImg(divId), id: divId+'img' ) |
---|
[306] | 196 | } |
---|
[278] | 197 | } |
---|
[306] | 198 | else |
---|
| 199 | img(src: dashImg()) |
---|
[307] | 200 | a( href: assetSubItemShowLink(assetSubItemL3.id), onclick: hideAssetTreePane() ) { |
---|
[306] | 201 | yieldUnescaped( assetSubItemL3.encodeAsHTML() ) |
---|
| 202 | } |
---|
[307] | 203 | a(href: assetSubItemCreateWithParentLink(assetSubItemL3.id), onclick: hideAssetTreePane()) { |
---|
[306] | 204 | img(src: addImg(), alt: 'Add', title: 'Add Sub Item') |
---|
| 205 | } |
---|
[278] | 206 | } // li |
---|
| 207 | |
---|
[306] | 208 | if(assetSubItemL3.subItems) { |
---|
[307] | 209 | div( id: divId, style: branchStyle(divId) ) { |
---|
[306] | 210 | ul() { |
---|
| 211 | for(assetSubItemL4 in assetSubItemL3.subItems.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }) { |
---|
| 212 | li() { |
---|
| 213 | // if(assetSubItemL4.subItems) { |
---|
[307] | 214 | // a( href: toggleBranch(nextDivId()) ) { |
---|
| 215 | // img( src: branchImg(divId), id: divId+'img' ) |
---|
[306] | 216 | // } |
---|
| 217 | // } |
---|
| 218 | // else |
---|
| 219 | img(src: dashImg()) |
---|
[307] | 220 | a( href: assetSubItemShowLink(assetSubItemL4.id), onclick: hideAssetTreePane() ) { |
---|
[306] | 221 | yieldUnescaped( assetSubItemL4.encodeAsHTML() ) |
---|
| 222 | } |
---|
[307] | 223 | // a(href: assetSubItemCreateWithParentLink(assetSubItemL4.id), onclick: hideAssetTreePane()) { |
---|
[306] | 224 | // img(src: addImg(), alt: 'Add', title: 'Add Sub Item') |
---|
| 225 | // } |
---|
| 226 | } // li |
---|
| 227 | |
---|
| 228 | } // assetSubItemL4 |
---|
| 229 | } // ul |
---|
| 230 | } // div |
---|
| 231 | } // if(assetSubItemL3.subItems) |
---|
| 232 | |
---|
| 233 | |
---|
| 234 | } // assetSubItemL3 |
---|
[278] | 235 | } // ul |
---|
| 236 | } // div |
---|
[306] | 237 | } // if(assetSubItemL2.subItems) |
---|
[278] | 238 | |
---|
[306] | 239 | } // assetSubItemL2 |
---|
[278] | 240 | } // ul |
---|
| 241 | } // div |
---|
[306] | 242 | } // if(assetSubItemL1.subItems) |
---|
[278] | 243 | |
---|
[306] | 244 | } // assetSubItemL1 |
---|
[278] | 245 | } // ul |
---|
| 246 | } // div |
---|
[306] | 247 | } // if(asset.assetSubItems) |
---|
[278] | 248 | |
---|
[306] | 249 | } // assets |
---|
[278] | 250 | } // ul |
---|
| 251 | } // div |
---|
[306] | 252 | } // if(section.assets) |
---|
[278] | 253 | |
---|
[306] | 254 | } //sections |
---|
[278] | 255 | } // ul |
---|
| 256 | } // div |
---|
[306] | 257 | } // if(site.sections) |
---|
| 258 | } // sites |
---|
| 259 | } // ul |
---|
| 260 | } // td |
---|
| 261 | } // tr |
---|
| 262 | } // table |
---|
| 263 | } // div |
---|
[278] | 264 | |
---|
[306] | 265 | div( class: 'buttons') { |
---|
| 266 | span(class: 'button') { |
---|
[307] | 267 | input( type: 'button', value: 'Close', onclick: hideAssetTreePane() ) |
---|
[306] | 268 | } |
---|
| 269 | } |
---|
| 270 | |
---|
[278] | 271 | } // mkp |
---|
| 272 | |
---|
| 273 | } // assetTree |
---|
| 274 | |
---|
| 275 | |
---|
| 276 | /** Imgs */ |
---|
| 277 | |
---|
| 278 | def treeRootImg() { |
---|
| 279 | resource(dir:'images/skin',file:'chart_organisation.png').toString() |
---|
| 280 | } |
---|
| 281 | def addImg() { |
---|
| 282 | resource(dir:'images/skin',file:'database_add.png').toString() |
---|
| 283 | } |
---|
| 284 | def copyImg() { |
---|
| 285 | resource(dir:'images/skin',file:'page_copy.png').toString() |
---|
| 286 | } |
---|
| 287 | def bulletTreePlusImg() { |
---|
| 288 | resource(dir:'images/skin',file:'bullet_tree_plus.png').toString() |
---|
| 289 | } |
---|
| 290 | // actually set in javascript function. |
---|
| 291 | def bulletTreeMinusImg() { |
---|
| 292 | resource(dir:'images/skin',file:'bullet_tree_minus.png').toString() |
---|
| 293 | } |
---|
| 294 | def dashImg() { |
---|
| 295 | resource(dir:'images/skin',file:'hline_short.png').toString() |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | /** js calls */ |
---|
| 299 | |
---|
[306] | 300 | def showPane() { |
---|
| 301 | 'javascript: showDiv(\"assetTreePane\");' |
---|
| 302 | } |
---|
| 303 | |
---|
[307] | 304 | def hideAssetTreePane() { |
---|
| 305 | def saveUrl = createLink(controller: 'appCore', action: 'saveAssetTreeStatus').toString() |
---|
| 306 | 'return hideAssetTreePane(\"assetTreePane\", \"assetTreeTable' + '\", \"' + saveUrl + '\");' |
---|
| 307 | } |
---|
| 308 | |
---|
[278] | 309 | def toggleBranch(divId) { |
---|
| 310 | /// @todo: toggleBranch is in overlayPane.js and should be moved to tree.js |
---|
[306] | 311 | 'javascript: toggleBranch(\"' + divId + '\", \"' + divId + 'img' +'\", \"' + bulletTreeMinusImg() +'\", \"' + bulletTreePlusImg() + '\");' |
---|
[278] | 312 | } |
---|
| 313 | |
---|
| 314 | /** Links */ |
---|
| 315 | |
---|
[308] | 316 | def siteCreateLink() { |
---|
| 317 | createLink(controller: 'siteDetailed', action: 'create').toString() |
---|
| 318 | } |
---|
[278] | 319 | def siteShowLink(id) { |
---|
| 320 | createLink(controller: 'siteDetailed', action: 'show', params: ['id': id] ).toString() |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | def siteEditLink(id) { |
---|
| 324 | createLink(controller: 'siteDetailed', action: 'edit', params: ['id': id] ).toString() |
---|
| 325 | } |
---|
| 326 | |
---|
[284] | 327 | def sectionCreateLink(siteId) { |
---|
| 328 | createLink(controller: 'sectionDetailed', action: 'create', params: ['site.id': siteId] ).toString() |
---|
[278] | 329 | } |
---|
| 330 | |
---|
| 331 | def sectionShowLink(id) { |
---|
| 332 | createLink(controller: 'sectionDetailed', action: 'show', params: ['id': id] ).toString() |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | def sectionEditLink(id) { |
---|
| 336 | createLink(controller: 'sectionDetailed', action: 'edit', params: ['id': id] ).toString() |
---|
| 337 | } |
---|
| 338 | |
---|
[284] | 339 | def assetCreateLink(sectionId) { |
---|
| 340 | createLink(controller: 'assetDetailed', action: 'create', params: ['section.id': sectionId] ).toString() |
---|
[278] | 341 | } |
---|
| 342 | |
---|
| 343 | def assetShowLink(id) { |
---|
| 344 | createLink(controller: 'assetDetailed', action: 'show', id: id ).toString() |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | def assetEditLink(id) { |
---|
| 348 | createLink(controller: 'assetDetailed', action: 'edit', id: id ).toString() |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | def assetCopyLink(id) { |
---|
[284] | 352 | createLink(controller: 'assetDetailed', action: 'copy', params: ['assetToCopy.id': id] ).toString() |
---|
[278] | 353 | } |
---|
| 354 | |
---|
[285] | 355 | def assetSubItemCreateLink(assetId) { |
---|
| 356 | createLink(controller: 'assetSubItemDetailed', action: 'create', params: ['asset.id': assetId] ).toString() |
---|
[278] | 357 | } |
---|
| 358 | |
---|
| 359 | def assetSubItemCreateWithParentLink(parentItemId) { |
---|
| 360 | createLink(controller: 'assetSubItemDetailed', action: 'create', params: ['parentItem.id': parentItemId] ).toString() |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | def assetSubItemShowLink(id) { |
---|
| 364 | createLink(controller: 'assetSubItemDetailed', action: 'show', params: ['id': id] ).toString() |
---|
| 365 | } |
---|
| 366 | |
---|
| 367 | def assetSubItemEditLink(id) { |
---|
| 368 | createLink(controller: 'assetSubItemDetailed', action: 'edit', params: ['id': id] ).toString() |
---|
| 369 | } |
---|
| 370 | |
---|
| 371 | } // end class |
---|