* Re-implemented autosave feature (ie. automatic backup / restore) for stories and comments

* Removed obsolete rescue methods
 * Moved contents of many individual skin files as subskins in the corresponding prototype skin file
 * Moved commentform_macro of Story prototype into compatibility module
This commit is contained in:
Tobi Schäfer 2007-10-16 16:48:14 +00:00
parent ec700a655f
commit 75644bde63
18 changed files with 132 additions and 146 deletions

View file

@ -109,13 +109,10 @@ Story.prototype.getTitle = function(limit) {
};
Story.prototype.edit_action = function() {
if (session.data.rescuedText) {
restoreRescuedText();
}
if (req.postParams.save) {
//try {
this.update(req.postParams);
delete session.data.backup;
res.message = gettext("The story was successfully updated.");
res.redirect(this.href());
//} catch (ex) {
@ -228,9 +225,6 @@ Story.prototype.rotate_action = function() {
};
Story.prototype.comment_action = function() {
if (session.data.rescuedText) {
restoreRescuedText();
}
var comment = new Comment(this);
if (req.postParams.save) {
try {
@ -239,6 +233,7 @@ Story.prototype.comment_action = function() {
// Force addition to aggressively cached subcollection
(this.story || this).comments.add(comment);
comment.notify(req.action);
delete session.data.backup;
res.message = gettext("The comment was successfully created.");
res.redirect(comment.href());
} catch (ex) {
@ -313,20 +308,6 @@ Story.prototype.comments_macro = function(param, mode) {
return;
};
Story.prototype.commentform_macro = function(param) {
if (this.commentsMode === "closed") {
return;
}
if (session.user) {
res.data.action = this.href("comment");
(new Comment()).renderSkin("Comment#edit");
} else {
html.link({href: this.site.members.href("login")},
param.text || gettext("Please login to add a comment"));
}
return;
};
Story.prototype.tags_macro = function() {
return res.write(this.getFormValue("tags"));
};
@ -477,12 +458,6 @@ Story.prototype.macro_filter = function(value, param) {
skin.allowMacro("imageoftheday");
skin.allowMacro("spacer");
// FIXME: allow module text macros
for (var i in app.modules) {
if (app.modules[i].allowTextMacros)
app.modules[i].allowTextMacros(skin);
}
var site;
if (this.site !== res.handlers.site) {
site = res.handlers.site;

View file

@ -163,15 +163,56 @@ for (var i in referrers) {
</noscript>
</table>
<% #restore %>
<script type="text/javascript">
<!--
$(function() {
if (!"<% session.backup %>") {
$("#restore").hide();
} else {
$("#restore").click(function() {
$("#title").val(decodeURIComponent("<% session.backup.title %>"));
$("#text").val(decodeURIComponent("<% session.backup.text %>"));
$(this).hide();
return;
});
}
var currentTitle, currentText;
$(".backup > :input").blur(function() {
var title = $.trim($("#title").val());
var text = $.trim($("#text").val());
if ((title || text) && (currentTitle || currentText) &&
(currentTitle !== title || currentText !== text)) {
$.ajax({
async: true,
type: "POST",
url: '<% root.href backup.js %>',
data: {title: encodeURIComponent(title),
text: encodeURIComponent(text)},
dataType: "json"
});
}
currentTitle = title;
currentText = text
return;;
});
return;
});
//-->
</script>
<% #edit %>
<% story.skin Story#restore %>
<form method="post" action="<% response.action %>">
<p>
<div class="small">Title:</div>
<div><% story.input title class="formTitle" %></div>
<div class="backup"><% story.input title class="formTitle" %></div>
</p>
<p>
<div class="small">Text:</div>
<div><% story.textarea text cols="30" rows="15" class="formText" %></div>
<div class="backup"><% story.textarea text cols="30" rows="15"
class="formText" %></div>
</p>
<p><fieldset>
<legend class="small">Options</legend>
@ -189,5 +230,6 @@ for (var i in referrers) {
<button type="submit" name="save" value="1">save</button>
<!--button type="submit" name="save" value="2">publish</button-->
<button type="submit" name="cancel" value="1">cancel</button>
<button type="button" id="restore" value="1">restore</button>
</p>
</form>