jellyfin-web/dashboard-ui/components/medialibrarycreator/medialibrarycreator.js

160 lines
4.4 KiB
JavaScript
Raw Normal View History

2015-10-15 11:48:43 -07:00
define([], function () {
var currentDeferred;
var hasChanges;
var currentOptions;
function onSubmit() {
var form = this;
var dlg = $(form).parents('paper-dialog')[0];
2015-10-15 19:06:44 -07:00
var name = $('#txtValue', form).val();
var type = $('#selectCollectionType', form).val();
var path = $('#txtPath', form).val();
ApiClient.addVirtualFolder(name, type, currentOptions.refresh, path).done(function () {
2015-10-15 11:48:43 -07:00
hasChanges = true;
PaperDialogHelper.close(dlg);
}).fail(function () {
Dashboard.showError(Globalize.translate('DefaultErrorMessage'));
});
return false;
}
function getCollectionTypeOptionsHtml(collectionTypeOptions) {
return collectionTypeOptions.filter(function (i) {
return i.isSelectable !== false;
}).map(function (i) {
return '<option value="' + i.value + '">' + i.name + '</option>';
}).join("");
}
function initEditor(page, collectionTypeOptions) {
2015-10-15 19:06:44 -07:00
$('#selectCollectionType', page).html(getCollectionTypeOptionsHtml(collectionTypeOptions)).val('').on('change', function () {
var dlg = $(this).parents('paper-dialog')[0];
var index = this.selectedIndex;
if (index != -1) {
var name = this.options[index].innerHTML
.replace('*', '')
.replace('&amp;', '&');
var value = this.value;
$('#txtValue', dlg).val(name);
var folderOption = collectionTypeOptions.filter(function (i) {
return i.value == value;
})[0];
$('.collectionTypeFieldDescription', dlg).html(folderOption.message || '');
}
});
$('#btnSelectPath').on('click', function () {
require(['directorybrowser'], function (directoryBrowser) {
var picker = new directoryBrowser();
picker.show({
callback: function (path) {
if (path) {
$('#txtPath', page).val(path);
}
picker.close();
}
});
});
});
2015-10-15 11:48:43 -07:00
$('form', page).off('submit', onSubmit).on('submit', onSubmit);
}
function onDialogClosed() {
$(this).remove();
Dashboard.hideLoadingMsg();
currentDeferred.resolveWith(null, [hasChanges]);
}
function editor() {
var self = this;
self.show = function (options) {
var deferred = DeferredBuilder.Deferred();
currentOptions = options;
currentDeferred = deferred;
hasChanges = false;
require(['components/paperdialoghelper'], function () {
HttpClient.send({
type: 'GET',
2015-10-15 19:06:44 -07:00
url: 'components/medialibrarycreator/medialibrarycreator.template.html'
2015-10-15 11:48:43 -07:00
}).done(function (template) {
var dlg = PaperDialogHelper.createDialog({
size: 'small',
theme: 'a'
});
var html = '';
html += '<h2 class="dialogHeader">';
html += '<paper-fab icon="arrow-back" class="mini btnCloseDialog"></paper-fab>';
var title = Globalize.translate('ButtonAddMediaLibrary');
html += '<div style="display:inline-block;margin-left:.6em;vertical-align:middle;">' + title + '</div>';
html += '</h2>';
html += '<div class="editorContent" style="max-width:800px;margin:auto;">';
html += Globalize.translateDocument(template);
html += '</div>';
dlg.innerHTML = html;
document.body.appendChild(dlg);
var editorContent = dlg.querySelector('.editorContent');
initEditor(editorContent, options.collectionTypeOptions);
$(dlg).on('iron-overlay-closed', onDialogClosed);
2015-10-15 19:06:44 -07:00
PaperDialogHelper.openWithHash(dlg, 'medialibrarycreator');
2015-10-15 11:48:43 -07:00
$('.btnCloseDialog', dlg).on('click', function () {
PaperDialogHelper.close(dlg);
});
});
});
return deferred.promise();
};
}
return editor;
});