* Refactored Archive due to buggy behaviour of the calendar and general inconsistent code

* Disabled tagging of layout images
 * Disabled "days" page mode (ie. switched to counting stories only)
 * Moved Site.href skin to Site#href (subskin)
 * Fixed minor issues
 * Edited text and messages
This commit is contained in:
Tobi Schäfer 2008-04-16 16:42:40 +00:00
parent d18a5b95fc
commit 06eed430a8
12 changed files with 181 additions and 165 deletions

View file

@ -22,13 +22,15 @@
// $URL$
//
Archive.Fields = ["year", "month", "day"];
Archive.PAGER = "page";
Archive.COLLECTION = "collection";
Archive.prototype.constructor = function(name, parent) {
Archive.prototype.constructor = function(name, type, parent) {
this.name = name;
this.type = type;
this.parent = parent;
return this;
};
}
Archive.prototype.getPermission = function(action) {
var site = res.handlers.site;
@ -44,7 +46,44 @@ Archive.prototype.getPermission = function(action) {
return site.archiveMode === Site.PUBLIC;
}
return false;
};
}
Archive.prototype.main_action = function() {
res.data.body = this.renderSkinAsString("Archive#main");
res.handlers.site.renderSkin("Site#page");
return;
}
Archive.prototype.page1_action = function() {
return res.redirect(this.href());
}
Archive.prototype.href = function(action) {
var buffer = [];
var archive = this;
while (archive.parent) {
buffer.push(archive.name);
archive = archive.parent;
}
buffer.push(res.handlers.site.href("archive"));
buffer.reverse();
if (action) {
if (this.type === Archive.PAGER) {
buffer.pop();
}
buffer.push(action);
}
return buffer.join("/");
}
Archive.prototype.getChildElement = function(name) {
if (name.startsWith(Archive.PAGER)) {
return new Archive(name, Archive.PAGER, this);
} else if (!isNaN(name)) {
return new Archive(name, Archive.COLLECTION, this);
}
return this.get(name);
}
Archive.prototype.link_macro = function(param, action, text) {
if (!this.getPermission(action)) {
@ -52,47 +91,13 @@ Archive.prototype.link_macro = function(param, action, text) {
}
switch (action) {
case "previous":
var page = this.getPage() - 1;
action = this.href("page" + page, true); break;
var page = this.getPage() - 1; break;
case "next":
var page = this.getPage() + 1;
action = this.href("page" + page, true); break;
var page = this.getPage() + 1; break;
}
var action = "page" + page;
return renderLink.call(global, param, action, text, this);
};
Archive.prototype.getChildElement = function(name) {
if (name.startsWith("page")) {
return new Archive(name);
} else if (!isNaN(name)) {
return new Archive(name, this);
}
return this.get(name);
};
Archive.prototype.href = function(action, full) {
res.push();
res.write(res.handlers.site.href("archive"));
res.write("/");
// FIXME: jala.Date.Calendar does not fully conform with href() generation
if (full) {
var value;
for each (var field in Archive.Fields) {
if (value = this.getDate(field)) {
res.write(value);
res.write("/");
}
}
}
action && res.write(action);
return res.pop();
};
Archive.prototype.main_action = function() {
res.data.body = this.renderSkinAsString("Archive#main");
res.handlers.site.renderSkin("Site#page");
return;
};
}
Archive.prototype.stories_macro = function() {
var day, storyDay;
@ -107,11 +112,15 @@ Archive.prototype.stories_macro = function() {
}
story.renderSkin("Story#preview");
return;
};
}
if (!this.parent) {
// FIXME: This is a little bit inconsistent and thus needs special care
var archive = this.type === Archive.PAGER ? this.parent : this;
if (!archive.parent) {
var site = res.handlers.site;
var offset = (page - 1) * pageSize;
res.debug(offset)
res.debug(pageSize)
var stories = site.stories.featured.list(offset, pageSize);
for each (var story in stories) {
renderStory(story);
@ -124,7 +133,7 @@ Archive.prototype.stories_macro = function() {
res.write(this.getFilter());
res.write(" limit " + pageSize);
res.write(" offset " + (page - 1) * pageSize);
sql = res.pop();
var sql = res.pop();
var db = getDBConnection("antville");
rows = db.executeRetrieval(sql);
@ -137,74 +146,81 @@ Archive.prototype.stories_macro = function() {
return;
};
Archive.prototype.getDate = function(part) {
if (path.contains(this) > -1) {
var value;
if (part) {
var site = res.handlers.site;
var offset = path.contains(site);
var index = Archive.Fields.indexOf(part);
var value = path[offset + 2 + index];
if (value && value.parent) {
return (part === "month" ? value.name - 1 : value.name);
}
} else {
var value;
var date = new Date;
(value = this.getDate("year")) && date.setYear(value);
(value = this.getDate("month")) && date.setMonth(value);
(value = this.getDate("day")) && date.setDate(value);
return new Date(date);
}
Archive.prototype.getSize = function() {
// FIXME: This is a little bit inconsistent and thus needs special care
var archive = this.type === Archive.PAGER ? this.parent : this;
if (!archive.parent) {
return res.handlers.site.stories.size();
}
return null;
};
var db = getDBConnection("antville");
var sql = "select count(*) as max from content " + this.getFilter();
var rows = db.executeRetrieval(sql);
rows.next();
return rows.getColumnItem("max");
}
Archive.prototype.getFilter = function() {
var buffer = [];
var archive = this;
do {
if (archive.type === Archive.COLLECTION) {
buffer.push(Number(archive.name));
}
} while (archive = archive.parent);
if (buffer.length > 0) {
buffer.reverse();
//buffer[1] && (buffer[1] += 1);
} else {
var now = new Date;
buffer.push(now.getDate());
buffer.push(now.getMonth() + 1);
buffer.push(now.getFullYear());
}
res.push();
var site = res.handlers.site;
res.write("where site_id = ");
res.write(site._id);
res.write(" and prototype = 'Story' and status <> 'closed'");
var keys = ["year", "month", "day"];
for (var i in buffer) {
res.write(" and ");
res.write(keys[i]);
res.write("(created) = ");
res.write(buffer[i]);
}
res.write(" order by created desc");
return res.pop();
}
Archive.prototype.getPage = function() {
if (this.name && this.name.startsWith("page")) {
if (this.type === Archive.PAGER) {
return Number(this.name.substr(4));
}
return 1;
};
}
Archive.prototype.getPageSize = function() {
return 10;
};
return res.handlers.site.pageSize;
}
Archive.prototype.getSize = function() {
if (!res.meta.archiveSize) {
var db = getDBConnection("antville");
var sql = "select count(*) as max from content " + this.getFilter();
var rows = db.executeRetrieval(sql);
rows.next();
res.meta.archiveSize = rows.getColumnItem("max");
Archive.prototype.getDate = function() {
var date = new Date;
var offset = path.contains(res.handlers.site.archive) + 1;
if (offset > -1) {
var archive;
var buffer = [];
for (var i=offset; i<path.length; i+=1) {
archive = path[i];
if (archive.type === Archive.COLLECTION) {
buffer.push(Number(archive.name));
}
}
}
return res.meta.archiveSize;
};
Archive.prototype.getFilter = function() {
if (!res.meta.archiveFilter) {
var site = res.handlers.site;
res.push();
res.write("where site_id = ");
res.write(site._id);
res.write(" and prototype = 'Story' and status <> 'closed'");
var part;
if (part = this.getDate("year")) {
res.write(" and year(created) = " + part);
}
if (part = this.getDate("month")) {
res.write(" and month(created) = " + (part + 1));
}
if (part = this.getDate("day")) {
res.write(" and day(created) = " + part);
}
res.write(" order by created desc");
res.meta.archiveFilter = res.pop();
}
return res.meta.archiveFilter;
};
Archive.prototype.page1_action = function() {
return res.redirect(this.href());
};
buffer[0] && date.setYear(buffer[0]);
buffer[1] && date.setMonth(buffer[1] - 1);
buffer[2] && date.setDate(buffer[2]);
return date;
}

View file

@ -22,6 +22,8 @@
## $URL$
##
## jala.Calendar is using this collection (Archive itself is retrieving
## stories from Stories.featured and via direct DB request)
_children = collection(Story)
_children.local = id
_children.foreign = site_id

View file

@ -1,10 +1,10 @@
<% #main %>
<div class="pagelink">
<% archive.link previous <% gettext "Newer stories" %>
<% archive.link previous <% gettext "Previous page" %>
prefix='<div class="pagelinkTop">... ' suffix="</div>" %>
</div>
<% archive.stories %>
<div class="pagelink">
<% archive.link next <% gettext "Older stories" %>
<% archive.link next <% gettext "Next page" %>
prefix='<div class="pagelinkBottom">... ' suffix="</div>" %>
</div>

View file

@ -208,7 +208,9 @@ Image.prototype.update = function(data) {
this.writeFiles(image, thumbnail);
}
this.setTags(data.tags || data.tag_array);
if (this.parent_type !== "Layout") {
this.setTags(data.tags || data.tag_array);
}
this.description = data.description;
this.touch();
return;

View file

@ -31,8 +31,11 @@ paste the following code:' %> <pre><% image.macro %></pre></p>
$(document).ready(function() {
if ("<% image.created %>") {
$(".name").hide();
$(".resize").hide();
$(".resize").hide();
};
if ("<% image.parent_type %>" === "Layout") {
$(".tags").hide();
}
});
</script>
<p class="storyTitle"><% response.title %></p><br />
@ -55,7 +58,7 @@ $(document).ready(function() {
<td class="small" valign="top"><% gettext Description suffix=: %></td>
<td><% image.textarea description %></td>
</tr>
<tr>
<tr class="tags">
<td class="small" valign="top"><% gettext Tags suffix=: %></td>
<td><% image.input tags %></td>
</tr>

View file

@ -90,7 +90,7 @@ Images.prototype.create_action = function() {
}
res.data.action = this.href(req.action);
res.data.title = gettext("Add image to site {0}", this._parent.title);
res.data.title = gettext("Add image to site {0}", res.handlers.site.title);
res.data.body = image.renderSkinAsString("Image#edit");
res.handlers.site.renderSkin("Site#page");
return;

View file

@ -156,11 +156,7 @@ Membership.prototype.status_macro = function() {
};
Membership.getByName = function(name) {
var site = res.handlers.site;
if (site) {
return site.members.get(name);
}
return null;
return res.handlers.site.members.get(name);
};
Membership.prototype.require = function(role) {

View file

@ -81,7 +81,7 @@ suffix="<br />" %>
</td>
<td width="10"> </td>
<td align="right" class="small">
<% site.link . view prefix="... " %><!--
<% site.link . <% gettext View %> prefix="... " %><!--
--><% site.link unsubscribe prefix="<br />... " %>
</td>
</tr>
@ -101,7 +101,7 @@ message.' %></p>
name="text"><% request.text encoding="form" %></textarea>
</p>
<p>
<button type="submit" name="send" value="1">send</button>
<button type="submit" name="cancel" value="1">cancel</button>
<button type="submit" name="send" value="1">Send</button>
<button type="submit" name="cancel" value="1">Cancel</button>
</p>
</form>

View file

@ -24,7 +24,7 @@
Site.getStatus = defineConstants(Site, "blocked", "regular", "trusted");
Site.getModes = defineConstants(Site, "closed", "restricted", "public", "open");
Site.getPageModes = defineConstants(Site, "days", "stories");
Site.getPageModes = defineConstants(Site, "stories"); //, "days");
Site.getCommentModes = defineConstants(Site, "disabled", "enabled");
Site.getArchiveModes = defineConstants(Site, "closed", "public");
Site.getNotificationModes = defineConstants(Site, "Nobody",
@ -110,7 +110,7 @@ Site.prototype.getPermission = function(action) {
return Site.require(Site.PUBLIC) &&
!Membership.require(Membership.SUBSCRIBER);
case "unsubscribe":
var membership = this.members.get(session.user.name)
var membership = this.members.get(session.user.name);
return User.require(User.REGULAR) &&
!membership.require(Membership.OWNER);
}
@ -189,11 +189,11 @@ Site.prototype.update = function(data) {
if (!data.name) {
throw Error(gettext("Please enter a name for your new site."));
} else if (data.name.length > 30) {
throw Error(gettext("Sorry, the name you chose is too long. Please enter a shorter one."));
throw Error(gettext("The chosen name is too long. Please enter a shorter one."));
} else if (/(\/|\\)/.test(data.name)) {
throw Error(gettext("Sorry, a site name may not contain any (back)slashes."));
throw Error(gettext("A site name may not contain any (back)slashes."));
} else if (data.name !== root.getAccessName(data.name)) {
throw Error(gettext("Sorry, there is already a site with this name."));
throw Error(gettext("There already is a site with this name."));
}
this.name = data.name;
this.title = data.title || data.name;
@ -227,7 +227,6 @@ Site.remove = function(site) {
HopObject.remove(site.stories);
HopObject.remove(site.images);
HopObject.remove(site.files)
// FIXME: HopObject.remove(site.layouts);
site.remove();
logAction("site", "removed");
return;
@ -261,7 +260,7 @@ Site.prototype.rss_xml_action = function() {
res.dependsOn(this.lastUpdate);
res.digest();
res.contentType = "text/xml";
res.write(this.getXml("union"));
res.write(this.getXml(this.stories.union));
return;
}
@ -269,7 +268,7 @@ Site.prototype.stories_xml_action = function() {
res.dependsOn(this.lastUpdate);
res.digest();
res.contentType = "text/xml";
res.write(this.getXml("recent"));
res.write(this.getXml(this.stories.recent));
return;
};
@ -277,7 +276,7 @@ Site.prototype.comments_xml_action = function() {
res.dependsOn(this.lastUpdate);
res.digest();
res.contentType = "text/xml";
res.write(this.getXml("comments"));
res.write(this.getXml(this.stories.comments));
return;
}
@ -295,8 +294,8 @@ Site.prototype.search_xml_action = function() {
return;
}
Site.prototype.getXml = function(type) {
type || (type = "recent");
Site.prototype.getXml = function(collection) {
collection || (collection = this.stories.recent);
var now = new Date;
var feed = new rome.SyndFeedImpl();
feed.setFeedType("rss_2.0");
@ -324,7 +323,7 @@ Site.prototype.getXml = function(type) {
var entries = new java.util.ArrayList();
var description;
var list = this.stories[type].list(0, 25);
var list = collection.list(0, 25);
for each (var item in list) {
entry = new rome.SyndEntryImpl();
item.title && entry.setTitle(item.title);
@ -429,28 +428,34 @@ Site.prototype.search_action = function() {
};
Site.prototype.subscribe_action = function() {
var membership = new Membership(session.user, Membership.SUBSCRIBER);
this.members.add(membership);
res.message = gettext('You successfully subscribed to the site "{0}".',
this.title);
try {
var membership = new Membership(session.user, Membership.SUBSCRIBER);
this.members.add(membership);
res.message = gettext('Successfully subscribed to site {0}.',
this.title);
} catch (ex) {
app.log(ex);
res.message = ex.toString();
}
res.redirect(this.href());
return;
};
Site.prototype.unsubscribe_action = function() {
if (req.postParams.proceed) {
//try {
Membership.remove(this.members.get(session.user.name));
res.message = gettext("Successfully unsubscribed the membership.");
try {
Membership.remove(Membership.getByName(session.user.name));
res.message = gettext("Successfully unsubscribed from site {0}.",
this.title);
res.redirect(this.href());
/*} catch (err) {
res.message = err.toString();
}*/
} catch (ex) {
app.log(ex)
res.message = ex.toString();
}
}
res.data.title = gettext("Remove subscription to {0}", this.title);
res.data.body = this.renderSkinAsString("HopObject#delete", {
text: gettext('You are about to remove the subscription to the site "{0}".',
text: gettext('You are about to unsubscribe from site {0}.',
this.title)
});
this.renderSkin("Site#page");
@ -474,7 +479,6 @@ Site.prototype.getMacroHandler = function(name) {
case "stories":
case "tags":
return this[name];
default:
return null;
}
@ -498,12 +502,15 @@ Site.prototype.stories_macro = function() {
};
Site.prototype.calendar_macro = function(param) {
if (this.archiveMode !== Site.PUBLIC) {
return;
}
var calendar = new jala.Date.Calendar(this.archive);
//calendar.setAccessNameFormat("yyyy/MM/dd");
calendar.setHrefFormat("yyyy/MM/dd/");
calendar.setHrefFormat("/yyyy/MM/dd/");
calendar.setLocale(this.getLocale());
calendar.setTimeZone(this.getTimeZone());
calendar.render(this.archive.getDate() || new Date);
calendar.render(this.archive.getDate());
return;
};
@ -536,19 +543,6 @@ Site.prototype.referrers_macro = function() {
return;
};
// FIXME: This can be removed if Layouts really are to disappear
Site.prototype.getLayouts = function() {
var result = [];
this.layouts.forEach(function() {
var layout = this;
result.push({
value: layout._id,
display: layout.title
});
});
return result;
};
Site.prototype.getLocale = function() {
var locale;
if (locale = this.cache.locale) {

View file

@ -1,6 +1,9 @@
<% #href %>
http://<% site.name %>.antville.org<% param.path %>
<% #main %>
<% site.stories %>
<
<% #edit %>
<form id="prefs" method="post" action="<% response.action %>">
<table border="0" cellspacing="0" cellpadding="2">
@ -24,7 +27,7 @@
<tr>
<td class="small"><% gettext Paging suffix=: %></td>
<td><% site.input pageSize size="5" maxlength="2" %>
<% site.select pageMode %></td>
<% site.select pageMode %> per page</td>
</tr>
<tr>
<td class="small"><% gettext Comments suffix=: %></td>

View file

@ -1,6 +1,6 @@
<% #main %>
<div class="pagelink"><% breadcrumbs %>
<% if <% tag.permission edit %> is true then <% tag.skin name="Tag#controls" %> %>
<% if <% tag.permission edit %> is true then <% tag.skin Tag#controls %> %>
</div><br />
<% list.prevLink %>
@ -25,6 +25,6 @@
location.href="<% tag.href action="rename" %>?name=" + name;
}'>Rename</button>
<button type="button" onclick='var name;
if (confirm("<% gettext 'Are you sure you want to remove the tag {0}?' <% tag.name %> %>)) {
if (confirm("<% gettext 'Are you sure you want to remove the tag {0}?' <% tag.name %> %>")) {
location.href="<% tag.href action="delete" %>";
}'>Delete</button>

View file

@ -1 +1 @@
<% taghub.tagged.skin name=<% taghub.tagged.type suffix="#preview" %> %>
<% taghub.tagged.skin <% taghub.tagged.type suffix="#preview" %> %>