* 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:
parent
ec700a655f
commit
75644bde63
18 changed files with 132 additions and 146 deletions
|
@ -66,13 +66,10 @@ Comment.prototype.main_action = function() {
|
|||
};
|
||||
|
||||
Comment.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 comment was successfully updated.");;
|
||||
res.redirect(this.story.href() + "#" + this._id);
|
||||
} catch (ex) {
|
||||
|
@ -121,29 +118,3 @@ Comment.remove = function() {
|
|||
this.remove();
|
||||
return;
|
||||
};
|
||||
|
||||
Comment.prototype.___comment_action = function() {
|
||||
if (session.data.rescuedText) {
|
||||
restoreRescuedText();
|
||||
}
|
||||
|
||||
var comment = new Comment;
|
||||
if (req.postParams.save) {
|
||||
try {
|
||||
comment.update(req.postParams);
|
||||
this.add(comment);
|
||||
res.message;
|
||||
res.redirect(comment.href());
|
||||
} catch (err) {
|
||||
res.message = err.toString();
|
||||
}
|
||||
}
|
||||
|
||||
res.data.action = this.href(req.action);
|
||||
res.data.title = gettext("Reply to comment of story {0}",
|
||||
res.handlers.story.getTitle());
|
||||
res.data.body = this.renderSkinAsString("Comment#replay");
|
||||
res.data.body += comment.renderSkinAsString("Comment#edit");
|
||||
this.site.renderSkin("page");
|
||||
return;
|
||||
};
|
||||
|
|
|
@ -37,16 +37,17 @@
|
|||
</div>
|
||||
|
||||
<% #edit %>
|
||||
<% comment.skin Story#restore %>
|
||||
<% parent.skin <% parent.type suffix="#comment" %> %>
|
||||
<a name="form" id="form"></a>
|
||||
<br />
|
||||
<a name="form" id="form"></a>
|
||||
<form method="post" action="<% response.action %>">
|
||||
<p>
|
||||
<p class="backup">
|
||||
<span class="small">Title:</span><br />
|
||||
<% comment.input title class="formTitle" %>
|
||||
</p>
|
||||
<p>
|
||||
<p class="backup">
|
||||
<span class="small">Text:</span><br />
|
||||
<% comment.textarea text cols="31" rows="10" class="formText" %>
|
||||
</p>
|
||||
|
@ -59,5 +60,6 @@
|
|||
<p>
|
||||
<button type="submit" name="save" value="1">save</button>
|
||||
<button type="submit" name="cancel" value="1">cancel</button>
|
||||
<button type="button" id="restore" value="1">restore</button>
|
||||
</p>
|
||||
</form>
|
||||
|
|
|
@ -767,32 +767,6 @@ function pingUpdatedSites() {
|
|||
return;
|
||||
}
|
||||
|
||||
// FIXME:
|
||||
function rescueText(param) {
|
||||
session.data.rescuedText = new Object();
|
||||
for (var i in param) {
|
||||
if (i.startsWith("content_"))
|
||||
session.data.rescuedText[i] = param[i];
|
||||
}
|
||||
session.data.rescuedText.discussions = param.discussions;
|
||||
session.data.rescuedText.topic = param.topic;
|
||||
session.data.rescuedText.discussions_array = param.discussions_array;
|
||||
session.data.rescuedText.topicidx = param.topicidx;
|
||||
session.data.rescuedText.online = param.online;
|
||||
session.data.rescuedText.editableby = param.editableby;
|
||||
session.data.rescuedText.createtime = param.createtime;
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME:
|
||||
function restoreRescuedText() {
|
||||
// copy story-parameters back to req.data
|
||||
for (var i in session.data.rescuedText)
|
||||
req.data[i] = session.data.rescuedText[i];
|
||||
session.data.rescuedText = null;
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME:
|
||||
function extractContent(param, origContent) {
|
||||
var result = {isMajorUpdate: false, exists: false, value: new HopObject()};
|
||||
|
|
|
@ -18,3 +18,16 @@ Best regards.
|
|||
The Management'
|
||||
<% membership.name %> <% this.kind %> <% this.href %>
|
||||
<% this.modifier %> <% this.modified short %> %>
|
||||
|
||||
<% #disclaimer %>
|
||||
<% gettext
|
||||
'DISCLAIMER
|
||||
===========
|
||||
This is message was automatically sent to you because you are listed as
|
||||
recipient of notification e-mails of the aforementioned site.
|
||||
|
||||
Thus, you will be notified whenever the site has undergone changes as
|
||||
specified in the site preferences.
|
||||
|
||||
If you think you have received this e-mail in error please contact the
|
||||
maintainer of the site.' %>
|
||||
|
|
|
@ -44,6 +44,8 @@ Root.prototype.getPermission = function(action) {
|
|||
return User.require(User.PRIVILEGED);
|
||||
}
|
||||
switch (action) {
|
||||
case "backup.js":
|
||||
return true;
|
||||
case "create":
|
||||
return this.getCreationPermission();
|
||||
case "default.hook":
|
||||
|
@ -152,6 +154,25 @@ Root.prototype.list_action = function() {
|
|||
return;
|
||||
};
|
||||
|
||||
Root.prototype.backup_js_action = function() {
|
||||
if (req.isPost()) {
|
||||
session.data.backup = {};
|
||||
for (var key in req.postParams) {
|
||||
session.data.backup[key] = req.postParams[key];
|
||||
}
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
Root.restore = function(ref) {
|
||||
var backup;
|
||||
if (backup = session.data.backup) {
|
||||
ref.title = decodeURIComponent(backup.title);
|
||||
ref.text = decodeURIComponent(backup.text);
|
||||
}
|
||||
return ref;
|
||||
};
|
||||
|
||||
Root.prototype.default_hook_action = function() {
|
||||
var ping = function(data) {
|
||||
if (data.type !== "Site") {
|
||||
|
|
|
@ -510,7 +510,7 @@ Site.prototype.unsubscribe_action = function() {
|
|||
|
||||
Site.prototype.robots_txt_action = function() {
|
||||
res.contentType = "text/plain";
|
||||
this.renderSkin("robots");
|
||||
this.renderSkin("Site#robots");
|
||||
return;
|
||||
};
|
||||
|
||||
|
|
|
@ -41,6 +41,36 @@ You can change it anytime you want.</p>
|
|||
<p>This site was created on <% site.created long %> by
|
||||
<% site.creator link %>.</p>
|
||||
|
||||
<% #search %>
|
||||
<form method="get" action="<% site.href search %>">
|
||||
<input type="text" name="q" class="searchbox" value="" />
|
||||
<button type="submit" name="search" value="1"
|
||||
class="searchbox">search</button>
|
||||
</form>
|
||||
|
||||
<% #robots %>
|
||||
User-agent: *
|
||||
Disallow: /referrers
|
||||
Disallow: /stories/top
|
||||
|
||||
<% #menuExt %>
|
||||
<script type="text/javascript" defer="defer">
|
||||
<!--
|
||||
var win = external.menuArguments;
|
||||
var url = "<% site.url %>stories/create?content_text=";
|
||||
var link = escape('<a href="' + win.location.href + '">' +
|
||||
win.document.title + "</a>: ");
|
||||
var text = escape(win.document.selection.createRange().text);
|
||||
win.location.href = url + link + text;
|
||||
//-->
|
||||
</script>
|
||||
|
||||
<% #menuExtRegistry %>
|
||||
REGEDIT4
|
||||
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Post to <% site.title %>]
|
||||
@="<% site.url %>menuext"
|
||||
"contexts"=hex:31
|
||||
|
||||
<% #edit %>
|
||||
<form id="prefs" method="post" action="<% response.action %>">
|
||||
<table border="0" cellspacing="0" cellpadding="2">
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
REGEDIT4
|
||||
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Post to <% site.title %>]
|
||||
@="<% site.url %>menuext"
|
||||
"contexts"=hex:31
|
|
@ -1,10 +0,0 @@
|
|||
<script type="text/javascript" defer="defer">
|
||||
<!--
|
||||
var win = external.menuArguments;
|
||||
var url = "<% site.url %>stories/create?content_text=";
|
||||
var link = escape('<a href="' + win.location.href + '">' +
|
||||
win.document.title + "</a>: ");
|
||||
var text = escape(win.document.selection.createRange().text);
|
||||
win.location.href = url + link + text;
|
||||
//-->
|
||||
</script>
|
|
@ -1,15 +0,0 @@
|
|||
<tr>
|
||||
<td colspan="2" nowrap="nowrap"><div class="listSeparator"> </div>
|
||||
<strong>E-mail notification</strong></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="small" nowrap="nowrap">New stories <br />or comments:</td>
|
||||
<td nowrap="nowrap"><% site.notify event="create" as="editor" %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="small" nowrap="nowrap">Updated stories <br />or comments:</td>
|
||||
<td nowrap="nowrap"><% site.notify event="update" as="editor" %></td>
|
||||
</tr><tr>
|
||||
<td class="small" nowrap="nowrap">New image <br />or file uploads:</td>
|
||||
<td nowrap="nowrap"><% site.notify event="upload" as="editor" %></td>
|
||||
</tr>
|
|
@ -1,17 +0,0 @@
|
|||
This is a notification to inform you that changes were applied to the site <% site.title %><% param.user prefix=" by user " %>.
|
||||
|
||||
For details please check the following URL:
|
||||
<% param.url %>
|
||||
|
||||
PLEASE DO NOT REPLY TO THIS MESSAGE.
|
||||
|
||||
Best regards,
|
||||
The autonomous Antville agent.
|
||||
|
||||
|
||||
DISCLAIMER:
|
||||
===========
|
||||
|
||||
This is a message automatically sent to you because you are listed as recipient of notification e-mails of the aforementioned site. Thus, you will be notified whenever the site has undergone changes as specified in the site preferences.
|
||||
|
||||
If you think you have received this e-mail in error please contact the maintainer of the site.
|
|
@ -68,7 +68,7 @@
|
|||
</div>
|
||||
|
||||
<div class="boxheader">search</div>
|
||||
<div class="box"><% site.skin searchbox %></div>
|
||||
<div class="box"><% site.skin Site#search %></div>
|
||||
|
||||
<div class="boxheader">calendar</div>
|
||||
<div class="box"><% site.calendar %></div>
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
User-agent: *
|
||||
Disallow: /referrers
|
||||
Disallow: /mostread
|
|
@ -1,4 +0,0 @@
|
|||
<form method="get" action="<% site.href search %>">
|
||||
<input type="text" name="q" class="searchbox" value="" />
|
||||
<button type="submit" name="search" value="1" class="searchbox">search</button>
|
||||
</form>
|
|
@ -55,16 +55,13 @@ Stories.prototype.main_action = function() {
|
|||
};
|
||||
|
||||
Stories.prototype.create_action = function() {
|
||||
if (session.data.rescuedText) {
|
||||
restoreRescuedText();
|
||||
}
|
||||
|
||||
var story = new Story;
|
||||
if (req.postParams.save) {
|
||||
try {
|
||||
story.update(req.postParams);
|
||||
this.add(story);
|
||||
story.notify(req.action);
|
||||
delete session.data.backup;
|
||||
res.message = gettext("The story was successfully created.");
|
||||
res.redirect(story.href());
|
||||
} catch (ex) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
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.content_macro = function(param) {
|
||||
switch (param.as) {
|
||||
case "editor" :
|
||||
|
|
Loading…
Add table
Reference in a new issue