1 // The Antville Project 2 // http://code.google.com/p/antville 3 // 4 // Copyright 2007-2011 by Tobi Schäfer. 5 // 6 // Copyright 2001–2007 Robert Gaggl, Hannes Wallnöfer, Tobi Schäfer, 7 // Matthias & Michael Platzer, Christoph Lincke. 8 // 9 // Licensed under the Apache License, Version 2.0 (the ``License''); 10 // you may not use this file except in compliance with the License. 11 // You may obtain a copy of the License at 12 // 13 // http://www.apache.org/licenses/LICENSE-2.0 14 // 15 // Unless required by applicable law or agreed to in writing, software 16 // distributed under the License is distributed on an ``AS IS'' BASIS, 17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 // See the License for the specific language governing permissions and 19 // limitations under the License. 20 // 21 // $Revision$ 22 // $Author$ 23 // $Date$ 24 // $URL$ 25 26 /** 27 * @fileOverview Defines the Images prototype 28 */ 29 30 markgettext("Images"); 31 markgettext("images"); 32 33 /** 34 * @name Images 35 * @constructor 36 * @property {Image} _children 37 * @property {Tag[]} alphabeticalGalleries 38 * @property {Tag[]} galleries 39 * @property {Tag[]} otherGalleries 40 * @extends HopObject 41 */ 42 43 /** 44 * 45 * @param {String} action 46 * @returns {Boolean} 47 */ 48 Images.prototype.getPermission = function(action) { 49 if (!this._parent.getPermission("main")) { 50 return false; 51 } 52 switch (action) { 53 case ".": 54 case "main": 55 case "create": 56 // FIXME: case "tags": 57 return Site.require(Site.OPEN) && session.user || 58 Membership.require(Membership.CONTRIBUTOR) || 59 User.require(User.PRIVILEGED); 60 case "all": 61 return this._parent.constructor !== Layout && 62 (Membership.require(Membership.MANAGER) || 63 User.require(User.PRIVILEGED)); 64 } 65 return false; 66 } 67 68 Images.prototype.main_action = function() { 69 var images, skin; 70 switch (this._parent.constructor) { 71 case Root: 72 case Site: 73 images = User.getMembership().images; 74 skin = "$Images#main"; 75 res.data.title = gettext("Member Images"); 76 break; 77 78 case Layout: 79 images = res.handlers.layout.images; 80 skin = "$Images#layout"; 81 res.data.title = gettext("Layout Images"); 82 break; 83 } 84 res.data.list = renderList(images, "$Image#listItem", 85 10, req.queryParams.page); 86 res.data.pager = renderPager(images, 87 this.href(req.action), 10, req.queryParams.page); 88 res.data.body = this.renderSkinAsString(skin); 89 res.handlers.site.renderSkin("Site#page"); 90 return; 91 } 92 93 Images.prototype.create_action = function() { 94 File.redirectOnUploadError(this.href(req.action)); 95 File.redirectOnExceededQuota(this.href()); 96 97 if (req.data.save) { 98 try { 99 var image = Image.add(req.params, this._parent); 100 image.notify(req.action); 101 JSON.sendPaddedResponse(image._id); 102 res.message = gettext('The image was successfully added.'); 103 res.redirect(image.href()); 104 } catch (ex) { 105 JSON.sendPaddedResponse(null); 106 res.status = 400; 107 res.message = ex.toString(); 108 app.log(ex); 109 } 110 } 111 112 res.data.action = this.href(req.action); 113 res.data.title = gettext("Add Image"); 114 HopObject.confirmConstructor(Image); 115 res.data.body = (new Image).renderSkinAsString("$Image#edit"); 116 res.handlers.site.renderSkin("Site#page"); 117 return; 118 } 119 120 Images.prototype.all_action = function() { 121 res.data.pager = renderPager(this, this.href(req.action), 122 10, req.queryParams.page); 123 res.data.list = renderList(this, "$Image#listItem", 124 10, req.queryParams.page); 125 res.data.title = gettext("All Images"); 126 res.data.body = this.renderSkinAsString("$Images#main"); 127 res.handlers.site.renderSkin("Site#page"); 128 return; 129 } 130 131 /** 132 * @namespace 133 * @field 134 */ 135 Images.Default = new function() { 136 var Image = function(name, description) { 137 var dir = new helma.File(app.appsProperties['static'], "www"); 138 var image = new helma.Image(new helma.File(dir, name)); 139 this.name = name; 140 this.description = description; 141 this.width = image.width; 142 this.height = image.height; 143 this.getUrl = function() { 144 return app.appsProperties.staticMountpoint + "/www/" + name; 145 } 146 this.render_macro = global.Image.prototype.render_macro; 147 this.thumbnail_macro = global.Image.prototype.thumbnail_macro; 148 return this; 149 } 150 151 var images = {}; 152 var add = function(name, description) { 153 images[name] = new Image(name, description); 154 return; 155 } 156 add("ant.png", "Ant"); 157 add("ant-icon.png", "Tiny Ant"); 158 add("big.gif", String.EMPTY); 159 add("bullet.gif", "*"); 160 add("dot.gif", String.EMPTY); 161 add("headbg.gif", String.EMPTY); 162 add("helma.png", "Helma Object Publisher"); 163 add("hop.gif", "Helma Object Publisher"); 164 add("manage.gif", "manage"); 165 add("marquee.gif", String.EMPTY); 166 add("menu.gif", "menu"); 167 add("pixel.gif", String.EMPTY); 168 add("recent.gif", "recent"); 169 add("rss.png", "RSS feed"); 170 add("smallanim.gif", "Made with Antville"); 171 add("smallchaos.gif", "Made with Antville"); 172 add("smallstraight.gif", "Made with Antville"); 173 add("smalltrans.gif", "Made with Antville"); 174 add("status.gif", "status"); 175 add("webloghead.gif", "Antville"); 176 add("xmlbutton.gif", "XML version of this page"); 177 return images; 178 } 179 180 /** 181 * @returns {Image[]} 182 */ 183 Images.prototype.mergeImages = function() { 184 var images = []; 185 var layout = this._parent; 186 while (layout) { 187 layout.images.forEach(function() { 188 if (images.indexOf(this) < 0) { 189 images.push(this); 190 } 191 return; 192 }); 193 layout = layout.parent; 194 } 195 return images.sort(Number.Sorter("created", Number.Sorter.DESC)); 196 } 197 198 /** 199 * 200 * @param {String} group 201 * @returns {Tag[]} 202 * @see Site#getTags 203 */ 204 Images.prototype.getTags = function(group) { 205 return this._parent.getTags("galleries", group); 206 } 207