define([], function () { function onSubmit() { Dashboard.showLoadingMsg(); var panel = $(this).parents('paper-dialog')[0]; var collectionId = $('#selectCollectionToAddTo', panel).val(); if (collectionId) { addToCollection(panel, collectionId); } else { createCollection(panel); } return false; } function createCollection(dlg) { var url = ApiClient.getUrl("Collections", { Name: $('#txtNewCollectionName', dlg).val(), IsLocked: !$('#chkEnableInternetMetadata', dlg).checked(), Ids: $('.fldSelectedItemIds', dlg).val() || '' //ParentId: getParameterByName('parentId') || LibraryMenu.getTopParentId() }); ApiClient.ajax({ type: "POST", url: url, dataType: "json" }).then(function (result) { Dashboard.hideLoadingMsg(); var id = result.Id; PaperDialogHelper.close(dlg); redirectToCollection(id); }); } function redirectToCollection(id) { var context = getParameterByName('context'); ApiClient.getItem(Dashboard.getCurrentUserId(), id).then(function (item) { Dashboard.navigate(LibraryBrowser.getHref(item, context)); }); } function addToCollection(dlg, id) { var url = ApiClient.getUrl("Collections/" + id + "/Items", { Ids: $('.fldSelectedItemIds', dlg).val() || '' }); ApiClient.ajax({ type: "POST", url: url }).then(function () { Dashboard.hideLoadingMsg(); PaperDialogHelper.close(dlg); Dashboard.alert(Globalize.translate('MessageItemsAdded')); }); } function onDialogClosed() { $(this).remove(); Dashboard.hideLoadingMsg(); } function populateCollections(panel) { Dashboard.showLoadingMsg(); var select = $('#selectCollectionToAddTo', panel); $('.newCollectionInfo', panel).hide(); var options = { Recursive: true, IncludeItemTypes: "BoxSet", SortBy: "SortName" }; ApiClient.getItems(Dashboard.getCurrentUserId(), options).then(function (result) { var html = ''; html += ''; html += result.Items.map(function (i) { return ''; }); select.html(html).val('').trigger('change'); Dashboard.hideLoadingMsg(); }); } function getEditorHtml() { var html = ''; html += '
'; return html; } function initEditor(content, items) { $('#selectCollectionToAddTo', content).on('change', function () { if (this.value) { $('.newCollectionInfo', content).hide(); $('#txtNewCollectionName', content).removeAttr('required'); } else { $('.newCollectionInfo', content).show(); $('#txtNewCollectionName', content).attr('required', 'required'); } }); $('.newCollectionForm', content).off('submit', onSubmit).on('submit', onSubmit); $('.fldSelectedItemIds', content).val(items.join(',')); if (items.length) { $('.fldSelectCollection', content).show(); populateCollections(content); } else { $('.fldSelectCollection', content).hide(); $('#selectCollectionToAddTo', content).html('').val('').trigger('change'); } } function collectioneditor() { var self = this; self.show = function (items) { items = items || []; require(['components/paperdialoghelper'], function () { var dlg = PaperDialogHelper.createDialog({ size: 'small' }); var html = ''; html += '