antville/code/HopObject/objectFunctions.js
2001-12-04 13:16:33 +00:00

115 lines
3.1 KiB
JavaScript

/**
* 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;
}
/**
* renders single dropdown
* input values: current Timestamp
*/
function createDDparam(prefix,ts,dropFormat) {
var ddParam = new HopObject();
if (dropFormat == "dd") {
ddParam.name = prefix + "Date";
ddParam.firstOption = "DD";
ddParam.currValue = ts ? ts.getDate() : null;
ddParam.start = 1;
ddParam.end = 31;
} else if (dropFormat == "MM") {
ddParam.name = prefix + "Month";
ddParam.firstOption = "MM";
ddParam.currValue = ts ? ts.getMonth() : null;
ddParam.start = 1;
ddParam.end = 12;
ddParam.valueOffset = -1;
} else if (dropFormat == "yyyy") {
ddParam.name = prefix + "Year";
ddParam.firstOption = "YYYY";
ddParam.currValue = ts ? ts.getFullYear() : null;
ddParam.start = 2000;
ddParam.end = 2010;
} else if (dropFormat == "HH") {
ddParam.name = prefix + "Hours";
ddParam.firstOption = "HH";
ddParam.currValue = ts ? ts.getHours() : null;
ddParam.start = 0;
ddParam.end = 23;
} else if (dropFormat == "mm") {
ddParam.name = prefix + "Minutes";
ddParam.firstOption = "mm";
ddParam.currValue = ts ? ts.getMinutes() : null;
ddParam.start = 0;
ddParam.end = 59;
} else if (dropFormat == "ss") {
ddParam.name = prefix + "Seconds";
ddParam.firstOption = "ss";
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,""));
}
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));
}
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);
}
/**
* creates parameter-object that will be passed to
* function that renders the input
*/
function createInputParam(propName,param) {
var inputParam = new Object();
inputParam.name = propName;
for (var i in param)
inputParam[i] = param[i];
inputParam.value = this[propName];
return (inputParam);
}