* 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:
parent
3d0fae4302
commit
1c3c51a0e1
7 changed files with 46 additions and 72 deletions
|
@ -90,10 +90,10 @@ HopObject.prototype.delete_action = function() {
|
|||
if (req.postParams.proceed) {
|
||||
//try {
|
||||
var str = this.toString();
|
||||
var href = this._parent.href();
|
||||
var url = this._parent.href();
|
||||
this.constructor.remove.call(this, this);
|
||||
res.message = gettext("{0} was successfully deleted.", str);
|
||||
res.redirect(session.data.retrace || href);
|
||||
res.redirect(User.popLocation() || url);
|
||||
/*} catch(ex) {
|
||||
res.message = ex;
|
||||
app.log(ex);
|
||||
|
|
|
@ -64,7 +64,6 @@ Images.prototype.create_action = function() {
|
|||
image.notify(req.action);
|
||||
res.message = gettext('The uploaded image was saved successfully. Its name is "{0}"',
|
||||
image.name);
|
||||
session.data.referrer = null;
|
||||
res.redirect(image.href());
|
||||
} catch (ex) {
|
||||
res.message = ex.toString();
|
||||
|
|
|
@ -81,11 +81,9 @@ Members.prototype.register_action = function() {
|
|||
this.add(membership);
|
||||
membership.notify(req.action, user.email,
|
||||
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!',
|
||||
title, user.name);
|
||||
res.redirect(url);
|
||||
res.redirect(User.popLocation() || this._parent.href());
|
||||
} catch (ex) {
|
||||
app.log(ex);
|
||||
res.message = ex;
|
||||
|
@ -134,20 +132,16 @@ Members.prototype.login_action = function() {
|
|||
if (req.postParams.login) {
|
||||
try {
|
||||
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.handlers.site.getTitle(), user.name);
|
||||
res.redirect(url);
|
||||
res.redirect(User.popLocation() || this._parent.href());
|
||||
} catch (ex) {
|
||||
res.message = ex;
|
||||
app.log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (!session.data.referrer) {
|
||||
session.data.referrer = req.data.http_referer;
|
||||
}
|
||||
User.pushLocation(req.data.http_referer);
|
||||
session.data.token = User.getSalt();
|
||||
res.data.action = this.href(req.action);
|
||||
res.data.title = gettext("Login");
|
||||
|
|
|
@ -272,48 +272,6 @@ Root.prototype.getCreationPermission = function() {
|
|||
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) {
|
||||
return app.properties.defaulthost + href;
|
||||
};
|
||||
|
|
|
@ -362,26 +362,30 @@ Site.prototype.referrers_action = function() {
|
|||
};
|
||||
|
||||
Site.prototype.search_action = function() {
|
||||
var search = stripTags(req.postParams.q);
|
||||
var db = getDBConnection("antville");
|
||||
var query = 'select id from content where site_id = ' + this._id +
|
||||
" and prototype = 'Story' and status <> 'closed' and " +
|
||||
" metadata like '%title:\"%" + search + "%\"%' or " +
|
||||
" metadata like '%text:\"%" + search + "%\"%' " +
|
||||
" order by created desc limit 25";
|
||||
var rows = db.executeRetrieval(query);
|
||||
var ref, counter = 0;
|
||||
res.push();
|
||||
while (rows.next()) {
|
||||
ref = Story.getById(rows.getColumnItem("id"));
|
||||
ref.renderSkin("Story#preview");
|
||||
counter += 1;
|
||||
var search = req.postParams.q = stripTags(req.postParams.q);
|
||||
if (!search) {
|
||||
res.message = gettext("Please enter a query in the search form.");
|
||||
} else {
|
||||
var db = getDBConnection("antville");
|
||||
var query = 'select id from content where site_id = ' + this._id +
|
||||
" and prototype = 'Story' and status <> 'closed' and " +
|
||||
" (metadata like '%title:\"%" + search + "%\"%' or " +
|
||||
" metadata like '%text:\"%" + search + "%\"%') " +
|
||||
" order by created desc limit 25";
|
||||
var rows = db.executeRetrieval(query);
|
||||
var ref, counter = 0;
|
||||
res.push();
|
||||
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}"',
|
||||
search, this.title);
|
||||
res.data.body = res.pop();
|
||||
this.renderSkin("page");
|
||||
return;
|
||||
};
|
||||
|
|
|
@ -225,6 +225,11 @@ Story.prototype.rotate_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);
|
||||
if (req.postParams.save) {
|
||||
try {
|
||||
|
|
|
@ -232,7 +232,7 @@ User.logout = function() {
|
|||
session.logout();
|
||||
res.setCookie(User.COOKIE, String.EMPTY);
|
||||
res.setCookie(User.HASHCOOKIE, String.EMPTY);
|
||||
delete session.data.referrer;
|
||||
User.popLocation();
|
||||
return;
|
||||
};
|
||||
|
||||
|
@ -258,3 +258,17 @@ User.getMembership = function() {
|
|||
}
|
||||
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;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue