var MediaLibraryPage = { addMediaLocation: function (virtualFolderIndex) { MediaLibraryPage.selectDirectory(function (path) { if (path) { var virtualFolder = MediaLibraryPage.virtualFolders[virtualFolderIndex]; MediaLibraryPage.lastVirtualFolderName = virtualFolder.Name; var refreshAfterChange = shouldRefreshLibraryAfterChanges(); ApiClient.addMediaPath(virtualFolder.Name, path, refreshAfterChange).done(MediaLibraryPage.processOperationResult); } }); }, selectDirectory: function (callback) { require(['directorybrowser'], function (directoryBrowser) { var picker = new directoryBrowser(); picker.show({ callback: callback }); MediaLibraryPage.directoryPicker = picker; }); }, deleteMediaLocation: function (button) { var folderIndex = button.getAttribute('data-folderindex'); var index = parseInt(button.getAttribute('data-index')); var virtualFolder = MediaLibraryPage.virtualFolders[folderIndex]; MediaLibraryPage.lastVirtualFolderName = virtualFolder.Name; var location = virtualFolder.Locations[index]; Dashboard.confirm(Globalize.translate('MessageConfirmRemoveMediaLocation'), Globalize.translate('HeaderRemoveMediaLocation'), function (confirmResult) { if (confirmResult) { var refreshAfterChange = shouldRefreshLibraryAfterChanges(); ApiClient.removeMediaPath(virtualFolder.Name, location, refreshAfterChange).done(MediaLibraryPage.processOperationResult); } }); } }; (function () { function changeCollectionType(page, virtualFolder) { Dashboard.alert({ message: Globalize.translate('HeaderChangeFolderTypeHelp'), title: Globalize.translate('HeaderChangeFolderType') }); } function processOperationResult(result) { var page = $($.mobile.activePage)[0]; reloadLibrary(page); } function addVirtualFolder(page) { //$('#textEntryForm', popup).on('submit', function () { // if (callback) { // if (showCollectionType) { // var collectionType = $('#selectCollectionType', popup).val(); // // The server expects an empty value for mixed // if (collectionType == 'mixed') { // collectionType = ''; // } // callback($('#txtValue', popup).val(), collectionType); // } else { // callback($('#txtValue', popup).val()); // } // } // return false; //}); require(['medialibraryeditor'], function (medialibraryeditor) { new medialibraryeditor().show({ collectionTypeOptions: getCollectionTypeOptions(), refresh: shouldRefreshLibraryAfterChanges() }).done(function (hasChanges) { if (hasChanges) { reloadLibrary(page); } }); }); } function deleteVirtualFolder(page, virtualFolder) { var msg = Globalize.translate('MessageAreYouSureYouWishToRemoveMediaFolder'); if (virtualFolder.Locations.length) { msg += "

" + Globalize.translate("MessageTheFollowingLocationWillBeRemovedFromLibrary") + "

"; msg += virtualFolder.Locations.join("
"); } Dashboard.confirm(msg, Globalize.translate('HeaderRemoveMediaFolder'), function (confirmResult) { if (confirmResult) { var refreshAfterChange = shouldRefreshLibraryAfterChanges(); ApiClient.removeVirtualFolder(virtualFolder.Name, refreshAfterChange).done(processOperationResult); } }); } function renameVirtualFolder(page, virtualFolder) { require(['prompt'], function (prompt) { prompt({ text: Globalize.translate('LabelNewName'), title: Globalize.translate('HeaderRenameMediaFolder'), callback: function (newName) { if (newName && newName != virtualFolder.Name) { var refreshAfterChange = shouldRefreshLibraryAfterChanges(); ApiClient.renameVirtualFolder(virtualFolder.Name, newName, refreshAfterChange).done(processOperationResult); } } }); }); } function showCardMenu(page, elem, virtualFolders) { var card = $(elem).parents('.card')[0]; var index = parseInt(card.getAttribute('data-index')); var virtualFolder = virtualFolders[index]; var menuItems = []; menuItems.push({ name: Globalize.translate('ButtonChangeType'), id: 'changetype', ironIcon: 'folder' }); menuItems.push({ name: Globalize.translate('ButtonRemove'), id: 'delete', ironIcon: 'remove' }); menuItems.push({ name: Globalize.translate('ButtonRename'), id: 'rename', ironIcon: 'mode-edit' }); require(['actionsheet'], function () { ActionSheetElement.show({ items: menuItems, positionTo: elem, callback: function (resultId) { switch (resultId) { case 'changetype': changeCollectionType(page, virtualFolder); break; case 'rename': renameVirtualFolder(page, virtualFolder); break; case 'delete': deleteVirtualFolder(page, virtualFolder); break; default: break; } } }); }); } function reloadLibrary(page) { Dashboard.showLoadingMsg(); ApiClient.getVirtualFolders().done(function (result) { reloadVirtualFolders(page, result); }); } function shouldRefreshLibraryAfterChanges() { return $($.mobile.activePage).is('#mediaLibraryPage'); } function reloadVirtualFolders(page, virtualFolders) { var html = ''; virtualFolders.push({ Name: Globalize.translate('ButtonAddMediaLibrary'), icon: 'add-circle', Locations: [], showType: false, showLocations: false, showMenu: false, showNameWithIcon: true, color: 'green', contentClass: 'addLibrary' }); for (var i = 0, length = virtualFolders.length; i < length; i++) { var virtualFolder = virtualFolders[i]; html += getVirtualFolderHtml(virtualFolder, i); } var divVirtualFolders = page.querySelector('#divVirtualFolders'); divVirtualFolders.innerHTML = html; $('.btnCardMenu', divVirtualFolders).on('click', function () { showCardMenu(page, this, virtualFolders); }); $('.addLibrary', divVirtualFolders).on('click', function () { addVirtualFolder(page); }); Dashboard.hideLoadingMsg(); } function getCollectionTypeOptions() { return [ { name: "", value: "" }, { name: Globalize.translate('FolderTypeMovies'), value: "movies" }, { name: Globalize.translate('FolderTypeMusic'), value: "music" }, { name: Globalize.translate('FolderTypeTvShows'), value: "tvshows" }, { name: Globalize.translate('FolderTypeBooks'), value: "books", message: Globalize.translate('MessageBookPluginRequired') }, { name: Globalize.translate('FolderTypeGames'), value: "games", message: Globalize.translate('MessageGamePluginRequired') }, { name: Globalize.translate('FolderTypeHomeVideos'), value: "homevideos" }, { name: Globalize.translate('FolderTypeMusicVideos'), value: "musicvideos" }, { name: Globalize.translate('FolderTypePhotos'), value: "photos" }, { name: Globalize.translate('FolderTypeUnset'), value: "mixed", message: Globalize.translate('MessageUnsetContentHelp') } ]; } function getIcon(type) { switch (type) { case "movies": return "local-movies"; case "music": return "library-music"; case "photos": return "photo"; case "livetv": return "live-tv"; case "tvshows": return "live-tv"; case "games": return "folder"; case "trailers": return "local-movies"; case "homevideos": return "video-library"; case "musicvideos": return "video-library"; case "books": return "folder"; case "channels": return "folder"; case "playlists": return "folder"; default: return "folder"; } } function getVirtualFolderHtml(virtualFolder, index) { var html = ''; html += '
'; html += '
'; html += '
'; html += '
'; var contentClass = "cardContent"; if (virtualFolder.contentClass) { contentClass += " " + virtualFolder.contentClass; } html += '
'; var imgUrl = ''; if (virtualFolder.PrimaryImageItemId) { imgUrl = ApiClient.getScaledImageUrl(virtualFolder.PrimaryImageItemId, { type: 'Primary' }); } if (imgUrl) { html += '
'; } else { html += '
'; if (virtualFolder.color) { html += '
'; } else { html += '
'; } html += ''; if (virtualFolder.showNameWithIcon) { html += '
'; html += virtualFolder.Name; html += "
"; } html += "
"; html += '
'; } // cardContent html += "
"; // cardScalable html += "
"; html += '
'; if (virtualFolder.showMenu !== false) { html += '
'; html += ''; html += "
"; } html += "
"; if (virtualFolder.showNameWithIcon) { html += ' '; } else { html += virtualFolder.Name; } html += "
"; var typeName = getCollectionTypeOptions().filter(function (t) { return t.value == virtualFolder.CollectionType; })[0]; typeName = typeName ? typeName.name : Globalize.translate('FolderTypeUnset'); html += "
"; if (virtualFolder.showType === false) { html += ' '; } else { html += typeName; } html += "
"; if (virtualFolder.showLocations === false) { html += "
"; html += ' '; html += "
"; } else if (!virtualFolder.Locations.length) { html += "
"; html += Globalize.translate('NumLocationsValue', virtualFolder.Locations.length); html += "
"; } else if (virtualFolder.Locations.length == 1) { html += "
"; html += virtualFolder.Locations[0]; html += "
"; } else { html += "
"; html += Globalize.translate('NumLocationsValue', virtualFolder.Locations.length); html += "
"; } // cardFooter html += "
"; // cardBox html += "
"; // card html += "
"; return html; } pageClassOn('pageinit', "mediaLibraryPage", function () { var page = this; $('#selectCollectionType', page).on('change', function () { var index = this.selectedIndex; if (index != -1) { var name = this.options[index].innerHTML .replace('*', '') .replace('&', '&'); var value = this.value; $('#txtValue', page).val(name); var folderOption = getCollectionTypeOptions().filter(function (i) { return i.value == value; })[0]; $('.collectionTypeFieldDescription', page).html(folderOption.message || ''); } }); }); pageClassOn('pageshow', "mediaLibraryPage", function () { var page = this; reloadLibrary(page); }); })(); var WizardLibraryPage = { next: function () { Dashboard.showLoadingMsg(); var apiClient = ApiClient; apiClient.ajax({ type: "POST", url: apiClient.getUrl('System/Configuration/MetadataPlugins/Autoset') }).done(function () { Dashboard.hideLoadingMsg(); Dashboard.navigate('wizardsettings.html'); }); } }; (function ($, document, window) { pageIdOn('pageshow', "mediaLibraryPage", function () { var page = this; // on here $('.btnRefresh', page).taskButton({ mode: 'on', progressElem: page.querySelector('.refreshProgress'), lastResultElem: $('.lastRefreshResult', page), taskKey: 'RefreshLibrary' }); }); pageIdOn('pagebeforehide', "mediaLibraryPage", function () { var page = this; // off here $('.btnRefresh', page).taskButton({ mode: 'off' }); }); })(jQuery, document, window);