antville/code/HopObject/objectFunctions.js

116 lines
3.1 KiB
JavaScript
Raw Normal View History

/**
* Return a name for the object to be used in the
* global linkedpath macro. Not the cleanest way to do
* this (lots of heuristics) but a simple one.
*
*/
function getNavigationName () {
var proto = this.__prototype__;
if (proto == "weblog")
return "Home";
else if (proto == "topicmgr")
return "Topics";
else if (proto == "story" || proto == "comment")
if (this.title)
return this.title;
else
return proto;
else if (this.groupname)
return this.groupname;
return this._name;
}
2001-06-18 08:57:33 +00:00
/**
* renders single dropdown
* input values: current Timestamp
*/
function createDDparam(prefix,ts,dropFormat) {
var ddParam = new HopObject();
if (dropFormat == "dd") {
ddParam.name = prefix + "Date";
2001-10-20 11:29:37 +00:00
ddParam.firstOption = "DD";
2001-06-18 08:57:33 +00:00
ddParam.currValue = ts ? ts.getDate() : null;
ddParam.start = 1;
ddParam.end = 31;
} else if (dropFormat == "MM") {
ddParam.name = prefix + "Month";
2001-10-20 11:29:37 +00:00
ddParam.firstOption = "MM";
2001-06-18 08:57:33 +00:00
ddParam.currValue = ts ? ts.getMonth() : null;
ddParam.start = 1;
ddParam.end = 12;
ddParam.valueOffset = -1;
} else if (dropFormat == "yyyy") {
ddParam.name = prefix + "Year";
2001-10-20 11:29:37 +00:00
ddParam.firstOption = "YYYY";
2001-06-18 08:57:33 +00:00
ddParam.currValue = ts ? ts.getFullYear() : null;
ddParam.start = 2000;
ddParam.end = 2010;
} else if (dropFormat == "HH") {
ddParam.name = prefix + "Hours";
2001-10-20 11:29:37 +00:00
ddParam.firstOption = "HH";
2001-06-18 08:57:33 +00:00
ddParam.currValue = ts ? ts.getHours() : null;
ddParam.start = 0;
ddParam.end = 23;
} else if (dropFormat == "mm") {
ddParam.name = prefix + "Minutes";
2001-10-20 11:29:37 +00:00
ddParam.firstOption = "mm";
2001-06-18 08:57:33 +00:00
ddParam.currValue = ts ? ts.getMinutes() : null;
ddParam.start = 0;
ddParam.end = 59;
} else if (dropFormat == "ss") {
ddParam.name = prefix + "Seconds";
2001-10-20 11:29:37 +00:00
ddParam.firstOption = "ss";
2001-06-18 08:57:33 +00:00
ddParam.currValue = ts ? ts.getSeconds() : null;
ddParam.start = 0;
ddParam.end = 59;
}
this.createDDOptions(ddParam);
return;
}
/**
* function creates array for rendering options
*/
function createDDOptions(ddParam) {
if (ddParam.firstOption) {
ddParam.add(this.createDDOption(ddParam.firstOption,""));
2001-06-18 08:57:33 +00:00
}
for (var i=ddParam.start;i<=ddParam.end;i++) {
var name = (i<10 ? "0" + i : i);
var value = (ddParam.valueOffset ? i+ddParam.valueOffset : i);
var sel = (ddParam.currValue == value ? true : false);
ddParam.add(this.createDDOption(name, value, sel));
2001-06-18 08:57:33 +00:00
}
this.chooser(ddParam);
}
/**
* function creates a single option-object for creation of select-dropdowns
*/
function createDDOption(name,value,sel) {
var opt = new HopObject()
opt.name = name;
opt.value = value;
opt.selected = sel;
return (opt);
}
2001-06-18 08:57:33 +00:00
/**
* creates parameter-object that will be passed to
* function that renders the input
*/
function createInputParam(propName,param) {
2001-09-05 21:25:47 +00:00
var inputParam = new Object();
2001-06-18 08:57:33 +00:00
inputParam.name = propName;
for (var i in param)
inputParam[i] = param[i];
inputParam.value = this[propName];
return (inputParam);
}