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");
 72       break;
 73       
 74       case Layout:
 75       images = res.handlers.layout.images;
 76       skin = "$Images#layout";
 77       res.data.title = gettext("Layout Images");
 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    if (this._parent.getDiskSpace() < 0) {
 91       res.message = gettext("Sorry, there is no disk space left. Please try to delete some files or images first.");
 92       res.redirect(this.href());
 93    }
 94 
 95    var image = new Image;
 96    image.parent = this._parent;
 97    
 98    if (req.postParams.save) {
 99       try {
100          image.update(req.postParams);
101          this.add(image);
102          image.notify(req.action);
103          res.message = gettext('The image was successfully added.');
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");
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("All Images");
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 = new 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("ant.png", "Ant");
155    add("ant-icon.png", "Tiny Ant");
156    add("big.gif", String.EMPTY);
157    add("bullet.gif", "*");
158    add("dot.gif", String.EMPTY);
159    add("headbg.gif", String.EMPTY);
160    add("helma.png", "Helma Object Publisher");
161    add("hop.gif", "Helma Object Publisher");
162    add("manage.gif", "manage");
163    add("marquee.gif", String.EMPTY);
164    add("menu.gif", "menu");
165    add("pixel.gif", String.EMPTY);
166    add("recent.gif", "recent");
167    add("rss.png", "RSS feed");
168    add("smallanim.gif", "Made with Antville");
169    add("smallchaos.gif", "Made with Antville");
170    add("smallstraight.gif", "Made with Antville");
171    add("smalltrans.gif", "Made with Antville");
172    add("status.gif", "status");
173    add("webloghead.gif", "Antville");
174    add("xmlbutton.gif", "XML version of this page");
175    return images;
176 }
177 
178 /**
179  * @returns {Image[]}
180  */
181 Images.prototype.mergeImages = function() {
182    var images = [];
183    var layout = this._parent;
184    while (layout) {
185       layout.images.forEach(function() {
186          if (images.indexOf(this) < 0) {
187             images.push(this);
188          }
189          return;
190       });
191       layout = layout.parent;
192    }
193    return images.sort(Number.Sorter("created", Number.Sorter.DESC));
194 }
195 
196 /**
197  * 
198  * @param {String} group
199  * @returns {Tag[]}
200  * @see Site#getTags
201  */
202 Images.prototype.getTags = function(group) {
203    return this._parent.getTags("galleries", group);
204 }
205