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