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:3341 $ 20 // $LastChangedBy:piefke3000 $ 21 // $LastChangedDate:2007-09-27 00:22:37 +0200 (Thu, 27 Sep 2007) $ 22 // $URL$ 23 // 24 25 /** 26 * @fileOverview Defines the Stories prototype 27 */ 28 29 markgettext("Stories"); 30 markgettext("stories"); 31 32 /** 33 * @name Stories 34 * @constructor 35 * @property {Story[]} _children 36 * @property {Tag[]} alphabeticalTags 37 * @property {Story[]} closed 38 * @property {Comment[]} comments 39 * @property {Story[]} featured 40 * @property {Tag[]} otherTags 41 * @property {Story[]} recent 42 * @property {Tag[]} tags 43 * @property {Story[]} top 44 * @property {Story[]} union 45 * @extends HopObject 46 */ 47 48 /** 49 * 50 * @param {String} action 51 * @returns {Boolean} 52 */ 53 Stories.prototype.getPermission = function(action) { 54 if (!this._parent.getPermission("main")) { 55 return false; 56 } 57 switch (action) { 58 case ".": 59 case "main": 60 case "create": 61 return Site.require(Site.OPEN) && session.user || 62 Membership.require(Membership.CONTRIBUTOR) || 63 User.require(User.PRIVILEGED); 64 65 case "all": 66 case "top": 67 case "closed": 68 return Membership.require(Membership.MANAGER) || 69 User.require(User.PRIVILEGED); 70 } 71 return false; 72 } 73 74 Stories.prototype.main_action = function() { 75 var stories = User.getMembership().stories; 76 res.data.list = renderList(stories, "$Story#listItem", 77 10, req.queryParams.page); 78 res.data.pager = renderPager(stories, 79 this.href(), 10, req.queryParams.page); 80 res.data.title = gettext("Member Stories"); 81 res.data.body = this.renderSkinAsString("$Stories#main"); 82 this._parent.renderSkin("Site#page"); 83 return; 84 } 85 86 Stories.prototype.create_action = function() { 87 var story = new Story; 88 if (req.postParams.save) { 89 try { 90 story.update(req.postParams); 91 this.add(story); 92 story.notify(req.action); 93 delete session.data.backup; 94 res.message = gettext("The story was successfully created."); 95 res.redirect(story.href()); 96 } catch (ex) { 97 res.message = ex; 98 app.log(ex); 99 } 100 } 101 102 res.data.title = gettext("Add Story"); 103 res.data.action = this.href(req.action); 104 res.data.body = story.renderSkinAsString("Story#edit"); 105 this._parent.renderSkin("Site#page"); 106 return; 107 } 108 109 Stories.prototype.closed_action = function() { 110 res.data.list = renderList(this.closed, 111 "$Story#listItem", 10, req.queryParams.page); 112 res.data.pager = renderPager(this.closed, 113 this.href(req.action), 10, req.queryParams.page); 114 res.data.title = gettext("Closed Stories"); 115 res.data.body = this.renderSkinAsString("$Stories#main"); 116 this._parent.renderSkin("Site#page"); 117 return; 118 } 119 120 Stories.prototype.all_action = function() { 121 res.data.list = renderList(this, "$Story#listItem", 10, req.queryParams.page); 122 res.data.pager = renderPager(this, 123 this.href(req.action), 10, req.queryParams.page); 124 res.data.title = gettext("All Stories"); 125 res.data.body = this.renderSkinAsString("$Stories#main"); 126 this._parent.renderSkin("Site#page"); 127 return; 128 } 129 130 Stories.prototype.top_action = function() { 131 res.data.title = gettext("Top Stories"); 132 res.data.body = this.renderSkinAsString("$Stories#top"); 133 this._parent.renderSkin("Site#page"); 134 return; 135 } 136 137 /** 138 * 139 * @param {Object} param 140 * @param {String} type 141 */ 142 Stories.prototype.list_macro = function(param, type) { 143 switch (type) { 144 case "top": 145 var counter = 1; 146 this.top.forEach(function() { 147 this.renderSkin("$Story#top", { 148 position: counter 149 }); 150 counter += 1; 151 }); 152 break; 153 } 154 return; 155 } 156 157 /** 158 * 159 * @param {String} group 160 * @returns {Tag[]} 161 * @see Site#getTags 162 */ 163 Stories.prototype.getTags = function(group) { 164 return this._parent.getTags("tags", group); 165 } 166 167 /** 168 * 169 * @param {String} name 170 * @returns {String[]} 171 */ 172 Stories.prototype.getAdminHeader = function(name) { 173 return ["#", "Tag", "Items"]; 174 } 175