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 // 18 // limitations under the License. 19 // $Revision:3339 $ 20 // $LastChangedBy:piefke3000 $ 21 // $LastChangedDate:2007-09-25 00:00:46 +0200 (Tue, 25 Sep 2007) $ 22 // $URL$ 23 // 24 25 /** 26 * @fileOverview Defines the Comment prototype. 27 */ 28 29 markgettext("Files"); 30 markgettext("files"); 31 32 /** 33 * @name Files 34 * @constructor 35 * @extends HopObject 36 */ 37 38 /** 39 * 40 * @param {String} action 41 * @returns {Boolean} 42 */ 43 Files.prototype.getPermission = function(action) { 44 if (!this._parent.getPermission("main")) { 45 return false; 46 } 47 switch (action) { 48 case ".": 49 case "main": 50 case "create": 51 return Site.require(Site.OPEN) && session.user || 52 Membership.require(Membership.CONTRIBUTOR) || 53 User.require(User.PRIVILEGED); 54 case "all": 55 return Membership.require(Membership.MANAGER) || 56 User.require(User.PRIVILEGED); 57 } 58 return false; 59 } 60 61 Files.prototype.create_action = function() { 62 if (this._parent.getDiskSpace() < 0) { 63 res.message = gettext("Sorry, there is no disk space left. Please try to delete some files or images first."); 64 res.redirect(this.href()); 65 } 66 67 var file = new File; 68 file.site = res.handlers.site; 69 if (req.postParams.save) { 70 try { 71 file.update(req.postParams); 72 this.add(file); 73 file.notify(req.action); 74 res.message = gettext('The file was successfully added.'); 75 res.redirect(this.href()); 76 } catch (ex) { 77 res.message = ex; 78 app.log(ex); 79 } 80 } 81 82 res.data.action = this.href(req.action); 83 res.data.title = gettext("Add File"); 84 res.data.body = file.renderSkinAsString("$File#edit"); 85 this._parent.renderSkin("Site#page"); 86 return; 87 } 88 89 Files.prototype.main_action = function() { 90 var files = User.getMembership().files; 91 res.data.list = renderList(files, "$File#listItem", 10, req.queryParams.page); 92 res.data.pager = renderPager(files, this.href(), 93 10, req.queryParams.page); 94 res.data.title = gettext("Member Files"); 95 res.data.body = this.renderSkinAsString("$Files#main"); 96 this._parent.renderSkin("Site#page"); 97 return; 98 } 99 100 Files.prototype.all_action = function() { 101 res.data.list = renderList(this, "$File#listItem", 10, req.queryParams.page); 102 res.data.pager = renderPager(this, 103 this.href(req.action), 10, req.queryParams.page); 104 res.data.title = gettext("All Files"); 105 res.data.body = this.renderSkinAsString("$Files#main"); 106 this._parent.renderSkin("Site#page"); 107 return; 108 } 109