antville/code/Story/actions.js

105 lines
2.8 KiB
JavaScript
Raw Normal View History

/**
* main action
*/
function main_action() {
res.data.title = this.site.title;
var storytitle = this.getRenderedContentPart("title");
if (storytitle)
res.data.title += ": " + stripTags(storytitle);
res.data.body = this.renderSkinAsString("main");
this.site.renderSkin("page");
// increment read-counter
this.incrementReadCounter();
logAccess();
}
/**
* edit action
*/
function edit_action() {
// restore any rescued text
if (session.data.rescuedText)
restoreRescuedText();
if (req.data.set) {
this.toggleOnline(req.data.set);
if (req.data.http_referer)
res.redirect(req.data.http_referer);
res.redirect(this.site.stories.href());
} else if (req.data.cancel) {
res.redirect(this.online ? this.href() : this.site.stories.href());
} else if (req.data.save || req.data.publish) {
try {
var result = this.evalStory(req.data, session.user);
res.message = result.toString();
res.redirect(result.url);
} catch (err) {
res.message = err.toString();
}
}
res.data.action = this.href(req.action);
res.data.title = "Edit story";
if (this.title)
res.data.title += ": " + encode(this.title);
res.data.body = this.renderSkinAsString("edit");
this.site.renderSkin("page");
}
/**
* delete action
*/
function delete_action() {
if (req.data.cancel)
res.redirect(this.site.stories.href());
else if (req.data.remove) {
try {
res.message = this.site.stories.deleteStory(this);
res.redirect(this.site.stories.href());
} catch (err) {
res.message = err.toString();
}
}
res.data.action = this.href(req.action);
res.data.title = "Delete story";
if (this.title)
res.data.title += ": " + encode(this.title);
var sp = new Object();
sp.what = this.title ? "the story "" + this.title + """ : "a story";
if (this.creator)
sp.what += " created by " + this.creator.name;
res.data.body = this.renderSkinAsString("delete", sp);
this.site.renderSkin("page");
}
/**
* comment action
*/
function comment_action() {
// restore any rescued text
if (session.data.rescuedText)
restoreRescuedText();
if (req.data.cancel)
res.redirect(this.href());
else if (req.data.save) {
try {
var result = this.evalComment(req.data, session.user);
res.message = result.toString();
res.redirect(this.href() + "#" + result.id);
} catch (err) {
res.message = err.toString();
}
}
res.data.action = this.href(req.action);
res.data.title = this.site.title;
if (this.title)
res.data.title += " - " + encode(this.title);
res.data.body = this.renderSkinAsString("comment");
this.site.renderSkin("page");
// increment read-counter
this.incrementReadCounter();
}