diff --git a/dashboard-ui/components/fileorganizer/fileorganizer.js b/dashboard-ui/components/fileorganizer/fileorganizer.js index f1f9beea22..d51e75082b 100644 --- a/dashboard-ui/components/fileorganizer/fileorganizer.js +++ b/dashboard-ui/components/fileorganizer/fileorganizer.js @@ -1,490 +1,130 @@ -define(['paperdialoghelper', 'paper-tabs', 'paper-item', 'paper-input', 'paper-fab', 'paper-item-body'], function (paperDialogHelper) { +define(['paperdialoghelper', 'paper-checkbox', 'paper-input', 'paper-button'], function (paperDialogHelper) { - var currentItemId; - var currentFile; - var currentDeferred; - var hasChanges = false; - var reloadItems; + function onApiFailure(e) { - function submitEpisodeForm(form) { + Dashboard.hideLoadingMsg(); + + Dashboard.alert({ + title: Globalize.translate('AutoOrganizeError'), + message: Globalize.translate('ErrorOrganizingFileWithErrorCode', e.getResponseHeader("X-Application-Error-Code")) + }); + } + + function initEpisodeForm(context, item) { + + $('.inputFile', context).html(item.OriginalFileName); + + $('#txtSeason', context).val(item.ExtractedSeasonNumber); + $('#txtEpisode', context).val(item.ExtractedEpisodeNumber); + $('#txtEndingEpisode', context).val(item.ExtractedEndingEpisodeNumber); + + $('#chkRememberCorrection', context).val(false); + + $('#hfResultId', context).val(item.Id); + + ApiClient.getItems(null, { + recursive: true, + includeItemTypes: 'Series', + sortBy: 'SortName' + + }).then(function (result) { + + var seriesHtml = result.Items.map(function (s) { + + return ''; + + }).join(''); + + seriesHtml = '' + seriesHtml; + + $('#selectSeries', context).html(seriesHtml); + + }, onApiFailure); + } + + function submitEpisodeForm(dlg) { Dashboard.showLoadingMsg(); - var resultId = $('#hfResultId', form).val(); - - var targetFolder = $('#spanTargetFolder', form).text(); - - var elemString = $('#hfNewSeriesProviderIds', form).val(); - var newSeriesName = $('#hfNewSeriesName', form).val(); - var newSeriesYear = $('#hfNewSeriesYear', form).val(); + var resultId = $('#hfResultId', dlg).val(); var options = { - SeriesId: $('#selectSeries', form).val(), - SeasonNumber: $('#txtSeason', form).val(), - EpisodeNumber: $('#txtEpisode', form).val(), - EndingEpisodeNumber: $('#txtEndingEpisode', form).val(), - RememberCorrection: $('#chkRememberCorrection', form).checked(), - NewSeriesProviderIds: elemString, - NewSeriesName: newSeriesName, - NewSeriesYear: newSeriesYear, - TargetFolder: targetFolder + SeriesId: $('#selectSeries', dlg).val(), + SeasonNumber: $('#txtSeason', dlg).val(), + EpisodeNumber: $('#txtEpisode', dlg).val(), + EndingEpisodeNumber: $('#txtEndingEpisode', dlg).val(), + RememberCorrection: $('#chkRememberCorrection', dlg).checked() }; ApiClient.performEpisodeOrganization(resultId, options).then(function () { Dashboard.hideLoadingMsg(); - document.querySelector('.organizerDialog').close(); - - reloadItems(); + dlg.submitted = true; + paperDialogHelper.close(dlg); }, onApiFailure); } - function submitMovieForm(form) { + return { + show: function (item) { + return new Promise(function (resolve, reject) { - Dashboard.showLoadingMsg(); + var xhr = new XMLHttpRequest(); + xhr.open('GET', 'components/fileorganizer/fileorganizer.template.html', true); - var resultId = $('#hfResultIdMovie', form).val(); + xhr.onload = function (e) { - var targetFolder = $('#selectMovieFolder', form).val(); - - var options = { - MovieName: $('#txtMovieName', form).val(), - MovieYear: $('#txtMovieYear', form).val(), - TargetFolder: targetFolder - }; - - ApiClient.performMovieOrganization(resultId, options).then(function () { - - Dashboard.hideLoadingMsg(); - - document.querySelector('.organizerDialog').close(); - - reloadItems(); - - }, onApiFailure); - } - - function searchForIdentificationResults(popup, itemtype) { - - var lookupInfo = { - Name: $('#txtMovieName', popup).val(), - Year: $('#txtMovieYear', popup).val(), - }; - - var url = ApiClient.getUrl("Items/RemoteSearch/Movie"); - - if (itemtype == 'tvshows') { - lookupInfo.Name = $('#txtNewSeriesName', popup).val(); - lookupInfo.Year = $('#txtNewSeriesYear', popup).val(); - url = ApiClient.getUrl("Items/RemoteSearch/Series"); - } - - if (!lookupInfo.Name) { - Dashboard.alert(Globalize.translate('MessagePleaseEnterNameOrId')); - return; - } - - lookupInfo = { - SearchInfo: lookupInfo, - IncludeDisabledProviders: true - }; - - Dashboard.showLoadingMsg(); - - ApiClient.ajax({ - type: "POST", - url: url, - data: JSON.stringify(lookupInfo), - dataType: "json", - contentType: "application/json" - - }).then(function (results) { - - Dashboard.hideLoadingMsg(); - showIdentificationSearchResults(popup, results, itemtype); - - $('#btnBack', popup).off('click').on('click', function () { - $('.identificationResultForm', popup).hide(); - $('.organizeMovieForm', popup).show(); - $('.createSeriesForm', popup).show(); - - if (itemtype == 'tvshows') { - $('#btnBack', popup).off('click').on('click', function () { - $('.createSeriesForm', popup).hide(); - $('.episodeCorrectionForm', popup).show(); - - $('#btnBack', popup).off('click').on('click', function () { - popup.close(); - }); - }); - } - else { - $('#btnBack', popup).off('click').on('click', function () { - popup.close(); + var template = this.response; + var dlg = paperDialogHelper.createDialog({ + removeOnClose: true, + size: 'small' }); + + dlg.classList.add('ui-body-a'); + dlg.classList.add('background-theme-a'); + + dlg.classList.add('formDialog'); + + var html = ''; + + html += Globalize.translateDocument(template); + + dlg.innerHTML = html; + document.body.appendChild(dlg); + + dlg.querySelector('.dialogHeaderTitle').innerHTML = Globalize.translate('FileOrganizeManually'); + + paperDialogHelper.open(dlg); + + dlg.addEventListener('iron-overlay-closed', function () { + + if (dlg.submitted) { + resolve(); + } else { + reject(); + } + }); + + dlg.querySelector('.btnCancel').addEventListener('click', function (e) { + + paperDialogHelper.close(dlg); + }); + + dlg.querySelector('form').addEventListener('submit', function (e) { + + submitEpisodeForm(dlg); + + e.preventDefault(); + return false; + }); + + initEpisodeForm(dlg, item); } + + xhr.send(); }); - - }, onApiFailure); - } - - function showIdentificationSearchResults(popup, results, itemtype) { - - $('.organizeMovieForm', popup).hide(); - $('.createSeriesForm', popup).hide(); - $('.identificationResultForm', popup).show(); - - var html = ''; - - for (var i = 0, length = results.length; i < length; i++) { - - var result = results[i]; - - html += getIdentifyResultHtml(result, i); - } - - var elem = $('.identificationSearchResultList', popup).html(html).trigger('create'); - - $('.searchImage', elem).on('click', function () { - - var index = parseInt(this.getAttribute('data-index')); - - var currentResult = results[index]; - - $('.identificationResultForm', popup).hide(); - - var targetName = currentResult.Name; - if (currentResult.ProductionYear) { - targetName = targetName + ' (' + currentResult.ProductionYear + ')'; - } - - if (itemtype == 'tvshows') { - $('#txtNewSeriesName', popup).val(currentResult.Name); - $('#txtNewSeriesYear', popup).val(currentResult.ProductionYear); - $('#txtSelectedNewSeries', popup).val(targetName); - $('#txtSelectedNewSeries2', popup).val(targetName); - $('#hfNewSeriesName', popup).val(currentResult.Name); - $('#hfNewSeriesYear', popup).val(currentResult.ProductionYear); - var elems = currentResult.ProviderIds; - $('#hfNewSeriesProviderIds', popup).val(JSON.stringify(elems)); - $('.createSeriesForm', popup).show(); - $('#btnBack', popup).off('click').on('click', function () { - $('.createSeriesForm', popup).hide(); - $('.episodeCorrectionForm', popup).show(); - $('#btnBack', popup).off('click').on('click', function () { - popup.close(); - }); - }); - } - else { - $('#txtMovieName', popup).val(currentResult.Name); - $('#txtMovieYear', popup).val(currentResult.ProductionYear); - $('#txtSelectedMovie', popup).val(targetName); - $('.organizeMovieForm', popup).show(); - $('#btnBack', popup).off('click').on('click', function () { - popup.close(); - }); - } - }); - } - - function getSearchImageDisplayUrl(url, provider) { - return ApiClient.getUrl("Items/RemoteSearch/Image", { imageUrl: url, ProviderName: provider }); - } - - function getIdentifyResultHtml(result, index) { - - var html = ''; - var cssClass = "searchImageContainer remoteImageContainer"; - - cssClass += " searchPosterImageContainer"; - - html += '
'; - - if (result.ImageUrl) { - var displayUrl = getSearchImageDisplayUrl(result.ImageUrl, result.SearchProviderName); - - html += ''; - } else { - - html += ''; - } - html += ''; - - html += '
'; - html += result.Name; - html += '
'; - - html += '
'; - html += result.ProductionYear || ' '; - html += '
'; - - html += '
'; - return html; - } - - function onEpisodeCorrectionFormSubmit() { - submitEpisodeForm(this); - return false; - } - - function onOrganizeMovieFormFormSubmit() { - submitMovieForm(this); - return false; - } - - function showTab(popup, index) { - $('.organizeMovieForm', popup).show(); - $('.episodeCorrectionForm', popup).show(); - $('.identificationResultForm', popup).hide(); - $('.createSeriesForm', popup).hide(); - $('.popupTabPage', popup).addClass('hide')[index].classList.remove('hide'); - - $('#btnBack', popup).off('click').on('click', function () { - popup.close(); - }); - } - - function initEditor(popup, item, allSeries, movieLocations, seriesLocations) { - - $('#divNewSeries', popup).hide(); - - showTab(popup, 0); - - $('.inputFile', popup).html(item.OriginalFileName); - - $('#txtSeason', popup).val(item.ExtractedSeasonNumber); - $('#txtEpisode', popup).val(item.ExtractedEpisodeNumber); - $('#txtEndingEpisode', popup).val(item.ExtractedEndingEpisodeNumber); - - $('#chkRememberCorrection', popup).val(false); - $('.extractedName', popup).html(item.ExtractedName); - - if (!item.ExtractedName || item.ExtractedName.length < 4) { - $('#divRememberCorrection', popup).hide(); - } - - $('#txtNewSeriesName', popup).val(item.ExtractedName); - $('#txtNewSeriesYear', popup).val(item.ExtractedYear); - - $('#hfResultId', popup).val(item.Id); - $('#hfResultIdMovie', popup).val(item.Id); - $('#hfNewSeriesProviderIds', popup).val(null); - $('#hfNewSeriesName', popup).val(null); - $('#hfNewSeriesYear', popup).val(null); - - $('#txtSelectedNewSeries', popup).val(null); - $('#txtSelectedNewSeries2', popup).val(null); - - $('#txtMovieName', popup).val(item.ExtractedMovieName); - $('#txtMovieYear', popup).val(item.ExtractedMovieYear); - $('#txtSelectedMovie', popup).val(null); - - var seriesHtml = allSeries.map(function (s) { - - return ''; - - }).join(''); - - seriesHtml = '' + seriesHtml; - - $('#selectSeries', popup).html(seriesHtml); - - - var movieFolderHtml = movieLocations.map(function (s) { - return ''; - }).join(''); - - if (movieLocations.length > 1) { - movieFolderHtml = '' + movieFolderHtml; - } - - var seriesFolderHtml = seriesLocations.map(function (s) { - return ''; - }).join(''); - - if (seriesLocations.length > 1) { - seriesFolderHtml = '' + seriesFolderHtml; - } - - $('#selectMovieFolder', popup).html(movieFolderHtml); - $('#selectSeriesFolder', popup).html(seriesFolderHtml); - - $('.episodeCorrectionForm').off('submit', onEpisodeCorrectionFormSubmit).on('submit', onEpisodeCorrectionFormSubmit); - $('.organizeMovieForm').off('submit', onOrganizeMovieFormFormSubmit).on('submit', onOrganizeMovieFormFormSubmit); - - $('#btnIdentifyMovie', popup).on('click', function () { - searchForIdentificationResults(popup, 'movies'); - }); - - $('#btnIdentifySeries', popup).on('click', function () { - searchForIdentificationResults(popup, 'tvshows'); - }); - - $('.txt-readonly', popup).keydown(function (e) { - e.preventDefault(); - }); - - $('#btnNewSeries', popup).on('click', function () { - $('.episodeCorrectionForm', popup).hide(); - $('.createSeriesForm', popup).show(); - - $('#btnBack', popup).off('click').on('click', function () { - - $('.createSeriesForm', popup).hide(); - $('.episodeCorrectionForm', popup).show(); - - $('#btnBack', popup).off('click').on('click', function () { - popup.close(); - }); - }); - }); - - $('.createSeriesForm').off('submit').on('submit', function () { - var folder = $('#selectSeriesFolder', popup).val(); - $('#spanTargetFolder', popup).text(folder); - - $('#divSelectSeries', popup).hide(); - $('#divNewSeries', popup).show(); - $('.episodeCorrectionForm', popup).show(); - $('.createSeriesForm', popup).hide(); - - $('#btnBack', popup).off('click').on('click', function () { - popup.close(); - }); - - return false; - }); - } - - function showEditor(page, item, allSeries, movieLocations, seriesLocations, reloadDelegate) { - - reloadItems = reloadDelegate; - - var xhr = new XMLHttpRequest(); - xhr.open('GET', 'components/fileorganizer/fileorganizer.template.html', true); - - xhr.onload = function (e) { - - var template = this.response; - - var dlg = createDialog(); - dlg.setAttribute('id', 'with-backdrop'); - - var html = ''; - //html += '
'; - html += '

'; - html += ''; - html += '
' + Globalize.translate('FileOrganizeManually') + '
'; - html += '

'; - //html += '
'; - - html += '
'; - html += 'TV Episode'; - html += 'Movie'; - html += '
'; - - html += '
'; - html += Globalize.translateDocument(template); - html += '
'; - - dlg.innerHTML = html; - document.body.appendChild(dlg); - - initEditor(dlg, item, allSeries, movieLocations, seriesLocations); - - // Has to be assigned a z-index after the call to .open() - $(dlg).on('iron-overlay-closed', onDialogClosed); - - var tabs = dlg.querySelector('paper-tabs'); - - $(tabs).on('iron-select', function () { - - var self = this; - - var selected = this.selected; - showTab(dlg, selected); - - //setTimeout(function () { - // Events.trigger(self, 'tabchange'); - //}, 400); - - }); - - //.on('tabchange', function () { - // var selected = this.selected; - - // showTab(dlg, selected); - //}); - - dlg.classList.add('organizerDialog'); - - paperDialogHelper.open(dlg); - //PaperDialogHelper.openWithHash(dlg, 'fileorganizer'); - //dlg.open(); - - $('#btnBack', dlg).on('click', function () { - paperDialogHelper.close(dlg); - }); - }; - - xhr.send(); - } - - function createDialog() { - //var dlg = document.createElement('paper-dialog'); - - var dlg = paperDialogHelper.createDialog({ - removeOnClose: true - }); - - dlg.classList.add('ui-body-a'); - dlg.classList.add('background-theme-a'); - - return dlg; - } - - function onApiFailure(e) { - - Dashboard.hideLoadingMsg(); - - document.querySelector('.organizerDialog').close(); - - if (e.status == 0) { - Dashboard.alert({ - title: 'Auto-Organize', - message: 'The operation is going to take a little longer. The view will be updated on completion.' - }); - } - else { - Dashboard.alert({ - title: Globalize.translate('AutoOrganizeError'), - message: Globalize.translate('ErrorOrganizingFileWithErrorCode', e.getResponseHeader("X-Application-Error-Code")) - }); - } - } - - function onDialogClosed() { - - $(this).remove(); - Dashboard.hideLoadingMsg(); - currentDeferred.resolveWith(null, [hasChanges]); - } - - window.FileOrganizer = { - show: function (page, item, allSeries, movieLocations, seriesLocations, reloadDelegate) { - - var deferred = DeferredBuilder.Deferred(); - - currentDeferred = deferred; - hasChanges = false; - - showEditor(page, item, allSeries, movieLocations, seriesLocations, reloadDelegate); - - return deferred.promise(); } }; -}); +}); \ No newline at end of file diff --git a/dashboard-ui/components/fileorganizer/fileorganizer.template.html b/dashboard-ui/components/fileorganizer/fileorganizer.template.html index cf560c836f..53368012e6 100644 --- a/dashboard-ui/components/fileorganizer/fileorganizer.template.html +++ b/dashboard-ui/components/fileorganizer/fileorganizer.template.html @@ -1,127 +1,34 @@ 
- ${HeaderInviteUser}
-
-
-

-
-
- - -
- -
- -
- - -
-
- - -
-
- - -
${LabelEndingEpisodeNumberHelp}
-
-
- - - -
-

- -

- - - - -
+
- -

-
- - -
-
- - -
-
- -
-
- - - -
-
- - -
-

- -

-
+

-
-
-
-

-
- - -
-
- - -
-
- -
-
- - -
-
- - -
-

- -

- -
-
- -
-
- -
-
-
-
-
+
+ + +
+
+ +
+
+ +
+
+ +
${LabelEndingEpisodeNumberHelp}
+
+
+
+ ${OptionRememberOrganizeCorrection} +
+
+ + + \ No newline at end of file diff --git a/dashboard-ui/components/guestinviter/guestinviter.js b/dashboard-ui/components/guestinviter/guestinviter.js index 83e2c229c3..568b5b742e 100644 --- a/dashboard-ui/components/guestinviter/guestinviter.js +++ b/dashboard-ui/components/guestinviter/guestinviter.js @@ -109,8 +109,8 @@ html += Globalize.translateDocument(template); dlg.innerHTML = html; - // needed for the collapsible document.body.appendChild(dlg); + // needed for the collapsible $(dlg.querySelector('form')).trigger('create'); paperDialogHelper.open(dlg); diff --git a/dashboard-ui/scripts/autoorganizelog.js b/dashboard-ui/scripts/autoorganizelog.js index d31960e7ce..b686e7e0f1 100644 --- a/dashboard-ui/scripts/autoorganizelog.js +++ b/dashboard-ui/scripts/autoorganizelog.js @@ -97,11 +97,11 @@ }, onApiFailure); } - function showEpisodeCorrectionPopup(page, item, allSeries, movieLocations, seriesLocations) { + function showEpisodeCorrectionPopup(page, item) { - require(['components/fileorganizer/fileorganizer'], function () { + require(['components/fileorganizer/fileorganizer'], function (fileorganizer) { - FileOrganizer.show(page, item, allSeries, movieLocations, seriesLocations, function () { + fileorganizer.show(item).then(function () { reloadItems(page); }); });