prevent the same key for user metadata

This commit is contained in:
Jacky 2017-11-16 15:17:51 -05:00
parent 1ad40bcd83
commit 46318a9bc4
2 changed files with 17 additions and 1 deletions

View File

@ -508,6 +508,7 @@ function init() {
"externals/imgareaselect/jquery.imgareaselect.js", "externals/imgareaselect/jquery.imgareaselect.js",
"externals/date.js", "externals/date.js",
"externals/jquery.i18n.js", "externals/jquery.i18n.js",
"externals/underscore-min.js",
"scripts/preferences.js", "scripts/preferences.js",
] ]
); );

View File

@ -50,6 +50,13 @@ dictionary = data;
$.i18n.setDictionary(dictionary); $.i18n.setDictionary(dictionary);
//End internationalization //End internationalization
function deDupUserMetaData(arrObj) {
result = _.uniq(JSON.parse(arrObj), function(x){
return x.name;
});
return JSON.stringify(result).replace(/"/g, '\"');
}
function PreferenceUI(tr, key, value) { function PreferenceUI(tr, key, value) {
var self = this; var self = this;
@ -65,7 +72,11 @@ function PreferenceUI(tr, key, value) {
$('<button class="button">').text($.i18n._('core-index')["edit"]).appendTo(td2).click(function() { $('<button class="button">').text($.i18n._('core-index')["edit"]).appendTo(td2).click(function() {
var newValue = window.prompt($.i18n._('core-index')["change-value"]+" " + key, value); var newValue = window.prompt($.i18n._('core-index')["change-value"]+" " + key, value);
if (newValue !== null) { if (newValue !== null) {
if (key === "userMetadata") {
newValue = deDupUserMetaData(newValue);
}
$(td1).text(newValue); $(td1).text(newValue);
$.post( $.post(
"command/core/set-preference", "command/core/set-preference",
{ {
@ -137,7 +148,11 @@ function populatePreferences(prefs) {
if (value !== null) { if (value !== null) {
var tr = table.insertRow(table.rows.length - 1); var tr = table.insertRow(table.rows.length - 1);
preferenceUIs.push(new PreferenceUI(tr, key, value)); preferenceUIs.push(new PreferenceUI(tr, key, value));
if (key === "userMetadata") {
value = deDupUserMetaData(value);
}
$.post( $.post(
"command/core/set-preference", "command/core/set-preference",
{ {