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 markgettext("Polls"); 30 markgettext("polls"); 31 32 /** 33 * @name Polls 34 * @constructor 35 * @property {Poll[]} _children 36 * @property {Poll[]} open 37 * @extends HopObject 38 */ 39 40 /** 41 * 42 * @param {String} action 43 * @returns {Boolean} 44 */ 45 Polls.prototype.getPermission = function(action) { 46 if (!this._parent.getPermission("main")) { 47 return false; 48 } 49 switch (action) { 50 case ".": 51 case "main": 52 case "create": 53 case "running": 54 return Site.require(Site.OPEN) && session.user || 55 Membership.require(Membership.CONTRIBUTOR) || 56 User.require(User.PRIVILEGED); 57 case "all": 58 return Membership.require(Membership.MANAGER) || 59 User.require(User.PRIVILEGED); 60 } 61 return false; 62 } 63 64 Polls.prototype.main_action = function() { 65 var polls = User.getMembership().polls; 66 res.data.list = renderList(polls, "$Poll#listItem", 10, req.queryParams.page); 67 res.data.pager = renderPager(polls, this.href(req.action), 68 10, req.queryParams.page); 69 res.data.title = gettext("Member Polls"); 70 res.data.body = this.renderSkinAsString("$Polls#main"); 71 this._parent.renderSkin("Site#page"); 72 return; 73 } 74 75 Polls.prototype.create_action = function() { 76 var poll = new Poll; 77 if (req.postParams.save) { 78 try { 79 poll.update(req.postParams); 80 this.add(poll); 81 poll.notify(req.action); 82 res.message = gettext("The poll was created successfully."); 83 res.redirect(poll.href()); 84 } catch (err) { 85 res.message = err.toString(); 86 } 87 } else { 88 req.postParams.title_array = [,,]; 89 } 90 res.data.action = this.href(req.action); 91 res.data.title = gettext("Add Poll"); 92 res.data.body = poll.renderSkinAsString("$Poll#edit"); 93 this._parent.renderSkin("Site#page"); 94 return; 95 } 96 97 Polls.prototype.running_action = function() { 98 res.data.list = renderList(this.running, 99 "$Poll#listItem", 10, req.queryParams.page); 100 res.data.pager = renderPager(this.running, 101 this.href(req.action), 10, req.queryParams.page); 102 res.data.title = gettext("Running Polls"); 103 res.data.body = this.renderSkinAsString("$Polls#main"); 104 this._parent.renderSkin("Site#page"); 105 return; 106 } 107 108 Polls.prototype.all_action = function() { 109 res.data.list = renderList(this, "$Poll#listItem", 10, req.queryParams.page); 110 res.data.pager = renderPager(this, 111 this.href(), 10, req.queryParams.page); 112 res.data.title = gettext("All Polls"); 113 res.data.body = this.renderSkinAsString("$Polls#main"); 114 this._parent.renderSkin("Site#page"); 115 return; 116 } 117