jellyfin-web/dashboard-ui/components/metadataeditor/metadataeditor.js

1241 lines
45 KiB
JavaScript
Raw Normal View History

define(['itemHelper', 'dialogHelper', 'datetime', 'loading', 'connectionManager', 'emby-checkbox', 'emby-input', 'emby-select', 'listViewStyle', 'emby-textarea', 'emby-button', 'paper-icon-button-light'], function (itemHelper, dialogHelper, datetime, loading, connectionManager) {
2016-01-06 13:16:16 -07:00
2016-02-15 21:54:20 -07:00
var currentContext;
2016-01-06 13:16:16 -07:00
var metadataEditorInfo;
var currentItem;
2016-03-23 12:06:36 -07:00
function isDialog() {
return currentContext.classList.contains('dialog');
}
2016-02-08 12:51:14 -07:00
function closeDialog(isSubmitted) {
2016-01-06 13:16:16 -07:00
2016-03-23 12:06:36 -07:00
if (isDialog()) {
2016-03-23 12:03:17 -07:00
dialogHelper.close(currentContext);
2016-02-15 21:54:20 -07:00
}
2016-02-08 12:51:14 -07:00
}
2016-01-06 13:16:16 -07:00
2016-02-08 12:51:14 -07:00
function submitUpdatedItem(form, item) {
2016-01-06 13:16:16 -07:00
2016-02-08 12:51:14 -07:00
function afterContentTypeUpdated() {
2016-01-06 13:16:16 -07:00
2016-02-24 23:38:12 -07:00
require(['toast'], function (toast) {
toast(Globalize.translate('MessageItemSaved'));
});
2016-02-08 12:51:14 -07:00
loading.hide();
2016-02-08 12:51:14 -07:00
closeDialog(true);
2016-01-06 13:16:16 -07:00
}
2016-02-08 12:51:14 -07:00
var apiClient = getApiClient();
apiClient.updateItem(item).then(function () {
2016-02-08 12:51:14 -07:00
2016-07-23 10:11:27 -07:00
var newContentType = form.querySelector('#selectContentType').value || '';
2016-02-08 12:51:14 -07:00
if ((metadataEditorInfo.ContentType || '') != newContentType) {
apiClient.ajax({
2016-02-08 12:51:14 -07:00
url: apiClient.getUrl('Items/' + item.Id + '/ContentType', {
2016-02-08 12:51:14 -07:00
ContentType: newContentType
}),
type: 'POST'
}).then(function () {
afterContentTypeUpdated();
});
} else {
afterContentTypeUpdated();
}
});
2016-01-06 13:16:16 -07:00
}
2016-02-08 12:51:14 -07:00
function getSelectedAirDays(form) {
2016-07-23 10:11:27 -07:00
var checked = form.querySelectorAll('.chkAirDay:checked') || [];
return Array.prototype.map.call(checked, function () {
2016-02-08 12:51:14 -07:00
return this.getAttribute('data-day');
2016-07-23 10:11:27 -07:00
});
2016-02-08 12:51:14 -07:00
}
function getAlbumArtists(form) {
2016-07-23 10:11:27 -07:00
return form.querySelector('#txtAlbumArtist').value.trim().split(';').filter(function (s) {
2016-02-08 12:51:14 -07:00
return s.length > 0;
2016-01-06 13:16:16 -07:00
2016-02-08 12:51:14 -07:00
}).map(function (a) {
return {
Name: a
};
});
2016-01-06 13:16:16 -07:00
}
2016-02-08 12:51:14 -07:00
function getArtists(form) {
2016-07-23 10:11:27 -07:00
return form.querySelector('#txtArtist').value.trim().split(';').filter(function (s) {
2016-02-08 12:51:14 -07:00
return s.length > 0;
2016-01-06 13:16:16 -07:00
2016-02-08 12:51:14 -07:00
}).map(function (a) {
return {
Name: a
};
});
2016-01-06 13:16:16 -07:00
}
2016-02-08 12:51:14 -07:00
function getDateFromForm(form, element, property) {
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
var val = form.querySelector(element).value;
2016-02-08 12:51:14 -07:00
if (!val) {
return null;
}
if (currentItem[property]) {
2016-05-05 21:50:06 -07:00
var date = datetime.parseISO8601Date(currentItem[property], true);
2016-02-08 12:51:14 -07:00
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;
2016-01-06 13:16:16 -07:00
}
2016-07-23 14:07:27 -07:00
function onSubmit(e) {
2016-01-06 13:16:16 -07:00
loading.show();
2016-01-06 13:16:16 -07:00
var form = this;
2016-02-08 12:51:14 -07:00
try {
var item = {
Id: currentItem.Id,
2016-07-23 10:11:27 -07:00
Name: form.querySelector('#txtName').value,
OriginalTitle: form.querySelector('#txtOriginalName').value,
ForcedSortName: form.querySelector('#txtSortName').value,
DisplayMediaType: form.querySelector('#txtDisplayMediaType').value,
CommunityRating: form.querySelector('#txtCommunityRating').value,
VoteCount: form.querySelector('#txtCommunityVoteCount').value,
HomePageUrl: form.querySelector('#txtHomePageUrl').value,
Budget: form.querySelector('#txtBudget').value,
Revenue: form.querySelector('#txtRevenue').value,
CriticRating: form.querySelector('#txtCriticRating').value,
CriticRatingSummary: form.querySelector('#txtCriticRatingSummary').value,
IndexNumber: form.querySelector('#txtIndexNumber').value || null,
AbsoluteEpisodeNumber: form.querySelector('#txtAbsoluteEpisodeNumber').value,
DvdEpisodeNumber: form.querySelector('#txtDvdEpisodeNumber').value,
DvdSeasonNumber: form.querySelector('#txtDvdSeasonNumber').value,
AirsBeforeSeasonNumber: form.querySelector('#txtAirsBeforeSeason').value,
AirsAfterSeasonNumber: form.querySelector('#txtAirsAfterSeason').value,
AirsBeforeEpisodeNumber: form.querySelector('#txtAirsBeforeEpisode').value,
ParentIndexNumber: form.querySelector('#txtParentIndexNumber').value || null,
DisplayOrder: form.querySelector('#selectDisplayOrder').value,
Players: form.querySelector('#txtPlayers').value,
Album: form.querySelector('#txtAlbum').value,
2016-02-08 12:51:14 -07:00
AlbumArtist: getAlbumArtists(form),
ArtistItems: getArtists(form),
2016-07-23 10:11:27 -07:00
Metascore: form.querySelector('#txtMetascore').value,
AwardSummary: form.querySelector('#txtAwardSummary').value,
Overview: form.querySelector('#txtOverview').value,
ShortOverview: form.querySelector('#txtShortOverview').value,
Status: form.querySelector('#selectStatus').value,
2016-02-08 12:51:14 -07:00
AirDays: getSelectedAirDays(form),
2016-07-23 10:11:27 -07:00
AirTime: form.querySelector('#txtAirTime').value,
Genres: editableListViewValues(form.querySelector("#listGenres")),
ProductionLocations: editableListViewValues(form.querySelector("#listCountries")),
Tags: editableListViewValues(form.querySelector("#listTags")),
Keywords: editableListViewValues(form.querySelector("#listKeywords")),
Studios: editableListViewValues(form.querySelector("#listStudios")).map(function (element) { return { Name: element }; }),
2016-02-08 12:51:14 -07:00
PremiereDate: getDateFromForm(form, '#txtPremiereDate', 'PremiereDate'),
DateCreated: getDateFromForm(form, '#txtDateAdded', 'DateCreated'),
EndDate: getDateFromForm(form, '#txtEndDate', 'EndDate'),
2016-07-23 10:11:27 -07:00
ProductionYear: form.querySelector('#txtProductionYear').value,
AspectRatio: form.querySelector('#txtOriginalAspectRatio').value,
Video3DFormat: form.querySelector('#select3dFormat').value,
2016-02-08 12:51:14 -07:00
2016-07-23 10:11:27 -07:00
OfficialRating: form.querySelector('#selectOfficialRating').value,
CustomRating: form.querySelector('#selectCustomRating').value,
2016-02-08 12:51:14 -07:00
People: currentItem.People,
LockData: form.querySelector("#chkLockData").checked,
2016-07-23 10:11:27 -07:00
LockedFields: Array.prototype.filter.call(form.querySelectorAll('.selectLockedField'), function (c) {
2016-02-08 12:51:14 -07:00
return !c.checked;
}).map(function (c) {
return c.getAttribute('data-value');
})
};
2016-07-23 14:07:27 -07:00
item.ProviderIds = Object.assign({}, currentItem.ProviderIds);
2016-02-08 12:51:14 -07:00
2016-07-23 10:11:27 -07:00
var idElements = form.querySelectorAll('.txtExternalId');
2016-07-23 14:07:27 -07:00
Array.prototype.map.call(idElements, function (idElem) {
var providerKey = idElem.getAttribute('data-providerkey');
item.ProviderIds[providerKey] = idElem.value;
2016-02-08 12:51:14 -07:00
});
2016-07-23 10:11:27 -07:00
item.PreferredMetadataLanguage = form.querySelector('#selectLanguage').value;
item.PreferredMetadataCountryCode = form.querySelector('#selectCountry').value;
2016-02-08 12:51:14 -07:00
if (currentItem.Type == "Person") {
2016-07-23 10:11:27 -07:00
var placeOfBirth = form.querySelector('#txtPlaceOfBirth').value;
2016-02-08 12:51:14 -07:00
item.ProductionLocations = placeOfBirth ? [placeOfBirth] : [];
}
if (currentItem.Type == "Series") {
// 600000000
2016-07-23 10:11:27 -07:00
var seriesRuntime = form.querySelector('#txtSeriesRuntime').value;
2016-02-08 12:51:14 -07:00
item.RunTimeTicks = seriesRuntime ? (seriesRuntime * 600000000) : null;
}
2016-07-23 10:11:27 -07:00
var tagline = form.querySelector('#txtTagline').value;
2016-02-08 12:51:14 -07:00
item.Taglines = tagline ? [tagline] : [];
submitUpdatedItem(form, item);
2016-07-23 14:07:27 -07:00
2016-02-08 12:51:14 -07:00
} catch (err) {
alert(err);
}
2016-07-23 14:07:27 -07:00
e.preventDefault();
e.stopPropagation();
2016-01-06 13:16:16 -07:00
// Disable default form submission
return false;
}
2016-01-23 11:45:50 -07:00
function parentWithClass(elem, className) {
while (!elem.classList || !elem.classList.contains(className)) {
elem = elem.parentNode;
if (!elem) {
return null;
}
}
return elem;
}
function editableListViewValues(list) {
2016-07-23 10:11:27 -07:00
return Array.prototype.map.call(list.querySelectorAll('.textValue'), function (el) { return el.textContent; });
2016-01-23 11:45:50 -07:00
}
function addElementToEditableListview(source, sortCallback) {
require(['prompt'], function (prompt) {
prompt({
2016-02-15 07:41:07 -07:00
label: 'Value:'
2016-02-08 11:05:29 -07:00
}).then(function (text) {
2016-07-23 10:11:27 -07:00
var list = parentWithClass(source, 'editableListviewContainer').querySelector('.paperList');
2016-02-08 11:05:29 -07:00
var items = editableListViewValues(list);
items.push(text);
2016-07-23 10:11:27 -07:00
populateListView(list, items, sortCallback);
2016-01-23 11:45:50 -07:00
});
});
}
function removeElementFromListview(source) {
2016-07-23 10:11:27 -07:00
var el = parentWithClass(source, 'listItem');
el.parentNode.removeChild(el);
2016-01-23 11:45:50 -07:00
}
2016-02-08 11:05:29 -07:00
function editPerson(context, person, index) {
2016-02-08 12:34:44 -07:00
require(['components/metadataeditor/personeditor'], function (personeditor) {
2016-02-08 11:05:29 -07:00
2016-02-08 12:34:44 -07:00
personeditor.show(person).then(function (updatedPerson) {
2016-02-08 11:05:29 -07:00
2016-02-08 12:34:44 -07:00
var isNew = index == -1;
2016-02-08 11:05:29 -07:00
2016-02-08 12:34:44 -07:00
if (isNew) {
currentItem.People.push(updatedPerson);
}
2016-02-08 11:05:29 -07:00
2016-02-08 12:34:44 -07:00
populatePeople(context, currentItem.People);
});
});
2016-02-08 11:05:29 -07:00
}
2016-05-11 07:36:28 -07:00
function showMoreMenu(context, button, user) {
2016-02-15 21:54:20 -07:00
2016-07-16 21:20:36 -07:00
require(['itemContextMenu'], function (itemContextMenu) {
itemContextMenu.show({
2016-02-15 21:54:20 -07:00
2016-07-16 21:20:36 -07:00
item: currentItem,
positionTo: button,
edit: false,
2016-07-17 11:55:07 -07:00
editImages: true,
editSubtitles: true,
2016-07-16 21:20:36 -07:00
sync: false,
share: false
2016-02-17 14:24:01 -07:00
2016-07-16 21:20:36 -07:00
}).then(function (result) {
2016-02-15 21:54:20 -07:00
2016-07-16 21:20:36 -07:00
if (result.deleted) {
Emby.Page.goHome();
2016-02-15 21:54:20 -07:00
2016-07-16 21:20:36 -07:00
} else if (result.updated) {
reload(context, currentItem.Id, currentItem.ServerId);
2016-02-15 21:54:20 -07:00
}
});
});
}
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(currentContext, currentItem.Id, currentItem.ServerId);
2016-02-15 21:54:20 -07:00
}
}
}
function bindItemChanged(context, apiClient) {
2016-02-15 21:54:20 -07:00
Events.on(apiClient, "websocketmessage", onWebSocketMessageReceived);
2016-02-15 21:54:20 -07:00
}
function unbindItemChanged(context, apiClient) {
2016-02-15 21:54:20 -07:00
Events.off(apiClient, "websocketmessage", onWebSocketMessageReceived);
2016-02-15 21:54:20 -07:00
}
2016-02-28 10:41:48 -07:00
function onEditorClick(e) {
2016-07-10 21:56:46 -07:00
2016-02-28 10:41:48 -07:00
var btnRemoveFromEditorList = parentWithClass(e.target, 'btnRemoveFromEditorList');
if (btnRemoveFromEditorList) {
removeElementFromListview(btnRemoveFromEditorList);
2016-07-10 21:56:46 -07:00
return;
2016-02-28 10:41:48 -07:00
}
var btnAddTextItem = parentWithClass(e.target, 'btnAddTextItem');
if (btnAddTextItem) {
addElementToEditableListview(btnAddTextItem);
}
}
function getApiClient() {
return connectionManager.getApiClient(currentItem.ServerId);
}
function init(context, apiClient) {
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('.btnCancel').addEventListener('click', function () {
2016-01-06 13:16:16 -07:00
closeDialog(false);
});
2016-02-15 21:54:20 -07:00
context.querySelector('.btnMore').addEventListener('click', function (e) {
getApiClient().getCurrentUser().then(function (user) {
2016-05-11 07:36:28 -07:00
showMoreMenu(context, e.target, user);
});
2016-02-15 21:54:20 -07:00
});
2016-02-08 12:51:14 -07:00
context.querySelector('.btnHeaderSave').addEventListener('click', function (e) {
context.querySelector('.btnSave').click();
});
2016-02-08 11:05:29 -07:00
context.querySelector('#chkLockData').addEventListener('click', function (e) {
if (!e.target.checked) {
2016-07-23 14:07:27 -07:00
showElement('.providerSettingsContainer');
2016-02-08 11:05:29 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('.providerSettingsContainer');
2016-02-08 11:05:29 -07:00
}
});
2016-02-28 10:41:48 -07:00
context.removeEventListener('click', onEditorClick);
context.addEventListener('click', onEditorClick);
2016-01-23 11:45:50 -07:00
2016-07-23 10:11:27 -07:00
var form = context.querySelector('form');
2016-07-23 14:07:27 -07:00
form.removeEventListener('submit', onSubmit);
2016-07-23 10:11:27 -07:00
form.addEventListener('submit', onSubmit);
2016-02-08 11:05:29 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector("#btnAddPerson").addEventListener('click', function (event, data) {
2016-02-08 11:05:29 -07:00
2016-02-08 12:34:44 -07:00
editPerson(context, {}, -1);
2016-02-08 11:05:29 -07:00
});
2016-02-15 21:54:20 -07:00
// For now this is only supported in dialog mode because we have a way of knowing when it closes
2016-03-23 12:06:36 -07:00
if (isDialog()) {
bindItemChanged(context, apiClient);
2016-02-15 21:54:20 -07:00
}
2016-01-06 13:16:16 -07:00
}
function getItem(itemId, serverId) {
var apiClient = connectionManager.getApiClient(serverId);
2016-01-06 13:16:16 -07:00
if (itemId) {
return apiClient.getItem(apiClient.getCurrentUserId(), itemId);
2016-01-06 13:16:16 -07:00
}
return apiClient.getRootFolder(apiClient.getCurrentUserId());
2016-01-06 13:16:16 -07:00
}
function getEditorConfig(itemId, serverId) {
var apiClient = connectionManager.getApiClient(serverId);
2016-01-06 13:16:16 -07:00
if (itemId) {
return apiClient.getJSON(apiClient.getUrl('Items/' + itemId + '/MetadataEditor'));
2016-01-06 13:16:16 -07:00
}
2016-02-08 22:45:33 -07:00
return Promise.resolve({});
2016-01-06 13:16:16 -07:00
}
function populateCountries(select, allCountries) {
var html = "";
html += "<option value=''></option>";
for (var i = 0, length = allCountries.length; i < length; i++) {
var culture = allCountries[i];
html += "<option value='" + culture.TwoLetterISORegionName + "'>" + culture.DisplayName + "</option>";
}
select.innerHTML = html;
}
function populateLanguages(select, languages) {
var html = "";
html += "<option value=''></option>";
for (var i = 0, length = languages.length; i < length; i++) {
var culture = languages[i];
html += "<option value='" + culture.TwoLetterISOLanguageName + "'>" + culture.DisplayName + "</option>";
}
select.innerHTML = html;
}
function renderContentTypeOptions(context, metadataInfo) {
if (!metadataInfo.ContentTypeOptions.length) {
2016-07-23 10:11:27 -07:00
hideElement('#fldContentType', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
showElement('#fldContentType', context);
2016-01-06 13:16:16 -07:00
}
var html = metadataInfo.ContentTypeOptions.map(function (i) {
return '<option value="' + i.Value + '">' + i.Name + '</option>';
}).join('');
2016-07-23 10:11:27 -07:00
var selectEl = context.querySelector('#selectContentType');
selectEl.innerHTML = html;
selectEl.value = metadataInfo.ContentType || '';
2016-01-06 13:16:16 -07:00
}
function onExternalIdChange() {
var formatString = this.getAttribute('data-formatstring');
var buttonClass = this.getAttribute('data-buttonclass');
if (this.value) {
2016-07-23 14:07:27 -07:00
document.querySelector('.' + buttonClass).setAttribute('href', formatString.replace('{0}', this.value));
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
document.querySelector('.' + buttonClass).setAttribute('href', '#');
2016-01-06 13:16:16 -07:00
}
}
function loadExternalIds(context, item, externalIds) {
var html = '';
var providerIds = item.ProviderIds || {};
for (var i = 0, length = externalIds.length; i < length; i++) {
var idInfo = externalIds[i];
var id = "txt1" + idInfo.Key;
var buttonId = "btnOpen1" + idInfo.Key;
var formatString = idInfo.UrlFormatString || '';
var labelText = Globalize.translate('LabelDynamicExternalId').replace('{0}', idInfo.Name);
2016-06-11 08:56:15 -07:00
html += '<div class="inputContainer">';
2016-06-11 09:34:00 -07:00
html += '<div style="display: flex; align-items: center;">';
2016-01-06 13:16:16 -07:00
var value = providerIds[idInfo.Key] || '';
2016-06-11 09:34:00 -07:00
html += '<div style="flex-grow:1;">';
2016-06-11 08:56:15 -07:00
html += '<input is="emby-input" class="txtExternalId" value="' + value + '" data-providerkey="' + idInfo.Key + '" data-formatstring="' + formatString + '" data-buttonclass="' + buttonId + '" id="' + id + '" label="' + labelText + '"/>';
2016-06-11 09:34:00 -07:00
html += '</div>';
2016-01-06 13:16:16 -07:00
if (formatString) {
2016-07-02 19:47:39 -07:00
html += '<a class="clearLink ' + buttonId + '" href="#" target="_blank" data-role="none" style="float: none; width: 1.75em"><button type="button" is="paper-icon-button-light" class="autoSize"><i class="md-icon">open_in_browser</i></button></a>';
2016-01-06 13:16:16 -07:00
}
2016-06-11 09:34:00 -07:00
html += '</div>';
2016-01-06 13:16:16 -07:00
html += '</div>';
}
2016-07-23 10:11:27 -07:00
var elem = context.querySelector('.externalIds', context);
elem.innerHTML = html;
2016-07-23 14:07:27 -07:00
2016-07-23 10:11:27 -07:00
var extIdEls = elem.querySelector('.txtExternalId') || [];
Array.prototype.forEach.call(extIdEls, function (el) {
2016-07-23 10:11:27 -07:00
el.addEventListener('change', onExternalIdChange.bind(el));
el.dispatchEvent(new Event('change'));
});
2016-07-23 10:11:27 -07:00
}
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
// Function to hide the element by selector or raw element
// Selector can be an element or a selector string
// Context is optional and restricts the querySelector to the context
function hideElement(selector, context, multiple) {
2016-07-23 10:11:27 -07:00
context = context || document;
if (typeof selector == 'string') {
var elements = multiple ? context.querySelectorAll(selector) : [context.querySelector(selector)];
Array.prototype.forEach.call(elements, function (el) {
if (el) {
el.classList.add('hide');
}
});
2016-07-23 10:11:27 -07:00
} else {
selector.classList.add('hide');
2016-07-23 10:11:27 -07:00
}
2016-01-06 13:16:16 -07:00
}
2016-07-23 10:11:27 -07:00
// Function to show the element by selector or raw element
// Selector can be an element or a selector string
// Context is optional and restricts the querySelector to the context
function showElement(selector, context, multiple) {
2016-07-23 10:11:27 -07:00
context = context || document;
if (typeof selector == 'string') {
var elements = multiple ? context.querySelectorAll(selector) : [context.querySelector(selector)];
Array.prototype.forEach.call(elements, function (el) {
if (el) {
el.classList.remove('hide');
}
});
2016-07-23 10:11:27 -07:00
} else {
selector.classList.remove('hide');
2016-07-23 10:11:27 -07:00
}
}
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
function setFieldVisibilities(context, item) {
2016-01-06 13:16:16 -07:00
if (item.Path && item.LocationType != 'Remote') {
2016-07-23 10:11:27 -07:00
showElement('#fldPath', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldPath', context);
2016-01-06 13:16:16 -07:00
}
2016-04-19 22:21:40 -07:00
if (item.Type == "Series" || item.Type == "Movie" || item.Type == "Trailer") {
2016-07-23 10:11:27 -07:00
showElement('#fldOriginalName', context);
2016-04-19 22:21:40 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldOriginalName', context);
2016-04-19 22:21:40 -07:00
}
2016-01-06 13:16:16 -07:00
if (item.Type == "Series") {
2016-07-23 10:11:27 -07:00
showElement('#fldSeriesRuntime', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldSeriesRuntime', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "Series" || item.Type == "Person") {
2016-07-23 10:11:27 -07:00
showElement('#fldEndDate', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldEndDate', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "Movie" || item.MediaType == "Game" || item.MediaType == "Trailer" || item.Type == "MusicVideo") {
2016-07-23 10:11:27 -07:00
showElement('#fldBudget', context);
showElement('#fldRevenue', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldBudget', context);
hideElement('#fldRevenue', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "MusicAlbum") {
2016-07-23 10:11:27 -07:00
showElement('#albumAssociationMessage', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#albumAssociationMessage', context)
2016-01-06 13:16:16 -07:00
}
if (item.MediaType == "Game") {
2016-07-23 10:11:27 -07:00
showElement('#fldPlayers', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldPlayers', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "Movie" || item.Type == "Trailer") {
2016-07-23 10:11:27 -07:00
showElement('#fldCriticRating', context);
showElement('#fldCriticRatingSummary', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldCriticRating', context);
hideElement('#fldCriticRatingSummary', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "Movie") {
2016-07-23 10:11:27 -07:00
showElement('#fldAwardSummary', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldAwardSummary', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "Movie" || item.Type == "Trailer") {
2016-07-23 10:11:27 -07:00
showElement('#fldMetascore', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldMetascore', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "Series") {
2016-07-23 10:11:27 -07:00
showElement('#fldStatus', context);
showElement('#fldAirDays', context);
showElement('#fldAirTime', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldStatus', context);
hideElement('#fldAirDays', context);
hideElement('#fldAirTime', context);
2016-01-06 13:16:16 -07:00
}
if (item.MediaType == "Video" && item.Type != "TvChannel") {
2016-07-23 10:11:27 -07:00
showElement('#fld3dFormat', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fld3dFormat', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "Audio") {
2016-07-23 10:11:27 -07:00
showElement('#fldAlbumArtist', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldAlbumArtist', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "Audio" || item.Type == "MusicVideo") {
2016-07-23 10:11:27 -07:00
showElement('#fldArtist', context);
showElement('#fldAlbum', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldArtist', context);
hideElement('#fldAlbum', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "Episode") {
2016-07-23 10:11:27 -07:00
showElement('#collapsibleDvdEpisodeInfo', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#collapsibleDvdEpisodeInfo', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "Episode" && item.ParentIndexNumber == 0) {
2016-07-23 10:11:27 -07:00
showElement('#collapsibleSpecialEpisodeInfo', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#collapsibleSpecialEpisodeInfo', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "Person" || item.Type == "Genre" || item.Type == "Studio" || item.Type == "GameGenre" || item.Type == "MusicGenre" || item.Type == "TvChannel") {
2016-07-23 10:11:27 -07:00
hideElement('#fldCommunityRating', context);
hideElement('#fldCommunityVoteCount', context);
hideElement('#genresCollapsible', context);
hideElement('#peopleCollapsible', context);
hideElement('#studiosCollapsible', context);
2016-01-06 13:16:16 -07:00
if (item.Type == "TvChannel") {
2016-07-23 10:11:27 -07:00
showElement('#fldOfficialRating', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldOfficialRating', context);
2016-01-06 13:16:16 -07:00
}
2016-07-23 10:11:27 -07:00
hideElement('#fldCustomRating', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
showElement('#fldCommunityRating', context);
showElement('#fldCommunityVoteCount', context);
showElement('#genresCollapsible', context);
showElement('#peopleCollapsible', context);
showElement('#studiosCollapsible', context);
showElement('#fldOfficialRating', context);
showElement('#fldCustomRating', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "MusicArtist") {
2016-07-23 10:11:27 -07:00
showElement('#countriesCollapsible', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#countriesCollapsible', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "TvChannel") {
2016-07-23 10:11:27 -07:00
hideElement('#tagsCollapsible', context);
hideElement('#metadataSettingsCollapsible', context);
hideElement('#fldPremiereDate', context);
hideElement('#fldDateAdded', context);
hideElement('#fldYear', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
showElement('#tagsCollapsible', context);
showElement('#metadataSettingsCollapsible', context);
showElement('#fldPremiereDate', context);
showElement('#fldDateAdded', context);
showElement('#fldYear', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "BoxSet") {
2016-07-23 10:11:27 -07:00
showElement('#keywordsCollapsible', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#keywordsCollapsible', context);
2016-01-06 13:16:16 -07:00
}
if (item.MediaType == "Video" && item.Type != "TvChannel") {
2016-07-23 10:11:27 -07:00
showElement('#fldSourceType', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldSourceType', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "Person") {
2016-07-23 10:11:27 -07:00
//todo
2016-06-11 08:56:15 -07:00
context.querySelector('#txtProductionYear').label(Globalize.translate('LabelBirthYear'));
context.querySelector("#txtPremiereDate").label(Globalize.translate('LabelBirthDate'));
context.querySelector("#txtEndDate").label(Globalize.translate('LabelDeathDate'));
2016-07-23 10:11:27 -07:00
showElement('#fldPlaceOfBirth');
2016-01-06 13:16:16 -07:00
} else {
2016-06-11 08:56:15 -07:00
context.querySelector('#txtProductionYear').label(Globalize.translate('LabelYear'));
context.querySelector("#txtPremiereDate").label(Globalize.translate('LabelReleaseDate'));
context.querySelector("#txtEndDate").label(Globalize.translate('LabelEndDate'));
2016-07-23 10:11:27 -07:00
hideElement('#fldPlaceOfBirth');
2016-01-06 13:16:16 -07:00
}
if (item.MediaType == "Video" && item.Type != "TvChannel") {
2016-07-23 10:11:27 -07:00
showElement('#fldOriginalAspectRatio');
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldOriginalAspectRatio');
2016-01-06 13:16:16 -07:00
}
if (item.Type == "Audio" || item.Type == "Episode" || item.Type == "Season") {
2016-07-23 10:11:27 -07:00
showElement('#fldIndexNumber');
2016-01-06 13:16:16 -07:00
if (item.Type == "Episode") {
2016-06-11 08:56:15 -07:00
context.querySelector('#txtIndexNumber').label(Globalize.translate('LabelEpisodeNumber'));
2016-01-06 13:16:16 -07:00
} else if (item.Type == "Season") {
2016-06-11 08:56:15 -07:00
context.querySelector('#txtIndexNumber').label(Globalize.translate('LabelSeasonNumber'));
2016-01-06 13:16:16 -07:00
} else if (item.Type == "Audio") {
2016-06-11 08:56:15 -07:00
context.querySelector('#txtIndexNumber').label(Globalize.translate('LabelTrackNumber'));
2016-01-06 13:16:16 -07:00
} else {
2016-06-11 08:56:15 -07:00
context.querySelector('#txtIndexNumber').label(Globalize.translate('LabelNumber'));
2016-01-06 13:16:16 -07:00
}
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldIndexNumber');
2016-01-06 13:16:16 -07:00
}
if (item.Type == "Audio" || item.Type == "Episode") {
2016-07-23 10:11:27 -07:00
showElement('#fldParentIndexNumber');
2016-01-06 13:16:16 -07:00
if (item.Type == "Episode") {
2016-06-11 08:56:15 -07:00
context.querySelector('#txtParentIndexNumber').label(Globalize.translate('LabelSeasonNumber'));
2016-01-06 13:16:16 -07:00
} else if (item.Type == "Audio") {
2016-06-11 08:56:15 -07:00
context.querySelector('#txtParentIndexNumber').label(Globalize.translate('LabelDiscNumber'));
2016-01-06 13:16:16 -07:00
} else {
2016-06-11 08:56:15 -07:00
context.querySelector('#txtParentIndexNumber').label(Globalize.translate('LabelParentNumber'));
2016-01-06 13:16:16 -07:00
}
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldParentIndexNumber', context);
2016-01-06 13:16:16 -07:00
}
if (item.Type == "BoxSet") {
2016-07-23 10:11:27 -07:00
showElement('#fldDisplayOrder', context);
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#selectDisplayOrder').innerHTML = '<option value="SortName">' + Globalize.translate('OptionSortName') + '</option><option value="PremiereDate">' + Globalize.translate('OptionReleaseDate') + '</option>';
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
context.querySelector('#selectDisplayOrder').innerHTML = '';
hideElement('#fldDisplayOrder', context);
2016-01-06 13:16:16 -07:00
}
2016-07-23 10:11:27 -07:00
var displaySettingFields = context.querySelectorAll('.fldDisplaySetting');
var hiddenDisplaySettingFields = Array.prototype.filter.call(displaySettingFields, function (field) {
return field.style.display != 'none';
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
});
if (hiddenDisplaySettingFields.length) {
showElement('#collapsibleDisplaySettings', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#collapsibleDisplaySettings', context);
2016-01-06 13:16:16 -07:00
}
}
function fillItemInfo(context, item, parentalRatingOptions) {
2016-07-23 10:11:27 -07:00
var select = context.querySelector('#selectOfficialRating');
2016-01-06 13:16:16 -07:00
populateRatings(parentalRatingOptions, select, item.OfficialRating);
2016-07-23 10:11:27 -07:00
select.value = item.OfficialRating || "";
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
select = context.querySelector('#selectCustomRating');
2016-01-06 13:16:16 -07:00
populateRatings(parentalRatingOptions, select, item.CustomRating);
2016-07-23 10:11:27 -07:00
select.value = item.CustomRating || "";
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
var selectStatus = context.querySelector('#selectStatus');
2016-01-06 13:16:16 -07:00
populateStatus(selectStatus);
2016-07-23 10:11:27 -07:00
selectStatus.value = item.Status || "";
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#select3dFormat', context).value = item.Video3DFormat || "";
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
Array.prototype.forEach.call(context.querySelectorAll('.chkAirDay', context), function (el) {
el.checked = (item.AirDays || []).indexOf(el.getAttribute('data-day')) != -1;
2016-01-06 13:16:16 -07:00
});
2016-07-23 10:11:27 -07:00
populateListView(context.querySelector('#listCountries'), item.ProductionLocations || []);
populateListView(context.querySelector('#listGenres'), item.Genres);
2016-01-06 13:16:16 -07:00
populatePeople(context, item.People || []);
2016-07-23 10:11:27 -07:00
populateListView(context.querySelector('#listStudios'), (item.Studios || []).map(function (element) { return element.Name || ''; }));
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
populateListView(context.querySelector('#listTags'), item.Tags);
populateListView(context.querySelector('#listKeywords'), item.Keywords);
2016-01-06 13:16:16 -07:00
var lockData = (item.LockData || false);
var chkLockData = context.querySelector("#chkLockData");
chkLockData.checked = lockData;
if (chkLockData.checked) {
2016-07-23 10:11:27 -07:00
hideElement('.providerSettingsContainer', context)
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
showElement('.providerSettingsContainer', context)
2016-01-06 13:16:16 -07:00
}
populateInternetProviderSettings(context, item, item.LockedFields);
2016-07-23 10:11:27 -07:00
context.querySelector('#txtPath').value = item.Path || '';
context.querySelector('#txtName').value = item.Name || "";
context.querySelector('#txtOriginalName').value = item.OriginalTitle || "";
2016-01-06 13:16:16 -07:00
context.querySelector('#txtOverview').value = item.Overview || '';
2016-07-23 10:11:27 -07:00
context.querySelector('#txtShortOverview').value = item.ShortOverview || "";
context.querySelector('#txtTagline').value = (item.Taglines && item.Taglines.length ? item.Taglines[0] : '');
context.querySelector('#txtSortName').value = item.ForcedSortName || "";
context.querySelector('#txtDisplayMediaType').value = item.DisplayMediaType || "";
context.querySelector('#txtCommunityRating').value = item.CommunityRating || "";
context.querySelector('#txtCommunityVoteCount').value = item.VoteCount || "";
context.querySelector('#txtHomePageUrl').value = item.HomePageUrl || "";
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#txtAwardSummary').value = item.AwardSummary || "";
context.querySelector('#txtMetascore').value = item.Metascore || "";
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#txtBudget').value = item.Budget || "";
context.querySelector('#txtRevenue').value = item.Revenue || "";
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#txtCriticRating').value = item.CriticRating || "";
context.querySelector('#txtCriticRatingSummary').value = item.CriticRatingSummary || "";
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#txtIndexNumber').value = ('IndexNumber' in item) ? item.IndexNumber : "";
context.querySelector('#txtParentIndexNumber').value = ('ParentIndexNumber' in item) ? item.ParentIndexNumber : "";
context.querySelector('#txtPlayers').value = item.Players || "";
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#txtAbsoluteEpisodeNumber').value = ('AbsoluteEpisodeNumber' in item) ? item.AbsoluteEpisodeNumber : "";
context.querySelector('#txtDvdEpisodeNumber').value = ('DvdEpisodeNumber' in item) ? item.DvdEpisodeNumber : "";
context.querySelector('#txtDvdSeasonNumber').value = ('DvdSeasonNumber' in item) ? item.DvdSeasonNumber : "";
context.querySelector('#txtAirsBeforeSeason').value = ('AirsBeforeSeasonNumber' in item) ? item.AirsBeforeSeasonNumber : "";
context.querySelector('#txtAirsAfterSeason').value = ('AirsAfterSeasonNumber' in item) ? item.AirsAfterSeasonNumber : "";
context.querySelector('#txtAirsBeforeEpisode').value = ('AirsBeforeEpisodeNumber' in item) ? item.AirsBeforeEpisodeNumber : "";
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#txtAlbum').value = item.Album || "";
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#txtAlbumArtist').value = (item.AlbumArtists || []).map(function (a) {
2016-01-06 13:16:16 -07:00
return a.Name;
2016-07-23 10:11:27 -07:00
}).join(';');
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#selectDisplayOrder').value = item.DisplayOrder;
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#txtArtist').value = (item.ArtistItems || []).map(function (a) {
2016-01-06 13:16:16 -07:00
return a.Name;
2016-07-23 10:11:27 -07:00
}).join(';');
2016-01-06 13:16:16 -07:00
var date;
if (item.DateCreated) {
try {
2016-05-05 21:50:06 -07:00
date = datetime.parseISO8601Date(item.DateCreated, true);
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#txtDateAdded').value = date.toISOString().slice(0, 10);
2016-01-06 13:16:16 -07:00
} catch (e) {
2016-07-23 10:11:27 -07:00
context.querySelector('#txtDateAdded').value = '';
2016-01-06 13:16:16 -07:00
}
} else {
2016-07-23 10:11:27 -07:00
context.querySelector('#txtDateAdded').value = '';
2016-01-06 13:16:16 -07:00
}
if (item.PremiereDate) {
try {
2016-05-05 21:50:06 -07:00
date = datetime.parseISO8601Date(item.PremiereDate, true);
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#txtPremiereDate').value = date.toISOString().slice(0, 10);
2016-01-06 13:16:16 -07:00
} catch (e) {
2016-07-23 10:11:27 -07:00
context.querySelector('#txtPremiereDate').value = '';
2016-01-06 13:16:16 -07:00
}
} else {
2016-07-23 10:11:27 -07:00
context.querySelector('#txtPremiereDate').value = '';
2016-01-06 13:16:16 -07:00
}
if (item.EndDate) {
try {
2016-05-05 21:50:06 -07:00
date = datetime.parseISO8601Date(item.EndDate, true);
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#txtEndDate').value = date.toISOString().slice(0, 10);
2016-01-06 13:16:16 -07:00
} catch (e) {
2016-07-23 10:11:27 -07:00
context.querySelector('#txtEndDate').value = '';
2016-01-06 13:16:16 -07:00
}
} else {
2016-07-23 10:11:27 -07:00
context.querySelector('#txtEndDate').value = '';
2016-01-06 13:16:16 -07:00
}
2016-07-23 10:11:27 -07:00
context.querySelector('#txtProductionYear').value = item.ProductionYear || "";
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#txtAirTime').value = item.AirTime || '';
2016-01-06 13:16:16 -07:00
var placeofBirth = item.ProductionLocations && item.ProductionLocations.length ? item.ProductionLocations[0] : '';
2016-07-23 10:11:27 -07:00
context.querySelector('#txtPlaceOfBirth').value = placeofBirth;
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#txtOriginalAspectRatio').value = item.AspectRatio || "";
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
context.querySelector('#selectLanguage').value = item.PreferredMetadataLanguage || "";
context.querySelector('#selectCountry').value = item.PreferredMetadataCountryCode || "";
2016-01-06 13:16:16 -07:00
if (item.RunTimeTicks) {
var minutes = item.RunTimeTicks / 600000000;
2016-07-23 10:11:27 -07:00
context.querySelector('#txtSeriesRuntime').value = Math.round(minutes);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
context.querySelector('#txtSeriesRuntime', context).value = "";
2016-01-06 13:16:16 -07:00
}
}
function populateRatings(allParentalRatings, select, currentValue) {
var html = "";
html += "<option value=''></option>";
var ratings = [];
var i, length, rating;
var currentValueFound = false;
for (i = 0, length = allParentalRatings.length; i < length; i++) {
rating = allParentalRatings[i];
ratings.push({ Name: rating.Name, Value: rating.Name });
if (rating.Name == currentValue) {
currentValueFound = true;
}
}
if (currentValue && !currentValueFound) {
ratings.push({ Name: currentValue, Value: currentValue });
}
for (i = 0, length = ratings.length; i < length; i++) {
rating = ratings[i];
html += "<option value='" + rating.Value + "'>" + rating.Name + "</option>";
}
2016-07-23 10:11:27 -07:00
select.innerHTML = html;
2016-01-06 13:16:16 -07:00
}
function populateStatus(select) {
var html = "";
html += "<option value=''></option>";
html += "<option value='Continuing'>" + Globalize.translate('OptionContinuing') + "</option>";
html += "<option value='Ended'>" + Globalize.translate('OptionEnded') + "</option>";
2016-07-23 10:11:27 -07:00
select.innerHTML = html;
2016-01-06 13:16:16 -07:00
}
function populateListView(list, items, sortCallback) {
2016-01-23 11:45:50 -07:00
items = items || [];
if (typeof (sortCallback) === 'undefined') {
items.sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); });
} else {
items = sortCallback(items);
}
var html = '';
for (var i = 0; i < items.length; i++) {
2016-07-02 11:29:10 -07:00
html += '<div class="listItem">';
2016-01-23 11:45:50 -07:00
2016-07-02 11:29:10 -07:00
html += '<button type="button" is="emby-button" data-index="' + i + '" class="fab autoSize mini"><i class="md-icon">live_tv</i></button>';
2016-01-23 11:45:50 -07:00
2016-07-02 11:29:10 -07:00
html += '<div class="listItemBody">';
2016-01-23 11:45:50 -07:00
html += '<div class="textValue">';
html += items[i];
html += '</div>';
2016-07-02 11:29:10 -07:00
html += '</div>';
2016-01-23 11:45:50 -07:00
2016-07-02 19:47:39 -07:00
html += '<button type="button" is="paper-icon-button-light" data-index="' + i + '" class="btnRemoveFromEditorList autoSize"><i class="md-icon">delete</i></button>';
2016-01-23 11:45:50 -07:00
2016-07-02 11:29:10 -07:00
html += '</div>';
2016-01-23 11:45:50 -07:00
}
list.innerHTML = html;
2016-01-06 13:16:16 -07:00
}
function populatePeople(context, people) {
var lastType = '';
var html = '';
2016-02-08 12:14:41 -07:00
var elem = context.querySelector('#peopleList');
2016-01-06 13:16:16 -07:00
for (var i = 0, length = people.length; i < length; i++) {
var person = people[i];
2016-07-02 11:29:10 -07:00
html += '<div class="listItem">';
2016-01-06 13:16:16 -07:00
2016-07-02 11:29:10 -07:00
html += '<button type="button" is="emby-button" data-index="' + i + '" class="btnEditPerson fab autoSize mini"><i class="md-icon">person</i></button>';
2016-01-06 13:16:16 -07:00
2016-07-02 11:29:10 -07:00
html += '<div class="listItemBody">';
2016-02-08 12:14:41 -07:00
html += '<a class="btnEditPerson clearLink" href="#" data-index="' + i + '">';
2016-01-06 13:16:16 -07:00
2016-02-08 12:14:41 -07:00
html += '<div class="textValue">';
html += (person.Name || '');
html += '</div>';
2016-01-06 13:16:16 -07:00
if (person.Role && person.Role != lastType) {
2016-07-02 11:29:10 -07:00
html += '<div class="secondary">' + (person.Role) + '</div>';
2016-01-06 13:16:16 -07:00
}
2016-02-08 12:14:41 -07:00
2016-01-06 13:16:16 -07:00
html += '</a>';
2016-07-02 11:29:10 -07:00
html += '</div>';
2016-01-06 13:16:16 -07:00
2016-07-02 19:47:39 -07:00
html += '<button type="button" is="paper-icon-button-light" data-index="' + i + '" class="btnDeletePerson autoSize"><i class="md-icon">delete</i></button>';
2016-01-06 13:16:16 -07:00
2016-07-02 11:29:10 -07:00
html += '</div>';
2016-01-06 13:16:16 -07:00
}
2016-02-08 12:14:41 -07:00
elem.innerHTML = html;
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
var deleteButton = elem.querySelector('.btnDeletePerson')
if (deleteButton) {
deleteButton.addEventListener('click', function () {
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
var index = parseInt(this.getAttribute('data-index'));
currentItem.People.splice(index, 1);
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
populatePeople(context, currentItem.People);
}.bind(deleteButton));
}
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
var editButton = elem.querySelector('.btnEditPerson')
if (editButton) {
editButton.addEventListener('click', function () {
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
var index = parseInt(this.getAttribute('data-index'));
2016-01-06 13:16:16 -07:00
2016-07-23 10:11:27 -07:00
editPerson(context, currentItem.People[index], index);
}.bind(editButton));
}
2016-01-06 13:16:16 -07:00
}
function generateSliders(fields, currentFields) {
var html = '';
for (var i = 0; i < fields.length; i++) {
var field = fields[i];
var name = field.name;
var value = field.value || field.name;
var checkedHtml = currentFields.indexOf(value) == -1 ? ' checked' : '';
2016-06-11 08:56:15 -07:00
html += '<label>';
html += '<input type="checkbox" is="emby-checkbox" class="selectLockedField" data-value="' + value + '"' + checkedHtml + '/>';
html += '<span>' + name + '</span>';
html += '</label>';
2016-01-06 13:16:16 -07:00
}
return html;
}
function populateInternetProviderSettings(context, item, lockedFields) {
2016-07-23 10:11:27 -07:00
var container = context.querySelector('.providerSettingsContainer');
2016-01-06 13:16:16 -07:00
lockedFields = lockedFields || new Array();
var metadatafields = [
{ name: Globalize.translate('OptionName'), value: "Name" },
{ name: Globalize.translate('OptionOverview'), value: "Overview" },
{ name: Globalize.translate('OptionGenres'), value: "Genres" },
{ name: Globalize.translate('OptionParentalRating'), value: "OfficialRating" },
{ name: Globalize.translate('OptionPeople'), value: "Cast" }
];
if (item.Type == "Person") {
metadatafields.push({ name: Globalize.translate('OptionBirthLocation'), value: "ProductionLocations" });
} else {
metadatafields.push({ name: Globalize.translate('OptionProductionLocations'), value: "ProductionLocations" });
}
if (item.Type == "Series") {
metadatafields.push({ name: Globalize.translate('OptionRuntime'), value: "Runtime" });
}
metadatafields.push({ name: Globalize.translate('OptionStudios'), value: "Studios" });
metadatafields.push({ name: Globalize.translate('OptionTags'), value: "Tags" });
metadatafields.push({ name: Globalize.translate('OptionKeywords'), value: "Keywords" });
metadatafields.push({ name: Globalize.translate('OptionImages'), value: "Images" });
metadatafields.push({ name: Globalize.translate('OptionBackdrops'), value: "Backdrops" });
if (item.Type == "Game") {
metadatafields.push({ name: Globalize.translate('OptionScreenshots'), value: "Screenshots" });
}
var html = '';
html += "<h1>" + Globalize.translate('HeaderEnabledFields') + "</h1>";
html += "<p>" + Globalize.translate('HeaderEnabledFieldsHelp') + "</p>";
html += generateSliders(metadatafields, lockedFields);
2016-07-23 10:11:27 -07:00
container.innerHTML = html;
2016-01-06 13:16:16 -07:00
}
function reload(context, itemId, serverId) {
2016-01-06 13:16:16 -07:00
loading.show();
2016-01-06 13:16:16 -07:00
Promise.all([getItem(itemId, serverId), getEditorConfig(itemId, serverId)]).then(function (responses) {
2016-01-06 13:16:16 -07:00
var item = responses[0];
metadataEditorInfo = responses[1];
currentItem = item;
var languages = metadataEditorInfo.Cultures;
var countries = metadataEditorInfo.Countries;
renderContentTypeOptions(context, metadataEditorInfo);
loadExternalIds(context, item, metadataEditorInfo.ExternalIdInfos);
populateLanguages(context.querySelector('#selectLanguage'), languages);
populateCountries(context.querySelector('#selectCountry'), countries);
2016-07-23 10:11:27 -07:00
LibraryBrowser.renderName(item, document.querySelector('.itemName'), true);
2016-01-06 13:16:16 -07:00
setFieldVisibilities(context, item);
fillItemInfo(context, item, metadataEditorInfo.ParentalRatingOptions);
if (item.MediaType == "Video" && item.Type != "Episode") {
2016-07-23 10:11:27 -07:00
showElement('#fldShortOverview', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldShortOverview', context);
2016-01-06 13:16:16 -07:00
}
if (item.MediaType == "Video" && item.Type != "Episode") {
2016-07-23 10:11:27 -07:00
showElement('#fldTagline', context);
2016-01-06 13:16:16 -07:00
} else {
2016-07-23 10:11:27 -07:00
hideElement('#fldTagline', context);
2016-01-06 13:16:16 -07:00
}
loading.hide();
2016-01-06 13:16:16 -07:00
});
}
return {
show: function (itemId, serverId) {
2016-01-06 13:16:16 -07:00
return new Promise(function (resolve, reject) {
loading.show();
2016-01-06 13:16:16 -07:00
var xhr = new XMLHttpRequest();
xhr.open('GET', 'components/metadataeditor/metadataeditor.template.html', true);
xhr.onload = function (e) {
var template = this.response;
2016-03-23 12:03:17 -07:00
var dlg = dialogHelper.createDialog({
2016-01-23 11:45:50 -07:00
removeOnClose: true,
2016-02-09 10:13:50 -07:00
size: 'medium'
2016-01-06 13:16:16 -07:00
});
2016-01-30 13:59:09 -07:00
dlg.classList.add('ui-body-b');
dlg.classList.add('background-theme-b');
2016-01-06 13:16:16 -07:00
dlg.classList.add('formDialog');
var html = '';
2016-03-05 12:07:58 -07:00
html += Globalize.translateDocument(template);
2016-01-06 13:16:16 -07:00
dlg.innerHTML = html;
document.body.appendChild(dlg);
2016-03-23 12:03:17 -07:00
dialogHelper.open(dlg);
2016-01-06 13:16:16 -07:00
2016-03-22 10:46:57 -07:00
dlg.addEventListener('close', function () {
unbindItemChanged(dlg, connectionManager.getApiClient(serverId));
2016-01-06 13:16:16 -07:00
resolve();
});
2016-02-15 21:54:20 -07:00
currentContext = dlg;
2016-01-06 13:16:16 -07:00
init(dlg, connectionManager.getApiClient(serverId));
2016-01-06 13:16:16 -07:00
reload(dlg, itemId, serverId);
2016-01-06 13:16:16 -07:00
}
2016-02-15 21:54:20 -07:00
xhr.send();
});
},
embed: function (elem, itemId, serverId) {
2016-02-15 21:54:20 -07:00
return new Promise(function (resolve, reject) {
loading.show();
2016-02-15 21:54:20 -07:00
var xhr = new XMLHttpRequest();
xhr.open('GET', 'components/metadataeditor/metadataeditor.template.html', true);
xhr.onload = function (e) {
var template = this.response;
2016-03-05 12:07:58 -07:00
elem.innerHTML = Globalize.translateDocument(template);
2016-02-15 21:54:20 -07:00
elem.querySelector('.btnCancel').classList.add('hide');
currentContext = elem;
init(elem, connectionManager.getApiClient(serverId));
reload(elem, itemId, serverId);
2016-02-15 21:54:20 -07:00
}
2016-01-06 13:16:16 -07:00
xhr.send();
});
}
};
});