2014-07-26 10:30:15 -07:00
|
|
|
|
(function () {
|
|
|
|
|
|
2014-12-10 23:20:28 -07:00
|
|
|
|
function cancelJob(page, id) {
|
|
|
|
|
|
2015-06-22 08:43:19 -07:00
|
|
|
|
var msg = Globalize.translate('CancelSyncJobConfirmation');
|
2014-12-10 23:20:28 -07:00
|
|
|
|
|
2015-06-22 08:43:19 -07:00
|
|
|
|
Dashboard.confirm(msg, Globalize.translate('HeaderCancelSyncJob'), function (result) {
|
2014-12-10 23:20:28 -07:00
|
|
|
|
|
2015-06-22 08:43:19 -07:00
|
|
|
|
if (result) {
|
|
|
|
|
Dashboard.showLoadingMsg();
|
2014-12-10 23:20:28 -07:00
|
|
|
|
|
2015-06-22 08:43:19 -07:00
|
|
|
|
ApiClient.ajax({
|
2014-12-10 23:20:28 -07:00
|
|
|
|
|
2015-06-22 08:43:19 -07:00
|
|
|
|
url: ApiClient.getUrl('Sync/Jobs/' + id),
|
|
|
|
|
type: 'DELETE'
|
2014-12-10 23:20:28 -07:00
|
|
|
|
|
2015-06-22 08:43:19 -07:00
|
|
|
|
}).done(function () {
|
2014-12-10 23:20:28 -07:00
|
|
|
|
|
2015-06-22 08:43:19 -07:00
|
|
|
|
reloadData(page);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-12-10 23:20:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-30 23:24:49 -07:00
|
|
|
|
function getSyncJobHtml(page, job, cardBoxCssClass, syncJobPage) {
|
2014-07-27 15:01:29 -07:00
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
2015-02-04 12:41:10 -07:00
|
|
|
|
html += "<div class='card squareCard' data-id='" + job.Id + "' data-status='" + job.Status + "'>";
|
2014-07-27 15:01:29 -07:00
|
|
|
|
|
2014-12-30 23:24:49 -07:00
|
|
|
|
html += '<div class="' + cardBoxCssClass + '">';
|
2014-07-27 15:01:29 -07:00
|
|
|
|
html += '<div class="cardScalable">';
|
|
|
|
|
|
|
|
|
|
html += '<div class="cardPadder"></div>';
|
|
|
|
|
|
2014-12-30 23:24:49 -07:00
|
|
|
|
syncJobPage += '?id=' + job.Id;
|
|
|
|
|
|
|
|
|
|
html += '<a class="cardContent" href="' + syncJobPage + '">';
|
2014-07-27 15:01:29 -07:00
|
|
|
|
|
|
|
|
|
var imgUrl;
|
2014-12-10 23:20:28 -07:00
|
|
|
|
var style = '';
|
2014-07-27 15:01:29 -07:00
|
|
|
|
|
|
|
|
|
if (job.PrimaryImageItemId) {
|
|
|
|
|
imgUrl = ApiClient.getScaledImageUrl(job.PrimaryImageItemId, {
|
|
|
|
|
type: "Primary",
|
|
|
|
|
width: 400,
|
|
|
|
|
tag: job.PrimaryImageTag
|
|
|
|
|
});
|
2014-12-12 20:56:30 -07:00
|
|
|
|
style = "background-position:center center;";
|
2014-12-10 23:20:28 -07:00
|
|
|
|
} else {
|
|
|
|
|
style = "background-color:#38c;background-position:center center;";
|
|
|
|
|
imgUrl = "css/images/items/detail/video.png";
|
2014-07-27 15:01:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-10 23:20:28 -07:00
|
|
|
|
html += '<div class="cardImage coveredCardImage lazy" data-src="' + imgUrl + '" style="' + style + '">';
|
|
|
|
|
|
2014-12-27 15:52:41 -07:00
|
|
|
|
if (job.Progress && job.Progress < 100) {
|
2014-12-10 23:20:28 -07:00
|
|
|
|
html += '<div class="cardFooter">';
|
|
|
|
|
html += "<div class='cardText cardProgress'>";
|
|
|
|
|
html += '<progress class="itemProgressBar" min="0" max="100" value="' + job.Progress + '"></progress>';
|
|
|
|
|
html += "</div>";
|
2014-07-27 15:01:29 -07:00
|
|
|
|
html += "</div>";
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-10 23:20:28 -07:00
|
|
|
|
html += "</div>";
|
|
|
|
|
|
2015-02-03 11:55:15 -07:00
|
|
|
|
var opacity = '.85';
|
|
|
|
|
var background = 'rgba(204,51,51,' + opacity + ')';
|
|
|
|
|
var text = Globalize.translate('SyncJobStatus' + job.Status);
|
|
|
|
|
|
2014-07-27 15:01:29 -07:00
|
|
|
|
if (job.Status == 'Completed') {
|
2015-02-03 11:55:15 -07:00
|
|
|
|
background = 'rgba(82, 181, 75, ' + opacity + ')';
|
2014-07-27 15:01:29 -07:00
|
|
|
|
}
|
2014-12-12 20:56:30 -07:00
|
|
|
|
else if (job.Status == 'CompletedWithError') {
|
2015-02-03 11:55:15 -07:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (job.Status == 'Queued') {
|
|
|
|
|
background = 'rgba(51, 136, 204, ' + opacity + ')';
|
2014-07-27 15:01:29 -07:00
|
|
|
|
}
|
2015-02-04 20:01:37 -07:00
|
|
|
|
else if (job.Status == 'ReadyToTransfer') {
|
|
|
|
|
background = 'rgba(51, 136, 204, ' + opacity + ')';
|
|
|
|
|
}
|
2015-02-04 12:13:00 -07:00
|
|
|
|
else if (job.Status == 'Transferring') {
|
|
|
|
|
background = 'rgba(72, 0, 255, ' + opacity + ')';
|
|
|
|
|
}
|
|
|
|
|
else if (job.Status == 'Converting') {
|
2015-02-04 20:01:37 -07:00
|
|
|
|
background = 'rgba(255, 106, 0, ' + opacity + ')';
|
2015-02-03 11:55:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-04 20:01:37 -07:00
|
|
|
|
html += '<div class="syncStatusBanner" style="background-color:' + background + ';position:absolute;top:0;right:0;padding:.5em .5em; text-align:left;color: #fff; font-weight: 500; text-transform:uppercase; border-bottom-left-radius: 3px;">';
|
2015-02-03 11:55:15 -07:00
|
|
|
|
html += text;
|
|
|
|
|
html += '</div>';
|
2014-07-27 15:01:29 -07:00
|
|
|
|
|
|
|
|
|
// cardContent
|
2014-12-30 23:24:49 -07:00
|
|
|
|
html += "</a>";
|
2014-07-27 15:01:29 -07:00
|
|
|
|
|
|
|
|
|
// cardScalable
|
|
|
|
|
html += "</div>";
|
|
|
|
|
|
2015-05-12 21:55:19 -07:00
|
|
|
|
html += '<div class="cardFooter outerCardFooter">';
|
2014-07-27 15:01:29 -07:00
|
|
|
|
|
|
|
|
|
var textLines = [];
|
|
|
|
|
|
|
|
|
|
if (job.ParentName) {
|
|
|
|
|
textLines.push(job.ParentName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
textLines.push(job.Name);
|
|
|
|
|
|
|
|
|
|
if (job.ItemCount == 1) {
|
2015-02-04 12:41:10 -07:00
|
|
|
|
textLines.push(Globalize.translate('ValueItemCount', job.ItemCount));
|
2014-07-27 15:01:29 -07:00
|
|
|
|
} else {
|
2015-02-04 12:41:10 -07:00
|
|
|
|
textLines.push(Globalize.translate('ValueItemCountPlural', job.ItemCount));
|
2014-07-27 15:01:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!job.ParentName) {
|
|
|
|
|
textLines.push(' ');
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-23 21:38:46 -07:00
|
|
|
|
html += '<div class="cardText" style="text-align:right; float:right;padding:0;">';
|
2015-07-14 09:39:34 -07:00
|
|
|
|
html += '<paper-icon-button icon="' + AppInfo.moreIcon + '" class="btnJobMenu"></paper-icon-button>';
|
2014-12-10 23:20:28 -07:00
|
|
|
|
html += "</div>";
|
|
|
|
|
|
2014-07-27 15:01:29 -07:00
|
|
|
|
for (var i = 0, length = textLines.length; i < length; i++) {
|
2014-12-10 23:20:28 -07:00
|
|
|
|
html += "<div class='cardText' style='margin-right:30px;'>";
|
2014-07-27 15:01:29 -07:00
|
|
|
|
html += textLines[i];
|
|
|
|
|
html += "</div>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// cardFooter
|
|
|
|
|
html += "</div>";
|
|
|
|
|
|
|
|
|
|
// cardBox
|
|
|
|
|
html += "</div>";
|
|
|
|
|
|
|
|
|
|
// card
|
|
|
|
|
html += "</div>";
|
|
|
|
|
|
|
|
|
|
return html;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-04 13:16:23 -07:00
|
|
|
|
function loadData(page, jobs) {
|
2014-07-26 10:30:15 -07:00
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
var lastTargetName = '';
|
|
|
|
|
|
2014-12-30 23:24:49 -07:00
|
|
|
|
var cardBoxCssClass = 'cardBox visualCardBox';
|
|
|
|
|
|
|
|
|
|
var syncJobPage = 'syncjob.html';
|
|
|
|
|
|
|
|
|
|
if ($(page).hasClass('mySyncPage')) {
|
|
|
|
|
syncJobPage = 'mysyncjob.html';
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-26 10:30:15 -07:00
|
|
|
|
for (var i = 0, length = jobs.length; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
var job = jobs[i];
|
2015-03-07 10:19:44 -07:00
|
|
|
|
var targetName = job.TargetName || 'Unknown';
|
2014-07-26 10:30:15 -07:00
|
|
|
|
|
|
|
|
|
if (targetName != lastTargetName) {
|
2014-12-30 23:24:49 -07:00
|
|
|
|
|
|
|
|
|
if (lastTargetName) {
|
|
|
|
|
html += '<br/>';
|
|
|
|
|
html += '<br/>';
|
|
|
|
|
html += '<br/>';
|
|
|
|
|
}
|
2014-07-26 10:30:15 -07:00
|
|
|
|
|
|
|
|
|
lastTargetName = targetName;
|
2014-12-30 23:24:49 -07:00
|
|
|
|
|
2015-03-07 15:43:53 -07:00
|
|
|
|
html += '<div class="detailSectionHeader">';
|
2015-01-28 20:58:39 -07:00
|
|
|
|
|
|
|
|
|
html += '<div style="display:inline-block;vertical-align:middle;">' + targetName + '</div>';
|
|
|
|
|
|
|
|
|
|
html += '</div>';
|
2014-07-26 10:30:15 -07:00
|
|
|
|
}
|
2014-07-27 15:01:29 -07:00
|
|
|
|
|
2014-12-30 23:24:49 -07:00
|
|
|
|
html += getSyncJobHtml(page, job, cardBoxCssClass, syncJobPage);
|
2014-07-26 10:30:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-29 18:56:25 -07:00
|
|
|
|
var elem = $('.syncActivity', page).html(html).lazyChildren();
|
|
|
|
|
Events.trigger(elem[0], 'create');
|
2015-01-22 23:15:15 -07:00
|
|
|
|
|
2014-12-10 23:20:28 -07:00
|
|
|
|
$('.btnJobMenu', elem).on('click', function () {
|
2015-07-02 05:55:07 -07:00
|
|
|
|
showJobMenu(page, this);
|
2014-12-10 23:20:28 -07:00
|
|
|
|
});
|
2014-12-30 23:24:49 -07:00
|
|
|
|
|
|
|
|
|
if (!jobs.length) {
|
|
|
|
|
|
|
|
|
|
elem.html('<div style="padding:1em .25em;">' + Globalize.translate('MessageNoSyncJobsFound') + '</div>');
|
|
|
|
|
}
|
2014-07-26 10:30:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-02 05:55:07 -07:00
|
|
|
|
function showJobMenu(page, elem) {
|
2014-07-26 10:30:15 -07:00
|
|
|
|
|
2014-12-10 23:20:28 -07:00
|
|
|
|
var card = $(elem).parents('.card');
|
2015-06-22 08:43:19 -07:00
|
|
|
|
var jobId = card.attr('data-id');
|
2015-02-04 12:41:10 -07:00
|
|
|
|
var status = card.attr('data-status');
|
2014-07-26 10:30:15 -07:00
|
|
|
|
|
2015-06-22 08:43:19 -07:00
|
|
|
|
var menuItems = [];
|
2014-12-10 23:20:28 -07:00
|
|
|
|
|
2015-02-04 12:41:10 -07:00
|
|
|
|
if (status == 'Cancelled') {
|
2015-06-22 08:43:19 -07:00
|
|
|
|
menuItems.push({
|
|
|
|
|
name: Globalize.translate('ButtonDelete'),
|
|
|
|
|
id: 'delete',
|
|
|
|
|
ironIcon: 'delete'
|
|
|
|
|
});
|
2015-02-04 12:41:10 -07:00
|
|
|
|
} else {
|
2015-06-22 08:43:19 -07:00
|
|
|
|
menuItems.push({
|
|
|
|
|
name: Globalize.translate('ButtonCancelSyncJob'),
|
|
|
|
|
id: 'cancel',
|
|
|
|
|
ironIcon: 'delete'
|
|
|
|
|
});
|
2015-02-04 12:41:10 -07:00
|
|
|
|
}
|
2014-12-10 23:20:28 -07:00
|
|
|
|
|
2015-06-22 08:43:19 -07:00
|
|
|
|
require(['actionsheet'], function () {
|
2014-12-10 23:20:28 -07:00
|
|
|
|
|
2015-06-22 08:43:19 -07:00
|
|
|
|
ActionSheetElement.show({
|
|
|
|
|
items: menuItems,
|
|
|
|
|
positionTo: elem,
|
|
|
|
|
callback: function (id) {
|
2014-12-10 23:20:28 -07:00
|
|
|
|
|
2015-06-22 08:43:19 -07:00
|
|
|
|
switch (id) {
|
2014-12-10 23:20:28 -07:00
|
|
|
|
|
2015-06-22 08:43:19 -07:00
|
|
|
|
case 'delete':
|
2015-07-02 05:55:07 -07:00
|
|
|
|
cancelJob(page, jobId);
|
2015-06-22 08:43:19 -07:00
|
|
|
|
break;
|
|
|
|
|
case 'cancel':
|
2015-07-02 05:55:07 -07:00
|
|
|
|
cancelJob(page, jobId);
|
2015-06-22 08:43:19 -07:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-12-10 23:20:28 -07:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function reloadData(page) {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
2014-07-26 10:30:15 -07:00
|
|
|
|
|
2014-12-30 23:24:49 -07:00
|
|
|
|
var options = {};
|
|
|
|
|
|
|
|
|
|
Dashboard.getCurrentUser().done(function (user) {
|
|
|
|
|
|
|
|
|
|
if ($(page).hasClass('mySyncPage')) {
|
|
|
|
|
options.UserId = Dashboard.getCurrentUserId();
|
|
|
|
|
}
|
2014-07-26 10:30:15 -07:00
|
|
|
|
|
2015-02-04 13:16:23 -07:00
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl('Sync/Jobs', options)).done(function (response) {
|
2014-07-26 10:30:15 -07:00
|
|
|
|
|
2015-02-04 13:16:23 -07:00
|
|
|
|
loadData(page, response.Items);
|
2014-07-26 10:30:15 -07:00
|
|
|
|
|
2014-12-30 23:24:49 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
|
|
|
|
|
});
|
2014-07-26 10:30:15 -07:00
|
|
|
|
});
|
2014-12-10 23:20:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-04 12:13:00 -07:00
|
|
|
|
function onWebSocketMessage(e, msg) {
|
2015-02-04 13:16:23 -07:00
|
|
|
|
|
2015-02-04 12:13:00 -07:00
|
|
|
|
var page = $.mobile.activePage;
|
|
|
|
|
|
2015-02-04 13:16:23 -07:00
|
|
|
|
if (msg.MessageType == "SyncJobs") {
|
|
|
|
|
loadData(page, msg.Data);
|
2015-02-04 12:13:00 -07:00
|
|
|
|
}
|
2015-02-04 13:16:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startListening(page) {
|
|
|
|
|
|
|
|
|
|
var startParams = "0,1500";
|
|
|
|
|
|
|
|
|
|
if ($(page).hasClass('mySyncPage')) {
|
|
|
|
|
startParams += "," + Dashboard.getCurrentUserId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ApiClient.isWebSocketOpen()) {
|
|
|
|
|
ApiClient.sendWebSocketMessage("SyncJobsStart", startParams);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function stopListening() {
|
|
|
|
|
|
|
|
|
|
if (ApiClient.isWebSocketOpen()) {
|
2015-02-04 20:01:37 -07:00
|
|
|
|
ApiClient.sendWebSocketMessage("SyncJobsStop", "");
|
2015-02-04 12:13:00 -07:00
|
|
|
|
}
|
2015-02-04 13:16:23 -07:00
|
|
|
|
|
2015-02-04 12:13:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 22:56:46 -07:00
|
|
|
|
$(document).on('pageshowready', ".syncActivityPage", function () {
|
2014-12-10 23:20:28 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
2015-01-24 15:33:26 -07:00
|
|
|
|
Dashboard.getPluginSecurityInfo().done(function (pluginSecurityInfo) {
|
|
|
|
|
|
2015-07-29 19:08:35 -07:00
|
|
|
|
if (pluginSecurityInfo.IsMBSupporter) {
|
|
|
|
|
$('.supporterPromotionContainer', page).hide();
|
2015-01-24 15:33:26 -07:00
|
|
|
|
} else {
|
2015-07-29 10:16:00 -07:00
|
|
|
|
$('.supporterPromotionContainer', page).show();
|
2015-07-29 19:08:35 -07:00
|
|
|
|
|
|
|
|
|
if (AppInfo.enableSupporterMembership) {
|
|
|
|
|
$('.supporterPromotion a', page).attr('href', 'http://emby.media/donate');
|
|
|
|
|
$('.supporterPromotion .btnLearnMore', page).show();
|
|
|
|
|
$('.supporterPromotion .mainText', page).html(Globalize.translate('HeaderSyncRequiresSupporterMembership'));
|
|
|
|
|
} else {
|
|
|
|
|
$('.supporterPromotion a', page).attr('href', '#');
|
|
|
|
|
$('.supporterPromotion .btnLearnMore', page).hide();
|
|
|
|
|
$('.supporterPromotion .mainText', page).html(Globalize.translate('HeaderSyncRequiresSupporterMembershipAppVersion'));
|
|
|
|
|
}
|
2015-01-24 15:33:26 -07:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2014-12-10 23:20:28 -07:00
|
|
|
|
reloadData(page);
|
2014-07-26 10:30:15 -07:00
|
|
|
|
|
2015-01-20 13:19:54 -07:00
|
|
|
|
// on here
|
|
|
|
|
$('.btnSync', page).taskButton({
|
|
|
|
|
mode: 'on',
|
|
|
|
|
progressElem: $('.syncProgress', page),
|
|
|
|
|
taskKey: 'SyncPrepare'
|
|
|
|
|
});
|
|
|
|
|
|
2015-02-04 13:16:23 -07:00
|
|
|
|
startListening(page);
|
2015-06-29 11:45:42 -07:00
|
|
|
|
$(ApiClient).on("websocketmessage", onWebSocketMessage);
|
2015-01-20 13:19:54 -07:00
|
|
|
|
|
2015-06-20 17:49:42 -07:00
|
|
|
|
}).on('pagebeforehide', ".syncActivityPage", function () {
|
2015-01-20 13:19:54 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
// off here
|
|
|
|
|
$('.btnSync', page).taskButton({
|
|
|
|
|
mode: 'off'
|
|
|
|
|
});
|
|
|
|
|
|
2015-02-04 13:16:23 -07:00
|
|
|
|
stopListening();
|
2015-06-29 11:45:42 -07:00
|
|
|
|
$(ApiClient).off("websocketmessage", onWebSocketMessage);
|
2014-07-26 10:30:15 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})();
|