define(['dialogHelper', 'jQuery', 'components/libraryoptionseditor/libraryoptionseditor', 'emby-input', 'emby-select', 'paper-icon-button-light', 'listViewStyle', 'formDialogStyle'], function (dialogHelper, $, libraryoptionseditor) { var currentDeferred; var hasChanges; var currentOptions; var paths = []; function onSubmit() { if (paths.length == 0) { require(['alert'], function (alert) { alert({ text: Globalize.translate('PleaseAddAtLeastOneFolder'), type: 'error' }); }); return false; } var form = this; var dlg = $(form).parents('.dialog')[0]; var name = $('#txtValue', form).val(); var type = $('#selectCollectionType', form).val(); if (type == 'mixed') { type = null; } var libraryOptions = libraryoptionseditor.getLibraryOptions(dlg.querySelector('.libraryOptions')); ApiClient.addVirtualFolder(name, type, currentOptions.refresh, paths, libraryOptions).then(function () { hasChanges = true; dialogHelper.close(dlg); }, function () { require(['toast'], function (toast) { toast(Globalize.translate('ErrorAddingMediaPathToVirtualFolder')); }); }); return false; } function getCollectionTypeOptionsHtml(collectionTypeOptions) { return collectionTypeOptions.filter(function (i) { return i.isSelectable !== false; }).map(function (i) { return ''; }).join(""); } function initEditor(page, collectionTypeOptions) { $('#selectCollectionType', page).html(getCollectionTypeOptionsHtml(collectionTypeOptions)).val('').on('change', function () { var value = this.value; var dlg = $(this).parents('.dialog')[0]; libraryoptionseditor.setContentType(dlg.querySelector('.libraryOptions'), (value == 'mixed' ? '' : value)); if (value) { dlg.querySelector('.libraryOptions').classList.remove('hide'); } else { dlg.querySelector('.libraryOptions').classList.add('hide'); } if (value == 'mixed') { return; } var index = this.selectedIndex; if (index != -1) { var name = this.options[index].innerHTML .replace('*', '') .replace('&', '&'); $('#txtValue', dlg).val(name); var folderOption = collectionTypeOptions.filter(function (i) { return i.value == value; })[0]; $('.collectionTypeFieldDescription', dlg).html(folderOption.message || ''); } }); $('.btnAddFolder', page).on('click', onAddButtonClick); $('form', page).off('submit', onSubmit).on('submit', onSubmit); } function onAddButtonClick() { var page = $(this).parents('.dlg-librarycreator')[0]; require(['directorybrowser'], function (directoryBrowser) { var picker = new directoryBrowser(); picker.show({ callback: function (path) { if (path) { addMediaLocation(page, path); } picker.close(); } }); }); } function getFolderHtml(path, index) { var html = ''; html += '