2010-10-20 20:11:15 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2010, Google Inc.
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions of source code must retain the above copyright
|
2010-10-20 20:11:15 +02:00
|
|
|
notice, this list of conditions and the following disclaimer.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions in binary form must reproduce the above
|
2010-10-20 20:11:15 +02:00
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Neither the name of Google Inc. nor the names of its
|
2010-10-20 20:11:15 +02:00
|
|
|
contributors may be used to endorse or promote products derived from
|
|
|
|
this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
*/
|
2010-10-20 20:11:15 +02:00
|
|
|
|
2010-08-02 03:49:10 +02:00
|
|
|
var preferenceUIs = [];
|
|
|
|
|
2014-07-03 15:05:39 +02:00
|
|
|
var lang = (navigator.language|| navigator.userLanguage).split("-")[0];
|
2013-09-04 21:13:55 +02:00
|
|
|
var dictionary = "";
|
|
|
|
$.ajax({
|
2014-12-03 14:52:06 +01:00
|
|
|
url : "command/core/load-language?",
|
2013-09-04 21:13:55 +02:00
|
|
|
type : "POST",
|
|
|
|
async : false,
|
|
|
|
data : {
|
|
|
|
module : "core",
|
|
|
|
//lang : lang
|
|
|
|
},
|
|
|
|
success : function(data) {
|
|
|
|
dictionary = data;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$.i18n.setDictionary(dictionary);
|
|
|
|
//End internationalization
|
|
|
|
|
2017-11-16 21:17:51 +01:00
|
|
|
function deDupUserMetaData(arrObj) {
|
2017-11-16 22:24:31 +01:00
|
|
|
var result = _.uniq(JSON.parse(arrObj), function(x){
|
2017-11-16 21:17:51 +01:00
|
|
|
return x.name;
|
|
|
|
});
|
|
|
|
|
|
|
|
return JSON.stringify(result).replace(/"/g, '\"');
|
|
|
|
}
|
2013-09-04 21:13:55 +02:00
|
|
|
|
2010-08-02 03:49:10 +02:00
|
|
|
function PreferenceUI(tr, key, value) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var td0 = tr.insertCell(0);
|
|
|
|
$(td0).text(key);
|
|
|
|
|
|
|
|
var td1 = tr.insertCell(1);
|
2011-10-08 01:44:11 +02:00
|
|
|
$(td1).text((value !== null) ? value : "");
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
var td2 = tr.insertCell(2);
|
|
|
|
|
2013-07-02 13:40:50 +02:00
|
|
|
$('<button class="button">').text($.i18n._('core-index')["edit"]).appendTo(td2).click(function() {
|
|
|
|
var newValue = window.prompt($.i18n._('core-index')["change-value"]+" " + key, value);
|
2011-10-08 01:44:11 +02:00
|
|
|
if (newValue !== null) {
|
2017-11-16 21:17:51 +01:00
|
|
|
if (key === "userMetadata") {
|
|
|
|
newValue = deDupUserMetaData(newValue);
|
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
$(td1).text(newValue);
|
2017-11-16 21:17:51 +01:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
$.post(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/set-preference",
|
2011-08-04 22:37:14 +02:00
|
|
|
{
|
|
|
|
name : key,
|
|
|
|
value : JSON.stringify(newValue)
|
|
|
|
},
|
|
|
|
function(o) {
|
|
|
|
if (o.code == "error") {
|
|
|
|
alert(o.message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-07-02 13:40:50 +02:00
|
|
|
$('<button class="button">').text($.i18n._('core-index')["delete"]).appendTo(td2).click(function() {
|
|
|
|
if (window.confirm($.i18n._('core-index')["delete-key"]+" " + key + "?")) {
|
2011-08-04 22:37:14 +02:00
|
|
|
$.post(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/set-preference",
|
2011-08-04 22:37:14 +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"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2011-10-08 01:44:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function populatePreferences(prefs) {
|
|
|
|
var body = $("#body-info").empty();
|
|
|
|
|
2013-07-11 15:01:45 +02:00
|
|
|
$("#or-proj-starting").text($.i18n._('core-project')["starting"]+"...");
|
2013-07-02 13:40:50 +02:00
|
|
|
$('<h1>').text($.i18n._('core-index')["preferences"]).appendTo(body);
|
2011-10-08 01:44:11 +02:00
|
|
|
|
|
|
|
var table = $('<table>')
|
|
|
|
.addClass("list-table")
|
|
|
|
.addClass("preferences")
|
2013-07-02 13:40:50 +02:00
|
|
|
.html('<tr><th>'+$.i18n._('core-index')["key"]+'</th><th>'+$.i18n._('core-index')["value"]+'</th><th></th></tr>')
|
2011-10-08 01:44:11 +02:00
|
|
|
.appendTo(body)[0];
|
|
|
|
|
|
|
|
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);
|
|
|
|
trLast.insertCell(1);
|
|
|
|
trLast.insertCell(2);
|
2013-09-04 21:13:55 +02:00
|
|
|
$('<button class="button">').text($.i18n._('core-index')["add-pref"]).appendTo(tdLast0).click(function() {
|
2013-07-02 13:40:50 +02:00
|
|
|
var key = window.prompt($.i18n._('core-index')["add-pref"]);
|
2011-10-08 01:44:11 +02:00
|
|
|
if (key) {
|
2013-07-02 13:40:50 +02:00
|
|
|
var value = window.prompt($.i18n._('core-index')["pref-key"]);
|
2011-10-08 01:44:11 +02:00
|
|
|
if (value !== null) {
|
|
|
|
var tr = table.insertRow(table.rows.length - 1);
|
|
|
|
preferenceUIs.push(new PreferenceUI(tr, key, value));
|
2017-11-16 21:17:51 +01:00
|
|
|
|
|
|
|
if (key === "userMetadata") {
|
|
|
|
value = deDupUserMetaData(value);
|
|
|
|
}
|
|
|
|
|
2011-10-08 01:44:11 +02:00
|
|
|
$.post(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/set-preference",
|
2011-10-08 01:44:11 +02:00
|
|
|
{
|
|
|
|
name : key,
|
|
|
|
value : JSON.stringify(value)
|
|
|
|
},
|
|
|
|
function(o) {
|
|
|
|
if (o.code == "error") {
|
|
|
|
alert(o.message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function onLoad() {
|
|
|
|
$.post(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/get-all-preferences",
|
2011-10-08 01:44:11 +02:00
|
|
|
null,
|
|
|
|
populatePreferences,
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$(onLoad);
|