owntone-server/admin-root/config.js

73 lines
2.2 KiB
JavaScript
Raw Normal View History

Event.observe(window,'load',function (e) {Config.init();});
// 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();
}
var Config = {
init: function () {
new Ajax.Request('/xml-rpc?method=stats',{method: 'get',onComplete: Config.updateStatus});
new Ajax.Request('/xml-rpc?method=config',{method: 'get',onComplete: Config.showConfig});
},
showConfig: function (request) {
$A(request.responseXML.getElementsByTagName('general')[0].childNodes).each(function (el) {
$(el.nodeName).value = Element.textContent(el);
});
},
updateStatus: function (request) {
$('config_path').appendChild(document.createTextNode(
Element.textContent(request.responseXML.getElementsByTagName('config_path')[0])));
}
}
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;
}