- changed to use AntvilleLib methods

- changed all preferences related macros since the site preferences are xml-encoded now
- discussions_macro() and addtofront_macro() now don't need an input type hidden anymore to preserve the submitted state
This commit is contained in:
Robert Gaggl 2003-08-02 11:00:26 +00:00
parent 9a1e050afe
commit f3d757c996

View file

@ -3,17 +3,17 @@
*/
function title_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("title", param));
Html.input(this.createInputParam("title", param));
else {
if (param && param.linkto) {
if (param.linkto == "main")
param.linkto = "";
openLink(this.href(param.linkto));
Html.openLink(this.href(param.linkto));
if (this.title && this.title.trim())
res.write(stripTags(this.title));
else
res.write("<i>[untitled]</i>");
closeLink();
Html.closeLink();
} else
res.write(this.title);
}
@ -25,7 +25,7 @@ function title_macro(param) {
*/
function alias_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("alias",param));
Html.input(this.createInputParam("alias", param));
else
res.write(this.alias);
}
@ -35,13 +35,10 @@ function alias_macro(param) {
* macro rendering tagline
*/
function tagline_macro(param) {
if (!this.tagline && param.as != "editor")
return;
if (param.as == "editor")
renderInputText(this.createInputParam("tagline",param));
else if (this.tagline)
res.write(stripTags(this.tagline));
Html.input(this.preferences.createInputParam("tagline", param));
else if (this.preferences.getProperty("tagline"))
res.write(stripTags(this.preferences.getProperty("tagline")));
}
@ -50,7 +47,7 @@ function tagline_macro(param) {
*/
function email_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("email",param));
Html.input(this.createInputParam("email", param));
else
res.write(this.email);
}
@ -61,9 +58,9 @@ function email_macro(param) {
*/
function bgcolor_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("bgcolor",param));
Html.input(this.preferences.createInputParam("bgcolor", param));
else
renderColor(this.bgcolor);
renderColor(this.preferences.getProperty("bgcolor"));
}
@ -72,9 +69,9 @@ function bgcolor_macro(param) {
*/
function textfont_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("textfont",param));
Html.input(this.preferences.createInputParam("textfont", param));
else
res.write(this.textfont);
res.write(this.preferences.getProperty("textfont"));
}
@ -83,9 +80,9 @@ function textfont_macro(param) {
*/
function textsize_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("textsize",param));
Html.input(this.preferences.createInputParam("textsize", param));
else
res.write(this.textsize);
res.write(this.preferences.getProperty("textsize"));
}
@ -94,9 +91,9 @@ function textsize_macro(param) {
*/
function textcolor_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("textcolor",param));
Html.input(this.preferences.createInputParam("textcolor", param));
else
renderColor(this.textcolor);
renderColor(this.preferences.getProperty("textcolor"));
}
@ -105,9 +102,9 @@ function textcolor_macro(param) {
*/
function linkcolor_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("linkcolor",param));
Html.input(this.preferences.createInputParam("linkcolor", param));
else
renderColor(this.linkcolor);
renderColor(this.preferences.getProperty("linkcolor"));
}
@ -116,9 +113,9 @@ function linkcolor_macro(param) {
*/
function alinkcolor_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("alinkcolor",param));
Html.input(this.preferences.createInputParam("alinkcolor", param));
else
renderColor(this.alinkcolor);
renderColor(this.preferences.getProperty("alinkcolor"));
}
@ -127,9 +124,9 @@ function alinkcolor_macro(param) {
*/
function vlinkcolor_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("vlinkcolor",param));
Html.input(this.preferences.createInputParam("vlinkcolor", param));
else
renderColor(this.vlinkcolor);
renderColor(this.preferences.getProperty("vlinkcolor"));
}
@ -138,9 +135,9 @@ function vlinkcolor_macro(param) {
*/
function titlefont_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("titlefont",param));
Html.input(this.preferences.createInputParam("titlefont", param));
else
res.write(this.titlefont);
res.write(this.preferences.getProperty("titlefont"));
}
@ -149,9 +146,9 @@ function titlefont_macro(param) {
*/
function titlesize_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("titlesize",param));
Html.input(this.preferences.createInputParam("titlesize", param));
else
res.write(this.titlesize);
res.write(this.preferences.getProperty("titlesize"));
}
@ -160,9 +157,9 @@ function titlesize_macro(param) {
*/
function titlecolor_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("titlecolor",param));
Html.input(this.preferences.createInputParam("titlecolor", param));
else
renderColor(this.titlecolor);
renderColor(this.preferences.getProperty("titlecolor"));
}
@ -171,9 +168,9 @@ function titlecolor_macro(param) {
*/
function smallfont_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("smallfont",param));
Html.input(this.preferences.createInputParam("smallfont", param));
else
res.write(this.smallfont);
res.write(this.preferences.getProperty("smallfont"));
}
@ -182,9 +179,9 @@ function smallfont_macro(param) {
*/
function smallsize_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("smallsize",param));
Html.input(this.preferences.createInputParam("smallsize", param));
else
res.write(this.smallsize);
res.write(this.preferences.getProperty("smallsize"));
}
@ -193,9 +190,9 @@ function smallsize_macro(param) {
*/
function smallcolor_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("smallcolor",param));
Html.input(this.preferences.createInputParam("smallcolor", param));
else
renderColor(this.smallcolor);
renderColor(this.preferences.getProperty("smallcolor"));
}
@ -203,9 +200,9 @@ function smallcolor_macro(param) {
* macro rendering lastupdate
*/
function lastupdate_macro(param) {
if (!this.lastupdate)
if (this.lastupdate)
res.write(formatTimestamp(this.lastupdate, param.format));
return;
return (formatTimestamp(this.lastupdate,param.format));
}
@ -213,9 +210,12 @@ function lastupdate_macro(param) {
* macro rendering online-status
*/
function online_macro(param) {
if (param.as == "editor")
renderInputCheckbox(this.createInputParam("online",param));
else if (this.online)
if (param.as == "editor") {
var inputParam = this.createInputParam("online", param);
if ((req.data.save && req.data.online) || (!req.data.save && this.online))
inputParam.checked = "checked";
Html.checkBox(inputParam);
} else if (this.online)
res.write(param.yes ? param.yes : "yes");
else
res.write(param.no ? param.no : "no");
@ -226,10 +226,15 @@ function online_macro(param) {
* macro rendering discussion-flag
*/
function hasdiscussions_macro(param) {
if (param.as == "editor")
renderInputCheckbox(this.createInputParam("discussions",param));
else
res.write(this.discussions ? "yes" : "no");
if (param.as == "editor") {
var inputParam = this.preferences.createInputParam("discussions", param);
if ((req.data.save && req.data.discussions) ||
(!req.data.save && this.preferences.getProperty("discussions")))
inputParam.checked = "checked";
Html.checkBox(inputParam);
} else
res.write(this.preferences.getProperty("discussions") ? "yes" : "no");
return;
}
@ -237,10 +242,14 @@ function hasdiscussions_macro(param) {
* macro rendering usercontrib-flag
*/
function usermaycontrib_macro(param) {
if (param.as == "editor")
renderInputCheckbox(this.createInputParam("usercontrib",param));
else
res.write(this.usercontrib ? "yes" : "no");
if (param.as == "editor") {
var inputParam = this.preferences.createInputParam("usercontrib", param);
if ((req.data.save && req.data.usercontrib) ||
(!req.data.save && this.preferences.getProperty("usercontrib")))
inputParam.checked = "checked";
Html.checkBox(inputParam);
} else
res.write(this.preferences.getProperty("usercontrib") ? "yes" : "no");
}
@ -249,9 +258,9 @@ function usermaycontrib_macro(param) {
*/
function showdays_macro(param) {
if (param.as == "editor")
renderInputText(this.createInputParam("days",param));
Html.input(this.preferences.createInputParam("days", param));
else
res.write(this.days);
res.write(this.preferences.getProperty("days"));
}
@ -259,10 +268,14 @@ function showdays_macro(param) {
* macro rendering archive-flag
*/
function showarchive_macro(param) {
if (param.as == "editor")
renderInputCheckbox(this.createInputParam("archive",param));
else
res.write(this.archive ? "yes" : "no");
if (param.as == "editor") {
var inputParam = this.preferences.createInputParam("archive", param);
if ((req.data.save && req.data.archive) ||
(!req.data.save && this.preferences.getProperty("archive")))
inputParam.checked = "checked";
Html.checkBox(inputParam);
} else
res.write(this.preferences.getProperty("archive") ? "yes" : "no");
}
@ -270,9 +283,12 @@ function showarchive_macro(param) {
* macro rendering enableping-flag
*/
function enableping_macro(param) {
if (param.as == "editor")
renderInputCheckbox(this.createInputParam("enableping",param));
else
if (param.as == "editor") {
var inputParam = this.createInputParam("enableping", param);
if ((req.data.save && req.data.enableping) || (!req.data.save && this.enableping))
inputParam.checked = "checked";
Html.checkBox(inputParam);
} else
res.write(this.enableping ? "yes" : "no");
}
@ -282,11 +298,13 @@ function enableping_macro(param) {
*/
function longdateformat_macro(param) {
if (param.as == "chooser")
this.renderDateformatChooser("long");
renderDateformatChooser("longdateformat",
this.getLocale(),
this.preferences.getProperty("longdateformat"));
else if (param.as == "editor")
renderInputText(this.createInputParam("longdateformat",param));
Html.input(this.preferences.createInputParam("longdateformat", param));
else
res.write(this.longdateformat);
res.write(this.preferences.getProperty("longdateformat"));
}
@ -295,11 +313,13 @@ function longdateformat_macro(param) {
*/
function shortdateformat_macro(param) {
if (param.as == "chooser")
this.renderDateformatChooser("short");
renderDateformatChooser("shortdateformat",
this.getLocale(),
this.preferences.getProperty("shortdateformat"));
else if (param.as == "editor")
renderInputText(this.createInputParam("shortdateformat",param));
Html.input(this.preferences.createInputParam("shortdateformat", param));
else
res.write(this.shortdateformat);
res.write(this.preferences.getProperty("shortdateformat"));
}
@ -327,7 +347,7 @@ function navigation_macro(param) {
if (!session.user)
return;
if (!param["for"] || param["for"] == "contributors") {
if (this.usercontrib || req.data.memberlevel >= CONTRIBUTOR)
if (this.preferences.getProperty("usercontrib") || req.data.memberlevel >= CONTRIBUTOR)
this.renderSkin("contribnavigation");
}
if (!param["for"] || param["for"] == "admins") {
@ -355,7 +375,7 @@ function storylist_macro(param) {
function calendar_macro(param) {
// do nothing if there is not a single story :-))
// or if archive of this site is disabled
if (!this.allstories.size() || !this.archive)
if (!this.allstories.size() || !this.preferences.getProperty("archive"))
return;
// define variables needed in this function
var calParam = new Object();
@ -387,7 +407,7 @@ function calendar_macro(param) {
else if (path.day)
var today = path.day.groupname.toString();
if (today) {
// instead of using the global parseTimestamp-function
// instead of using String.toDate
// we do it manually here to avoid that a day like 20021001
// would be changed to 20020930 in some cases
cal.set(java.util.Calendar.YEAR, parseInt(today.substring(0, 4), 10));
@ -404,7 +424,7 @@ function calendar_macro(param) {
calParam.year = cal.get(java.util.Calendar.YEAR);
// pre-render the year and month so we only have to append the days as we loop
var currMonth = formatTimestamp(cal.getTime(), "yyyyMM");
var currMonth = formatTimestamp(new Date(cal.getTime().getTime()), "yyyyMM");
// remember the index of the first and last days within this month.
// this is needed to optimize previous and next month links.
var lastDayIndex = 9999999;
@ -418,7 +438,7 @@ function calendar_macro(param) {
dayParam.day = "&nbsp;";
else {
var currGroupname = currMonth+daycnt.format("00");
var linkText = daycnt < 10 ? "&nbsp;"+daycnt+"&nbsp;" : daycnt;
var linkText = daycnt < 10 ? "&nbsp;" + daycnt + "&nbsp;" : daycnt.toString();
var currGroup = this.get(currGroupname);
if (currGroup) {
var idx = this.contains(currGroup);
@ -428,7 +448,7 @@ function calendar_macro(param) {
if (idx < lastDayIndex)
lastDayIndex = idx;
}
dayParam.day = "<a href=\"" + currGroup.href() + "\">" + linkText + "</a>";
dayParam.day = Html.linkAsString(currGroup.href(), linkText);
} else {
dayParam.day = linkText;
}
@ -489,7 +509,7 @@ function membercounter_macro(param) {
* of this site
*/
function history_macro(param) {
if (this.isNotPublic(session.user,req.data.memberlevel))
if (this.isAccessDenied(session.user, req.data.memberlevel))
return;
if (!param.show)
param.show = 5;
@ -498,7 +518,9 @@ function history_macro(param) {
this.lastmod.prefetchChildren(0, parseInt(param.show, 10));
while (cnt < param.show && this.lastmod.get(i)) {
var item = this.lastmod.get(i++);
if (!item.story || (item.story.online && item.story.discussions && item.site.discussions)) {
if (!item.story ||
(item.story.online && item.story.discussions &&
item.site.preferences.getProperty("discussions"))) {
item.renderSkin("historyview");
cnt++;
}
@ -519,19 +541,8 @@ function localechooser_macro(param) {
/**
* macro renders a list of available time zones as dropdown
*/
function timezonechooser_macro(param) {
var zones = java.util.TimeZone.getAvailableIDs();
var options = new Array();
var format = new java.text.DecimalFormat ("-0;+0");
var currentZone = this.getTimeZone();
for (var i in zones) {
var zone = java.util.TimeZone.getTimeZone (zones[i]);
options[i] = "GMT"+(format.format(zone.getRawOffset()/3600000))+" ("+zones[i]+")";
if (zones[i] == currentZone.getID())
var selectedIndex = i;
}
renderDropDownBox("timezone",options,selectedIndex);
renderTimeZoneChooser(this.getTimeZone());
}
@ -560,7 +571,7 @@ function listReferrers_macro() {
var c = getDBConnection("antville");
var dbError = c.getLastError();
if (dbError)
return (getMessage("error","database",dbError));
return getMessage("error.database", dbError);
// we're doing this with direct db access here
// (there's no need to do it with prototypes):
var d = new Date();
@ -572,7 +583,7 @@ function listReferrers_macro() {
var rows = c.executeRetrieval(query);
var dbError = c.getLastError();
if (dbError)
return (getMessage("error","database",dbError));
return getMessage("error.database", dbError);
var skinParam = new Object();
var referrer;
while (rows.next()) {
@ -595,9 +606,9 @@ function xmlbutton_macro(param) {
var img = root.images.get("xmlbutton");
if (!img)
return;
openLink(this.href("rss"));
Html.openLink(this.href("rss"));
renderImage(img, param);
closeLink();
Html.closeLink();
}
@ -613,7 +624,7 @@ function searchbox_macro(param) {
* function renders the months of the archive
*/
function monthlist_macro(param) {
if (!this.stories.size() || !this.archive)
if (!this.stories.size() || !this.preferences.getProperty("archive"))
return;
var size = param.limit ? Math.min(this.size(), param.limit) : this.size();
for (var i=0;i<size;i++) {
@ -621,10 +632,10 @@ function monthlist_macro(param) {
var next = this.get(i+1);
if (!next || next.groupname.substring(0, 6) < curr.groupname.substring(0, 6)) {
res.write(param.itemprefix);
openLink(curr.href());
var ts = parseTimestamp(curr.groupname.substring(0,6),"yyyyMM");
Html.openLink(curr.href());
var ts = curr.groupname.substring(0, 6).toDate("yyyyMM", this.getTimeZone());
res.write(formatTimestamp(ts, param.format ? param.format : "MMMM yyyy"));
closeLink();
Html.closeLink();
res.write(param.itemsuffix);
}
}