define(["dialogHelper", "loading", "apphost", "layoutManager", "connectionManager", "appRouter", "globalize", "emby-checkbox", "emby-input", "paper-icon-button-light", "emby-select", "material-icons", "css!./../formdialog", "emby-button", "emby-linkbutton", "flexStyles"], function(dialogHelper, loading, appHost, layoutManager, connectionManager, appRouter, globalize) { "use strict"; function parentWithClass(elem, className) { for (; !elem.classList || !elem.classList.contains(className);) if (!(elem = elem.parentNode)) return null; return elem } function onSubmit(e) { loading.show(); var panel = parentWithClass(this, "dialog"), collectionId = panel.querySelector("#selectCollectionToAddTo").value, apiClient = connectionManager.getApiClient(currentServerId); return collectionId ? addToCollection(apiClient, panel, collectionId) : createCollection(apiClient, panel), e.preventDefault(), !1 } function createCollection(apiClient, dlg) { var url = apiClient.getUrl("Collections", { Name: dlg.querySelector("#txtNewCollectionName").value, IsLocked: !dlg.querySelector("#chkEnableInternetMetadata").checked, Ids: dlg.querySelector(".fldSelectedItemIds").value || "" }); apiClient.ajax({ type: "POST", url: url, dataType: "json" }).then(function(result) { loading.hide(); var id = result.Id; dlg.submitted = !0, dialogHelper.close(dlg), redirectToCollection(apiClient, id) }) } function redirectToCollection(apiClient, id) { appRouter.showItem(id, apiClient.serverId()) } function addToCollection(apiClient, dlg, id) { var url = apiClient.getUrl("Collections/" + id + "/Items", { Ids: dlg.querySelector(".fldSelectedItemIds").value || "" }); apiClient.ajax({ type: "POST", url: url }).then(function() { loading.hide(), dlg.submitted = !0, dialogHelper.close(dlg), require(["toast"], function(toast) { toast(globalize.translate("sharedcomponents#MessageItemsAdded")) }) }) } function triggerChange(select) { select.dispatchEvent(new CustomEvent("change", {})) } function populateCollections(panel) { loading.show(); var select = panel.querySelector("#selectCollectionToAddTo"); panel.querySelector(".newCollectionInfo").classList.add("hide"); var options = { Recursive: !0, IncludeItemTypes: "BoxSet", SortBy: "SortName", EnableTotalRecordCount: !1 }, apiClient = connectionManager.getApiClient(currentServerId); apiClient.getItems(apiClient.getCurrentUserId(), options).then(function(result) { var html = ""; html += '", html += result.Items.map(function(i) { return '" }), select.innerHTML = html, select.value = "", triggerChange(select), loading.hide() }) } function getEditorHtml() { var html = ""; return html += '