/* eslint-disable indent */ /** * Module for media library editor. * @module components/mediaLibraryEditor/mediaLibraryEditor */ 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.css'; import '../../elements/emby-button/paper-icon-button-light'; import '../formdialog.css'; import '../../elements/emby-toggle/emby-toggle'; import '../../assets/css/flexstyles.css'; 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); }, () => { import('../toast/toast').then((toast) => { 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); }, () => { import('../toast/toast').then((toast) => { toast(globalize.translate('ErrorAddingMediaPathToVirtualFolder')); }); }); } function onRemoveClick(btnRemovePath, location) { const button = btnRemovePath; const virtualFolder = currentOptions.library; import('../confirm/confirm').then(({default: confirm}) => { 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')); }, () => { import('../toast/toast').then((toast) => { toast(globalize.translate('ErrorDefault')); }); }); }); }); } function onListItemClick(e) { const listItem = dom.parentWithClass(e.target, 'listItem'); if (listItem) { const index = parseInt(listItem.getAttribute('data-index')); 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 += `