2007-09-21 13:54:30 +00:00
|
|
|
|
// The Antville Project
|
|
|
|
|
// http://code.google.com/p/antville
|
|
|
|
|
//
|
2014-07-04 17:16:51 +02:00
|
|
|
|
// Copyright 2001–2014 by the Workers of Antville.
|
2007-09-21 13:54:30 +00:00
|
|
|
|
//
|
|
|
|
|
// 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
|
|
|
|
|
//
|
2014-07-04 15:32:18 +02:00
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2007-09-21 13:54:30 +00:00
|
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
|
2009-11-02 16:16:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* @fileOverview Defines the Skins prototype.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-07-04 15:44:41 +02:00
|
|
|
|
markgettext('Skins');
|
|
|
|
|
markgettext('skins');
|
2010-05-24 13:32:40 +00:00
|
|
|
|
|
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) {
|
2014-07-04 15:10:47 +02:00
|
|
|
|
this.name = name;
|
2007-11-03 20:18:18 +00:00
|
|
|
|
this.parent = parent;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-02 16:16:41 +00:00
|
|
|
|
/**
|
2014-07-04 15:10:47 +02:00
|
|
|
|
*
|
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) {
|
2014-07-04 15:44:41 +02: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
|
|
|
|
/**
|
2014-07-04 15:10:47 +02: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) {
|
2014-07-04 15:32:18 +02:00
|
|
|
|
if (this.parent) {
|
|
|
|
|
var group = path[path.length - 1].name;
|
|
|
|
|
var skin = this.getSkin(group, name);
|
|
|
|
|
if (skin) {
|
|
|
|
|
return skin;
|
|
|
|
|
}
|
2014-07-04 15:44:41 +02:00
|
|
|
|
if (global[group] || group === 'Global') {
|
2014-07-04 15:32:18 +02:00
|
|
|
|
return this.getSkin(group, name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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() {
|
2014-07-04 15:32:18 +02:00
|
|
|
|
if (this.parent) {
|
|
|
|
|
res.redirect(res.handlers.layout.skins.href(req.action));
|
|
|
|
|
}
|
|
|
|
|
return HopObject.prototype.onRequest.call(this);
|
2009-12-13 22:29:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Skins.prototype.main_action = function() {
|
2014-07-04 15:44:41 +02:00
|
|
|
|
res.data.title = gettext('Basic Skins');
|
|
|
|
|
res.data.body = this.renderSkinAsString('$Skins#main');
|
|
|
|
|
res.handlers.site.renderSkin('Site#page');
|
2014-07-04 15:32:18 +02: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() {
|
2014-07-04 15:32:18 +02:00
|
|
|
|
if (req.postParams.save) {
|
|
|
|
|
try {
|
|
|
|
|
var prototype = req.postParams.prototype;
|
|
|
|
|
var name = stripTags(req.postParams.name);
|
|
|
|
|
if (!prototype || !req.postParams.name) {
|
2014-07-04 15:44:41 +02:00
|
|
|
|
throw Error(gettext('Please choose a prototype and enter a skin name'));
|
2014-07-04 15:32:18 +02:00
|
|
|
|
} else if (name !== req.postParams.name || /\s/.test(name) || NAMEPATTERN.test(name)) {
|
2014-07-04 15:44:41 +02:00
|
|
|
|
throw Error(gettext('Please avoid special characters or HTML code in the name field.'));
|
2014-07-04 15:32:18 +02:00
|
|
|
|
} else if (Skin.getByName(prototype, name)) {
|
2014-07-04 15:44:41 +02:00
|
|
|
|
throw Error('Sorry, there is already a skin with that name. Please enter a different one.');
|
2007-09-21 13:54:30 +00:00
|
|
|
|
}
|
2014-07-04 15:32:18 +02:00
|
|
|
|
var skin = this.getSkin(prototype, name);
|
|
|
|
|
skin.update(req.postParams);
|
2014-07-04 15:44:41 +02:00
|
|
|
|
res.message = gettext('The changes were saved successfully.');
|
2014-07-04 15:32:18 +02:00
|
|
|
|
if (req.postParams.save == 1) {
|
2014-07-04 15:44:41 +02:00
|
|
|
|
res.redirect(skin.href('edit'));
|
2014-07-04 15:32:18 +02:00
|
|
|
|
} else {
|
2014-07-04 15:44:41 +02:00
|
|
|
|
res.redirect(res.handlers.layout.skins.href('modified'));
|
2014-07-04 15:32:18 +02:00
|
|
|
|
}
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
res.message = ex;
|
|
|
|
|
app.log(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
res.data.title = gettext('Add Skin');
|
|
|
|
|
res.data.action = this.href(req.action);
|
|
|
|
|
HopObject.confirmConstructor(Skin);
|
2014-07-04 15:44:41 +02:00
|
|
|
|
res.data.body = (new Skin).renderSkinAsString('$Skin#edit');
|
|
|
|
|
this.renderSkin('$Skins#page');
|
2014-07-04 15:32:18 +02:00
|
|
|
|
return;
|
2008-04-21 13:57:01 +00:00
|
|
|
|
}
|
2007-09-21 13:54:30 +00:00
|
|
|
|
|
|
|
|
|
Skins.prototype.modified_action = function() {
|
2014-07-04 15:44:41 +02:00
|
|
|
|
res.data.title = gettext('Modified Skins');
|
2014-12-21 17:20:22 +01:00
|
|
|
|
res.data.list = renderList(this.modified, '$Skin#listItem');
|
|
|
|
|
res.data.body = this.renderSkinAsString('$Skins#list');
|
2014-07-04 15:44:41 +02:00
|
|
|
|
res.handlers.site.renderSkin('Site#page');
|
2014-07-04 15:32:18 +02: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() {
|
2014-07-04 15:32:18 +02:00
|
|
|
|
if (this.parent) {
|
|
|
|
|
res.redirect(res.handlers.layout.skins.href(req.action));
|
|
|
|
|
}
|
2014-12-21 17:20:22 +01:00
|
|
|
|
res.push()
|
2023-08-26 22:32:00 +02:00
|
|
|
|
for (let set of this.getListOfSkins()) {
|
2014-12-21 17:20:22 +01:00
|
|
|
|
res.write(renderList(set[1], '$Skin#listItem'));
|
|
|
|
|
}
|
|
|
|
|
res.data.list = res.pop();
|
2014-07-04 15:44:41 +02:00
|
|
|
|
res.data.title = gettext('All Skins');
|
2014-12-21 17:20:22 +01:00
|
|
|
|
res.data.body = this.renderSkinAsString('$Skins#list');
|
2014-07-04 15:44:41 +02:00
|
|
|
|
res.handlers.site.renderSkin('Site#page');
|
2014-07-04 15:32:18 +02:00
|
|
|
|
return;
|
2008-04-21 13:57:01 +00:00
|
|
|
|
}
|
2007-09-21 13:54:30 +00:00
|
|
|
|
|
|
|
|
|
Skins.prototype.safe_action = function() {
|
2014-12-21 17:20:22 +01:00
|
|
|
|
res.data.title = gettext('Modified Skins (Safe Mode)');
|
|
|
|
|
res.data.list = renderList(this.modified, '$Skin#listItem');
|
|
|
|
|
res.data.body = this.renderSkinAsString('$Skins#list');
|
2014-07-04 15:44:41 +02:00
|
|
|
|
this.renderSkin('$Skins#page');
|
2014-07-04 15:32:18 +02: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
|
|
|
|
/**
|
2014-07-04 15:10:47 +02: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) {
|
2014-07-04 15:32:18 +02: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
|
|
|
|
|
|
|
|
|
/**
|
2014-07-04 15:10:47 +02:00
|
|
|
|
*
|
2009-12-13 22:29:21 +00:00
|
|
|
|
* @returns {String}
|
|
|
|
|
*/
|
2015-01-07 14:34:37 +01:00
|
|
|
|
Skins.prototype.getListOfSkins = function() {
|
|
|
|
|
var result = [];
|
2014-07-04 15:32:18 +02:00
|
|
|
|
var options = Skin.getPrototypeOptions();
|
2023-08-26 22:32:00 +02:00
|
|
|
|
for (let option of options) {
|
2014-12-21 17:20:22 +01:00
|
|
|
|
var skins = [];
|
|
|
|
|
var prototype = option.value;
|
|
|
|
|
var skinfiles = app.getSkinfilesInPath(res.skinpath);
|
|
|
|
|
var skin = createSkin(skinfiles[prototype][prototype]);
|
2023-08-26 22:32:00 +02:00
|
|
|
|
for (let name of skin.getSubskinNames()) {
|
2014-12-21 17:20:22 +01:00
|
|
|
|
var subskin = this.getSkin(prototype, name);
|
|
|
|
|
skins.push(subskin);
|
2014-07-04 15:32:18 +02:00
|
|
|
|
}
|
2015-02-14 17:38:54 +01:00
|
|
|
|
skins.sort(new String.Sorter('name'));
|
2015-01-07 14:34:37 +01:00
|
|
|
|
result.push([prototype, skins]);
|
2014-07-04 15:32:18 +02:00
|
|
|
|
}
|
2015-01-07 14:34:37 +01:00
|
|
|
|
return result;
|
2009-12-13 22:29:21 +00:00
|
|
|
|
}
|