update metadata editor

This commit is contained in:
Luke Pulverenti 2016-02-08 14:51:14 -05:00
parent 40b4010ce4
commit ee7c67b429
2 changed files with 196 additions and 26 deletions

View File

@ -4,41 +4,204 @@
var metadataEditorInfo;
var currentItem;
function onWebSocketMessageReceived(e, data) {
var msg = data;
if (msg.MessageType === "LibraryChanged") {
if (msg.Data.ItemsUpdated.indexOf(currentItem.Id) != -1) {
console.log('Item updated - reloading metadata');
reload(currentDialog, currentItem.Id);
}
}
}
function bindItemChanged() {
Events.on(ApiClient, "websocketmessage", onWebSocketMessageReceived);
}
function unbindItemChanged() {
Events.off(ApiClient, "websocketmessage", onWebSocketMessageReceived);
}
function closeDialog(isSubmitted) {
paperDialogHelper.close(currentDialog);
}
function submitUpdatedItem(form, item) {
function afterContentTypeUpdated() {
Dashboard.alert(Globalize.translate('MessageItemSaved'));
Dashboard.hideLoadingMsg();
closeDialog(true);
}
ApiClient.updateItem(item).then(function () {
var newContentType = $('#selectContentType', form).val() || '';
if ((metadataEditorInfo.ContentType || '') != newContentType) {
ApiClient.ajax({
url: ApiClient.getUrl('Items/' + item.Id + '/ContentType', {
ContentType: newContentType
}),
type: 'POST'
}).then(function () {
afterContentTypeUpdated();
});
} else {
afterContentTypeUpdated();
}
});
}
function getSelectedAirDays(form) {
return $('.chkAirDay:checked', form).map(function () {
return this.getAttribute('data-day');
}).get();
}
function getAlbumArtists(form) {
return $('#txtAlbumArtist', form).val().trim().split(';').filter(function (s) {
return s.length > 0;
}).map(function (a) {
return {
Name: a
};
});
}
function getArtists(form) {
return $('#txtArtist', form).val().trim().split(';').filter(function (s) {
return s.length > 0;
}).map(function (a) {
return {
Name: a
};
});
}
function getDateFromForm(form, element, property) {
var val = $(element, form).val();
if (!val) {
return null;
}
if (currentItem[property]) {
var date = parseISO8601Date(currentItem[property], { toLocal: true });
var parts = date.toISOString().split('T');
// If the date is the same, preserve the time
if (parts[0].indexOf(val) == 0) {
var iso = parts[1];
val += 'T' + iso;
}
}
return val;
}
function onSubmit() {
Dashboard.showLoadingMsg();
var form = this;
try {
var item = {
Id: currentItem.Id,
Name: $('#txtName', form).val(),
ForcedSortName: $('#txtSortName', form).val(),
DisplayMediaType: $('#txtDisplayMediaType', form).val(),
CommunityRating: $('#txtCommunityRating', form).val(),
VoteCount: $('#txtCommunityVoteCount', form).val(),
HomePageUrl: $('#txtHomePageUrl', form).val(),
Budget: $('#txtBudget', form).val(),
Revenue: $('#txtRevenue', form).val(),
CriticRating: $('#txtCriticRating', form).val(),
CriticRatingSummary: $('#txtCriticRatingSummary', form).val(),
IndexNumber: $('#txtIndexNumber', form).val() || null,
DisplaySpecialsWithSeasons: form.querySelector('#chkDisplaySpecialsInline').checked,
AbsoluteEpisodeNumber: $('#txtAbsoluteEpisodeNumber', form).val(),
DvdEpisodeNumber: $('#txtDvdEpisodeNumber', form).val(),
DvdSeasonNumber: $('#txtDvdSeasonNumber', form).val(),
AirsBeforeSeasonNumber: $('#txtAirsBeforeSeason', form).val(),
AirsAfterSeasonNumber: $('#txtAirsAfterSeason', form).val(),
AirsBeforeEpisodeNumber: $('#txtAirsBeforeEpisode', form).val(),
ParentIndexNumber: $('#txtParentIndexNumber', form).val() || null,
DisplayOrder: $('#selectDisplayOrder', form).val(),
Players: $('#txtPlayers', form).val(),
Album: $('#txtAlbum', form).val(),
AlbumArtist: getAlbumArtists(form),
ArtistItems: getArtists(form),
Metascore: $('#txtMetascore', form).val(),
AwardSummary: $('#txtAwardSummary', form).val(),
Overview: $('#txtOverview', form).val(),
ShortOverview: $('#txtShortOverview', form).val(),
Status: $('#selectStatus', form).val(),
AirDays: getSelectedAirDays(form),
AirTime: $('#txtAirTime', form).val(),
Genres: editableListViewValues($("#listGenres", form)),
ProductionLocations: editableListViewValues($("#listCountries", form)),
Tags: editableListViewValues($("#listTags", form)),
Keywords: editableListViewValues($("#listKeywords", form)),
Studios: editableListViewValues($("#listStudios", form)).map(function (element) { return { Name: element }; }),
PremiereDate: getDateFromForm(form, '#txtPremiereDate', 'PremiereDate'),
DateCreated: getDateFromForm(form, '#txtDateAdded', 'DateCreated'),
EndDate: getDateFromForm(form, '#txtEndDate', 'EndDate'),
ProductionYear: $('#txtProductionYear', form).val(),
AspectRatio: $('#txtOriginalAspectRatio', form).val(),
Video3DFormat: $('#select3dFormat', form).val(),
OfficialRating: $('#selectOfficialRating', form).val(),
CustomRating: $('#selectCustomRating', form).val(),
People: currentItem.People,
LockData: form.querySelector("#chkLockData").checked,
LockedFields: $('.selectLockedField', form).get().filter(function (c) {
return !c.checked;
}).map(function (c) {
return c.getAttribute('data-value');
})
};
item.ProviderIds = $.extend({}, currentItem.ProviderIds || {});
$('.txtExternalId', form).each(function () {
var providerkey = this.getAttribute('data-providerkey');
item.ProviderIds[providerkey] = this.value;
});
item.PreferredMetadataLanguage = $('#selectLanguage', form).val();
item.PreferredMetadataCountryCode = $('#selectCountry', form).val();
if (currentItem.Type == "Person") {
var placeOfBirth = $('#txtPlaceOfBirth', form).val();
item.ProductionLocations = placeOfBirth ? [placeOfBirth] : [];
}
if (currentItem.Type == "Series") {
// 600000000
var seriesRuntime = $('#txtSeriesRuntime', form).val();
item.RunTimeTicks = seriesRuntime ? (seriesRuntime * 600000000) : null;
}
var tagline = $('#txtTagline', form).val();
item.Taglines = tagline ? [tagline] : [];
submitUpdatedItem(form, item);
} catch (err) {
alert(err);
}
// Disable default form submission
return false;
}
@ -103,6 +266,11 @@
closeDialog(false);
});
context.querySelector('.btnHeaderSave').addEventListener('click', function (e) {
context.querySelector('.btnSave').click();
});
context.querySelector('#chkLockData').addEventListener('click', function (e) {
if (!e.target.checked) {
@ -831,7 +999,6 @@
function reload(context, itemId) {
unbindItemChanged();
Dashboard.showLoadingMsg();
Promise.all([getItem(itemId), getEditorConfig(itemId)]).then(function (responses) {
@ -875,7 +1042,6 @@
}
Dashboard.hideLoadingMsg();
bindItemChanged(context);
});
}

View File

@ -3,6 +3,10 @@
<div class="dialogHeaderTitle">
${ButtonEdit}
</div>
<paper-button class="btnHeaderSave accent" tabindex="-1" style="margin-left:auto;">
<iron-icon icon="check"></iron-icon>
<span>${ButtonSave}</span>
</paper-button>
</div>
<form class="editItemMetadataForm editMetadataForm ">