2014-01-20 23:10:58 -07:00
|
|
|
|
(function ($, document, window) {
|
|
|
|
|
|
|
|
|
|
var query = {
|
|
|
|
|
|
|
|
|
|
StartIndex: 0,
|
2014-01-30 21:50:09 -07:00
|
|
|
|
Limit: 20
|
2014-01-20 23:10:58 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var currentResult;
|
|
|
|
|
|
|
|
|
|
function showStatusMessage(id) {
|
|
|
|
|
|
|
|
|
|
var item = currentResult.Items.filter(function (i) {
|
|
|
|
|
return i.Id == id;
|
|
|
|
|
|
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
|
|
Dashboard.alert({
|
|
|
|
|
|
|
|
|
|
title: getStatusText(item, false),
|
|
|
|
|
message: item.StatusMessage
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteOriginalFile(page, id) {
|
|
|
|
|
|
|
|
|
|
var item = currentResult.Items.filter(function (i) {
|
|
|
|
|
return i.Id == id;
|
|
|
|
|
|
|
|
|
|
})[0];
|
|
|
|
|
|
2014-06-16 18:56:23 -07:00
|
|
|
|
var message = Globalize.translate('MessageFileWillBeDeleted') + '<p style="word-wrap:break-word;">' + item.OriginalPath + '</p><p>' + Globalize.translate('MessageSureYouWishToProceed') + '</p>';
|
2014-01-20 23:10:58 -07:00
|
|
|
|
|
2014-06-16 18:56:23 -07:00
|
|
|
|
Dashboard.confirm(message, Globalize.translate('HeaderDeleteFile'), function (confirmResult) {
|
2014-01-20 23:10:58 -07:00
|
|
|
|
|
|
|
|
|
if (confirmResult) {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
2014-01-22 10:05:06 -07:00
|
|
|
|
|
2014-01-20 23:10:58 -07:00
|
|
|
|
ApiClient.deleteOriginalFileFromOrganizationResult(id).done(function () {
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-22 10:05:06 -07:00
|
|
|
|
function organizeEpsiodeWithCorrections(page, item) {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
ApiClient.getItems({
|
|
|
|
|
recursive: true,
|
|
|
|
|
includeItemTypes: 'Series',
|
|
|
|
|
sortBy: 'SortName'
|
|
|
|
|
|
|
|
|
|
}).done(function (result) {
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
|
|
|
|
|
showEpisodeCorrectionPopup(page, item, result.Items);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showEpisodeCorrectionPopup(page, item, allSeries) {
|
|
|
|
|
|
|
|
|
|
var popup = $('.episodeCorrectionPopup', page).popup("open");
|
|
|
|
|
|
|
|
|
|
$('.inputFile', popup).html(item.OriginalFileName);
|
|
|
|
|
|
|
|
|
|
$('#txtSeason', popup).val(item.ExtractedSeasonNumber);
|
|
|
|
|
$('#txtEpisode', popup).val(item.ExtractedEpisodeNumber);
|
|
|
|
|
$('#txtEndingEpisode', popup).val(item.ExtractedEndingEpisodeNumber);
|
|
|
|
|
|
|
|
|
|
$('#hfResultId', popup).val(item.Id);
|
2014-01-23 14:09:00 -07:00
|
|
|
|
|
2014-01-22 10:05:06 -07:00
|
|
|
|
var seriesHtml = allSeries.map(function (s) {
|
|
|
|
|
|
|
|
|
|
return '<option value="' + s.Id + '">' + s.Name + '</option>';
|
|
|
|
|
|
|
|
|
|
}).join('');
|
|
|
|
|
|
|
|
|
|
seriesHtml = '<option value=""></option>' + seriesHtml;
|
|
|
|
|
|
|
|
|
|
$('#selectSeries', popup).html(seriesHtml).selectmenu('refresh');
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-20 23:10:58 -07:00
|
|
|
|
function organizeFile(page, id) {
|
|
|
|
|
|
|
|
|
|
var item = currentResult.Items.filter(function (i) {
|
|
|
|
|
return i.Id == id;
|
|
|
|
|
|
|
|
|
|
})[0];
|
|
|
|
|
|
2014-01-22 10:05:06 -07:00
|
|
|
|
if (!item.TargetPath) {
|
|
|
|
|
|
|
|
|
|
if (item.Type == "Episode") {
|
|
|
|
|
organizeEpsiodeWithCorrections(page, item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-16 18:56:23 -07:00
|
|
|
|
var message = Globalize.translate('MessageFollowingFileWillBeMovedFrom') + '<p style="word-wrap:break-word;">' + item.OriginalPath + '</p><p>' + Globalize.translate('MessageDestinationTo') + '</p><p style="word-wrap:break-word;">' + item.TargetPath + '</p>';
|
2014-01-23 14:09:00 -07:00
|
|
|
|
|
|
|
|
|
if (item.DuplicatePaths.length) {
|
2014-06-16 18:56:23 -07:00
|
|
|
|
message += '<p><b>' + Globalize.translate('MessageDuplicatesWillBeDeleted') + '</b></p>';
|
2014-01-23 14:09:00 -07:00
|
|
|
|
|
|
|
|
|
message += '<p style="word-wrap:break-word;">' + item.DuplicatePaths.join('<br/>') + '</p>';
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-16 18:56:23 -07:00
|
|
|
|
message += '<p>' + Globalize.translate('MessageSureYouWishToProceed') + '</p>';
|
2014-01-20 23:10:58 -07:00
|
|
|
|
|
2014-06-16 18:56:23 -07:00
|
|
|
|
Dashboard.confirm(message, Globalize.translate('HeaderOrganizeFile'), function (confirmResult) {
|
2014-01-20 23:10:58 -07:00
|
|
|
|
|
|
|
|
|
if (confirmResult) {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
ApiClient.performOrganization(id).done(function () {
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
2014-01-22 10:05:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function submitEpisodeForm(form) {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var page = $(form).parents('.page');
|
|
|
|
|
|
|
|
|
|
var resultId = $('#hfResultId', form).val();
|
|
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
|
|
|
|
|
|
SeriesId: $('#selectSeries', form).val(),
|
|
|
|
|
SeasonNumber: $('#txtSeason', form).val(),
|
|
|
|
|
EpisodeNumber: $('#txtEpisode', form).val(),
|
2014-04-14 20:54:52 -07:00
|
|
|
|
EndingEpisodeNumber: $('#txtEndingEpisode', form).val()
|
2014-01-22 10:05:06 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ApiClient.performEpisodeOrganization(resultId, options).done(function () {
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
|
|
|
|
|
$('.episodeCorrectionPopup', page).popup("close");
|
2014-01-20 23:10:58 -07:00
|
|
|
|
|
2014-01-22 10:05:06 -07:00
|
|
|
|
reloadItems(page);
|
|
|
|
|
|
|
|
|
|
});
|
2014-01-20 23:10:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function reloadItems(page) {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
ApiClient.getFileOrganizationResults(query).done(function (result) {
|
|
|
|
|
|
|
|
|
|
currentResult = result;
|
|
|
|
|
renderResults(page, result);
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getStatusText(item, enhance) {
|
|
|
|
|
|
|
|
|
|
var status = item.Status;
|
|
|
|
|
|
|
|
|
|
var color = null;
|
|
|
|
|
|
2014-01-21 09:24:12 -07:00
|
|
|
|
if (status == 'SkippedExisting') {
|
2014-06-16 18:56:23 -07:00
|
|
|
|
status = Globalize.translate('StatusSkipped');
|
2014-01-20 23:10:58 -07:00
|
|
|
|
}
|
|
|
|
|
else if (status == 'Failure') {
|
|
|
|
|
color = '#cc0000';
|
2014-06-16 18:56:23 -07:00
|
|
|
|
status = Globalize.translate('StatusFailed');
|
2014-01-20 23:10:58 -07:00
|
|
|
|
}
|
|
|
|
|
if (status == 'Success') {
|
|
|
|
|
color = 'green';
|
2014-06-16 18:56:23 -07:00
|
|
|
|
status = Globalize.translate('StatusSuccess');
|
2014-01-20 23:10:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (enhance && enhance) {
|
|
|
|
|
|
|
|
|
|
if (item.StatusMessage) {
|
|
|
|
|
|
|
|
|
|
return '<a style="color:' + color + ';" data-resultid="' + item.Id + '" href="#" class="btnShowStatusMessage">' + status + '</a>';
|
|
|
|
|
} else {
|
|
|
|
|
return '<span data-resultid="' + item.Id + '" style="color:' + color + ';">' + status + '</span>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderResults(page, result) {
|
|
|
|
|
|
|
|
|
|
var rows = result.Items.map(function (item) {
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
html += '<tr>';
|
|
|
|
|
|
2014-01-22 10:05:06 -07:00
|
|
|
|
html += '<td class="organizerButtonCell">';
|
2014-01-20 23:10:58 -07:00
|
|
|
|
|
|
|
|
|
|
2014-01-22 10:05:06 -07:00
|
|
|
|
if (item.Status != 'Success') {
|
2014-06-16 18:56:23 -07:00
|
|
|
|
html += '<button data-resultid="' + item.Id + '" type="button" data-inline="true" data-icon="delete" data-mini="true" data-iconpos="notext" class="btnDeleteResult organizerButton" title="' + Globalize.translate('ButtonDeleteFile') + '">' + Globalize.translate('ButtonDeleteFile') + '</button>';
|
|
|
|
|
html += '<button data-resultid="' + item.Id + '" type="button" data-inline="true" data-icon="action" data-mini="true" data-iconpos="notext" class="btnProcessResult organizerButton" title="' + Globalize.translate('ButtonOrganizeFile') + '">' + Globalize.translate('ButtonOrganizeFile') + '</button>';
|
2014-01-22 10:05:06 -07:00
|
|
|
|
}
|
2014-01-20 23:10:58 -07:00
|
|
|
|
|
|
|
|
|
html += '</td>';
|
|
|
|
|
|
|
|
|
|
html += '<td>';
|
|
|
|
|
|
2014-01-22 10:05:06 -07:00
|
|
|
|
var date = parseISO8601Date(item.Date, { toLocal: true });
|
|
|
|
|
html += date.toLocaleDateString();
|
2014-01-20 23:10:58 -07:00
|
|
|
|
|
2014-01-22 10:05:06 -07:00
|
|
|
|
html += '</td>';
|
2014-01-20 23:10:58 -07:00
|
|
|
|
|
2014-01-22 10:05:06 -07:00
|
|
|
|
html += '<td>';
|
|
|
|
|
var status = item.Status;
|
2014-01-20 23:10:58 -07:00
|
|
|
|
|
2014-01-22 10:05:06 -07:00
|
|
|
|
if (status == 'SkippedExisting') {
|
|
|
|
|
html += '<div style="color:blue;">';
|
|
|
|
|
html += item.OriginalFileName;
|
|
|
|
|
html += '</div>';
|
2014-01-20 23:10:58 -07:00
|
|
|
|
}
|
2014-01-22 10:05:06 -07:00
|
|
|
|
else if (status == 'Failure') {
|
|
|
|
|
html += '<a data-resultid="' + item.Id + '" style="color:red;" href="#" class="btnShowStatusMessage">';
|
|
|
|
|
html += item.OriginalFileName;
|
|
|
|
|
html += '</a>';
|
|
|
|
|
} else {
|
|
|
|
|
html += '<div style="color:green;">';
|
|
|
|
|
html += item.OriginalFileName;
|
|
|
|
|
html += '</div>';
|
2014-01-20 23:10:58 -07:00
|
|
|
|
}
|
2014-01-22 10:05:06 -07:00
|
|
|
|
html += '</td>';
|
2014-01-20 23:10:58 -07:00
|
|
|
|
|
2014-01-22 10:05:06 -07:00
|
|
|
|
html += '<td>';
|
|
|
|
|
html += item.TargetPath || '';
|
2014-01-20 23:10:58 -07:00
|
|
|
|
html += '</td>';
|
|
|
|
|
|
|
|
|
|
html += '</tr>';
|
|
|
|
|
|
|
|
|
|
return html;
|
|
|
|
|
}).join('');
|
|
|
|
|
|
|
|
|
|
var elem = $('.resultBody', page).html(rows).parents('.tblOrganizationResults').table("refresh").trigger('create');
|
|
|
|
|
|
|
|
|
|
$('.btnShowStatusMessage', elem).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var id = this.getAttribute('data-resultid');
|
|
|
|
|
|
|
|
|
|
showStatusMessage(id);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnProcessResult', elem).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var id = this.getAttribute('data-resultid');
|
|
|
|
|
|
|
|
|
|
organizeFile(page, id);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnDeleteResult', elem).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var id = this.getAttribute('data-resultid');
|
|
|
|
|
|
|
|
|
|
deleteOriginalFile(page, id);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var pagingHtml = LibraryBrowser.getPagingHtml(query, result.TotalRecordCount, false, [], false);
|
|
|
|
|
$('.listTopPaging', page).html(pagingHtml).trigger('create');
|
|
|
|
|
|
|
|
|
|
if (result.TotalRecordCount > query.Limit && result.TotalRecordCount > 50) {
|
|
|
|
|
$('.listBottomPaging', page).html(pagingHtml).trigger('create');
|
|
|
|
|
} else {
|
|
|
|
|
$('.listBottomPaging', page).empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('.btnNextPage', page).on('click', function () {
|
|
|
|
|
query.StartIndex += query.Limit;
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnPreviousPage', page).on('click', function () {
|
|
|
|
|
query.StartIndex -= query.Limit;
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
2014-01-22 10:05:06 -07:00
|
|
|
|
|
|
|
|
|
if (result.TotalRecordCount) {
|
|
|
|
|
$('.btnClearLog', page).show();
|
|
|
|
|
} else {
|
|
|
|
|
$('.btnClearLog', page).hide();
|
|
|
|
|
}
|
2014-01-20 23:10:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-22 10:05:06 -07:00
|
|
|
|
$(document).on('pageinit', "#libraryFileOrganizerLogPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
$('.btnClearLog', page).on('click', function () {
|
|
|
|
|
|
|
|
|
|
ApiClient.clearOrganizationLog().done(function () {
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}).on('pageshow', "#libraryFileOrganizerLogPage", function () {
|
2014-01-20 23:10:58 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
|
2015-01-20 13:19:54 -07:00
|
|
|
|
// on here
|
|
|
|
|
$('.btnOrganize', page).taskButton({
|
|
|
|
|
mode: 'on',
|
|
|
|
|
progressElem: $('.organizeProgress', page),
|
2015-01-20 14:32:48 -07:00
|
|
|
|
panel: $('.organizeTaskPanel', page),
|
2015-01-20 13:19:54 -07:00
|
|
|
|
taskKey: 'AutoOrganize'
|
|
|
|
|
});
|
|
|
|
|
|
2014-01-20 23:10:58 -07:00
|
|
|
|
}).on('pagehide', "#libraryFileOrganizerLogPage", function () {
|
|
|
|
|
|
2015-01-20 14:32:48 -07:00
|
|
|
|
var page = this;
|
|
|
|
|
|
2014-01-20 23:10:58 -07:00
|
|
|
|
currentResult = null;
|
2015-01-20 13:19:54 -07:00
|
|
|
|
|
|
|
|
|
// off here
|
|
|
|
|
$('.btnOrganize', page).taskButton({
|
|
|
|
|
mode: 'off'
|
|
|
|
|
});
|
2014-01-20 23:10:58 -07:00
|
|
|
|
});
|
|
|
|
|
|
2014-01-22 10:05:06 -07:00
|
|
|
|
window.OrganizerLogPage = {
|
|
|
|
|
|
|
|
|
|
onEpisodeCorrectionFormSubmit: function () {
|
|
|
|
|
|
|
|
|
|
submitEpisodeForm(this);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-01-20 23:10:58 -07:00
|
|
|
|
})(jQuery, document, window);
|