2007-09-21 13:54:30 +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.
|
|
|
|
//
|
2007-09-22 21:48:33 +00:00
|
|
|
// $Revision:3337 $
|
|
|
|
// $LastChangedBy:piefke3000 $
|
|
|
|
// $LastChangedDate:2007-09-21 15:54:30 +0200 (Fri, 21 Sep 2007) $
|
2007-09-21 13:54:30 +00:00
|
|
|
// $URL$
|
|
|
|
//
|
|
|
|
|
2009-11-02 16:16:41 +00:00
|
|
|
/**
|
|
|
|
* @fileOverview Defines the Skins prototype.
|
|
|
|
*/
|
|
|
|
|
2010-05-24 13:32:40 +00:00
|
|
|
markgettext("Skins");
|
|
|
|
markgettext("skins");
|
|
|
|
|
2009-11-02 16:16:41 +00:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2007-11-03 20:18:18 +00:00
|
|
|
Skins.prototype.constructor = function(name, parent) {
|
|
|
|
this.name = name;
|
|
|
|
this.parent = parent;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2009-11-02 16:16:41 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {String} action
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
2007-09-21 13:54:30 +00:00
|
|
|
Skins.prototype.getPermission = function(action) {
|
2007-11-03 20:18:18 +00:00
|
|
|
return res.handlers.layout.getPermission("main");
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|
2007-09-21 13:54:30 +00:00
|
|
|
|
2009-11-02 16:16:41 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {String} name
|
|
|
|
* @returns {Skins|Skin}
|
|
|
|
*/
|
2007-11-03 20:18:18 +00:00
|
|
|
Skins.prototype.getChildElement = function(name) {
|
2008-03-21 22:16:54 +00:00
|
|
|
if (this.parent) {
|
2008-04-27 14:35:35 +00:00
|
|
|
var group = path[path.length - 1].name;
|
|
|
|
var skin = this.getSkin(group, name);
|
|
|
|
if (skin) {
|
|
|
|
return skin;
|
2008-03-21 22:16:54 +00:00
|
|
|
}
|
2008-04-27 14:35:35 +00:00
|
|
|
if (global[group] || group === "Global") {
|
|
|
|
return this.getSkin(group, name);
|
2008-03-21 22:16:54 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-03 20:18:18 +00:00
|
|
|
return new Skins(name, this);
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|
2007-11-23 17:57:59 +00:00
|
|
|
|
2009-12-13 22:29:21 +00:00
|
|
|
Skins.prototype.onRequest = function() {
|
|
|
|
if (this.parent) {
|
|
|
|
res.redirect(res.handlers.layout.skins.href(req.action));
|
2008-03-27 15:10:31 +00:00
|
|
|
}
|
2009-12-13 22:29:21 +00:00
|
|
|
return HopObject.prototype.onRequest.call(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Skins.prototype.main_action = function() {
|
|
|
|
res.data.title = gettext("Basic Skins");
|
2008-04-21 13:35:50 +00:00
|
|
|
res.data.body = this.renderSkinAsString("$Skins#main");
|
2008-03-21 22:16:54 +00:00
|
|
|
res.handlers.site.renderSkin("Site#page");
|
2007-11-03 20:18:18 +00:00
|
|
|
return;
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|
2007-11-03 20:18:18 +00:00
|
|
|
|
2007-09-21 13:54:30 +00:00
|
|
|
Skins.prototype.create_action = function() {
|
2010-02-06 21:38:49 +00:00
|
|
|
var skin = new Skin;
|
2007-09-30 23:59:13 +00:00
|
|
|
if (req.postParams.save) {
|
2007-09-21 13:54:30 +00:00
|
|
|
try {
|
2010-02-06 21:38:49 +00:00
|
|
|
var prototype = req.postParams.prototype;
|
|
|
|
var name = stripTags(req.postParams.name);
|
|
|
|
if (!prototype || !req.postParams.name) {
|
2010-01-10 14:40:36 +00:00
|
|
|
throw Error(gettext("Please choose a prototype and enter a skin name"));
|
2010-02-06 22:34:06 +00:00
|
|
|
} else if (name !== req.postParams.name || /\s/.test(name) || NAMEPATTERN.test(name)) {
|
|
|
|
throw Error(gettext("Please avoid special characters or HTML code in the name field."));
|
2010-02-06 21:38:49 +00:00
|
|
|
} else if (Skin.getByName(prototype, name)) {
|
|
|
|
throw Error("Sorry, there is already a skin with that name. Please enter a different one.");
|
2007-09-21 13:54:30 +00:00
|
|
|
}
|
2010-02-06 21:38:49 +00:00
|
|
|
skin = this.getSkin(prototype, name);
|
2008-04-27 14:35:35 +00:00
|
|
|
skin.update(req.postParams);
|
2007-09-30 23:59:13 +00:00
|
|
|
res.message = gettext("The changes were saved successfully.");
|
|
|
|
if (req.postParams.save == 1) {
|
|
|
|
res.redirect(skin.href("edit"));
|
|
|
|
} else {
|
2008-04-15 22:02:29 +00:00
|
|
|
res.redirect(res.handlers.layout.skins.href("modified"));
|
2007-09-30 23:59:13 +00:00
|
|
|
}
|
2007-09-21 13:54:30 +00:00
|
|
|
} catch (ex) {
|
|
|
|
res.message = ex;
|
|
|
|
app.log(ex);
|
|
|
|
}
|
2008-04-27 14:35:35 +00:00
|
|
|
}
|
2010-02-06 21:38:49 +00:00
|
|
|
res.data.title = gettext('Add Skin');
|
2007-09-30 23:59:13 +00:00
|
|
|
res.data.action = this.href(req.action);
|
2008-04-21 13:35:50 +00:00
|
|
|
res.data.body = skin.renderSkinAsString("$Skin#edit");
|
|
|
|
this.renderSkin("$Skins#page");
|
2007-09-21 13:54:30 +00:00
|
|
|
return;
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|
2007-09-21 13:54:30 +00:00
|
|
|
|
|
|
|
Skins.prototype.modified_action = function() {
|
2009-12-13 22:29:21 +00:00
|
|
|
res.data.title = gettext("Modified Skins");
|
2007-11-03 20:18:18 +00:00
|
|
|
res.push();
|
2009-12-13 22:29:21 +00:00
|
|
|
this.renderSkin("$Skins#header");
|
2007-11-03 20:18:18 +00:00
|
|
|
this.modified.forEach(function() {
|
2008-04-21 13:35:50 +00:00
|
|
|
this.renderSkin("$Skin#listItem");
|
2007-11-03 20:18:18 +00:00
|
|
|
});
|
2009-12-13 22:29:21 +00:00
|
|
|
res.data.body = res.pop();
|
2008-01-13 01:39:01 +00:00
|
|
|
res.handlers.site.renderSkin("Site#page");
|
2007-09-21 13:54:30 +00:00
|
|
|
return;
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|
2007-09-21 13:54:30 +00:00
|
|
|
|
2010-01-10 14:40:36 +00:00
|
|
|
Skins.prototype.all_action = function() {
|
2008-03-26 12:33:54 +00:00
|
|
|
if (this.parent) {
|
2009-12-13 22:29:21 +00:00
|
|
|
res.redirect(res.handlers.layout.skins.href(req.action));
|
2008-03-26 12:33:54 +00:00
|
|
|
}
|
|
|
|
res.data.list = this.getOutline();
|
2009-12-13 22:29:21 +00:00
|
|
|
res.data.title = gettext("All Skins");
|
2010-01-10 14:40:36 +00:00
|
|
|
res.data.body = this.renderSkinAsString("$Skins#all");
|
2008-01-13 01:39:01 +00:00
|
|
|
res.handlers.site.renderSkin("Site#page");
|
2007-09-21 13:54:30 +00:00
|
|
|
return;
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|
2007-09-21 13:54:30 +00:00
|
|
|
|
|
|
|
Skins.prototype.safe_action = function() {
|
2009-12-13 22:29:21 +00:00
|
|
|
res.data.title = gettext("Modified Skins");
|
2008-04-16 18:03:41 +00:00
|
|
|
res.push();
|
|
|
|
this.modified.forEach(function() {
|
2008-04-21 13:35:50 +00:00
|
|
|
this.renderSkin("$Skin#listItem");
|
2008-04-16 18:03:41 +00:00
|
|
|
});
|
2009-12-13 22:29:21 +00:00
|
|
|
res.data.title = "Modified Skins";
|
|
|
|
res.data.body = res.pop();
|
2008-04-21 13:35:50 +00:00
|
|
|
this.renderSkin("$Skins#page");
|
2007-09-21 13:54:30 +00:00
|
|
|
return;
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|
2007-09-21 13:54:30 +00:00
|
|
|
|
2009-11-02 16:16:41 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {String} group
|
|
|
|
* @param {String} name
|
|
|
|
* @returns {Skin}
|
|
|
|
*/
|
2008-04-27 14:35:35 +00:00
|
|
|
Skins.prototype.getSkin = function(group, name) {
|
2008-05-02 21:33:40 +00:00
|
|
|
return Skin.getByName(group, name) || new Skin(group, name);
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|
2009-12-13 22:29:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
2011-01-07 15:06:49 +00:00
|
|
|
Skins.prototype.getOutline = function() {
|
2011-01-07 14:55:24 +00:00
|
|
|
var skinfiles, prototype, skin, subskins, names, skins = [];
|
2009-12-13 22:29:21 +00:00
|
|
|
var options = Skin.getPrototypeOptions();
|
|
|
|
|
|
|
|
for each (var option in options) {
|
|
|
|
names = [];
|
2011-01-07 14:55:24 +00:00
|
|
|
prototype = option.value;
|
|
|
|
skinfiles = app.getSkinfilesInPath(res.skinpath);
|
|
|
|
skin = createSkin(skinfiles[prototype][prototype]);
|
|
|
|
subskins = skin.getSubskinNames();
|
|
|
|
for each (var subskin in subskins) {
|
|
|
|
names.push(subskin);
|
2009-12-13 22:29:21 +00:00
|
|
|
}
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
2011-01-07 15:06:49 +00:00
|
|
|
return res.pop();
|
2009-12-13 22:29:21 +00:00
|
|
|
}
|