/** * Module for media library editor. * @module components/mediaLibraryEditor/mediaLibraryEditor */ import escapeHtml from 'escape-html'; import 'jquery'; import loading from '../loading/loading'; import dialogHelper from '../dialogHelper/dialogHelper'; import dom from '../../scripts/dom'; import libraryoptionseditor from '../libraryoptionseditor/libraryoptionseditor'; import globalize from '../../scripts/globalize'; import '../../elements/emby-button/emby-button'; import '../listview/listview.scss'; import '../../elements/emby-button/paper-icon-button-light'; import '../formdialog.scss'; import '../../elements/emby-toggle/emby-toggle'; import '../../styles/flexstyles.scss'; import './style.scss'; import toast from '../toast/toast'; import confirm from '../confirm/confirm'; import template from './mediaLibraryEditor.template.html'; function onEditLibrary() { if (isCreating) { return false; } isCreating = true; loading.show(); const dlg = dom.parentWithClass(this, 'dlg-libraryeditor'); let libraryOptions = libraryoptionseditor.getLibraryOptions(dlg.querySelector('.libraryOptions')); libraryOptions = Object.assign(currentOptions.library.LibraryOptions || {}, libraryOptions); ApiClient.updateVirtualFolderOptions(currentOptions.library.ItemId, libraryOptions).then(() => { hasChanges = true; isCreating = false; loading.hide(); dialogHelper.close(dlg); }, () => { isCreating = false; loading.hide(); }); return false; } function addMediaLocation(page, path, networkSharePath) { const virtualFolder = currentOptions.library; const refreshAfterChange = currentOptions.refresh; ApiClient.addMediaPath(virtualFolder.Name, path, networkSharePath, refreshAfterChange).then(() => { hasChanges = true; refreshLibraryFromServer(page); }, () => { toast(globalize.translate('ErrorAddingMediaPathToVirtualFolder')); }); } function updateMediaLocation(page, path, networkSharePath) { const virtualFolder = currentOptions.library; ApiClient.updateMediaPath(virtualFolder.Name, { Path: path, NetworkPath: networkSharePath }).then(() => { hasChanges = true; refreshLibraryFromServer(page); }, () => { toast(globalize.translate('ErrorAddingMediaPathToVirtualFolder')); }); } function onRemoveClick(btnRemovePath, location) { const button = btnRemovePath; const virtualFolder = currentOptions.library; confirm({ title: globalize.translate('HeaderRemoveMediaLocation'), text: globalize.translate('MessageConfirmRemoveMediaLocation'), confirmText: globalize.translate('Delete'), primary: 'delete' }).then(() => { const refreshAfterChange = currentOptions.refresh; ApiClient.removeMediaPath(virtualFolder.Name, location, refreshAfterChange).then(() => { hasChanges = true; refreshLibraryFromServer(dom.parentWithClass(button, 'dlg-libraryeditor')); }, () => { toast(globalize.translate('ErrorDefault')); }); }); } function onListItemClick(e) { const listItem = dom.parentWithClass(e.target, 'listItem'); if (listItem) { const index = parseInt(listItem.getAttribute('data-index'), 10); const pathInfos = currentOptions.library.LibraryOptions?.PathInfos || []; const pathInfo = index == null ? {} : pathInfos[index] || {}; const originalPath = pathInfo.Path || (index == null ? null : currentOptions.library.Locations[index]); const btnRemovePath = dom.parentWithClass(e.target, 'btnRemovePath'); if (btnRemovePath) { onRemoveClick(btnRemovePath, originalPath); return; } showDirectoryBrowser(dom.parentWithClass(listItem, 'dlg-libraryeditor'), originalPath, pathInfo.NetworkPath); } } function getFolderHtml(pathInfo, index) { let html = ''; html += `