diff --git a/core/Global.js b/core/Global.js new file mode 100644 index 00000000..91f43763 --- /dev/null +++ b/core/Global.js @@ -0,0 +1,67 @@ +/* + * Helma License Notice + * + * The contents of this file are subject to the Helma License + * Version 2.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://adele.helma.org/download/helma/license.txt + * + * Copyright 1998-2005 Helma Software. All Rights Reserved. + * + * $RCSfile: Date.js,v $ + * $Author: czv $ + * $Revision: 1.2 $ + * $Date: 2006/04/24 07:02:17 $ + */ + + +app.addRepository("modules/core/String.js"); + + +/** + * write out a property contained in app.properties + * @param Object containing the name of the property + */ +function property_macro(param) { + res.write(app.properties[param.name] || String.NULL); + return; +} + + +/** + * wrapper to output a string from within a skin + * just to be able to use different encodings + * @param Object containing the string as text property + */ +function write_macro(param) { + res.write(param.text || String.NULL); + return; +} + + +/** + * renders the current datetime + * @param Object containing a formatting string as format property + */ +function now_macro(param) { + var d = new Date(); + if (param.format) { + res.write(d.format(param.format)); + } else if (param.as == "timestamp") { + res.write(d.getTime()); + } else { + res.write(d); + } + return; +} + + +/** + * renders a global skin + */ +function skin_macro(param) { + if (param.name) { + renderSkin(param.name); + } + return; +} diff --git a/core/HopObject.js b/core/HopObject.js new file mode 100644 index 00000000..f97853eb --- /dev/null +++ b/core/HopObject.js @@ -0,0 +1,125 @@ +/* + * Helma License Notice + * + * The contents of this file are subject to the Helma License + * Version 2.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://adele.helma.org/download/helma/license.txt + * + * Copyright 1998-2005 Helma Software. All Rights Reserved. + * + * $RCSfile: Date.js,v $ + * $Author: czv $ + * $Revision: 1.2 $ + * $Date: 2006/04/24 07:02:17 $ + */ + + +app.addRepository("modules/core/Number.js"); +app.addRepository("modules/core/String.js"); + + +/** + * macro returns the id of a HopObject + */ +HopObject.prototype.id_macro = function(param) { + res.write(this._id); + return; +}; + + +/** + * macro returns the url for any hopobject + */ +HopObject.prototype.href_macro = function(param) { + res.write(this.href(param.action || String.NULLSTR)); + return; +}; + + +/** + * macro rendering a skin or displaying + * its source (param.as == "source") + */ +HopObject.prototype.skin_macro = function(param) { + if (param.name) { + if (param.as == "source") { + var str = app.skinfiles[this._prototype][param.name]; + if (str && param.unwrap == "true") { + str = str.unwrap(); + } + } else { + var str = this.renderSkinAsString(param.name, param); + } + res.write(str); + } + return; +}; + + +/** + * this macro renders a text depending on + * the value of a given property + */ +HopObject.prototype.switch_macro = function(param) { + if (param.name) { + res.write(this[param.name] ? param.on : param.off); + } + return; +}; + + +/** + * generic macro that loops over the childobjects + * and renders a specified skin for each of them + * @param Object providing the following properties: + * skin: the skin to render for each item (required) + * collection: the collection containing the items + * limit: max. number of items per page + * (req.data.page determines the page number) + * sort: property name to use for sorting + * order: sort order (either "asc" or "desc") + */ +HopObject.prototype.loop_macro = function(param) { + if (!param.skin) { + return; + } + var items = param.collection ? this[param.collection] : this; + if (!items || !items.size || items.size() < 1) { + return; + } + // set default values + var min = 0, max = items.size(); + var pagesize = max; + if (param.limit) { + var n = parseInt(param.limit, 10); + if (!isNaN(n)) { + pagesize = n; + } + var pagenr = parseInt(req.data.page, 10); + if (isNaN(pagenr)) { + pagenr = 0; + } + min = Math.min(max, pagenr * pagesize); + max = Math.min(max, min + pagesize); + } + if (param.sort) { + var allitems = items.list(); + var test = allitems[0][param.sort]; + if (!test || isNaN(test)) { + var Sorter = String.Sorter; + } else { + var Sorter = Number.Sorter; + } + allitems.sort(new Sorter(param.sort, Sorter[param.order.toUpperCase()])); + var itemlist = allitems.slice(min, max); + } else { + var itemlist = items.list(min, max); + } + var skinParam = {}; + for (var i=0; i str2) return order * 1; if (str1 < str2) @@ -83,7 +84,7 @@ String.random = function(len, mode) { var x = Math.random() * Math.pow(10,len); return Math.floor(x); } - var keystr = ""; + var keystr = String.NULL; for (var i=0; i/g, replacement); diff --git a/core/all.js b/core/all.js index 714e8911..8f107375 100644 --- a/core/all.js +++ b/core/all.js @@ -10,8 +10,8 @@ * * $RCSfile: all.js,v $ * $Author: czv $ - * $Revision: 1.3 $ - * $Date: 2006/04/24 08:27:00 $ + * $Revision: 1.4 $ + * $Date: 2006/05/30 18:34:31 $ */ // convenience SingleFileRepository to load all the @@ -22,3 +22,5 @@ app.addRepository('modules/core/Date.js'); app.addRepository('modules/core/Number.js'); app.addRepository('modules/core/Object.js'); app.addRepository('modules/core/String.js'); +app.addRepository('modules/core/HopObject.js'); +app.addRepository('modules/core/Global.js');