2016-08-06 07:07:44 -07:00
|
|
|
|
define(['dialogHelper', 'jQuery', 'emby-button', 'listViewStyle', 'paper-icon-button-light'], function (dialogHelper, $) {
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
|
|
|
|
var currentDeferred;
|
|
|
|
|
var hasChanges;
|
|
|
|
|
var currentOptions;
|
|
|
|
|
|
|
|
|
|
function addMediaLocation(page, path) {
|
|
|
|
|
|
|
|
|
|
var virtualFolder = currentOptions.library;
|
|
|
|
|
|
|
|
|
|
var refreshAfterChange = currentOptions.refresh;
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.addMediaPath(virtualFolder.Name, path, refreshAfterChange).then(function () {
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2015-10-16 11:55:35 -07:00
|
|
|
|
hasChanges = true;
|
2015-10-15 20:17:42 -07:00
|
|
|
|
refreshLibraryFromServer(page);
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
}, function () {
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2016-02-24 23:38:12 -07:00
|
|
|
|
require(['toast'], function (toast) {
|
|
|
|
|
toast(Globalize.translate('ErrorAddingMediaPathToVirtualFolder'));
|
|
|
|
|
});
|
2015-10-16 11:55:35 -07:00
|
|
|
|
});
|
2015-10-15 20:17:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onRemoveClick() {
|
|
|
|
|
|
|
|
|
|
var button = this;
|
|
|
|
|
var index = parseInt(button.getAttribute('data-index'));
|
|
|
|
|
|
|
|
|
|
var virtualFolder = currentOptions.library;
|
|
|
|
|
|
|
|
|
|
var location = virtualFolder.Locations[index];
|
|
|
|
|
|
2016-02-22 12:12:06 -07:00
|
|
|
|
require(['confirm'], function (confirm) {
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2016-02-22 12:12:06 -07:00
|
|
|
|
confirm(Globalize.translate('MessageConfirmRemoveMediaLocation'), Globalize.translate('HeaderRemoveMediaLocation')).then(function () {
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
|
|
|
|
var refreshAfterChange = currentOptions.refresh;
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.removeMediaPath(virtualFolder.Name, location, refreshAfterChange).then(function () {
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2015-10-16 11:55:35 -07:00
|
|
|
|
hasChanges = true;
|
2015-10-15 20:17:42 -07:00
|
|
|
|
refreshLibraryFromServer($(button).parents('.editorContent')[0]);
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
}, function () {
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2016-02-24 23:38:12 -07:00
|
|
|
|
require(['toast'], function (toast) {
|
|
|
|
|
toast(Globalize.translate('DefaultErrorMessage'));
|
|
|
|
|
});
|
2015-10-15 20:17:42 -07:00
|
|
|
|
});
|
2016-02-22 12:12:06 -07:00
|
|
|
|
});
|
2015-10-15 20:17:42 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getFolderHtml(path, index) {
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
2016-08-06 07:07:44 -07:00
|
|
|
|
html += '<div class="listItem lnkPath">';
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2016-08-06 07:07:44 -07:00
|
|
|
|
html += '<i class="listItemIcon md-icon">folder</i>';
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2016-08-06 07:07:44 -07:00
|
|
|
|
html += '<div class="listItemBody">';
|
|
|
|
|
html += '<h3 class="listItemBodyText">';
|
2015-10-15 20:17:42 -07:00
|
|
|
|
html += path;
|
2016-08-06 07:07:44 -07:00
|
|
|
|
html += '</h3>';
|
|
|
|
|
html += '</div>';
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2016-08-06 07:07:44 -07:00
|
|
|
|
html += '<button is="paper-icon-button-light" class="btnRemovePath" data-index="' + index + '"><i class="md-icon">remove_circle</i></button>';
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2016-08-06 07:07:44 -07:00
|
|
|
|
html += '</div>';
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
|
|
|
|
return html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function refreshLibraryFromServer(page) {
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getVirtualFolders().then(function (result) {
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
|
|
|
|
var library = result.filter(function (f) {
|
|
|
|
|
|
|
|
|
|
return f.Name == currentOptions.library.Name;
|
|
|
|
|
|
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
|
|
if (library) {
|
|
|
|
|
currentOptions.library = library;
|
|
|
|
|
renderLibrary(page, currentOptions);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderLibrary(page, options) {
|
|
|
|
|
var foldersHtml = options.library.Locations.map(getFolderHtml).join('');
|
|
|
|
|
|
|
|
|
|
page.querySelector('.folderList').innerHTML = foldersHtml;
|
|
|
|
|
|
|
|
|
|
$(page.querySelectorAll('.btnRemovePath')).on('click', onRemoveClick);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onAddButtonClick() {
|
|
|
|
|
|
|
|
|
|
var page = $(this).parents('.editorContent')[0];
|
|
|
|
|
|
|
|
|
|
require(['directorybrowser'], function (directoryBrowser) {
|
|
|
|
|
|
|
|
|
|
var picker = new directoryBrowser();
|
|
|
|
|
|
|
|
|
|
picker.show({
|
|
|
|
|
|
|
|
|
|
callback: function (path) {
|
|
|
|
|
|
|
|
|
|
if (path) {
|
|
|
|
|
addMediaLocation(page, path);
|
|
|
|
|
}
|
|
|
|
|
picker.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function initEditor(page, options) {
|
|
|
|
|
renderLibrary(page, options);
|
|
|
|
|
|
|
|
|
|
$('.btnAddFolder', page).on('click', onAddButtonClick);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onDialogClosed() {
|
|
|
|
|
|
|
|
|
|
$(this).remove();
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
currentDeferred.resolveWith(null, [hasChanges]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function editor() {
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
self.show = function (options) {
|
|
|
|
|
|
2016-02-17 19:55:15 -07:00
|
|
|
|
var deferred = jQuery.Deferred();
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
|
|
|
|
currentOptions = options;
|
|
|
|
|
currentDeferred = deferred;
|
|
|
|
|
hasChanges = false;
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
|
xhr.open('GET', 'components/medialibraryeditor/medialibraryeditor.template.html', true);
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
xhr.onload = function (e) {
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
var template = this.response;
|
2016-03-23 12:03:17 -07:00
|
|
|
|
var dlg = dialogHelper.createDialog({
|
2015-12-14 08:43:03 -07:00
|
|
|
|
size: 'small',
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
// In (at least) chrome this is causing the text field to not be editable
|
|
|
|
|
modal: false
|
|
|
|
|
});
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2016-01-30 13:59:09 -07:00
|
|
|
|
dlg.classList.add('ui-body-a');
|
|
|
|
|
dlg.classList.add('background-theme-a');
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
var html = '';
|
|
|
|
|
html += '<h2 class="dialogHeader">';
|
2016-08-06 12:56:35 -07:00
|
|
|
|
html += '<button type="button" is="emby-button" icon="arrow-back" class="fab mini btnCloseDialog" tabindex="-1"><i class="md-icon">arrow_back</i></button>';
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
html += '<div style="display:inline-block;margin-left:.6em;vertical-align:middle;">' + options.library.Name + '</div>';
|
|
|
|
|
html += '</h2>';
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
html += '<div class="editorContent" style="max-width:800px;margin:auto;">';
|
2016-03-05 12:07:58 -07:00
|
|
|
|
html += Globalize.translateDocument(template);
|
2015-12-14 08:43:03 -07:00
|
|
|
|
html += '</div>';
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
dlg.innerHTML = html;
|
|
|
|
|
document.body.appendChild(dlg);
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
var editorContent = dlg.querySelector('.editorContent');
|
|
|
|
|
initEditor(editorContent, options);
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2016-03-22 10:46:57 -07:00
|
|
|
|
$(dlg).on('close', onDialogClosed);
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2016-03-23 12:03:17 -07:00
|
|
|
|
dialogHelper.open(dlg);
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
$('.btnCloseDialog', dlg).on('click', function () {
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
2016-03-23 12:03:17 -07:00
|
|
|
|
dialogHelper.close(dlg);
|
2015-10-15 20:17:42 -07:00
|
|
|
|
});
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
refreshLibraryFromServer(editorContent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xhr.send();
|
2015-10-15 20:17:42 -07:00
|
|
|
|
|
|
|
|
|
return deferred.promise();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return editor;
|
|
|
|
|
});
|