(function ($, document, window) { var query = { StartIndex: 0, Limit: 20 }; 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]; var message = 'The following file will be deleted:
' + item.OriginalPath + '
Are you sure you wish to proceed?
'; Dashboard.confirm(message, "Delete File", function (confirmResult) { if (confirmResult) { Dashboard.showLoadingMsg(); ApiClient.deleteOriginalFileFromOrganizationResult(id).done(function () { Dashboard.hideLoadingMsg(); reloadItems(page); }); } }); } 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); if (item.ExtractedName) { $('#fldRememberCorrection', popup).hide(); } else { $('#fldRememberCorrection', popup).hide(); } $('#chkRememberEpisodeCorrection', popup).checked(false).checkboxradio('refresh'); var seriesHtml = allSeries.map(function (s) { return ''; }).join(''); seriesHtml = '' + seriesHtml; $('#selectSeries', popup).html(seriesHtml).selectmenu('refresh'); } function organizeFile(page, id) { var item = currentResult.Items.filter(function (i) { return i.Id == id; })[0]; if (!item.TargetPath) { if (item.Type == "Episode") { organizeEpsiodeWithCorrections(page, item); } return; } var message = 'The following file will be moved from:' + item.OriginalPath + '
to:
' + item.TargetPath + '
'; if (item.DuplicatePaths.length) { message += 'In addition the following dupliates will be deleted:
'; message += '' + item.DuplicatePaths.join('
') + '
Are you sure you wish to proceed?
'; Dashboard.confirm(message, "Organize File", function (confirmResult) { if (confirmResult) { Dashboard.showLoadingMsg(); ApiClient.performOrganization(id).done(function () { Dashboard.hideLoadingMsg(); reloadItems(page); }); } }); } 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(), EndingEpisodeNumber: $('#txtEndingEpisode', form).val(), RememberCorrection: $('#chkRememberEpisodeCorrection', form).checked() }; ApiClient.performEpisodeOrganization(resultId, options).done(function () { Dashboard.hideLoadingMsg(); $('.episodeCorrectionPopup', page).popup("close"); reloadItems(page); }); } 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; if (status == 'SkippedExisting') { status = 'Skipped'; } else if (status == 'Failure') { color = '#cc0000'; status = 'Failed'; } if (status == 'Success') { color = 'green'; status = 'Success'; } if (enhance && enhance) { if (item.StatusMessage) { return '' + status + ''; } else { return '' + status + ''; } } return status; } function renderResults(page, result) { var rows = result.Items.map(function (item) { var html = ''; html += '