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