2007-06-23 14:53:39 +00:00
|
|
|
//
|
|
|
|
|
// The Antville Project
|
|
|
|
|
// http://code.google.com/p/antville
|
|
|
|
|
//
|
|
|
|
|
// Copyright 2001-2007 by The Antville People
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the ``License'');
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
//
|
|
|
|
|
// $Revision$
|
|
|
|
|
// $LastChangedBy$
|
|
|
|
|
// $LastChangedDate$
|
|
|
|
|
// $URL$
|
|
|
|
|
//
|
|
|
|
|
|
2007-09-14 23:25:23 +00:00
|
|
|
HopObject.prototype.map = function(values) {
|
|
|
|
|
for (var i in values) {
|
|
|
|
|
this[i] = values[i];
|
2007-08-19 16:28:46 +00:00
|
|
|
}
|
2007-08-23 17:17:40 +00:00
|
|
|
return;
|
2007-08-19 16:28:46 +00:00
|
|
|
};
|
|
|
|
|
|
2007-09-14 00:16:06 +00:00
|
|
|
HopObject.prototype.onRequest = function() {
|
|
|
|
|
if (req.postParams.cancel) {
|
|
|
|
|
switch (this.constructor) {
|
|
|
|
|
case Membership:
|
2007-09-14 13:21:21 +00:00
|
|
|
case Members:
|
2007-09-14 00:16:06 +00:00
|
|
|
res.redirect(this._parent.href());
|
|
|
|
|
default:
|
|
|
|
|
res.redirect(this.href());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FIXME: do we still need this?
|
|
|
|
|
if (app.data.redirectPostRequests && path.site && req.isPost())
|
|
|
|
|
res.redirect(app.data.redirectPostRequests);
|
|
|
|
|
|
|
|
|
|
autoLogin();
|
|
|
|
|
res.handlers.membership = User.getMembership();
|
|
|
|
|
|
|
|
|
|
// FIXME: this can go, soon
|
|
|
|
|
res.data.memberlevel = Membership.getLevel();
|
|
|
|
|
|
|
|
|
|
// FIXME: context has to go in the end
|
|
|
|
|
res.handlers.context = res.handlers.site;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// if root.sys_frontSite is set and the site is online
|
|
|
|
|
// we put it into res.handlers.site to ensure that the mirrored
|
|
|
|
|
// site works as expected
|
|
|
|
|
if (!path.Site && root.sys_frontSite && root.sys_frontSite.online)
|
|
|
|
|
res.handlers.site = root.sys_frontSite;
|
|
|
|
|
if (res.handlers.site) {
|
|
|
|
|
if (res.handlers.site.blocked)
|
|
|
|
|
res.redirect(root.href("blocked"));
|
|
|
|
|
if (session.user)
|
|
|
|
|
res.data.memberlevel = res.handlers.site.members.getMembershipLevel(session.user);
|
|
|
|
|
// set a handler that contains the context
|
|
|
|
|
res.handlers.context = res.handlers.site;
|
|
|
|
|
} else {
|
|
|
|
|
// set a handler that contains the context
|
|
|
|
|
res.handlers.context = root;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (session.data.layout) {
|
|
|
|
|
// test drive a layout
|
|
|
|
|
res.handlers.layout = session.data.layout;
|
|
|
|
|
res.message = session.data.layout.renderSkinAsString("testdrive");
|
|
|
|
|
} else {
|
|
|
|
|
// define layout handler
|
|
|
|
|
res.handlers.layout = res.handlers.context.getLayout();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set skinpath
|
|
|
|
|
res.skinpath = res.handlers.layout.getSkinPath();
|
|
|
|
|
|
|
|
|
|
if (session.user && session.user.blocked) {
|
|
|
|
|
// user was blocked recently, so log out
|
|
|
|
|
session.logout();
|
|
|
|
|
res.message = new Exception("accountBlocked");
|
|
|
|
|
res.redirect(res.handlers.context.href());
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-14 13:13:50 +00:00
|
|
|
if (!this.getPermission(req.action)) {
|
|
|
|
|
res.status = 401;
|
|
|
|
|
res.write("Sorry, you are not allowed to access this part of the site.");
|
|
|
|
|
res.stop();
|
|
|
|
|
}
|
2007-09-14 00:16:06 +00:00
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
HopObject.prototype.onUnhandledMacro = function(name) {
|
2007-09-14 23:25:23 +00:00
|
|
|
return;
|
|
|
|
|
|
2007-09-14 00:16:06 +00:00
|
|
|
switch (name) {
|
|
|
|
|
default:
|
2007-09-14 23:25:23 +00:00
|
|
|
return this[name];
|
2007-09-14 00:16:06 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
HopObject.prototype.touch = function() {
|
2007-09-14 23:25:23 +00:00
|
|
|
return this.map({
|
2007-09-14 00:16:06 +00:00
|
|
|
modified: new Date,
|
|
|
|
|
modifier: session.user
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
HopObject.prototype.getPermission = function() {
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
2007-09-08 17:20:59 +00:00
|
|
|
HopObject.prototype.input_macro = function(param, name) {
|
|
|
|
|
param.name = name;
|
|
|
|
|
param.value = this.getFormValue(name);
|
|
|
|
|
return html.input(param);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
HopObject.prototype.checkbox_macro = function(param, name) {
|
|
|
|
|
param.name = name;
|
|
|
|
|
param.id = name;
|
|
|
|
|
param.value = String(this.getFormOptions(name)[0].value);
|
|
|
|
|
param.selectedValue = String(this.getFormValue(name));
|
2007-09-14 23:25:23 +00:00
|
|
|
var label = param.label;
|
|
|
|
|
delete param.label;
|
2007-09-08 17:20:59 +00:00
|
|
|
//res.debug(name + ": " + param.value + " / " + this.getFormValue(name));
|
2007-09-14 23:25:23 +00:00
|
|
|
html.checkBox(param);
|
|
|
|
|
if (label) {
|
|
|
|
|
html.element("label", label, {"for": name});
|
|
|
|
|
}
|
|
|
|
|
return;
|
2007-09-08 17:20:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
HopObject.prototype.select_macro = function(param, name) {
|
|
|
|
|
param.name = name;
|
|
|
|
|
return html.dropDown(param, this.getFormOptions(name),
|
|
|
|
|
this.getFormValue(name));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
HopObject.prototype.getFormValue = function(name) {
|
|
|
|
|
//res.debug(name + ": " + req.data[name] + " / " + ((value = req.data[name]) !== null))
|
|
|
|
|
if (req.isPost()) {
|
|
|
|
|
return req.postParams[name];
|
|
|
|
|
} else {
|
2007-09-14 23:25:23 +00:00
|
|
|
var value = this[name];
|
2007-09-08 17:20:59 +00:00
|
|
|
return value instanceof HopObject ? value._id : value;
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
HopObject.prototype.getFormOptions = function(name) {
|
|
|
|
|
return [{value: true, display: "enabled"}];
|
2007-06-23 14:53:39 +00:00
|
|
|
};
|
|
|
|
|
|
2007-09-08 17:20:59 +00:00
|
|
|
HopObject.prototype.link_macro = function(param, url, text) {
|
2007-09-14 00:16:06 +00:00
|
|
|
if (this.getPermission(url)) {
|
|
|
|
|
renderLink.call(global, param, url, text, this);
|
|
|
|
|
}
|
|
|
|
|
return;
|
2007-06-23 14:53:39 +00:00
|
|
|
};
|
|
|
|
|
|
2007-09-08 17:20:59 +00:00
|
|
|
HopObject.prototype.created_macro = function(param, format) {
|
2007-09-14 23:25:23 +00:00
|
|
|
res.write(formatDate(this.created, format || param.format));
|
2007-06-23 14:53:39 +00:00
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
2007-09-08 17:20:59 +00:00
|
|
|
HopObject.prototype.modified_macro = function(param, format) {
|
2007-09-14 23:25:23 +00:00
|
|
|
res.write(formatDate(this.modified, format || param.format));
|
2007-06-23 14:53:39 +00:00
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
HopObject.prototype.creator_macro = function(param) {
|
|
|
|
|
if (!this.creator)
|
|
|
|
|
return;
|
|
|
|
|
if (param.as == "link" && this.creator.url)
|
|
|
|
|
Html.link({href: this.creator.url}, this.creator.name);
|
|
|
|
|
else if (param.as == "url")
|
|
|
|
|
res.write(this.creator.url);
|
|
|
|
|
else
|
|
|
|
|
res.write(this.creator.name);
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
HopObject.prototype.modifier_macro = function(param) {
|
|
|
|
|
if (!this.modifier)
|
|
|
|
|
return;
|
|
|
|
|
if (param.as == "link" && this.modifier.url)
|
|
|
|
|
Html.link({href: this.modifier.url}, this.modifier.name);
|
|
|
|
|
else if (param.as == "url")
|
|
|
|
|
res.write(this.modifier.url);
|
|
|
|
|
else
|
|
|
|
|
res.write(this.modifier.name);
|
|
|
|
|
return;
|
|
|
|
|
};
|
2007-09-14 00:16:06 +00:00
|
|
|
|
2007-06-23 14:53:39 +00:00
|
|
|
HopObject.prototype.getNavigationName = function() {
|
|
|
|
|
var proto = this._prototype;
|
|
|
|
|
var display;
|
|
|
|
|
if (display = getDisplay(proto))
|
|
|
|
|
return display;
|
|
|
|
|
return this.__name__;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
HopObject.prototype.applyModuleMethod = function(module, funcName, param) {
|
|
|
|
|
if (module && module[funcName])
|
|
|
|
|
module[funcName].apply(this, [param]);
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
2007-09-08 17:20:59 +00:00
|
|
|
HopObject.prototype.toString = function() {
|
|
|
|
|
return this.constructor.name + " #" + this._id;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*HopObject.prototype.valueOf = function() {
|
|
|
|
|
return this._id;
|
|
|
|
|
};*/
|
|
|
|
|
|
|
|
|
|
HopObject.prototype.link_filter = function(value, param, action) {
|
|
|
|
|
return renderLink(param, action, value, this);
|
2007-09-14 00:16:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
HopObject.prototype.removeChildren = function() {
|
|
|
|
|
while (this.size() > 0) {
|
|
|
|
|
this.get(0).remove();
|
|
|
|
|
}
|
|
|
|
|
return;
|
2007-09-08 17:20:59 +00:00
|
|
|
};
|
2007-09-14 23:25:23 +00:00
|
|
|
|
|
|
|
|
HopObject.prototype.handleMetadata = function(name) {
|
|
|
|
|
this.__defineGetter__(name, function() {
|
|
|
|
|
return this.properties.get(name);
|
|
|
|
|
});
|
|
|
|
|
this.__defineSetter__(name, function(value) {
|
|
|
|
|
return this.properties.set(name, value);
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
};
|