Whohoho!!! This is the first commit where you actually can

save the changes made on config.html.
The result of the save is displayed as an ugly alert with
the xml response, but it works!
This commit is contained in:
Anders Betnér 2006-05-21 19:46:22 +00:00
parent 5d611fe52a
commit 1804fdf595
2 changed files with 29 additions and 18 deletions

View File

@ -17,16 +17,10 @@ function init() {
Config.init(); Config.init();
} }
var ConfigXML = { var ConfigXML = {
config: [], config: {},
configIndex: {},
getOptionFromElementName: function (name) { getOptionFromElementName: function (name) {
var id = name.replace(/.*:/,''); return this.configIndex[name];
return Try.these(
function () {ConfigXml.config['Server'][id];},
function () {ConfigXml.config['Music_Files'][id];},
function () {ConfigXml.config['Database'][id];},
function () {ConfigXml.config['Plugins'][id];},
function () {ConfigXml.config['Transcoding'][id];}
);
}, },
getOption: function (section,id) { getOption: function (section,id) {
return this.config[section][id]; return this.config[section][id];
@ -67,7 +61,10 @@ var ConfigXML = {
}); });
} }
}); });
// Double index everything one as [section][id]
// and one as [config_section:id]
items[item.getAttribute('id')] = returnItem; items[item.getAttribute('id')] = returnItem;
ConfigXML.configIndex[returnItem.config_section+ ':' +returnItem.id] = returnItem;
}); });
ConfigXML.config[section.getAttribute('name')] = items; ConfigXML.config[section.getAttribute('name')] = items;
}); });
@ -334,15 +331,29 @@ function saved(req) {
alert(req.responseText); alert(req.responseText);
} }
function saveForm() { function saveForm() {
var getString = []; var postVars = [];
$A($('theform').getElementsByTagName('input')).each(function (input,i) { var multiple = {};
if (input.value != '') { $A($('theform').getElementsByTagName('select')).each(function (select) {
getString.push(Form.Element.serialize(input.id)); postVars.push(Form.Element.serialize(select.id));
}
}); });
getString = getString.join('&'); $A($('theform').getElementsByTagName('input')).each(function (input) {
new Ajax.Request('/xml-rpc?method=updateconfig&'+getString,{method: 'get', if (ConfigXML.getOptionFromElementName(input.name).multiple) {
onComplete: saved if (multiple[input.name]) {
multiple[input.name].push(encodeURIComponent(input.value));
} else {
multiple[input.name] = [input.value];
}
} else {
postVars.push(Form.Element.serialize(input.id));
};
});
$H(multiple).each(function (item) {
postVars.push(item.key + '=' + item.value.join(','));
});
new Ajax.Request('/xml-rpc?method=updateconfig',
{method: 'post',
parameters: postVars.join('&'),
onComplete: saved
}); });
} }
function cancelForm() { function cancelForm() {

View File

@ -60,7 +60,7 @@
<option value="1">Yes</option> <option value="1">Yes</option>
</options> </options>
</item> </item>
<item id="debug" config_section="general"> <item id="debuglevel" config_section="general">
<name>Debug Level</name> <name>Debug Level</name>
<short_description> <short_description>
Possible values are 0 to 9, 9 being the most detailed debug level. Possible values are 0 to 9, 9 being the most detailed debug level.