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    var file = new File;
 60    file.site = res.handlers.site;
 61    if (req.postParams.save) {
 62       try {
 63          file.update(req.postParams);
 64          this.add(file);
 65          file.notify(req.action);
 66          res.message = gettext('The file was added successfully. Its name is "{0}"', file.name);
 67          res.redirect(this.href());
 68       } catch (ex) {
 69          res.message = ex;
 70          app.log(ex);
 71       }
 72    }
 73    
 74    res.data.action = this.href(req.action);
 75    res.data.title = gettext("Add file to site {0}", this._parent.title);
 76    res.data.body = file.renderSkinAsString("$File#edit");
 77    this._parent.renderSkin("Site#page");
 78    return;
 79 }
 80 
 81 Files.prototype.main_action = function() {
 82    var files = User.getMembership().files;
 83    res.data.list = renderList(files, "$File#listItem", 10, req.queryParams.page);
 84    res.data.pager = renderPager(files, this.href(), 
 85          10, req.queryParams.page);
 86    res.data.title = gettext("Member files of {0}", this._parent.title);
 87    res.data.body = this.renderSkinAsString("$Files#main");
 88    this._parent.renderSkin("Site#page");
 89    return;
 90 }
 91 
 92 Files.prototype.all_action = function() {
 93    res.data.list = renderList(this, "$File#listItem", 10, req.queryParams.page);
 94    res.data.pager = renderPager(this, 
 95          this.href(req.action), 10, req.queryParams.page);
 96    res.data.title = gettext("Files of {0}", this._parent.title);
 97    res.data.body = this.renderSkinAsString("$Files#main");
 98    this._parent.renderSkin("Site#page");
 99    return;
100 }
101