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