2018-10-23 01:05:09 +03:00
|
|
|
define(["loading", "dialogHelper", "dom", "components/libraryoptionseditor/libraryoptionseditor", "emby-button", "listViewStyle", "paper-icon-button-light", "formDialogStyle", "emby-toggle", "flexStyles"], function(loading, dialogHelper, dom, libraryoptionseditor) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
function addMediaLocation(page, path, networkSharePath) {
|
2019-05-06 17:26:18 -07:00
|
|
|
var virtualFolder = currentOptions.library;
|
|
|
|
var refreshAfterChange = currentOptions.refresh;
|
2018-10-23 01:05:09 +03:00
|
|
|
ApiClient.addMediaPath(virtualFolder.Name, path, networkSharePath, refreshAfterChange).then(function() {
|
2019-05-06 17:26:18 -07:00
|
|
|
hasChanges = true;
|
|
|
|
refreshLibraryFromServer(page);
|
2018-10-23 01:05:09 +03:00
|
|
|
}, function() {
|
|
|
|
require(["toast"], function(toast) {
|
2019-05-06 17:26:18 -07:00
|
|
|
toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder"));
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateMediaLocation(page, path, networkSharePath) {
|
|
|
|
var virtualFolder = currentOptions.library;
|
|
|
|
ApiClient.updateMediaPath(virtualFolder.Name, {
|
|
|
|
Path: path,
|
|
|
|
NetworkPath: networkSharePath
|
|
|
|
}).then(function() {
|
2019-05-06 17:26:18 -07:00
|
|
|
hasChanges = true;
|
|
|
|
refreshLibraryFromServer(page);
|
2018-10-23 01:05:09 +03:00
|
|
|
}, function() {
|
|
|
|
require(["toast"], function(toast) {
|
2019-05-06 17:26:18 -07:00
|
|
|
toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder"));
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onRemoveClick(btnRemovePath, location) {
|
2019-05-06 17:26:18 -07:00
|
|
|
var button = btnRemovePath;
|
|
|
|
var virtualFolder = currentOptions.library;
|
2018-10-23 01:05:09 +03:00
|
|
|
require(["confirm"], function(confirm) {
|
|
|
|
confirm({
|
|
|
|
title: Globalize.translate("HeaderRemoveMediaLocation"),
|
|
|
|
text: Globalize.translate("MessageConfirmRemoveMediaLocation"),
|
|
|
|
confirmText: Globalize.translate("ButtonDelete"),
|
|
|
|
primary: "cancel"
|
|
|
|
}).then(function() {
|
|
|
|
var refreshAfterChange = currentOptions.refresh;
|
|
|
|
ApiClient.removeMediaPath(virtualFolder.Name, location, refreshAfterChange).then(function() {
|
2019-05-06 17:26:18 -07:00
|
|
|
hasChanges = true;
|
|
|
|
refreshLibraryFromServer(dom.parentWithClass(button, "dlg-libraryeditor"));
|
2018-10-23 01:05:09 +03:00
|
|
|
}, function() {
|
|
|
|
require(["toast"], function(toast) {
|
2019-05-06 17:26:18 -07:00
|
|
|
toast(Globalize.translate("DefaultErrorMessage"));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onListItemClick(e) {
|
|
|
|
var listItem = dom.parentWithClass(e.target, "listItem");
|
|
|
|
if (listItem) {
|
2019-05-06 17:26:18 -07:00
|
|
|
var index = parseInt(listItem.getAttribute("data-index"));
|
|
|
|
var pathInfos = (currentOptions.library.LibraryOptions || {}).PathInfos || [];
|
|
|
|
var pathInfo = null == index ? {} : pathInfos[index] || {};
|
|
|
|
var originalPath = pathInfo.Path || (null == index ? null : currentOptions.library.Locations[index]);
|
|
|
|
var btnRemovePath = dom.parentWithClass(e.target, "btnRemovePath");
|
2018-10-23 01:05:09 +03:00
|
|
|
if (btnRemovePath) return void onRemoveClick(btnRemovePath, originalPath);
|
2019-05-06 17:26:18 -07:00
|
|
|
showDirectoryBrowser(dom.parentWithClass(listItem, "dlg-libraryeditor"), originalPath, pathInfo.NetworkPath);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFolderHtml(pathInfo, index) {
|
|
|
|
var html = "";
|
2019-05-06 17:26:18 -07:00
|
|
|
html += '<div class="listItem listItem-border lnkPath" data-index="' + index + '" style="padding-left:.5em;">';
|
|
|
|
html += '<div class="' + (pathInfo.NetworkPath ? "listItemBody two-line" : "listItemBody") + '">';
|
|
|
|
html += '<h3 class="listItemBodyText">';
|
|
|
|
html += pathInfo.Path;
|
|
|
|
html += "</h3>";
|
|
|
|
if (pathInfo.NetworkPath) {
|
|
|
|
html += '<div class="listItemBodyText secondary">' + pathInfo.NetworkPath + "</div>";
|
|
|
|
}
|
|
|
|
html += "</div>";
|
|
|
|
html += '<button type="button" is="paper-icon-button-light" class="listItemButton btnRemovePath" data-index="' + index + '"><i class="md-icon">remove_circle</i></button>';
|
|
|
|
html += "</div>";
|
|
|
|
return html;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function refreshLibraryFromServer(page) {
|
|
|
|
ApiClient.getVirtualFolders().then(function(result) {
|
|
|
|
var library = result.filter(function(f) {
|
|
|
|
return f.Name === currentOptions.library.Name
|
|
|
|
})[0];
|
2019-05-06 17:26:18 -07:00
|
|
|
if (library) {
|
|
|
|
currentOptions.library = library;
|
|
|
|
renderLibrary(page, currentOptions);
|
|
|
|
}
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderLibrary(page, options) {
|
|
|
|
var pathInfos = (options.library.LibraryOptions || {}).PathInfos || [];
|
|
|
|
pathInfos.length || (pathInfos = options.library.Locations.map(function(p) {
|
|
|
|
return {
|
|
|
|
Path: p
|
|
|
|
}
|
2019-05-06 17:26:18 -07:00
|
|
|
}));
|
|
|
|
if (options.library.CollectionType === 'boxsets') {
|
|
|
|
page.querySelector(".folders").classList.add("hide");
|
|
|
|
} else {
|
|
|
|
page.querySelector(".folders").classList.remove("hide");
|
|
|
|
}
|
|
|
|
page.querySelector(".folderList").innerHTML = pathInfos.map(getFolderHtml).join("");
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onAddButtonClick() {
|
2019-05-06 17:26:18 -07:00
|
|
|
showDirectoryBrowser(dom.parentWithClass(this, "dlg-libraryeditor"));
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function showDirectoryBrowser(context, originalPath, networkPath) {
|
|
|
|
require(["directorybrowser"], function(directoryBrowser) {
|
|
|
|
var picker = new directoryBrowser;
|
|
|
|
picker.show({
|
|
|
|
enableNetworkSharePath: !0,
|
|
|
|
pathReadOnly: null != originalPath,
|
|
|
|
path: originalPath,
|
|
|
|
networkSharePath: networkPath,
|
|
|
|
callback: function(path, networkSharePath) {
|
2019-05-06 17:26:18 -07:00
|
|
|
path && (originalPath ? updateMediaLocation(context, originalPath, networkSharePath) : addMediaLocation(context, path, networkSharePath));
|
|
|
|
picker.close();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function onToggleAdvancedChange() {
|
|
|
|
var dlg = dom.parentWithClass(this, "dlg-libraryeditor");
|
|
|
|
libraryoptionseditor.setAdvancedVisible(dlg.querySelector(".libraryOptions"), this.checked)
|
|
|
|
}
|
|
|
|
|
|
|
|
function initEditor(dlg, options) {
|
2019-05-06 17:26:18 -07:00
|
|
|
renderLibrary(dlg, options);
|
|
|
|
dlg.querySelector(".btnAddFolder").addEventListener("click", onAddButtonClick);
|
|
|
|
dlg.querySelector(".folderList").addEventListener("click", onListItemClick);
|
|
|
|
dlg.querySelector(".chkAdvanced").addEventListener("change", onToggleAdvancedChange);
|
|
|
|
libraryoptionseditor.embed(dlg.querySelector(".libraryOptions"), options.library.CollectionType, options.library.LibraryOptions).then(function() {
|
|
|
|
onToggleAdvancedChange.call(dlg.querySelector(".chkAdvanced"));
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onDialogClosing() {
|
2019-05-06 17:26:18 -07:00
|
|
|
var dlg = this;
|
|
|
|
var libraryOptions = libraryoptionseditor.getLibraryOptions(dlg.querySelector(".libraryOptions"));
|
|
|
|
libraryOptions = Object.assign(currentOptions.library.LibraryOptions || {}, libraryOptions);
|
|
|
|
ApiClient.updateVirtualFolderOptions(currentOptions.library.ItemId, libraryOptions);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onDialogClosed() {
|
2019-05-06 17:26:18 -07:00
|
|
|
loading.hide();
|
|
|
|
hasChanges = true;
|
|
|
|
currentDeferred.resolveWith(null, [hasChanges]);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function editor() {
|
|
|
|
this.show = function(options) {
|
|
|
|
var deferred = jQuery.Deferred();
|
2019-05-06 17:26:18 -07:00
|
|
|
currentOptions = options;
|
|
|
|
currentDeferred = deferred;
|
|
|
|
hasChanges = false;
|
2018-10-23 01:05:09 +03:00
|
|
|
var xhr = new XMLHttpRequest;
|
2019-05-06 17:26:18 -07:00
|
|
|
xhr.open("GET", "components/medialibraryeditor/medialibraryeditor.template.html", true);
|
|
|
|
xhr.onload = function(e) {
|
|
|
|
var template = this.response;
|
|
|
|
var dlg = dialogHelper.createDialog({
|
|
|
|
size: "medium-tall",
|
|
|
|
modal: false,
|
|
|
|
removeOnClose: true,
|
|
|
|
scrollY: false
|
|
|
|
});
|
|
|
|
dlg.classList.add("dlg-libraryeditor");
|
|
|
|
dlg.classList.add("ui-body-a");
|
|
|
|
dlg.classList.add("background-theme-a");
|
|
|
|
dlg.classList.add("formDialog");
|
|
|
|
dlg.innerHTML = Globalize.translateDocument(template);
|
|
|
|
dlg.querySelector(".formDialogHeaderTitle").innerHTML = options.library.Name;
|
|
|
|
initEditor(dlg, options);
|
|
|
|
dlg.addEventListener("closing", onDialogClosing);
|
|
|
|
dlg.addEventListener("close", onDialogClosed);
|
|
|
|
dialogHelper.open(dlg);
|
|
|
|
dlg.querySelector(".btnCancel").addEventListener("click", function() {
|
|
|
|
dialogHelper.close(dlg);
|
|
|
|
});
|
|
|
|
refreshLibraryFromServer(dlg);
|
|
|
|
};
|
|
|
|
xhr.send();
|
|
|
|
return deferred.promise();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
2019-05-06 17:26:18 -07:00
|
|
|
|
|
|
|
var currentDeferred;
|
|
|
|
var currentOptions;
|
|
|
|
|
2019-05-06 21:26:48 -07:00
|
|
|
var hasChanges = false;
|
|
|
|
|
2019-05-06 17:26:18 -07:00
|
|
|
return editor;
|
2018-10-23 01:05:09 +03:00
|
|
|
});
|