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 res.data.body = (new Story).renderSkinAsString("Story#edit"); 107 this._parent.renderSkin("Site#page"); 108 return; 109 } 110 111 Stories.prototype.closed_action = function() { 112 res.data.list = renderList(this.closed, 113 "$Story#listItem", 10, req.queryParams.page); 114 res.data.pager = renderPager(this.closed, 115 this.href(req.action), 10, req.queryParams.page); 116 res.data.title = gettext("Closed Stories"); 117 res.data.body = this.renderSkinAsString("$Stories#main"); 118 this._parent.renderSkin("Site#page"); 119 return; 120 } 121 122 Stories.prototype.all_action = function() { 123 res.data.list = renderList(this, "$Story#listItem", 10, req.queryParams.page); 124 res.data.pager = renderPager(this, 125 this.href(req.action), 10, req.queryParams.page); 126 res.data.title = gettext("All Stories"); 127 res.data.body = this.renderSkinAsString("$Stories#main"); 128 this._parent.renderSkin("Site#page"); 129 return; 130 } 131 132 Stories.prototype.top_action = function() { 133 res.data.title = gettext("Top Stories"); 134 res.data.body = this.renderSkinAsString("$Stories#top"); 135 this._parent.renderSkin("Site#page"); 136 return; 137 } 138 139 /** 140 * 141 * @param {Object} param 142 * @param {String} type 143 */ 144 Stories.prototype.list_macro = function(param, type) { 145 switch (type) { 146 case "top": 147 var counter = 1; 148 this.top.forEach(function() { 149 this.renderSkin("$Story#top", { 150 position: counter 151 }); 152 counter += 1; 153 }); 154 break; 155 } 156 return; 157 } 158 159 /** 160 * 161 * @param {String} group 162 * @returns {Tag[]} 163 * @see Site#getTags 164 */ 165 Stories.prototype.getTags = function(group) { 166 return this._parent.getTags("tags", group); 167 } 168 169 /** 170 * 171 * @param {String} name 172 * @returns {String[]} 173 */ 174 Stories.prototype.getAdminHeader = function(name) { 175 return ["#", "Tag", "Items"]; 176 } 177