info view: make unique on split; compare correctly on edit

This commit is contained in:
rlx 2016-01-14 14:43:04 +05:30
parent d54f524953
commit d3de45766d

View file

@ -285,10 +285,14 @@ oml.ui.infoView = function(externalData, isMixed) {
&& Ox.decodeHTMLEntities(value).split(separator).some(function(value) { && Ox.decodeHTMLEntities(value).split(separator).some(function(value) {
return Ox.endsWith(value, ' (Ed.)'); return Ox.endsWith(value, ' (Ed.)');
}); });
return Ox.decodeHTMLEntities(value).split(separator).map(function(value) { return Ox.unique(
return Ox.encodeHTMLEntities(value).replace(/ \(Ed\.\)/, '') Ox.decodeHTMLEntities(value).split(separator).map(function(value) {
+ (isEditor ? ' (Ed.)' : ''); value = Ox.encodeHTMLEntities(value);
}); return isEditor
? value.replace(/ \(Ed\.\)$/, '') + ' (Ed.)'
: value;
})
);
} }
function toggleCoverSize(ratio) { function toggleCoverSize(ratio) {
@ -470,7 +474,11 @@ oml.ui.infoView = function(externalData, isMixed) {
)), )),
tooltip: isEditable ? oml.getEditTooltip() : '', tooltip: isEditable ? oml.getEditTooltip() : '',
value: Ox.encodeHTMLEntities( 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({ .css({
@ -727,13 +735,14 @@ oml.ui.infoView = function(externalData, isMixed) {
}); });
function editMetadata(key, value) { function editMetadata(key, value) {
if (value != data[key]) { var edit = Ox.extend(
var edit = {id: !isMultiple ? data.id : ui.listSelection}; {id: !isMultiple ? data.id : ui.listSelection},
edit[key] = key == 'author' key,
? splitValue(value || [], 'author') Ox.contains(arrayKeys, key)
: Ox.contains(arrayKeys, key) ? splitValue(value || '', key)
? value ? value.split(separator) : [] : value
: value; );
if (!Ox.isEqual(edit[key], data[key])) {
data[key] = edit[key]; data[key] = edit[key];
oml.api.edit(edit, function(result) { oml.api.edit(edit, function(result) {
if (!isMultiple || ui.updateResults) { if (!isMultiple || ui.updateResults) {