2010-08-02 03:49:10 +02:00
|
|
|
var preferenceUIs = [];
|
|
|
|
|
|
|
|
function onLoad() {
|
|
|
|
$.post(
|
2010-08-22 08:16:13 +02:00
|
|
|
"/command/core/get-all-preferences",
|
2010-08-02 03:49:10 +02:00
|
|
|
null,
|
|
|
|
populatePreferences,
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$(onLoad);
|
|
|
|
|
|
|
|
function populatePreferences(prefs) {
|
2010-10-14 19:39:41 +02:00
|
|
|
var body = $("#body-info").empty();
|
2010-08-02 03:49:10 +02:00
|
|
|
|
|
|
|
$('<h1>').text("Preferences").appendTo(body);
|
|
|
|
|
2010-10-14 19:39:41 +02:00
|
|
|
var table = $('<table>').addClass("list-table").addClass("preferences").html('<tr><th>Key</th><th>Value</th><th></th></tr>').appendTo(body)[0];
|
2010-08-02 03:49:10 +02:00
|
|
|
for (var k in prefs) {
|
|
|
|
var tr = table.insertRow(table.rows.length);
|
|
|
|
preferenceUIs.push(new PreferenceUI(tr, k, prefs[k]));
|
|
|
|
}
|
|
|
|
|
|
|
|
var trLast = table.insertRow(table.rows.length);
|
|
|
|
var tdLast0 = trLast.insertCell(0);
|
2010-10-14 19:39:41 +02:00
|
|
|
trLast.insertCell(1);
|
|
|
|
trLast.insertCell(2);
|
2010-10-16 08:43:01 +02:00
|
|
|
$('<button class="button">').text("Add Preference").appendTo(tdLast0).click(function() {
|
2010-10-14 19:39:41 +02:00
|
|
|
var key = window.prompt("Preference key:");
|
2010-08-02 03:49:10 +02:00
|
|
|
if (key) {
|
2010-10-14 19:39:41 +02:00
|
|
|
var value = window.prompt("Preference key value:");
|
2010-08-02 03:49:10 +02:00
|
|
|
if (value != null) {
|
|
|
|
var tr = table.insertRow(table.rows.length - 1);
|
|
|
|
preferenceUIs.push(new PreferenceUI(tr, key, value));
|
|
|
|
|
|
|
|
$.post(
|
2010-08-22 08:16:13 +02:00
|
|
|
"/command/core/set-preference",
|
2010-08-02 03:49:10 +02:00
|
|
|
{
|
|
|
|
name : key,
|
|
|
|
value : JSON.stringify(value)
|
|
|
|
},
|
|
|
|
function(o) {
|
|
|
|
if (o.code == "error") {
|
|
|
|
alert(o.message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function PreferenceUI(tr, key, value) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var td0 = tr.insertCell(0);
|
|
|
|
$(td0).text(key);
|
|
|
|
|
|
|
|
var td1 = tr.insertCell(1);
|
|
|
|
$(td1).text(value != null ? value : "");
|
|
|
|
|
|
|
|
var td2 = tr.insertCell(2);
|
|
|
|
|
2010-10-16 08:43:01 +02:00
|
|
|
$('<button class="button">').text("Edit").appendTo(td2).click(function() {
|
2010-10-14 19:39:41 +02:00
|
|
|
var newValue = window.prompt("Change value of preference key " + key, value);
|
2010-08-02 03:49:10 +02:00
|
|
|
if (newValue != null) {
|
|
|
|
$(td1).text(newValue);
|
|
|
|
$.post(
|
2010-08-22 08:16:13 +02:00
|
|
|
"/command/core/set-preference",
|
2010-08-02 03:49:10 +02:00
|
|
|
{
|
|
|
|
name : key,
|
|
|
|
value : JSON.stringify(newValue)
|
|
|
|
},
|
|
|
|
function(o) {
|
|
|
|
if (o.code == "error") {
|
|
|
|
alert(o.message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-10-16 08:43:01 +02:00
|
|
|
$('<button class="button">').text("Delete").appendTo(td2).click(function() {
|
2010-08-02 03:49:10 +02:00
|
|
|
if (window.confirm("Delete preference key " + key + "?")) {
|
|
|
|
$.post(
|
2010-08-22 08:16:13 +02:00
|
|
|
"/command/core/set-preference",
|
2010-08-02 03:49:10 +02:00
|
|
|
{
|
|
|
|
name : key
|
|
|
|
},
|
|
|
|
function(o) {
|
|
|
|
if (o.code == "ok") {
|
|
|
|
$(tr).remove();
|
|
|
|
|
|
|
|
for (var i = 0; i < preferenceUIs.length; i++) {
|
|
|
|
if (preferenceUIs[i] === self) {
|
|
|
|
preferenceUIs.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (o.code == "error") {
|
|
|
|
alert(o.message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|