From f012d999425f9fc6b8eaae7c4ca4f9fe7b98715c Mon Sep 17 00:00:00 2001 From: j Date: Tue, 12 Nov 2019 17:50:24 +0000 Subject: [PATCH] shared itemView utils --- static/js/infoView.indiancinema.js | 19 +++---------------- static/js/infoView.js | 17 ++--------------- static/js/infoViewUtils.js | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 31 deletions(-) create mode 100644 static/js/infoViewUtils.js diff --git a/static/js/infoView.indiancinema.js b/static/js/infoView.indiancinema.js index 9776dd42..277c706d 100644 --- a/static/js/infoView.indiancinema.js +++ b/static/js/infoView.indiancinema.js @@ -621,19 +621,6 @@ pandora.ui.infoView = function(data, isMixed) { $('
').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) { if (value != data[key]) { var itemKey = Ox.getObjectById(pandora.site.itemKeys, key); @@ -661,7 +648,7 @@ pandora.ui.infoView = function(data, isMixed) { edit[key] = value; } 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) { if (!isMultiple) { @@ -763,14 +750,14 @@ pandora.ui.infoView = function(data, isMixed) { specialListKeys.indexOf(key) > -1 && itemKey && itemKey.type[0] == 'date' ) { ret = value.split('; ').map(function(date) { - date = cleanupDate(date) + date = pandora.cleanupDate(date) return date ? formatLink(Ox.formatDate(date, ['', '%Y', '%B %Y', '%B %e, %Y'][date.split('-').length], true ), key, date) : ''; }).join('; '); } else if (['releasedate'].indexOf(key) > -1) { - value = cleanupDate(value); + value = pandora.cleanupDate(value); ret = value ? Ox.formatDate(value, ['', '%Y', '%B %Y', '%B %e, %Y'][value.split('-').length], true diff --git a/static/js/infoView.js b/static/js/infoView.js index 9c18ff69..a484ac27 100644 --- a/static/js/infoView.js +++ b/static/js/infoView.js @@ -371,19 +371,6 @@ pandora.ui.infoView = function(data, isMixed) { $('
').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) { if (value != data[key]) { var itemKey = Ox.getObjectById(pandora.site.itemKeys, key); @@ -400,7 +387,7 @@ pandora.ui.infoView = function(data, isMixed) { edit[key] = value ? value : null; } 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) { 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' ) { ret = value.split('; ').map(function(date) { - date = cleanupDate(date) + date = pandora.cleanupDate(date) return date ? formatLink(Ox.formatDate(date, ['', '%Y', '%B %Y', '%B %e, %Y'][date.split('-').length], true diff --git a/static/js/infoViewUtils.js b/static/js/infoViewUtils.js new file mode 100644 index 00000000..9ab90665 --- /dev/null +++ b/static/js/infoViewUtils.js @@ -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 +}; +