shared itemView utils

This commit is contained in:
j 2019-11-12 17:50:24 +00:00
parent f60222c9b5
commit f012d99942
3 changed files with 21 additions and 31 deletions

View file

@ -621,19 +621,6 @@ pandora.ui.infoView = function(data, isMixed) {
$('<div>').css({height: '16px'}).appendTo($statistics); $('<div>').css({height: '16px'}).appendTo($statistics);
function cleanupDate(value) {
if (/\d{2}-\d{2}-\d{4}/.test(value)) {
value = Ox.reverse(value.split('-')).join('-')
}
if (/\d{4}i\/\d{2}\/\d{d}/.test(value)) {
value = value.split('/').join('-')
}
if (/\d{2}\/\d{2}\/\d{4}/.test(value)) {
value = Ox.reverse(value.split('/')).join('-')
}
return value
}
function editMetadata(key, value) { function editMetadata(key, value) {
if (value != data[key]) { if (value != data[key]) {
var itemKey = Ox.getObjectById(pandora.site.itemKeys, key); var itemKey = Ox.getObjectById(pandora.site.itemKeys, key);
@ -661,7 +648,7 @@ pandora.ui.infoView = function(data, isMixed) {
edit[key] = value; edit[key] = value;
} }
if (itemKey && itemKey.type && itemKey.type[0] == 'date') { if (itemKey && itemKey.type && itemKey.type[0] == 'date') {
edit[key] = edit[key].map(cleanupDate); edit[key] = edit[key].map(pandora.cleanupDate);
} }
pandora.api.edit(edit, function(result) { pandora.api.edit(edit, function(result) {
if (!isMultiple) { if (!isMultiple) {
@ -763,14 +750,14 @@ pandora.ui.infoView = function(data, isMixed) {
specialListKeys.indexOf(key) > -1 && itemKey && itemKey.type[0] == 'date' specialListKeys.indexOf(key) > -1 && itemKey && itemKey.type[0] == 'date'
) { ) {
ret = value.split('; ').map(function(date) { ret = value.split('; ').map(function(date) {
date = cleanupDate(date) date = pandora.cleanupDate(date)
return date ? formatLink(Ox.formatDate(date, return date ? formatLink(Ox.formatDate(date,
['', '%Y', '%B %Y', '%B %e, %Y'][date.split('-').length], ['', '%Y', '%B %Y', '%B %e, %Y'][date.split('-').length],
true true
), key, date) : ''; ), key, date) : '';
}).join('; '); }).join('; ');
} else if (['releasedate'].indexOf(key) > -1) { } else if (['releasedate'].indexOf(key) > -1) {
value = cleanupDate(value); value = pandora.cleanupDate(value);
ret = value ? Ox.formatDate(value, ret = value ? Ox.formatDate(value,
['', '%Y', '%B %Y', '%B %e, %Y'][value.split('-').length], ['', '%Y', '%B %Y', '%B %e, %Y'][value.split('-').length],
true true

View file

@ -371,19 +371,6 @@ pandora.ui.infoView = function(data, isMixed) {
$('<div>').css({height: '16px'}).appendTo($statistics); $('<div>').css({height: '16px'}).appendTo($statistics);
function cleanupDate(value) {
if (/\d{2}-\d{2}-\d{4}/.test(value)) {
value = Ox.reverse(value.split('-')).join('-')
}
if (/\d{4}i\/\d{2}\/\d{d}/.test(value)) {
value = value.split('/').join('-')
}
if (/\d{2}\/\d{2}\/\d{4}/.test(value)) {
value = Ox.reverse(value.split('/')).join('-')
}
return value
}
function editMetadata(key, value) { function editMetadata(key, value) {
if (value != data[key]) { if (value != data[key]) {
var itemKey = Ox.getObjectById(pandora.site.itemKeys, key); var itemKey = Ox.getObjectById(pandora.site.itemKeys, key);
@ -400,7 +387,7 @@ pandora.ui.infoView = function(data, isMixed) {
edit[key] = value ? value : null; edit[key] = value ? value : null;
} }
if (itemKey && itemKey.type && itemKey.type[0] == 'date') { if (itemKey && itemKey.type && itemKey.type[0] == 'date') {
edit[key] = edit[key].map(cleanupDate); edit[key] = edit[key].map(pandora.cleanupDate);
} }
pandora.api.edit(edit, function(result) { pandora.api.edit(edit, function(result) {
if (!isMultiple) { if (!isMultiple) {
@ -474,7 +461,7 @@ pandora.ui.infoView = function(data, isMixed) {
listKeys.indexOf(key) > -1 && Ox.getObjectById(pandora.site.itemKeys, key).type[0] == 'date' listKeys.indexOf(key) > -1 && Ox.getObjectById(pandora.site.itemKeys, key).type[0] == 'date'
) { ) {
ret = value.split('; ').map(function(date) { ret = value.split('; ').map(function(date) {
date = cleanupDate(date) date = pandora.cleanupDate(date)
return date ? formatLink(Ox.formatDate(date, return date ? formatLink(Ox.formatDate(date,
['', '%Y', '%B %Y', '%B %e, %Y'][date.split('-').length], ['', '%Y', '%B %Y', '%B %e, %Y'][date.split('-').length],
true true

View file

@ -0,0 +1,16 @@
'use strict';
pandora.cleanupDate = function(value) {
if (/\d{2}-\d{2}-\d{4}/.test(value)) {
value = Ox.reverse(value.split('-')).join('-')
}
if (/\d{4}i\/\d{2}\/\d{d}/.test(value)) {
value = value.split('/').join('-')
}
if (/\d{2}\/\d{2}\/\d{4}/.test(value)) {
value = Ox.reverse(value.split('/')).join('-')
}
return value
};