* Added User.popLocation() and User.popLocation() methods for temporarily storing a user's location, ie. to get back where the user came from when it was necessary to login

* Removed Root.searchSites() method (will be back later)
 * Added checks for empty searches in Site.search_action()
This commit is contained in:
Tobi Schäfer 2007-10-17 16:25:01 +00:00
parent 3d0fae4302
commit 1c3c51a0e1
7 changed files with 46 additions and 72 deletions

View file

@ -90,10 +90,10 @@ HopObject.prototype.delete_action = function() {
if (req.postParams.proceed) { if (req.postParams.proceed) {
//try { //try {
var str = this.toString(); var str = this.toString();
var href = this._parent.href(); var url = this._parent.href();
this.constructor.remove.call(this, this); this.constructor.remove.call(this, this);
res.message = gettext("{0} was successfully deleted.", str); res.message = gettext("{0} was successfully deleted.", str);
res.redirect(session.data.retrace || href); res.redirect(User.popLocation() || url);
/*} catch(ex) { /*} catch(ex) {
res.message = ex; res.message = ex;
app.log(ex); app.log(ex);

View file

@ -64,7 +64,6 @@ Images.prototype.create_action = function() {
image.notify(req.action); image.notify(req.action);
res.message = gettext('The uploaded image was saved successfully. Its name is "{0}"', res.message = gettext('The uploaded image was saved successfully. Its name is "{0}"',
image.name); image.name);
session.data.referrer = null;
res.redirect(image.href()); res.redirect(image.href());
} catch (ex) { } catch (ex) {
res.message = ex.toString(); res.message = ex.toString();

View file

@ -81,11 +81,9 @@ Members.prototype.register_action = function() {
this.add(membership); this.add(membership);
membership.notify(req.action, user.email, membership.notify(req.action, user.email,
gettext('Welcome to "{0}"!', title)); gettext('Welcome to "{0}"!', title));
var url = session.data.referrer || this._parent.href();
delete session.data.referrer;
res.message = gettext('Welcome to "{0}", {1}. Have fun!', res.message = gettext('Welcome to "{0}", {1}. Have fun!',
title, user.name); title, user.name);
res.redirect(url); res.redirect(User.popLocation() || this._parent.href());
} catch (ex) { } catch (ex) {
app.log(ex); app.log(ex);
res.message = ex; res.message = ex;
@ -134,20 +132,16 @@ Members.prototype.login_action = function() {
if (req.postParams.login) { if (req.postParams.login) {
try { try {
var user = User.login(req.postParams); var user = User.login(req.postParams);
var url = session.data.referrer || this._parent.href();
delete session.data.referrer;
res.message = gettext('Welcome to "{0}", {1}. Have fun!', res.message = gettext('Welcome to "{0}", {1}. Have fun!',
res.handlers.site.getTitle(), user.name); res.handlers.site.getTitle(), user.name);
res.redirect(url); res.redirect(User.popLocation() || this._parent.href());
} catch (ex) { } catch (ex) {
res.message = ex; res.message = ex;
app.log(ex); app.log(ex);
} }
} }
if (!session.data.referrer) { User.pushLocation(req.data.http_referer);
session.data.referrer = req.data.http_referer;
}
session.data.token = User.getSalt(); session.data.token = User.getSalt();
res.data.action = this.href(req.action); res.data.action = this.href(req.action);
res.data.title = gettext("Login"); res.data.title = gettext("Login");

View file

@ -272,48 +272,6 @@ Root.prototype.getCreationPermission = function() {
return true; return true;
}; };
Root.prototype.searchSites = function(query, sid) {
// result array
var result = new Array();
// break up search string
var unquote = new RegExp("\\\\", "g");
query = query.replace(unquote, "\\\\");
unquote = new RegExp("\'", "g");
query = query.replace(unquote, "\'\'");
var qarr = query.split(" ");
// construct query
var where = "select AV_TEXT.TEXT_ID, site.name from AV_TEXT, site "+
"where AV_TEXT.TEXT_F_SITE = site.id " +
"and AV_TEXT.TEXT_ISONLINE > 0 and ";
for (var i in qarr) {
where += "(AV_TEXT.TEXT_RAWCONTENT like '%" + qarr[i].toLowerCase() +
"%') ";
if (i < qarr.length-1)
where += "and ";
}
// search only in the specified site
if (sid)
where += "and site.id = " + sid + " ";
else
where += "and site.mode = 'online' ";
where += "order by AV_TEXT.TEXT_CREATETIME desc";
var dbcon = getDBConnection ("antville");
var dbres = dbcon.executeRetrieval(where);
if (dbres) {
while (dbres.next()) {
var item = new Object();
item.sid = dbres.getColumnItem (1).toString();
item.sitealias = dbres.getColumnItem (2);
result[result.length] = item;
}
}
dbres.release();
return result;
};
Root.prototype.processHref = function(href) { Root.prototype.processHref = function(href) {
return app.properties.defaulthost + href; return app.properties.defaulthost + href;
}; };

View file

@ -362,26 +362,30 @@ Site.prototype.referrers_action = function() {
}; };
Site.prototype.search_action = function() { Site.prototype.search_action = function() {
var search = stripTags(req.postParams.q); var search = req.postParams.q = stripTags(req.postParams.q);
var db = getDBConnection("antville"); if (!search) {
var query = 'select id from content where site_id = ' + this._id + res.message = gettext("Please enter a query in the search form.");
" and prototype = 'Story' and status <> 'closed' and " + } else {
" metadata like '%title:\"%" + search + "%\"%' or " + var db = getDBConnection("antville");
" metadata like '%text:\"%" + search + "%\"%' " + var query = 'select id from content where site_id = ' + this._id +
" order by created desc limit 25"; " and prototype = 'Story' and status <> 'closed' and " +
var rows = db.executeRetrieval(query); " (metadata like '%title:\"%" + search + "%\"%' or " +
var ref, counter = 0; " metadata like '%text:\"%" + search + "%\"%') " +
res.push(); " order by created desc limit 25";
while (rows.next()) { var rows = db.executeRetrieval(query);
ref = Story.getById(rows.getColumnItem("id")); var ref, counter = 0;
ref.renderSkin("Story#preview"); res.push();
counter += 1; while (rows.next()) {
ref = Story.getById(rows.getColumnItem("id"));
ref.renderSkin("Story#preview");
counter += 1;
}
rows.release();
res.message = ngettext("Found {0} result.", "Found {0} results.", counter);
res.data.body = res.pop();
} }
rows.release();
res.message = ngettext("Found {0} result.", "Found {0} results.", counter);
res.data.title = gettext('Search results for "{0}" in site "{1}"', res.data.title = gettext('Search results for "{0}" in site "{1}"',
search, this.title); search, this.title);
res.data.body = res.pop();
this.renderSkin("page"); this.renderSkin("page");
return; return;
}; };

View file

@ -225,6 +225,11 @@ Story.prototype.rotate_action = function() {
}; };
Story.prototype.comment_action = function() { Story.prototype.comment_action = function() {
if (!User.require(User.REGULAR)) {
User.pushLocation(this.href(req.action) + "#form");
res.message = gettext("Please login to add a comment.");
res.redirect(this.site.members.href("login"));
}
var comment = new Comment(this); var comment = new Comment(this);
if (req.postParams.save) { if (req.postParams.save) {
try { try {

View file

@ -232,7 +232,7 @@ User.logout = function() {
session.logout(); session.logout();
res.setCookie(User.COOKIE, String.EMPTY); res.setCookie(User.COOKIE, String.EMPTY);
res.setCookie(User.HASHCOOKIE, String.EMPTY); res.setCookie(User.HASHCOOKIE, String.EMPTY);
delete session.data.referrer; User.popLocation();
return; return;
}; };
@ -258,3 +258,17 @@ User.getMembership = function() {
} }
return membership || new Membership; return membership || new Membership;
}; };
User.pushLocation = function(url) {
if (!session.data.location) {
res.debug("Pushing location " + url);
session.data.location = url;
}
return;
};
User.popLocation = function() {
var url = session.data.location;
delete session.data.location;
return url;
};