antville/code/Skins/Skins.js
Tobi Schäfer 32c52791fe * Refactored code and skins in respect for comprehensive i18n
* Refactored and unified remove() methods and calls for greater flexibility as well as reliability
 * Added option to remove all comments by a user to Comment.remove() method and $Comment#delete skin
 * Added global #listItemFlag skin as well as listItemFlag_macro() for rendering vertically written text of items in a list view (e.g. closed)
 * Fixed bug in gettext_macro() and ngettext_macro() causing incorrect whitespace
 * Refactored timezone and locale handling
 * Modified automatic translation of untitled links in HopObject.link_macro()
 * Added honeypot to login and registration forms
 * Fixed client-side JavaScript to be evaluated when login or registration form is submitted, not only when the submit button is clicked
 * Removed redundant filter expression from DB mapping of Membership.images collection
 * Added Membership.content collection
 * Changed terminology from open to running polls, thus renaming Polls.open_action() method and Polls.open collection
 * Moved a lot of CSS used in root or administration sections from Site#stylesheet to $Root#stylesheet skin
 * Added Root.updateDomains() method (most likely already obsolete)
 * Removed Root.processHref() method (only necessary for very advanced setup) and obsolete comments
 * Fixed Root.xgettext() method to correctly read UTF-8 encoded data
 * Fixed Site.deleted_macro() to return the date object for late formatting
 * Refactored Site.processHref() for more convenient custom domain name mapping
 * Renamed Skins.advanced_action() method to Skins.all_action()
 * Removed redundant filter from Stories.comments collection
 * Removed unnecessary filter from Story.comments collection
2010-01-10 14:40:36 +00:00

220 lines
5.9 KiB
JavaScript

//
// 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:3337 $
// $LastChangedBy:piefke3000 $
// $LastChangedDate:2007-09-21 15:54:30 +0200 (Fri, 21 Sep 2007) $
// $URL$
//
/**
* @fileOverview Defines the Skins prototype.
*/
/**
* @name Skins
* @constructor
* @param {String} name
* @param {Skins} parent
* @property {Skin[]} _children
* @property {Skin[]} custom
* @property {Skin[]} modified
* @property {String} name
* @property {Skins} parent
* @extends HopObject
*/
Skins.prototype.constructor = function(name, parent) {
this.name = name;
this.parent = parent;
return this;
}
/**
*
* @param {String} action
* @returns {Boolean}
*/
Skins.prototype.getPermission = function(action) {
return res.handlers.layout.getPermission("main");
}
/**
*
* @param {String} name
* @returns {Skins|Skin}
*/
Skins.prototype.getChildElement = function(name) {
if (this.parent) {
var group = path[path.length - 1].name;
var skin = this.getSkin(group, name);
if (skin) {
return skin;
}
if (global[group] || group === "Global") {
return this.getSkin(group, name);
}
}
return new Skins(name, this);
}
Skins.prototype.onRequest = function() {
if (this.parent) {
res.redirect(res.handlers.layout.skins.href(req.action));
}
return HopObject.prototype.onRequest.call(this);
}
Skins.prototype.main_action = function() {
res.data.title = gettext("Basic Skins");
res.data.body = this.renderSkinAsString("$Skins#main");
res.handlers.site.renderSkin("Site#page");
return;
}
Skins.prototype.create_action = function() {
var skin = this.getSkin(req.postParams.prototype, req.postParams.name);
if (req.postParams.save) {
try {
if (!req.postParams.prototype || !req.postParams.name) {
throw Error(gettext("Please choose a prototype and enter a skin name"));
}
skin.update(req.postParams);
res.message = gettext("The changes were saved successfully.");
if (req.postParams.save == 1) {
res.redirect(skin.href("edit"));
} else {
res.redirect(res.handlers.layout.skins.href("modified"));
}
} catch (ex) {
res.message = ex;
app.log(ex);
}
}
if (skin.getSource()) {
res.redirect(skin.href("edit")); // FIXME: Needs testing
//res.data.title = gettext("Edit skin: {0}.{1}", skin.prototype, skin.name);
} else {
res.data.title = gettext('Add Skin');
}
res.data.action = this.href(req.action);
res.data.body = skin.renderSkinAsString("$Skin#edit");
this.renderSkin("$Skins#page");
return;
}
Skins.prototype.modified_action = function() {
res.data.title = gettext("Modified Skins");
res.push();
this.renderSkin("$Skins#header");
this.modified.forEach(function() {
this.renderSkin("$Skin#listItem");
});
res.data.body = res.pop();
res.handlers.site.renderSkin("Site#page");
return;
}
Skins.prototype.all_action = function() {
if (this.parent) {
res.redirect(res.handlers.layout.skins.href(req.action));
}
res.data.list = this.getOutline();
res.data.title = gettext("All Skins");
res.data.body = this.renderSkinAsString("$Skins#all");
res.handlers.site.renderSkin("Site#page");
return;
}
Skins.prototype.safe_action = function() {
res.data.title = gettext("Modified Skins");
res.push();
this.modified.forEach(function() {
this.renderSkin("$Skin#listItem");
});
res.data.title = "Modified Skins";
res.data.body = res.pop();
this.renderSkin("$Skins#page");
return;
}
/**
*
* @param {String} group
* @param {String} name
* @returns {Skin}
*/
Skins.prototype.getSkin = function(group, name) {
return Skin.getByName(group, name) || new Skin(group, name);
}
/**
*
* @param {String} type
* @returns {String}
*/
Skins.prototype.getOutline = function(type) {
var key = "outline:" + type;
var outline = this.cache[key];
if (outline) {
return outline;
}
var prototype, skin, subskins, names, skins = [];
var options = Skin.getPrototypeOptions();
for each (var option in options) {
prototype = option.value;
names = [];
for (var name in app.skinfiles[prototype]) {
if (name === prototype && type !== "custom") {
skin = createSkin(app.skinfiles[prototype][name]);
subskins = skin.getSubskinNames();
for each (var subskin in subskins) {
names.push(subskin);
}
} else if (name !== prototype && type === "custom") {
names.push(name);
}
}
names.sort();
skins.push([prototype, names]);
}
res.push();
for each (var item in skins) {
prototype = item[0];
skin = item[1];
if (skin && skin.length > 0) {
html.openTag("li");
html.openTag("a", {href: "#", name: prototype, id: prototype});
res.write(prototype);
html.closeTag("a");
html.openTag("ul");
for each (var name in skin) {
subskin = this.getSkin(prototype, name);
html.openTag("li");
html.link({href: subskin.href("edit")},
subskin.prototype + "." + subskin.name);
html.closeTag("li");
}
html.closeTag("ul");
html.closeTag("li");
}
}
return this.cache[key] = res.pop();
}