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