mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-26 07:05:57 -05:00
Made the Cancel work
This commit is contained in:
parent
62811717f7
commit
5d222cfc91
@ -69,10 +69,10 @@ var ConfigXML = {
|
|||||||
var ConfigInitialValues = {
|
var ConfigInitialValues = {
|
||||||
values: {},
|
values: {},
|
||||||
getValues: function () {
|
getValues: function () {
|
||||||
return $H(this.values);
|
return $H(ConfigInitialValues.values);
|
||||||
},
|
},
|
||||||
getValue: function (section,id) {
|
getValue: function (section,id) {
|
||||||
return this.values[section+':'+id];
|
return ConfigInitialValues.values[section+':'+id];
|
||||||
},
|
},
|
||||||
parseXML: function (xmldoc) {
|
parseXML: function (xmldoc) {
|
||||||
// IE and w3c treat xmldoc differently make shore firstChild is firstchild of <config>
|
// IE and w3c treat xmldoc differently make shore firstChild is firstchild of <config>
|
||||||
@ -175,6 +175,7 @@ var Config = {
|
|||||||
if (!values || values.length == 0) {
|
if (!values || values.length == 0) {
|
||||||
values = [''];
|
values = [''];
|
||||||
}
|
}
|
||||||
|
var parentSpan = Builder.node('span');
|
||||||
values.each(function (val,i) {
|
values.each(function (val,i) {
|
||||||
var span = document.createElement('span');
|
var span = document.createElement('span');
|
||||||
span.appendChild(BuildElement.input(postId+i,postId,
|
span.appendChild(BuildElement.input(postId+i,postId,
|
||||||
@ -193,8 +194,11 @@ var Config = {
|
|||||||
Event.observe(href,'click',Config._removeItemEvent);
|
Event.observe(href,'click',Config._removeItemEvent);
|
||||||
span.appendChild(href);
|
span.appendChild(href);
|
||||||
span.appendChild(Builder.node('br'));
|
span.appendChild(Builder.node('br'));
|
||||||
frag.appendChild(span);
|
parentSpan.appendChild(span);
|
||||||
});
|
});
|
||||||
|
// This is used by cancelForm to find out how
|
||||||
|
// many options a multiple group has
|
||||||
|
frag.appendChild(parentSpan);
|
||||||
href = Builder.node('a',{href:'javascript://',className:'addItemHref'},item.add_item_label);
|
href = Builder.node('a',{href:'javascript://',className:'addItemHref'},item.add_item_label);
|
||||||
frag.appendChild(href);
|
frag.appendChild(href);
|
||||||
Event.observe(href,'click',Config._addItemEvent);
|
Event.observe(href,'click',Config._addItemEvent);
|
||||||
@ -226,10 +230,7 @@ var Config = {
|
|||||||
return frag;
|
return frag;
|
||||||
},
|
},
|
||||||
_addItemEvent: function (e) {
|
_addItemEvent: function (e) {
|
||||||
var span = Event.element(e);
|
var span = Event.element(e).previousSibling.lastChild;
|
||||||
while (span.nodeName.toLowerCase() != 'span') {
|
|
||||||
span = span.previousSibling;
|
|
||||||
}
|
|
||||||
Config._addItem(span);
|
Config._addItem(span);
|
||||||
},
|
},
|
||||||
_addItem: function(span) {
|
_addItem: function(span) {
|
||||||
@ -263,8 +264,7 @@ var Config = {
|
|||||||
Config._removeItem(span);
|
Config._removeItem(span);
|
||||||
},
|
},
|
||||||
_removeItem: function(span) {
|
_removeItem: function(span) {
|
||||||
if ((span.previousSibling && span.previousSibling.nodeName.toLowerCase() == 'span')||
|
if (span.parentNode.childNodes.length > 1) {
|
||||||
(span.nextSibling.nodeName.toLowerCase() == 'span')) {
|
|
||||||
Element.remove(span);
|
Element.remove(span);
|
||||||
} else {
|
} else {
|
||||||
span.getElementsByTagName('input')[0].value='';
|
span.getElementsByTagName('input')[0].value='';
|
||||||
@ -351,24 +351,42 @@ function saveForm() {
|
|||||||
postVars.push(item.key + '=' + item.value.join(','));
|
postVars.push(item.key + '=' + item.value.join(','));
|
||||||
});
|
});
|
||||||
new Ajax.Request('/xml-rpc?method=updateconfig',
|
new Ajax.Request('/xml-rpc?method=updateconfig',
|
||||||
{method: 'post',
|
{method: 'post',
|
||||||
parameters: postVars.join('&'),
|
parameters: postVars.join('&'),
|
||||||
onComplete: saved
|
onComplete: saved});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
function cancelForm() {
|
function cancelForm() {
|
||||||
alert("Cancel doesn't work, reload the page to revert your changes");
|
|
||||||
return;
|
|
||||||
ConfigXML.getSections().each(function (section){
|
ConfigXML.getSections().each(function (section){
|
||||||
ConfigXML.getItems(section).each(function (itemId) {
|
ConfigXML.getItems(section).each(function (itemId) {
|
||||||
var item = ConfigXML.getOption(section,itemId);
|
var item = ConfigXML.getOption(section,itemId);
|
||||||
var itemConfigId = item.config_section + ':' + item.id;
|
var itemConfigId = item.config_section + ':' + item.id;
|
||||||
if (item.multiple) {
|
if (item.multiple) {
|
||||||
var values = ConfigInitialValues.getValue(itemConfigId);
|
var values = ConfigInitialValues.getValue(item.config_section,itemId);
|
||||||
if (!values || values.length == 0) {
|
if (!values || values.length == 0) {
|
||||||
values = [''];
|
values = [''];
|
||||||
}
|
}
|
||||||
//###TODO do the multiple thing
|
var initialValuesCount = values.length;
|
||||||
|
var currentElements = document.getElementsByName(itemConfigId);
|
||||||
|
var i=0;
|
||||||
|
while (initialValuesCount < currentElements.length) {
|
||||||
|
i++;
|
||||||
|
if (i > 10) {
|
||||||
|
alert('Getting dizy; too many turns in this loop (silly errormessage 1');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Config._removeItem(currentElements[0].parentNode);
|
||||||
|
}
|
||||||
|
while (initialValuesCount > currentElements.length) {
|
||||||
|
i++;
|
||||||
|
if (i > 10) {
|
||||||
|
alert('An important part came off (silly errormessage 2');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Config._addItem(currentElements[currentElements.length-1].parentNode);
|
||||||
|
}
|
||||||
|
values.each(function (val,i){
|
||||||
|
currentElements[i].value = val;
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
//###TODO potential error a select without a default value
|
//###TODO potential error a select without a default value
|
||||||
$(itemConfigId).value = ConfigInitialValues.getValue(item.config_section,item.id) || item.default_value || '';
|
$(itemConfigId).value = ConfigInitialValues.getValue(item.config_section,item.id) || item.default_value || '';
|
||||||
|
Loading…
Reference in New Issue
Block a user