2006-05-17 14:42:56 -04:00
|
|
|
Event.observe(window,'load',init);
|
2006-04-12 17:01:38 -04:00
|
|
|
|
|
|
|
// Config isn't defined until after the Event.observe above
|
|
|
|
// I could have put it below Config = ... but I want all window.load events
|
|
|
|
// at the start of the file
|
|
|
|
function init() {
|
|
|
|
Config.init();
|
2006-05-17 14:42:56 -04:00
|
|
|
Event.observe($('button_save'),'click',saveForm);
|
2006-05-16 17:39:22 -04:00
|
|
|
}
|
|
|
|
var ConfigXML = {
|
|
|
|
config: [],
|
|
|
|
getOption: function (section,id) {
|
|
|
|
return this.config[section][id];
|
|
|
|
},
|
|
|
|
getSections: function () {
|
|
|
|
return $H(this.config).keys();
|
|
|
|
},
|
|
|
|
getItems: function(section) {
|
|
|
|
return $H(this.config[section]).keys();
|
|
|
|
},
|
|
|
|
parseXML: function(xmlDoc) {
|
|
|
|
$A(xmlDoc.getElementsByTagName('section')).each(function (section) {
|
|
|
|
var items = {};
|
|
|
|
var option;
|
|
|
|
$A(section.getElementsByTagName('item')).each(function (item) {
|
|
|
|
option = {config_section: item.getAttribute('config_section'),
|
|
|
|
name: Element.textContent(item.getElementsByTagName('name')[0]),
|
|
|
|
short_description: Element.textContent(item.getElementsByTagName('short_description')[0]),
|
|
|
|
type: Element.textContent(item.getElementsByTagName('type')[0])};
|
|
|
|
if ('select' == option.type) {
|
|
|
|
var options = [];
|
|
|
|
$A(item.getElementsByTagName('option')).each(function (option) {
|
|
|
|
options.push({value: option.getAttribute('value'),
|
|
|
|
label: Element.textContent(option)});
|
|
|
|
});
|
|
|
|
option.options = options;
|
|
|
|
option.default_value = Element.textContent(item.getElementsByTagName('default_value')[0]);
|
|
|
|
}
|
|
|
|
if (('short_text_multiple' == option.type) ||
|
|
|
|
('long_text_multiple' == option.type)) {
|
|
|
|
option.add_item_text = Element.textContent(item.getElementsByTagName('add_item_text')[0]);
|
|
|
|
}
|
|
|
|
items[item.getAttribute('id')] = option;
|
|
|
|
});
|
|
|
|
ConfigXML.config[section.getAttribute('name')] = items;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2006-04-12 17:01:38 -04:00
|
|
|
var Config = {
|
2006-05-10 13:37:29 -04:00
|
|
|
configPath: '',
|
|
|
|
configOptionValues: '',
|
2006-04-12 17:01:38 -04:00
|
|
|
init: function () {
|
2006-05-10 13:37:29 -04:00
|
|
|
new Ajax.Request('/config.xml',{method: 'get',onComplete: Config.storeConfigLayout});
|
|
|
|
},
|
|
|
|
storeConfigLayout: function (request) {
|
|
|
|
Config.layout = request.responseXML;
|
2006-05-16 17:39:22 -04:00
|
|
|
ConfigXML.parseXML(request.responseXML);
|
2006-04-12 17:01:38 -04:00
|
|
|
new Ajax.Request('/xml-rpc?method=stats',{method: 'get',onComplete: Config.updateStatus});
|
2006-05-10 13:37:29 -04:00
|
|
|
},
|
|
|
|
updateStatus: function (request) {
|
|
|
|
Config.configPath = Element.textContent(request.responseXML.getElementsByTagName('config_path')[0]);
|
|
|
|
// $('config_path').appendChild(document.createTextNode(
|
|
|
|
|
|
|
|
// );
|
|
|
|
new Ajax.Request('/xml-rpc?method=config',{method: 'get',onComplete: Config.showConfig});
|
2006-04-12 17:01:38 -04:00
|
|
|
},
|
|
|
|
showConfig: function (request) {
|
2006-05-10 13:37:29 -04:00
|
|
|
Config.configOptionValues = request.responseXML;
|
2006-05-16 17:39:22 -04:00
|
|
|
var sections = ConfigXML.getSections();
|
2006-05-10 13:37:29 -04:00
|
|
|
sections.each(function (section) {
|
|
|
|
var head = document.createElement('div');
|
|
|
|
head.className= 'naviheader';
|
2006-05-16 17:39:22 -04:00
|
|
|
head.appendChild(document.createTextNode(section));
|
2006-05-10 13:37:29 -04:00
|
|
|
var body = document.createElement('div');
|
|
|
|
body.className = 'navibox';
|
2006-05-16 17:39:22 -04:00
|
|
|
if ('Server' == section) {
|
2006-05-10 13:37:29 -04:00
|
|
|
body.appendChild(Builder.node('span',{id:'config_path'},'Config File'));
|
|
|
|
body.appendChild(document.createTextNode(Config.configPath));
|
|
|
|
body.appendChild(Builder.node('br'));
|
|
|
|
body.appendChild(Builder.node('div',{style: 'clear: both;'}));
|
|
|
|
}
|
2006-05-16 17:39:22 -04:00
|
|
|
ConfigXML.getItems(section).each(function (itemId) {
|
|
|
|
body.appendChild(Config._buildItem(section,itemId));
|
2006-05-10 13:37:29 -04:00
|
|
|
});
|
|
|
|
$('theform').appendChild(head);
|
|
|
|
$('theform').appendChild(body);
|
2006-04-12 17:01:38 -04:00
|
|
|
});
|
|
|
|
},
|
2006-05-10 16:14:11 -04:00
|
|
|
_getConfigOptionValue: function(id,multiple) {
|
|
|
|
if (multiple) {
|
|
|
|
var ret = [];
|
|
|
|
var option = Config.configOptionValues.getElementsByTagName(id);
|
|
|
|
if (option.length > 0) {
|
|
|
|
$A(option[0].getElementsByTagName('item')).each(function (item) {
|
|
|
|
ret.push(Element.textContent(item));
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
ret.push('');
|
|
|
|
}
|
|
|
|
return ret;
|
2006-05-10 13:37:29 -04:00
|
|
|
} else {
|
2006-05-10 16:14:11 -04:00
|
|
|
var value = Config.configOptionValues.getElementsByTagName(id);
|
|
|
|
if (value.length > 0) {
|
|
|
|
return Element.textContent(value[0]);
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
2006-05-10 13:37:29 -04:00
|
|
|
}
|
|
|
|
},
|
2006-05-16 17:39:22 -04:00
|
|
|
_buildItem: function(section,itemId) {
|
2006-05-16 19:12:40 -04:00
|
|
|
var frag = document.createDocumentFragment();
|
2006-05-12 07:01:54 -04:00
|
|
|
var href;
|
|
|
|
var span;
|
2006-05-16 17:39:22 -04:00
|
|
|
var item = ConfigXML.getOption(section,itemId);
|
|
|
|
var postId = item.config_section + ':' + itemId;
|
2006-05-16 19:12:40 -04:00
|
|
|
var inputSize = 80;
|
|
|
|
var noBrowse = false;
|
2006-05-16 17:39:22 -04:00
|
|
|
switch(item.type) {
|
2006-05-10 13:37:29 -04:00
|
|
|
case 'short_text':
|
2006-05-16 19:12:40 -04:00
|
|
|
inputSize = 20;
|
|
|
|
// Yes, we're falling through
|
2006-05-10 13:37:29 -04:00
|
|
|
case 'long_text':
|
2006-05-17 10:28:39 -04:00
|
|
|
frag.appendChild(BuildElement.input(postId,postId,
|
2006-05-16 17:39:22 -04:00
|
|
|
item.name,
|
2006-05-16 19:12:40 -04:00
|
|
|
Config._getConfigOptionValue(itemId),
|
|
|
|
inputSize,
|
2006-05-16 17:39:22 -04:00
|
|
|
item.short_description,
|
2006-05-16 19:12:40 -04:00
|
|
|
''));
|
|
|
|
frag.appendChild(Builder.node('br'));
|
2006-05-10 16:14:11 -04:00
|
|
|
break;
|
|
|
|
case 'short_text_multiple':
|
2006-05-16 19:12:40 -04:00
|
|
|
inputSize = 20;
|
|
|
|
noBrowse = true;
|
|
|
|
// Yes, we're falling through
|
2006-05-10 16:14:11 -04:00
|
|
|
case 'long_text_multiple':
|
|
|
|
Config._getConfigOptionValue(itemId,true).each(function (value,i) {
|
2006-05-12 07:01:54 -04:00
|
|
|
var span = document.createElement('span');
|
2006-05-17 10:28:39 -04:00
|
|
|
span.appendChild(BuildElement.input(postId+i,postId,
|
2006-05-16 17:39:22 -04:00
|
|
|
item.name,
|
2006-05-16 19:12:40 -04:00
|
|
|
value,inputSize,
|
2006-05-16 17:39:22 -04:00
|
|
|
item.short_description
|
2006-05-10 16:14:11 -04:00
|
|
|
));
|
2006-05-16 19:12:40 -04:00
|
|
|
if (!noBrowse) {
|
|
|
|
href = Builder.node('a',{href: 'javascript://'},'Browse');
|
|
|
|
Event.observe(href,'click',Config._browse);
|
|
|
|
span.appendChild(href);
|
|
|
|
}
|
|
|
|
span.appendChild(document.createTextNode('\u00a0\u00a0'));
|
|
|
|
href = Builder.node('a',{href: 'javascript://'},'Remove');
|
|
|
|
Event.observe(href,'click',Config._removeItem);
|
|
|
|
span.appendChild(href);
|
|
|
|
span.appendChild(Builder.node('br'));
|
|
|
|
frag.appendChild(span);
|
2006-05-10 16:14:11 -04:00
|
|
|
});
|
2006-05-12 07:01:54 -04:00
|
|
|
href = Builder.node('a',{href:'javascript://',className:'addItemHref'},
|
2006-05-16 17:39:22 -04:00
|
|
|
item.add_item_text);
|
2006-05-16 19:12:40 -04:00
|
|
|
frag.appendChild(href);
|
2006-05-12 07:01:54 -04:00
|
|
|
Event.observe(href,'click',Config._addItem);
|
2006-05-16 19:12:40 -04:00
|
|
|
frag.appendChild(Builder.node('div',{style:'clear: both'}));
|
2006-05-10 16:14:11 -04:00
|
|
|
break;
|
2006-05-10 13:37:29 -04:00
|
|
|
case 'select':
|
2006-05-12 06:02:59 -04:00
|
|
|
var value = Config._getConfigOptionValue(itemId);
|
|
|
|
if (!value) {
|
2006-05-16 17:39:22 -04:00
|
|
|
value = item.default_value;
|
2006-05-12 06:02:59 -04:00
|
|
|
}
|
2006-05-16 19:12:40 -04:00
|
|
|
frag.appendChild(BuildElement.select(postId,
|
2006-05-16 17:39:22 -04:00
|
|
|
item.name,
|
|
|
|
item.options,
|
2006-05-12 06:02:59 -04:00
|
|
|
value,
|
2006-05-16 19:12:40 -04:00
|
|
|
item.short_description));
|
|
|
|
frag.appendChild(Builder.node('br'));
|
2006-05-10 13:37:29 -04:00
|
|
|
break;
|
|
|
|
}
|
2006-05-16 19:12:40 -04:00
|
|
|
return frag;
|
2006-05-12 07:01:54 -04:00
|
|
|
},
|
|
|
|
_addItem: function(e) {
|
|
|
|
var span = Event.element(e);
|
|
|
|
while (span.nodeName.toLowerCase() != 'span') {
|
|
|
|
span = span.previousSibling;
|
|
|
|
}
|
|
|
|
var frag = document.createDocumentFragment();
|
|
|
|
span = span.cloneNode(true);
|
|
|
|
span.getElementsByTagName('label')[0].setAttribute('for','hej');
|
|
|
|
span.getElementsByTagName('input')[0].id = 'hej';
|
|
|
|
span.getElementsByTagName('input')[0].value = '';
|
2006-05-16 19:12:40 -04:00
|
|
|
var hrefs = span.getElementsByTagName('a');
|
|
|
|
if ('Netscape' == navigator.appName) {
|
|
|
|
// Firefox et al doesn't copy registered events on an element deep clone
|
|
|
|
// Don't know if that is w3c or if IE has it right
|
2006-05-16 19:31:11 -04:00
|
|
|
if (hrefs.length == 1) {
|
2006-05-16 19:12:40 -04:00
|
|
|
Event.observe(hrefs[0],'click',Config._removeItem);
|
|
|
|
} else {
|
|
|
|
Event.observe(hrefs[0],'click',Config._browse);
|
|
|
|
Event.observe(hrefs[1],'click',Config._removeItem);
|
|
|
|
}
|
|
|
|
}
|
2006-05-12 07:01:54 -04:00
|
|
|
var src = Event.element(e);
|
|
|
|
src.parentNode.insertBefore(span,src);
|
2006-05-16 19:12:40 -04:00
|
|
|
},
|
|
|
|
_removeItem: function(e) {
|
|
|
|
var span = Event.element(e);
|
|
|
|
while (span.nodeName.toLowerCase() != 'span') {
|
|
|
|
span = span.parentNode;
|
|
|
|
}
|
|
|
|
if ((span.previousSibling && span.previousSibling.nodeName.toLowerCase() == 'span')||
|
|
|
|
(span.nextSibling.nodeName.toLowerCase() == 'span')) {
|
|
|
|
Element.remove(span);
|
|
|
|
} else {
|
|
|
|
span.getElementsByTagName('input')[0].value='';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_browse: function(e) {
|
|
|
|
alert('Browse directories');
|
2006-05-10 13:37:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
var BuildElement = {
|
2006-05-17 10:28:39 -04:00
|
|
|
input: function(id,name,displayName,value,size,short_description,long_description) {
|
2006-05-10 13:37:29 -04:00
|
|
|
|
|
|
|
var frag = document.createDocumentFragment();
|
|
|
|
var label = document.createElement('label');
|
|
|
|
|
|
|
|
label.setAttribute('for',id);
|
|
|
|
label.appendChild(document.createTextNode(displayName));
|
|
|
|
frag.appendChild(label);
|
|
|
|
|
2006-05-17 10:28:39 -04:00
|
|
|
frag.appendChild(Builder.node('input',{id: id,name: name,className: 'text',
|
2006-05-10 13:37:29 -04:00
|
|
|
value: value,size: size}));
|
|
|
|
frag.appendChild(document.createTextNode('\u00a0'));
|
|
|
|
frag.appendChild(document.createTextNode(short_description));
|
2006-05-12 06:02:59 -04:00
|
|
|
|
2006-05-10 13:37:29 -04:00
|
|
|
return frag;
|
|
|
|
},
|
|
|
|
select: function(id,displayName,options,value,short_description,long_description) {
|
|
|
|
var frag = document.createDocumentFragment();
|
|
|
|
var label = document.createElement('label');
|
|
|
|
label.setAttribute('for',id);
|
|
|
|
label.appendChild(document.createTextNode(displayName));
|
|
|
|
frag.appendChild(label);
|
|
|
|
|
2006-05-16 17:39:22 -04:00
|
|
|
var select = Builder.node('select',{id: id,name: id,size: 1});
|
2006-05-10 13:37:29 -04:00
|
|
|
$A(options).each(function (option) {
|
2006-05-16 17:39:22 -04:00
|
|
|
select.appendChild(Builder.node('option',{value: option.value},
|
|
|
|
option.label));
|
2006-05-10 13:37:29 -04:00
|
|
|
});
|
2006-05-12 06:02:59 -04:00
|
|
|
select.value = value;
|
2006-05-10 13:37:29 -04:00
|
|
|
frag.appendChild(select);
|
|
|
|
frag.appendChild(document.createTextNode('\u00a0'));
|
|
|
|
frag.appendChild(document.createTextNode(short_description));
|
2006-05-12 06:02:59 -04:00
|
|
|
|
2006-05-10 13:37:29 -04:00
|
|
|
return frag;
|
2006-04-12 17:01:38 -04:00
|
|
|
}
|
2006-05-10 13:37:29 -04:00
|
|
|
|
2006-04-12 17:01:38 -04:00
|
|
|
}
|
2006-05-17 14:42:56 -04:00
|
|
|
function saved(req) {
|
|
|
|
alert(req.responseText);
|
|
|
|
}
|
|
|
|
function saveForm() {
|
|
|
|
var getString = [];
|
|
|
|
$A($('theform').getElementsByTagName('input')).each(function (input,i) {
|
|
|
|
if ((i > 10) && (i < 17)) {
|
|
|
|
getString.push(Form.Element.serialize(input.id));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
getString = getString.join('&');
|
|
|
|
new Ajax.Request('/xml-rpc?method=updateconfig&'+getString,{method: 'get',
|
|
|
|
onComplete: saved
|
|
|
|
});
|
|
|
|
}
|
2006-04-12 17:01:38 -04:00
|
|
|
Object.extend(Element, {
|
|
|
|
removeChildren: function(element) {
|
|
|
|
while(element.hasChildNodes()) {
|
|
|
|
element.removeChild(element.firstChild);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
textContent: function(node) {
|
|
|
|
if ((!node) || !node.hasChildNodes()) {
|
|
|
|
// Empty text node
|
|
|
|
return '';
|
|
|
|
} else {
|
|
|
|
if (node.textContent) {
|
|
|
|
// W3C ?
|
|
|
|
return node.textContent;
|
|
|
|
} else if (node.text) {
|
|
|
|
// IE
|
|
|
|
return node.text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// We shouldn't end up here;
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
/* Detta script finns att hamta pa http://www.jojoxx.net och
|
|
|
|
far anvandas fritt sa lange som dessa rader star kvar. */
|
|
|
|
function DataDumper(obj,n,prefix){
|
|
|
|
var str=""; prefix=(prefix)?prefix:""; n=(n)?n+1:1; var ind=""; for(var i=0;i<n;i++){ ind+=" "; }
|
|
|
|
if(typeof(obj)=="string"){
|
|
|
|
str+=ind+prefix+"String:\""+obj+"\"\n";
|
|
|
|
} else if(typeof(obj)=="number"){
|
|
|
|
str+=ind+prefix+"Number:"+obj+"\n";
|
|
|
|
} else if(typeof(obj)=="function"){
|
|
|
|
str+=ind+prefix+"Function:"+obj+"\n";
|
|
|
|
} else if(typeof(obj) == 'boolean') {
|
|
|
|
str+=ind+prefix+"Boolean:" + obj + "\n";
|
|
|
|
} else {
|
|
|
|
var type="Array";
|
|
|
|
for(var i in obj){ type=(type=="Array"&&i==parseInt(i))?"Array":"Object"; }
|
|
|
|
str+=ind+prefix+type+"[\n";
|
|
|
|
if(type=="Array"){
|
|
|
|
for(var i in obj){ str+=DataDumper(obj[i],n,i+"=>"); }
|
|
|
|
} else {
|
|
|
|
for(var i in obj){ str+=DataDumper(obj[i],n,i+"=>"); }
|
|
|
|
}
|
|
|
|
str+=ind+"]\n";
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|