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 /** 30 * @name Images 31 * @constructor 32 * @property {Image} _children 33 * @property {Tag[]} alphabeticalGalleries 34 * @property {Tag[]} galleries 35 * @property {Tag[]} otherGalleries 36 * @extends HopObject 37 */ 38 39 /** 40 * 41 * @param {String} action 42 * @returns {Boolean} 43 */ 44 Images.prototype.getPermission = function(action) { 45 if (!this._parent.getPermission("main")) { 46 return false; 47 } 48 switch (action) { 49 case ".": 50 case "main": 51 case "create": 52 // FIXME: case "tags": 53 return Site.require(Site.OPEN) && session.user || 54 Membership.require(Membership.CONTRIBUTOR) || 55 User.require(User.PRIVILEGED); 56 case "all": 57 return this._parent.constructor !== Layout && 58 (Membership.require(Membership.MANAGER) || 59 User.require(User.PRIVILEGED)); 60 } 61 return false; 62 } 63 64 Images.prototype.main_action = function() { 65 var images, skin; 66 switch (this._parent.constructor) { 67 case Root: 68 case Site: 69 images = User.getMembership().images; 70 skin = "$Images#main"; 71 res.data.title = gettext("Member images of {0}", this._parent.title); 72 break; 73 74 case Layout: 75 images = res.handlers.layout.images; 76 skin = "$Images#layout"; 77 res.data.title = gettext("Layout images of {0}", res.handlers.site.title); 78 break; 79 } 80 res.data.list = renderList(images, "$Image#listItem", 81 10, req.queryParams.page); 82 res.data.pager = renderPager(images, 83 this.href(req.action), 10, req.queryParams.page); 84 res.data.body = this.renderSkinAsString(skin); 85 res.handlers.site.renderSkin("Site#page"); 86 return; 87 } 88 89 Images.prototype.create_action = function() { 90 var image = new Image; 91 image.site = res.handlers.site; 92 // We need to set the parent's type for getting the correct file path 93 image.parent_type = this._parent._prototype; 94 95 if (req.postParams.save) { 96 try { 97 image.update(req.postParams); 98 this.add(image); 99 // FIXME: To be removed if work-around for Helma bug #607 passes 100 //image.setTags(req.postParams.tags || req.postParams.tag_array); 101 image.notify(req.action); 102 res.message = gettext('The uploaded image was saved successfully. Its name is "{0}"', 103 image.name); 104 res.redirect(image.href()); 105 } catch (ex) { 106 res.message = ex.toString(); 107 app.log(ex); 108 } 109 } 110 111 res.data.action = this.href(req.action); 112 res.data.title = gettext("Add image to site {0}", res.handlers.site.title); 113 res.data.body = image.renderSkinAsString("$Image#edit"); 114 res.handlers.site.renderSkin("Site#page"); 115 return; 116 } 117 118 Images.prototype.all_action = function() { 119 res.data.pager = renderPager(this, this.href(req.action), 120 10, req.queryParams.page); 121 res.data.list = renderList(this, "$Image#listItem", 122 10, req.queryParams.page); 123 res.data.title = gettext("Images of {0}", this._parent.title); 124 res.data.body = this.renderSkinAsString("$Images#main"); 125 res.handlers.site.renderSkin("Site#page"); 126 return; 127 } 128 129 /** 130 * @namespace 131 * @field 132 */ 133 Images.Default = (function() { 134 var Image = function(name, description) { 135 var fpath = app.properties.staticPath + "www/" + name; 136 var image = new helma.Image(fpath); 137 this.name = name; 138 this.description = description; 139 this.width = image.width; 140 this.height = image.height; 141 this.getUrl = function() { 142 return app.properties.staticUrl + "www/" + name; 143 } 144 this.render_macro = global.Image.prototype.render_macro; 145 this.thumbnail_macro = global.Image.prototype.thumbnail_macro; 146 return this; 147 } 148 149 var images = {}; 150 var add = function(name, description) { 151 images[name] = new Image(name, description); 152 return; 153 } 154 add("rss.png", "RSS feed"); 155 add("webloghead.gif", "Antville"); 156 add("bullet.gif", "*"); 157 add("smallanim.gif", "Made with Antville"); 158 add("smallchaos.gif", "Made with Antville"); 159 add("smallstraight.gif", "Made with Antville"); 160 add("smalltrans.gif", "Made with Antville"); 161 add("xmlbutton.gif", "XML version of this page"); 162 add("hop.gif", "Helma Object Publisher"); 163 add("marquee.gif", String.EMPTY); 164 add("pixel.gif", String.EMPTY); 165 add("dot.gif", String.EMPTY); 166 return images; 167 })(); 168 169 /** 170 * @returns {Image[]} 171 */ 172 Images.prototype.mergeImages = function() { 173 var images = []; 174 var layout = this._parent; 175 while (layout) { 176 layout.images.forEach(function() { 177 if (images.indexOf(this) < 0) { 178 images.push(this); 179 } 180 return; 181 }); 182 layout = layout.parent; 183 } 184 return images.sort(Number.Sorter("created", Number.Sorter.DESC)); 185 } 186 187 /** 188 * 189 * @param {String} group 190 * @returns {Tag[]} 191 * @see Site#getTags 192 */ 193 Images.prototype.getTags = function(group) { 194 return this._parent.getTags("galleries", group); 195 } 196 197 /** 198 * 199 */ 200 Images.remove = function() { 201 if (this.constructor === Images) { 202 HopObject.remove(this); 203 } 204 return; 205 } 206