2006-05-17 14:42:56 -04:00
|
|
|
Event.observe(window,'load',init);
|
2006-05-18 14:48:53 -04:00
|
|
|
//###TODO
|
2006-05-21 11:01:05 -04:00
|
|
|
// * Disable/enable save/cancel, Add key and onchange listeners keep a note on changed items
|
|
|
|
// * create the path/file browser
|
2006-05-24 17:47:32 -04:00
|
|
|
// * better errormessage for non writable config
|
2006-05-21 11:01:05 -04:00
|
|
|
// * make tabs?
|
|
|
|
// * add warning if leaving page without saving
|
2006-05-18 14:48:53 -04:00
|
|
|
|
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
|
2006-05-31 16:10:21 -04:00
|
|
|
var DEBUG = window.location.toString().match(/debug.*/);
|
|
|
|
if ('debug=validate' == DEBUG) {
|
|
|
|
DEBUG = 'validate';
|
|
|
|
}
|
2006-04-12 17:01:38 -04:00
|
|
|
function init() {
|
|
|
|
Config.init();
|
2006-05-16 17:39:22 -04:00
|
|
|
}
|
|
|
|
var ConfigXML = {
|
2006-05-21 15:46:22 -04:00
|
|
|
config: {},
|
2006-06-04 14:03:10 -04:00
|
|
|
getItem: function (id) {
|
|
|
|
return this.config[id];
|
2006-05-18 14:48:53 -04:00
|
|
|
},
|
2006-06-04 14:03:10 -04:00
|
|
|
getAllItems: function () {
|
|
|
|
return $H(this.config);
|
2006-05-16 17:39:22 -04:00
|
|
|
},
|
|
|
|
parseXML: function(xmlDoc) {
|
|
|
|
$A(xmlDoc.getElementsByTagName('section')).each(function (section) {
|
|
|
|
$A(section.getElementsByTagName('item')).each(function (item) {
|
2006-05-20 17:51:14 -04:00
|
|
|
var returnItem = {};
|
2006-05-21 16:55:56 -04:00
|
|
|
$A(item.attributes).each(function (attr) {
|
|
|
|
returnItem[attr.name] = attr.value;
|
|
|
|
});
|
2006-05-27 17:04:19 -04:00
|
|
|
Element.cleanWhitespace(item);
|
2006-05-20 17:51:14 -04:00
|
|
|
$A(item.childNodes).each(function (node) {
|
|
|
|
if (Element.textContent(node) == '') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ('options' == node.nodeName) {
|
|
|
|
var options = [];
|
|
|
|
$A(item.getElementsByTagName('option')).each(function (option) {
|
|
|
|
options.push({value: option.getAttribute('value'),
|
|
|
|
label: Element.textContent(option)});
|
|
|
|
});
|
|
|
|
returnItem['options'] = options;
|
|
|
|
} else {
|
|
|
|
returnItem[node.nodeName] = Element.textContent(node);
|
|
|
|
}
|
2006-05-21 16:55:56 -04:00
|
|
|
$A(node.attributes).each(function (attr) {
|
|
|
|
returnItem[attr.name] = attr.value;
|
|
|
|
});
|
2006-05-20 17:51:14 -04:00
|
|
|
});
|
2006-06-04 14:03:10 -04:00
|
|
|
ConfigXML.config[returnItem.id] = returnItem;
|
2006-05-16 17:39:22 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2006-05-18 17:47:49 -04:00
|
|
|
var ConfigInitialValues = {
|
|
|
|
values: {},
|
2006-06-04 14:03:10 -04:00
|
|
|
getValue: function (id) {
|
|
|
|
return ConfigInitialValues.values[id];
|
2006-05-20 17:51:14 -04:00
|
|
|
},
|
2006-05-18 17:47:49 -04:00
|
|
|
parseXML: function (xmldoc) {
|
|
|
|
// IE and w3c treat xmldoc differently make shore firstChild is firstchild of <config>
|
|
|
|
if (xmldoc.childNodes[1] && xmldoc.childNodes[1].nodeName == 'config') {
|
|
|
|
sections = $A(xmldoc.childNodes[1].childNodes);
|
|
|
|
} else {
|
|
|
|
sections = $A(xmldoc.firstChild.childNodes);
|
|
|
|
}
|
|
|
|
sections.each(function (section) {
|
|
|
|
var sectionName = section.nodeName;
|
|
|
|
$A(section.childNodes).each(function (node) {
|
2006-05-24 03:53:51 -04:00
|
|
|
if (node.firstChild && node.firstChild.hasChildNodes()) {
|
2006-05-18 17:47:49 -04:00
|
|
|
var values = [];
|
|
|
|
$A(node.childNodes).each(function (n) {
|
|
|
|
values.push(Element.textContent(n));
|
|
|
|
});
|
|
|
|
ConfigInitialValues.values[sectionName+':'+node.nodeName] = values;
|
|
|
|
} else {
|
|
|
|
ConfigInitialValues.values[sectionName+':'+node.nodeName] = Element.textContent(node);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2006-04-12 17:01:38 -04:00
|
|
|
var Config = {
|
2006-05-10 13:37:29 -04:00
|
|
|
configPath: '',
|
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) {
|
2006-06-04 14:03:10 -04:00
|
|
|
// Need to store this until showConfig is run
|
|
|
|
Config.tmpConfigXML = 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]);
|
2006-05-18 14:48:53 -04:00
|
|
|
Config.isWritable = Element.textContent(request.responseXML.getElementsByTagName('writable_config')[0]) == '1';
|
2006-05-10 13:37:29 -04:00
|
|
|
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-18 17:47:49 -04:00
|
|
|
ConfigInitialValues.parseXML(request.responseXML);
|
2006-06-04 14:03:10 -04:00
|
|
|
$A(Config.tmpConfigXML.getElementsByTagName('section')).each(function (section) {
|
2006-05-10 13:37:29 -04:00
|
|
|
var head = document.createElement('div');
|
|
|
|
head.className= 'naviheader';
|
2006-06-04 14:03:10 -04:00
|
|
|
var sectionName = section.getAttribute('name');
|
|
|
|
head.appendChild(document.createTextNode(sectionName));
|
2006-05-10 13:37:29 -04:00
|
|
|
var body = document.createElement('div');
|
|
|
|
body.className = 'navibox';
|
2006-06-04 14:03:10 -04:00
|
|
|
if ('Server' == sectionName) {
|
2006-05-24 17:47:32 -04:00
|
|
|
body.appendChild(Builder.node('span',{id:'config_path'},'Config File Location'));
|
2006-05-10 13:37:29 -04:00
|
|
|
body.appendChild(document.createTextNode(Config.configPath));
|
|
|
|
body.appendChild(Builder.node('br'));
|
|
|
|
body.appendChild(Builder.node('div',{style: 'clear: both;'}));
|
|
|
|
}
|
2006-06-04 14:03:10 -04:00
|
|
|
$A(section.getElementsByTagName('item')).each(function (item) {
|
|
|
|
body.appendChild(Config._buildItem(item.getAttribute('id')));
|
2006-05-10 13:37:29 -04:00
|
|
|
});
|
|
|
|
$('theform').appendChild(head);
|
|
|
|
$('theform').appendChild(body);
|
2006-05-18 14:48:53 -04:00
|
|
|
});
|
2006-06-04 14:03:10 -04:00
|
|
|
// Won't be using the config.xml XML doc anymore get rid of it
|
|
|
|
Config.tmpConfigXML = '';
|
2006-05-18 14:48:53 -04:00
|
|
|
if (!Config.isWritable) {
|
|
|
|
Effect.Appear('config_not_writable_warning');
|
|
|
|
} else {
|
|
|
|
// Create save and cancel buttons
|
2006-05-18 17:47:49 -04:00
|
|
|
// var save = Builder.node('button',{id: 'button_save', disabled: 'disabled'},'Save');
|
|
|
|
var save = Builder.node('button',{id: 'button_save'},'Save');
|
|
|
|
Event.observe(save,'click',saveForm);
|
2006-05-18 14:48:53 -04:00
|
|
|
var cancel = Builder.node('button',{id: 'button_cancel'},'Cancel');
|
2006-05-18 17:47:49 -04:00
|
|
|
Event.observe(cancel,'click',cancelForm);
|
2006-05-18 14:48:53 -04:00
|
|
|
var spacer = document.createTextNode('\u00a0\u00a0');
|
|
|
|
var buttons = $('buttons');
|
2006-05-20 13:30:48 -04:00
|
|
|
if (navigator.platform.toLowerCase().indexOf('mac') != -1) {
|
2006-05-18 14:48:53 -04:00
|
|
|
// We're on mac
|
|
|
|
buttons.appendChild(cancel);
|
|
|
|
buttons.appendChild(spacer);
|
|
|
|
buttons.appendChild(save);
|
|
|
|
} else {
|
2006-05-20 17:51:14 -04:00
|
|
|
//###TODO What about all them unix variants?
|
2006-05-18 14:48:53 -04:00
|
|
|
buttons.appendChild(save);
|
|
|
|
buttons.appendChild(spacer);
|
|
|
|
buttons.appendChild(cancel);
|
|
|
|
}
|
|
|
|
}
|
2006-05-26 17:56:04 -04:00
|
|
|
var advanced = Builder.node('a',{href: 'javascript://',id:'basic_config_button'},'Show basic config');
|
|
|
|
Event.observe(advanced,'click',Config._showBasicConfig);
|
|
|
|
var basic = Builder.node('a',{href: 'javascript://',id:'advanced_config_button'},'Show advanced config');
|
|
|
|
Event.observe(basic,'click',Config._showAdvancedConfig);
|
|
|
|
if (Cookie.getVar('show_advanced_config')) {
|
|
|
|
basic.style.display = 'none';
|
|
|
|
} else {
|
|
|
|
advanced.style.display = 'none';
|
|
|
|
}
|
|
|
|
var div = $('toggle_basic_advanced');
|
|
|
|
div.appendChild(advanced);
|
|
|
|
div.appendChild(basic);
|
2006-05-18 17:47:49 -04:00
|
|
|
},
|
2006-06-04 14:03:10 -04:00
|
|
|
_buildItem: function(itemId) {
|
2006-05-26 17:56:04 -04:00
|
|
|
var frag = document.createElement('div');
|
2006-05-12 07:01:54 -04:00
|
|
|
var href;
|
2006-06-04 14:03:10 -04:00
|
|
|
var item = ConfigXML.getItem(itemId);
|
2006-05-16 17:39:22 -04:00
|
|
|
switch(item.type) {
|
2006-05-20 17:51:14 -04:00
|
|
|
case 'text':
|
|
|
|
if (item.multiple) {
|
2006-06-04 14:03:10 -04:00
|
|
|
var values = ConfigInitialValues.getValue(itemId);
|
2006-05-24 18:02:44 -04:00
|
|
|
if (!values || values.length === 0) {
|
2006-05-21 11:01:05 -04:00
|
|
|
values = [''];
|
2006-05-20 17:51:14 -04:00
|
|
|
}
|
2006-05-26 17:56:04 -04:00
|
|
|
// var parentSpan = Builder.node('span');
|
2006-05-20 17:51:14 -04:00
|
|
|
values.each(function (val,i) {
|
2006-05-24 17:47:32 -04:00
|
|
|
var div = document.createElement('div');
|
2006-06-04 14:03:10 -04:00
|
|
|
div.appendChild(BuildElement.input(itemId+i,itemId,
|
2006-05-20 17:51:14 -04:00
|
|
|
item.name,
|
|
|
|
val || item.default_value || '',
|
|
|
|
item.size || 20,
|
|
|
|
item.short_description,
|
|
|
|
''));
|
|
|
|
if (item.browse) {
|
|
|
|
href = Builder.node('a',{href: 'javascript://'},'Browse');
|
|
|
|
Event.observe(href,'click',Config._browse);
|
2006-05-24 17:47:32 -04:00
|
|
|
div.appendChild(href);
|
2006-05-20 17:51:14 -04:00
|
|
|
}
|
2006-05-24 17:47:32 -04:00
|
|
|
div.appendChild(document.createTextNode('\u00a0\u00a0'));
|
2006-05-20 17:51:14 -04:00
|
|
|
href = Builder.node('a',{href: 'javascript://'},'Remove');
|
2006-05-20 19:25:46 -04:00
|
|
|
Event.observe(href,'click',Config._removeItemEvent);
|
2006-05-24 17:47:32 -04:00
|
|
|
div.appendChild(href);
|
|
|
|
div.appendChild(Builder.node('br'));
|
2006-05-26 17:56:04 -04:00
|
|
|
frag.appendChild(div);
|
2006-05-20 17:51:14 -04:00
|
|
|
});
|
2006-05-24 17:15:13 -04:00
|
|
|
// This is used by cancelForm to find out how
|
|
|
|
// many options a multiple group has
|
2006-05-26 17:56:04 -04:00
|
|
|
// frag.appendChild(parentSpan);
|
2006-05-20 17:51:14 -04:00
|
|
|
href = Builder.node('a',{href:'javascript://',className:'addItemHref'},item.add_item_label);
|
|
|
|
frag.appendChild(href);
|
2006-05-20 19:25:46 -04:00
|
|
|
Event.observe(href,'click',Config._addItemEvent);
|
2006-05-20 17:51:14 -04:00
|
|
|
frag.appendChild(Builder.node('div',{style:'clear: both'}));
|
|
|
|
} else {
|
2006-06-04 14:03:10 -04:00
|
|
|
frag.appendChild(BuildElement.input(itemId,itemId,
|
2006-05-20 17:51:14 -04:00
|
|
|
item.name,
|
2006-06-04 14:03:10 -04:00
|
|
|
ConfigInitialValues.getValue(itemId) || item.default_value || '',
|
2006-05-20 17:51:14 -04:00
|
|
|
item.size || 20,
|
|
|
|
item.short_description,
|
|
|
|
''));
|
|
|
|
if (item.browse) {
|
2006-05-16 19:12:40 -04:00
|
|
|
href = Builder.node('a',{href: 'javascript://'},'Browse');
|
|
|
|
Event.observe(href,'click',Config._browse);
|
2006-05-20 17:51:14 -04:00
|
|
|
frag.appendChild(href);
|
2006-05-16 19:12:40 -04:00
|
|
|
}
|
2006-05-20 17:51:14 -04:00
|
|
|
frag.appendChild(Builder.node('br'));
|
2006-05-12 06:02:59 -04:00
|
|
|
}
|
2006-05-20 17:51:14 -04:00
|
|
|
break;
|
|
|
|
case 'select':
|
2006-06-04 14:03:10 -04:00
|
|
|
frag.appendChild(BuildElement.select(itemId,
|
2006-05-16 17:39:22 -04:00
|
|
|
item.name,
|
|
|
|
item.options,
|
2006-06-04 14:03:10 -04:00
|
|
|
ConfigInitialValues.getValue(itemId) || item.default_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-24 18:02:44 -04:00
|
|
|
default:
|
|
|
|
alert('This should not happen (1)');
|
|
|
|
break;
|
2006-05-10 13:37:29 -04:00
|
|
|
}
|
2006-05-26 17:56:04 -04:00
|
|
|
if (!Cookie.getVar('show_advanced_config') && item.advanced) {
|
|
|
|
frag.style.display = 'none';
|
|
|
|
}
|
2006-05-16 19:12:40 -04:00
|
|
|
return frag;
|
2006-05-12 07:01:54 -04:00
|
|
|
},
|
2006-05-20 19:25:46 -04:00
|
|
|
_addItemEvent: function (e) {
|
2006-05-26 18:55:42 -04:00
|
|
|
var div = Event.element(e).previousSibling;
|
2006-05-24 17:47:32 -04:00
|
|
|
Config._addItem(div);
|
2006-05-20 19:25:46 -04:00
|
|
|
},
|
2006-05-24 17:47:32 -04:00
|
|
|
_addItem: function(div) {
|
|
|
|
var newSpan = div.cloneNode(true);
|
2006-05-20 19:25:46 -04:00
|
|
|
var id = newSpan.getElementsByTagName('input')[0].id;
|
2006-05-20 18:37:41 -04:00
|
|
|
var num = parseInt(id.match(/\d+$/));
|
|
|
|
num++;
|
2006-05-24 18:02:44 -04:00
|
|
|
id = id.replace(/\d+$/,'') + num;
|
2006-05-20 18:37:41 -04:00
|
|
|
|
2006-05-20 19:25:46 -04:00
|
|
|
newSpan.getElementsByTagName('label')[0].setAttribute('for',id);
|
|
|
|
newSpan.getElementsByTagName('input')[0].id = id;
|
|
|
|
newSpan.getElementsByTagName('input')[0].value = '';
|
2006-05-24 17:47:32 -04:00
|
|
|
newSpan.style.display = 'none';
|
2006-05-20 19:25:46 -04:00
|
|
|
var hrefs = newSpan.getElementsByTagName('a');
|
2006-05-16 19:12:40 -04:00
|
|
|
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-20 19:25:46 -04:00
|
|
|
Event.observe(hrefs[0],'click',Config._removeItemEvent);
|
2006-05-16 19:12:40 -04:00
|
|
|
} else {
|
|
|
|
Event.observe(hrefs[0],'click',Config._browse);
|
2006-05-20 19:25:46 -04:00
|
|
|
Event.observe(hrefs[1],'click',Config._removeItemEvent);
|
2006-05-16 19:12:40 -04:00
|
|
|
}
|
|
|
|
}
|
2006-05-24 17:47:32 -04:00
|
|
|
div.parentNode.insertBefore(newSpan,div.nextSibling);
|
|
|
|
Effect.BlindDown(newSpan,{duration: 0.2});
|
2006-05-16 19:12:40 -04:00
|
|
|
},
|
2006-05-20 19:25:46 -04:00
|
|
|
_removeItemEvent: function (e) {
|
2006-05-27 13:30:11 -04:00
|
|
|
var div = Event.element(e).parentNode;
|
2006-05-24 17:47:32 -04:00
|
|
|
Config._removeItem(div);
|
2006-05-20 19:25:46 -04:00
|
|
|
},
|
2006-05-26 16:22:21 -04:00
|
|
|
_removeItem: function(div,noAnimation) {
|
2006-05-27 13:30:11 -04:00
|
|
|
if (div.parentNode.getElementsByTagName('input').length > 1) {
|
2006-05-26 16:22:21 -04:00
|
|
|
if (noAnimation) {
|
|
|
|
// cancelForm uses a loop to delete elements, the loop can't wait
|
|
|
|
// for Effect.BlindUp to finish
|
|
|
|
Element.remove(div);
|
|
|
|
} else {
|
|
|
|
Effect.BlindUp(div,{duration: 0.2, afterFinish: function (){Element.remove(div);}});
|
|
|
|
}
|
2006-05-16 19:12:40 -04:00
|
|
|
} else {
|
2006-05-24 17:47:32 -04:00
|
|
|
div.getElementsByTagName('input')[0].value='';
|
2006-05-16 19:12:40 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
_browse: function(e) {
|
2006-05-20 17:51:14 -04:00
|
|
|
alert('Browse');
|
2006-05-26 17:56:04 -04:00
|
|
|
},
|
|
|
|
_showAdvancedConfig: function (e) {
|
|
|
|
Element.toggle('advanced_config_button');
|
|
|
|
Element.toggle('basic_config_button');
|
|
|
|
Cookie.setVar('show_advanced_config','true',30);
|
2006-06-04 14:03:10 -04:00
|
|
|
ConfigXML.getAllItems().each(function (item) {
|
2006-05-26 17:56:04 -04:00
|
|
|
if (item.value.advanced) {
|
|
|
|
var element = $(item.key);
|
|
|
|
if (!element) {
|
|
|
|
// Handle options with multiple values
|
|
|
|
$A(document.getElementsByName(item.key)).each(function (el) {
|
|
|
|
Effect.BlindDown(el.parentNode.parentNode);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Effect.BlindDown(element.parentNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
_showBasicConfig: function (e) {
|
|
|
|
Element.toggle('advanced_config_button');
|
|
|
|
Element.toggle('basic_config_button');
|
|
|
|
Cookie.removeVar('show_advanced_config');
|
2006-06-04 14:03:10 -04:00
|
|
|
ConfigXML.getAllItems().each(function (item) {
|
2006-05-26 17:56:04 -04:00
|
|
|
if (item.value.advanced) {
|
|
|
|
var element = $(item.key);
|
|
|
|
if (!element) {
|
|
|
|
// Handle options with multiple values
|
|
|
|
$A(document.getElementsByName(item.key)).each(function (el) {
|
|
|
|
Effect.BlindUp(el.parentNode.parentNode);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Effect.BlindUp($(item.key).parentNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2006-05-10 13:37:29 -04:00
|
|
|
}
|
2006-05-24 18:02:44 -04:00
|
|
|
};
|
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-20 13:30:48 -04:00
|
|
|
if (Config.isWritable) {
|
|
|
|
frag.appendChild(Builder.node('input',{id: id,name: name,className: 'text',
|
|
|
|
value: value,size: size}));
|
|
|
|
} else {
|
|
|
|
frag.appendChild(Builder.node('input',{id: id,name: name,className: 'text',
|
|
|
|
value: value,size: size, disabled: 'disabled'}));
|
|
|
|
}
|
2006-05-20 17:51:14 -04:00
|
|
|
frag.appendChild(document.createTextNode('\u00a0'));
|
|
|
|
if (short_description) {
|
|
|
|
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-20 13:30:48 -04:00
|
|
|
if (!Config.isWritable) {
|
|
|
|
select.disabled = 'disabled';
|
|
|
|
}
|
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);
|
2006-05-21 11:01:05 -04:00
|
|
|
frag.appendChild(document.createTextNode('\u00a0'));
|
|
|
|
if (short_description) {
|
|
|
|
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-24 18:02:44 -04:00
|
|
|
};
|
|
|
|
|
2006-05-17 14:42:56 -04:00
|
|
|
function saved(req) {
|
2006-05-22 16:46:29 -04:00
|
|
|
if ('200' == Element.textContent(req.responseXML.getElementsByTagName('status')[0])) {
|
|
|
|
alert('Saved');
|
|
|
|
} else {
|
|
|
|
alert("Couldn't save and if this weren't a beta I'd tell you why");
|
|
|
|
}
|
2006-05-17 14:42:56 -04:00
|
|
|
}
|
|
|
|
function saveForm() {
|
2006-05-21 15:46:22 -04:00
|
|
|
var postVars = [];
|
|
|
|
var multiple = {};
|
2006-05-29 16:00:58 -04:00
|
|
|
|
2006-05-21 15:46:22 -04:00
|
|
|
$A($('theform').getElementsByTagName('select')).each(function (select) {
|
2006-05-29 16:00:58 -04:00
|
|
|
if (DEBUG) {
|
|
|
|
debug(select.id,select.value);
|
|
|
|
} else {
|
|
|
|
postVars.push(Form.Element.serialize(select.id));
|
|
|
|
}
|
2006-05-17 14:42:56 -04:00
|
|
|
});
|
2006-05-29 16:00:58 -04:00
|
|
|
|
2006-05-21 15:46:22 -04:00
|
|
|
$A($('theform').getElementsByTagName('input')).each(function (input) {
|
2006-06-04 14:03:10 -04:00
|
|
|
if (ConfigXML.getItem(input.name).multiple) {
|
2006-05-21 15:46:22 -04:00
|
|
|
if (multiple[input.name]) {
|
|
|
|
multiple[input.name].push(encodeURIComponent(input.value));
|
|
|
|
} else {
|
|
|
|
multiple[input.name] = [input.value];
|
|
|
|
}
|
|
|
|
} else {
|
2006-05-29 16:00:58 -04:00
|
|
|
if (DEBUG) {
|
|
|
|
debug(input.id,input.value);
|
|
|
|
} else {
|
|
|
|
postVars.push(Form.Element.serialize(input.id));
|
|
|
|
}
|
2006-05-24 18:02:44 -04:00
|
|
|
}
|
2006-05-21 15:46:22 -04:00
|
|
|
});
|
2006-05-29 16:00:58 -04:00
|
|
|
|
2006-05-21 15:46:22 -04:00
|
|
|
$H(multiple).each(function (item) {
|
2006-05-29 16:00:58 -04:00
|
|
|
if (DEBUG) {
|
|
|
|
debug(item.key,item.value.join(','));
|
|
|
|
} else {
|
|
|
|
postVars.push(item.key + '=' + item.value.join(','));
|
|
|
|
}
|
2006-05-21 15:46:22 -04:00
|
|
|
});
|
2006-05-29 16:00:58 -04:00
|
|
|
if (DEBUG) {
|
|
|
|
return;
|
|
|
|
}
|
2006-05-21 15:46:22 -04:00
|
|
|
new Ajax.Request('/xml-rpc?method=updateconfig',
|
2006-05-24 17:15:13 -04:00
|
|
|
{method: 'post',
|
|
|
|
parameters: postVars.join('&'),
|
|
|
|
onComplete: saved});
|
2006-05-31 16:10:21 -04:00
|
|
|
|
2006-05-29 16:00:58 -04:00
|
|
|
function debug(id,value) {
|
|
|
|
var getArr = [];
|
2006-05-31 16:10:21 -04:00
|
|
|
var getString;
|
|
|
|
if ('validate' == DEBUG) {
|
|
|
|
var a = id.split(':');
|
|
|
|
getArr.push('section='+encodeURIComponent(a[0]));
|
|
|
|
getArr.push('key='+encodeURIComponent(a[1]));
|
|
|
|
getArr.push('value='+encodeURIComponent(value));
|
|
|
|
getArr.push('verify_only=1');
|
|
|
|
getString = '/xml-rpc?method=setconfig&' + getArr.join('&');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
getString = '/xml-rpc?method=updateconfig&' + Form.Element.serialize(id);
|
|
|
|
}
|
|
|
|
var output = id + '=' + value;
|
|
|
|
new Ajax.Request(getString,
|
2006-05-29 16:00:58 -04:00
|
|
|
{method: 'get',
|
2006-05-30 03:02:16 -04:00
|
|
|
onComplete: function(req){
|
|
|
|
var errorString = Element.textContent(req.responseXML.getElementsByTagName('statusstring')[0]);
|
|
|
|
if (errorString != 'Success') {
|
|
|
|
console.log(output + ' => ' + errorString);
|
|
|
|
}
|
|
|
|
}});
|
2006-05-31 16:10:21 -04:00
|
|
|
|
2006-05-29 16:00:58 -04:00
|
|
|
|
|
|
|
}
|
2006-05-17 14:42:56 -04:00
|
|
|
}
|
2006-05-18 17:47:49 -04:00
|
|
|
function cancelForm() {
|
2006-06-04 14:03:10 -04:00
|
|
|
ConfigXML.getAllItems().each(function (item) {
|
|
|
|
// this is from a hash $H hence use value
|
|
|
|
item = item.value;
|
|
|
|
if (item.multiple) {
|
|
|
|
var values = ConfigInitialValues.getValue(item.id);
|
|
|
|
if (!values || values.length === 0) {
|
|
|
|
values = [''];
|
|
|
|
}
|
|
|
|
var initialValuesCount = values.length;
|
|
|
|
var currentElements = document.getElementsByName(item.id);
|
2006-05-24 17:15:13 -04:00
|
|
|
var i=0;
|
2006-06-04 14:03:10 -04:00
|
|
|
while (initialValuesCount < currentElements.length) {
|
|
|
|
i++;
|
|
|
|
if (i > 10) {
|
|
|
|
alert('Getting dizzy; too many turns in this loop (silly errormessage 1)');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Config._removeItem(currentElements[0].parentNode,'noAnimation');
|
|
|
|
}
|
|
|
|
while (initialValuesCount > currentElements.length) {
|
|
|
|
i++;
|
|
|
|
if (i > 10) {
|
|
|
|
alert('An important part came off (silly errormessage 2)');
|
2006-05-26 16:22:21 -04:00
|
|
|
return;
|
2006-05-24 17:15:13 -04:00
|
|
|
}
|
2006-06-04 14:03:10 -04:00
|
|
|
Config._addItem(currentElements[currentElements.length-1].parentNode);
|
2006-05-20 19:25:46 -04:00
|
|
|
}
|
2006-06-04 14:03:10 -04:00
|
|
|
values.each(function (val,i){
|
|
|
|
currentElements[i].value = val;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
//###TODO potential error a select without a default value
|
|
|
|
$(item.id).value = ConfigInitialValues.getValue(item.id) || item.default_value || '';
|
|
|
|
}
|
2006-05-20 19:25:46 -04:00
|
|
|
});
|
|
|
|
return;
|
2006-05-27 17:04:19 -04:00
|
|
|
}
|