From d3de45766ddcdb0437daaaaf94d4e6e1b6161139 Mon Sep 17 00:00:00 2001 From: rlx Date: Thu, 14 Jan 2016 14:43:04 +0530 Subject: [PATCH] info view: make unique on split; compare correctly on edit --- static/js/infoView.js | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/static/js/infoView.js b/static/js/infoView.js index dbe18b1..23515ca 100644 --- a/static/js/infoView.js +++ b/static/js/infoView.js @@ -285,10 +285,14 @@ oml.ui.infoView = function(externalData, isMixed) { && Ox.decodeHTMLEntities(value).split(separator).some(function(value) { return Ox.endsWith(value, ' (Ed.)'); }); - return Ox.decodeHTMLEntities(value).split(separator).map(function(value) { - return Ox.encodeHTMLEntities(value).replace(/ \(Ed\.\)/, '') - + (isEditor ? ' (Ed.)' : ''); - }); + return Ox.unique( + Ox.decodeHTMLEntities(value).split(separator).map(function(value) { + value = Ox.encodeHTMLEntities(value); + return isEditor + ? value.replace(/ \(Ed\.\)$/, '') + ' (Ed.)' + : value; + }) + ); } function toggleCoverSize(ratio) { @@ -470,7 +474,11 @@ oml.ui.infoView = function(externalData, isMixed) { )), tooltip: isEditable ? oml.getEditTooltip() : '', value: Ox.encodeHTMLEntities( - (data.author || []).join(separator) + (data.author || []).map(function(value, index) { + return index < data.author.length - 1 + ? value.replace(/ \(Ed\.\)$/, '') + : value; + }).join(separator) ) }) .css({ @@ -727,13 +735,14 @@ oml.ui.infoView = function(externalData, isMixed) { }); function editMetadata(key, value) { - if (value != data[key]) { - var edit = {id: !isMultiple ? data.id : ui.listSelection}; - edit[key] = key == 'author' - ? splitValue(value || [], 'author') - : Ox.contains(arrayKeys, key) - ? value ? value.split(separator) : [] - : value; + var edit = Ox.extend( + {id: !isMultiple ? data.id : ui.listSelection}, + key, + Ox.contains(arrayKeys, key) + ? splitValue(value || '', key) + : value + ); + if (!Ox.isEqual(edit[key], data[key])) { data[key] = edit[key]; oml.api.edit(edit, function(result) { if (!isMultiple || ui.updateResults) {