2016-02-12 21:34:47 -07:00
|
|
|
|
define(['paperdialoghelper', 'paper-checkbox', 'paper-input', 'paper-button'], function (paperDialogHelper) {
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
function onApiFailure(e) {
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
Dashboard.alert({
|
|
|
|
|
title: Globalize.translate('AutoOrganizeError'),
|
|
|
|
|
message: Globalize.translate('ErrorOrganizingFileWithErrorCode', e.getResponseHeader("X-Application-Error-Code"))
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
function initEpisodeForm(context, item) {
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
$('.inputFile', context).html(item.OriginalFileName);
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
$('#txtSeason', context).val(item.ExtractedSeasonNumber);
|
|
|
|
|
$('#txtEpisode', context).val(item.ExtractedEpisodeNumber);
|
|
|
|
|
$('#txtEndingEpisode', context).val(item.ExtractedEndingEpisodeNumber);
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
$('#chkRememberCorrection', context).val(false);
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
$('#hfResultId', context).val(item.Id);
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
ApiClient.getItems(null, {
|
|
|
|
|
recursive: true,
|
|
|
|
|
includeItemTypes: 'Series',
|
|
|
|
|
sortBy: 'SortName'
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
}).then(function (result) {
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
var seriesHtml = result.Items.map(function (s) {
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
return '<option value="' + s.Id + '">' + s.Name + '</option>';
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
}).join('');
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
seriesHtml = '<option value=""></option>' + seriesHtml;
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
$('#selectSeries', context).html(seriesHtml);
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
|
|
|
|
}, onApiFailure);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
function submitEpisodeForm(dlg) {
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
var resultId = $('#hfResultId', dlg).val();
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
var options = {
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
SeriesId: $('#selectSeries', dlg).val(),
|
|
|
|
|
SeasonNumber: $('#txtSeason', dlg).val(),
|
|
|
|
|
EpisodeNumber: $('#txtEpisode', dlg).val(),
|
|
|
|
|
EndingEpisodeNumber: $('#txtEndingEpisode', dlg).val(),
|
|
|
|
|
RememberCorrection: $('#chkRememberCorrection', dlg).checked()
|
2016-02-12 15:42:11 -07:00
|
|
|
|
};
|
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
ApiClient.performEpisodeOrganization(resultId, options).then(function () {
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
dlg.submitted = true;
|
|
|
|
|
paperDialogHelper.close(dlg);
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
|
|
|
|
}, onApiFailure);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
return {
|
|
|
|
|
show: function (item) {
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
|
xhr.open('GET', 'components/fileorganizer/fileorganizer.template.html', true);
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
xhr.onload = function (e) {
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
var template = this.response;
|
|
|
|
|
var dlg = paperDialogHelper.createDialog({
|
|
|
|
|
removeOnClose: true,
|
|
|
|
|
size: 'small'
|
2016-02-12 15:42:11 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
dlg.classList.add('ui-body-a');
|
|
|
|
|
dlg.classList.add('background-theme-a');
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
dlg.classList.add('formDialog');
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
var html = '';
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
html += Globalize.translateDocument(template);
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
dlg.innerHTML = html;
|
|
|
|
|
document.body.appendChild(dlg);
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
dlg.querySelector('.dialogHeaderTitle').innerHTML = Globalize.translate('FileOrganizeManually');
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
paperDialogHelper.open(dlg);
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
dlg.addEventListener('iron-overlay-closed', function () {
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
if (dlg.submitted) {
|
|
|
|
|
resolve();
|
|
|
|
|
} else {
|
|
|
|
|
reject();
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
dlg.querySelector('.btnCancel').addEventListener('click', function (e) {
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
paperDialogHelper.close(dlg);
|
|
|
|
|
});
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
dlg.querySelector('form').addEventListener('submit', function (e) {
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
submitEpisodeForm(dlg);
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
initEpisodeForm(dlg, item);
|
|
|
|
|
}
|
2016-02-12 15:42:11 -07:00
|
|
|
|
|
2016-02-12 21:34:47 -07:00
|
|
|
|
xhr.send();
|
2016-02-12 15:42:11 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2016-02-12 21:34:47 -07:00
|
|
|
|
});
|