define(['serverNotifications', 'events', 'scripts/taskbutton', 'datetime', 'paper-icon-button-light'], function (serverNotifications, events, taskButton, datetime) {
'use strict';
var query = {
StartIndex: 0,
Limit: 50
};
var currentResult;
var page;
function parentWithClass(elem, className) {
while (!elem.classList || !elem.classList.contains(className)) {
elem = elem.parentNode;
if (!elem) {
return null;
}
}
return elem;
}
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 = Globalize.translate('MessageFileWillBeDeleted') + '
' + item.OriginalPath + '
' + Globalize.translate('MessageSureYouWishToProceed');
require(['confirm'], function (confirm) {
confirm(message, Globalize.translate('HeaderDeleteFile')).then(function () {
Dashboard.showLoadingMsg();
ApiClient.deleteOriginalFileFromOrganizationResult(id).then(function () {
Dashboard.hideLoadingMsg();
reloadItems(page, true);
}, Dashboard.processErrorResponse);
});
});
}
function organizeFileWithCorrections(page, item) {
showCorrectionPopup(page, item);
}
function showCorrectionPopup(page, item) {
require(['components/fileorganizer/fileorganizer'], function (fileorganizer) {
fileorganizer.show(item).then(function () {
reloadItems(page, false);
});
});
}
function organizeFile(page, id) {
var item = currentResult.Items.filter(function (i) {
return i.Id == id;
})[0];
if (!item.TargetPath) {
if (item.Type == "Episode") {
organizeFileWithCorrections(page, item);
}
return;
}
var message = Globalize.translate('MessageFollowingFileWillBeMovedFrom') + '
' + item.OriginalPath + '
' + Globalize.translate('MessageDestinationTo') + '
' + item.TargetPath;
if (item.DuplicatePaths.length) {
message += '
' + Globalize.translate('MessageDuplicatesWillBeDeleted');
message += '
' + item.DuplicatePaths.join('
');
}
message += '
' + Globalize.translate('MessageSureYouWishToProceed');
require(['confirm'], function (confirm) {
confirm(message, Globalize.translate('HeaderOrganizeFile')).then(function () {
Dashboard.showLoadingMsg();
ApiClient.performOrganization(id).then(function () {
Dashboard.hideLoadingMsg();
reloadItems(page, true);
}, Dashboard.processErrorResponse);
});
});
}
function reloadItems(page, showSpinner) {
if (showSpinner) {
Dashboard.showLoadingMsg();
}
ApiClient.getFileOrganizationResults(query).then(function (result) {
currentResult = result;
renderResults(page, result);
Dashboard.hideLoadingMsg();
}, Dashboard.processErrorResponse);
}
function getStatusText(item, enhance) {
var status = item.Status;
var color = null;
if (status == 'SkippedExisting') {
status = Globalize.translate('StatusSkipped');
}
else if (status == 'Failure') {
color = '#cc0000';
status = Globalize.translate('StatusFailed');
}
if (status == 'Success') {
color = 'green';
status = Globalize.translate('StatusSuccess');
}
if (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 += '