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:3346 $ 20 // $LastChangedBy:piefke3000 $ 21 // $LastChangedDate:2007-10-04 20:48:35 +0200 (Thu, 04 Oct 2007) $ 22 // $URL$ 23 // 24 25 /** 26 * @fileOverview Defines the Polls prototype 27 */ 28 29 /** 30 * @name Polls 31 * @constructor 32 * @property {Poll[]} _children 33 * @property {Poll[]} open 34 * @extends HopObject 35 */ 36 37 /** 38 * 39 * @param {String} action 40 * @returns {Boolean} 41 */ 42 Polls.prototype.getPermission = function(action) { 43 if (!this._parent.getPermission("main")) { 44 return false; 45 } 46 switch (action) { 47 case ".": 48 case "main": 49 case "create": 50 case "open": 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 Polls.prototype.main_action = function() { 62 var polls = User.getMembership().polls; 63 res.data.list = renderList(polls, "$Poll#listItem", 10, req.queryParams.page); 64 res.data.pager = renderPager(polls, this.href(req.action), 65 10, req.queryParams.page); 66 res.data.title = gettext("Member polls of {0}", this._parent.title); 67 res.data.body = this.renderSkinAsString("$Polls#main"); 68 this._parent.renderSkin("Site#page"); 69 return; 70 } 71 72 Polls.prototype.create_action = function() { 73 var poll = new Poll; 74 if (req.postParams.save) { 75 try { 76 poll.update(req.postParams); 77 this.add(poll); 78 poll.notify(req.action); 79 res.message = gettext("The poll was created successfully."); 80 res.redirect(poll.href()); 81 } catch (err) { 82 res.message = err.toString(); 83 } 84 } else { 85 req.postParams.title_array = [,,]; 86 } 87 res.data.action = this.href(req.action); 88 res.data.title = gettext("Add poll to site {0}", this._parent.title); 89 res.data.body = poll.renderSkinAsString("$Poll#edit"); 90 this._parent.renderSkin("Site#page"); 91 return; 92 } 93 94 Polls.prototype.open_action = function() { 95 res.data.list = renderList(this.open, 96 "$Poll#listItem", 10, req.queryParams.page); 97 res.data.pager = renderPager(this.open, 98 this.href(req.action), 10, req.queryParams.page); 99 res.data.title = gettext("Open polls of {0}", this._parent.title); 100 res.data.body = this.renderSkinAsString("$Polls#main"); 101 this._parent.renderSkin("Site#page"); 102 return; 103 } 104 105 Polls.prototype.all_action = function() { 106 res.data.list = renderList(this, "$Poll#listItem", 10, req.queryParams.page); 107 res.data.pager = renderPager(this, 108 this.href(), 10, req.queryParams.page); 109 res.data.title = gettext("Polls of {0}", this._parent.title); 110 res.data.body = this.renderSkinAsString("$Polls#main"); 111 this._parent.renderSkin("Site#page"); 112 return; 113 } 114