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