      1 // The Antville Project
      2 // http://code.google.com/p/antville
      3 //
      4 // Copyright 2007-2011 by Tobi Schäfer.
      5 //
      6 // Copyright 2001–2007 Robert Gaggl, Hannes Wallnöfer, Tobi Schäfer,
      7 // Matthias & Michael Platzer, Christoph Lincke.
      8 //
      9 // Licensed under the Apache License, Version 2.0 (the ``License'');
     10 // you may not use this file except in compliance with the License.
     11 // You may obtain a copy of the License at
     12 //
     13 //    http://www.apache.org/licenses/LICENSE-2.0
     14 //
     15 // Unless required by applicable law or agreed to in writing, software
     16 // distributed under the License is distributed on an ``AS IS'' BASIS,
     17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     18 // See the License for the specific language governing permissions and
     19 // limitations under the License.
     20 //
     21 // $Revision$
     22 // $Author$
     23 // $Date$
     24 // $URL$
     25
     26 /**
     27  * @fileOverview Defines the Comment prototype.
     28  */
     29
     30 markgettext("Files");
     31 markgettext("files");
     32
     33 /**
     34  * @name Files
     35  * @constructor
     36  * @extends HopObject
     37  */
     38
     39 /**
     40  *
     41  * @param {String} action
     42  * @returns {Boolean}
     43  */
     44 Files.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       return Site.require(Site.OPEN) && session.user ||
     53             Membership.require(Membership.CONTRIBUTOR) ||
     54             User.require(User.PRIVILEGED);
     55       case "all":
     56       return Membership.require(Membership.MANAGER) ||
     57             User.require(User.PRIVILEGED);
     58    }
     59    return false;
     60 }
     61
     62 Files.prototype.create_action = function() {
     63    File.redirectOnUploadError(this.href(req.action));
     64    File.redirectOnExceededQuota(this.href());
     65
     66    if (req.postParams.save) {
     67       try {
     68          var file = File.add(req.postParams);
     69          file.notify(req.action);
     70          res.message = gettext('The file was successfully added.');
     71          res.redirect(this.href());
     72       } catch (ex) {
     73          res.message = ex;
     74          app.log(ex);
     75       }
     76    }
     77
     78    res.data.action = this.href(req.action);
     79    res.data.title = gettext("Add File");
     80    HopObject.confirmConstructor(File);
     81    res.data.body = (new 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