1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

unify sync components

This commit is contained in:
Luke Pulverenti 2016-12-24 14:15:27 -05:00
parent 55b5cebda5
commit db403c3cd4
21 changed files with 447 additions and 279 deletions

View file

@ -14,12 +14,12 @@
},
"devDependencies": {},
"ignore": [],
"version": "1.4.397",
"_release": "1.4.397",
"version": "1.4.399",
"_release": "1.4.399",
"_resolution": {
"type": "version",
"tag": "1.4.397",
"commit": "9adcc0001dbf032595448070447de469a8f24130"
"tag": "1.4.399",
"commit": "b926b582df014a7b2b54e93dca167db73d59bbcb"
},
"_source": "https://github.com/MediaBrowser/emby-webcomponents.git",
"_target": "^1.2.1",

View file

@ -16,6 +16,11 @@ define(['apphost', 'globalize', 'connectionManager', 'itemHelper', 'embyRouter',
var commands = [];
if (itemHelper.isLocalItem(item)) {
return commands;
}
if (itemHelper.supportsAddingToCollection(item)) {
commands.push({
name: globalize.translate('sharedcomponents#AddToCollection'),

View file

@ -111,10 +111,20 @@ define(['apphost'], function (appHost) {
return user.Policy.IsAdministrator;
}
function isLocalItem(item) {
if (item && item.Id && item.Id.indexOf('local') === 0) {
return true;
}
return false;
}
return {
getDisplayName: getDisplayName,
supportsAddingToCollection: supportsAddingToCollection,
supportsAddingToPlaylist: supportsAddingToPlaylist,
isLocalItem: isLocalItem,
canIdentify: function (user, itemType) {

View file

@ -353,6 +353,6 @@
"HeaderPlayMyMedia": "\u041c\u0435\u043d\u0456\u04a3 \u0442\u0430\u0441\u044b\u0493\u044b\u0448\u0434\u0435\u0440\u0435\u043a\u0442\u0435\u0440\u0456\u043c\u0434\u0456 \u043e\u0439\u043d\u0430\u0442\u0443",
"HeaderDiscoverEmbyPremiere": "Emby Premiere \u0430\u0448\u044b\u04a3\u044b\u0437",
"OneChannel": "\u0411\u0456\u0440 \u0430\u0440\u043d\u0430\u0434\u0430\u043d",
"ConfirmRemoveDownload": "Remove download?",
"ConfirmRemoveDownload": "\u0416\u04af\u043a\u0442\u0435\u0443\u0434\u0456 \u0430\u043b\u0430\u0441\u0442\u0430\u0439\u043c\u044b\u0437 \u0431\u0430?",
"AddedOnValue": "\u04ae\u0441\u0442\u0435\u043b\u0433\u0435\u043d\u0456 {0}"
}

View file

@ -353,6 +353,6 @@
"HeaderPlayMyMedia": "Reproduzir minha M\u00eddia",
"HeaderDiscoverEmbyPremiere": "Descobrir o Emby Premiere",
"OneChannel": "Um canal",
"ConfirmRemoveDownload": "Remove download?",
"AddedOnValue": "Adicionado em {0}"
"ConfirmRemoveDownload": "Remover download?",
"AddedOnValue": "Adicionado {0}"
}

View file

@ -353,6 +353,6 @@
"HeaderPlayMyMedia": "\u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043c\u043e\u0438 \u043c\u0435\u0434\u0438\u0430\u0434\u0430\u043d\u043d\u044b\u0435",
"HeaderDiscoverEmbyPremiere": "\u041e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 Emby Premiere",
"OneChannel": "\u041e\u0434\u0438\u043d \u043a\u0430\u043d\u0430\u043b",
"ConfirmRemoveDownload": "Remove download?",
"ConfirmRemoveDownload": "\u0418\u0437\u044a\u044f\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443?",
"AddedOnValue": "\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e {0}"
}

View file

@ -68,8 +68,8 @@
"ConfirmDeleteItem": "Deleting this item will delete it from both the file system and your media library. Are you sure you wish to continue?",
"Refresh": "\u5237\u65b0",
"RefreshQueued": "\u5217\u961f\u5df2\u5237\u65b0\u3002",
"AddToCollection": "Add to collection",
"HeaderAddToCollection": "Add to Collection",
"AddToCollection": "\u52a0\u5165\u5408\u96c6",
"HeaderAddToCollection": "\u52a0\u5165\u5408\u96c6",
"NewCollection": "\u65b0\u5408\u96c6",
"LabelCollection": "Collection:",
"Help": "\u5e2e\u52a9",
@ -114,7 +114,7 @@
"Open": "\u6253\u5f00",
"Play": "\u64ad\u653e",
"Queue": "\u52a0\u5165\u961f\u5217",
"Shuffle": "\u6401\u7f6e",
"Shuffle": "\u968f\u673a\u64ad\u653e",
"Identify": "\u8bc6\u522b",
"EditImages": "\u4fee\u6539\u56fe\u7247",
"EditInfo": "\u7f16\u8f91\u4fe1\u606f",
@ -162,7 +162,7 @@
"LabelOverview": "\u5185\u5bb9\u6982\u8ff0\uff1a",
"LabelShortOverview": "\u7b80\u4ecb\uff1a",
"LabelReleaseDate": "\u53d1\u884c\u65e5\u671f\uff1a",
"LabelYear": "Year:",
"LabelYear": "\u5e74\u4efd\uff1a",
"LabelPlaceOfBirth": "\u51fa\u751f\u5730\uff1a",
"LabelAirDays": "\u64ad\u51fa\u65e5\u671f\uff1a",
"LabelAirTime": "\u64ad\u51fa\u65f6\u95f4\uff1a",
@ -213,14 +213,14 @@
"Continuing": "\u7ee7\u7eed",
"Ended": "\u7ed3\u675f",
"HeaderEnabledFields": "\u5df2\u542f\u7528\u7684\u680f",
"HeaderEnabledFieldsHelp": "Uncheck a field to lock it and prevent it's data from being changed.",
"HeaderEnabledFieldsHelp": "\u53cd\u9009\u680f\u4ee5\u9501\u5b9a\u5e76\u4e0d\u8ba9\u5176\u6570\u636e\u88ab\u66f4\u6539\u3002",
"Backdrops": "\u80cc\u666f",
"Images": "\u56fe\u7247",
"Keywords": "\u5173\u952e\u8bcd",
"Runtime": "\u64ad\u653e\u65f6\u95f4",
"Runtime": "\u64ad\u653e\u65f6\u957f",
"ProductionLocations": "Production locations",
"BirthLocation": "\u51fa\u751f\u5730",
"ParentalRating": "Parental Rating",
"ParentalRating": "\u5bb6\u957f\u5206\u7ea7",
"Name": "\u540d\u79f0",
"Overview": "\u6982\u8ff0",
"LabelType": "\u7c7b\u578b\uff1a",
@ -256,7 +256,7 @@
"PleaseEnterNameOrId": "\u8bf7\u8f93\u5165\u4e00\u4e2a\u540d\u79f0\u6216\u4e00\u4e2a\u5916\u90e8ID\u3002",
"MessageItemSaved": "\u9879\u76ee\u5df2\u4fdd\u5b58\u3002",
"SearchResults": "\u641c\u7d22\u7ed3\u679c",
"SyncToOtherDevice": "Sync to other device",
"SyncToOtherDevice": "\u540c\u6b65\u5230\u5176\u4ed6\u8bbe\u5907",
"MakeAvailableOffline": "Make available offline",
"ServerNameIsRestarting": "Emby Server - {0} is restarting.",
"ServerNameIsShuttingDown": "Emby Server - {0} is shutting down.",
@ -264,7 +264,7 @@
"ConfirmDeleteItems": "Deleting these items will delete them from both the file system and your media library. Are you sure you wish to continue?",
"PleaseRestartServerName": "Please restart Emby Server - {0}.",
"SyncJobCreated": "Sync job created.",
"LabelSyncTo": "Sync to:",
"LabelSyncTo": "\u540c\u6b65\u5230\uff1a",
"LabelSyncJobName": "Sync job name:",
"LabelQuality": "Quality:",
"LabelSyncNoTargetsHelp": "It looks like you don't currently have any apps that support sync.",
@ -278,7 +278,7 @@
"AutomaticallySyncNewContentHelp": "New content added to this folder will be automatically synced to the device.",
"LabelItemLimit": "Item limit:",
"LabelItemLimitHelp": "Optional. Set a limit to the number of items that will be synced.",
"PleaseSelectDeviceToSyncTo": "Please select a device to sync to.",
"PleaseSelectDeviceToSyncTo": "\u8bf7\u9009\u62e9\u60a8\u60f3\u8981\u540c\u6b65\u5230\u7684\u8bbe\u5907\u3002",
"Screenshots": "Screenshots",
"MoveRight": "Move right",
"MoveLeft": "Move left",

View file

@ -455,6 +455,10 @@
});
return promise.then(function () {
if (layoutManager.tv) {
scrollHelper.centerFocus.off(dlg.querySelector('.formDialogContent'), false);
}
if (submitted) {
return Promise.resolve();
}

View file

@ -0,0 +1,512 @@
define(['connectionManager', 'serverNotifications', 'events', 'datetime', 'dom', 'imageLoader', 'loading', 'globalize', 'apphost', 'layoutManager', 'scrollHelper', 'dialogHelper', 'shell', 'listViewStyle', 'paper-icon-button-light', 'emby-button', 'formDialogStyle'], function (connectionManager, serverNotifications, events, datetime, dom, imageLoader, loading, globalize, appHost, layoutManager, scrollHelper, dialogHelper, shell) {
'use strict';
function renderJob(context, job, dialogOptions) {
require(['syncDialog'], function (syncDialog) {
syncDialog.renderForm({
elem: context.querySelector('.syncJobFormContent'),
dialogOptions: dialogOptions,
dialogOptionsFn: getTargetDialogOptionsFn(dialogOptions),
showName: true,
readOnlySyncTarget: true
}).then(function () {
fillJobValues(context, job, dialogOptions);
});
});
}
function getTargetDialogOptionsFn(dialogOptions) {
return function (targetId) {
return Promise.resolve(dialogOptions);
};
}
function getJobItemHtml(jobItem, apiClient, index) {
var html = '';
html += '<div class="listItem" data-itemid="' + jobItem.Id + '" data-status="' + jobItem.Status + '" data-remove="' + jobItem.IsMarkedForRemoval + '">';
var hasActions = ['Queued', 'Cancelled', 'Failed', 'ReadyToTransfer', 'Transferring', 'Converting', 'Synced'].indexOf(jobItem.Status) != -1;
var imgUrl;
if (jobItem.PrimaryImageItemId) {
imgUrl = apiClient.getImageUrl(jobItem.PrimaryImageItemId, {
type: "Primary",
width: 80,
tag: jobItem.PrimaryImageTag,
minScale: 1.5
});
}
if (imgUrl) {
html += '<button type="button" is="emby-button" class="blue mini fab autoSize" icon="sync" style="background-image:url(\'' + imgUrl + '\');background-repeat:no-repeat;background-position:center center;background-size: cover;"><i style="visibility:hidden;" class="md-icon">sync</i></button>';
}
else {
html += '<button type="button" is="emby-button" class="blue mini fab autoSize" icon="sync"><i class="md-icon">sync</i></button>';
}
html += '<div class="listItemBody three-line">';
html += '<div>';
html += jobItem.ItemName;
html += '</div>';
if (jobItem.Status == 'Failed') {
html += '<div class="secondary" style="color:red;">';
} else {
html += '<div class="secondary">';
}
html += globalize.translate('SyncJobItemStatus' + jobItem.Status);
if (jobItem.Status == 'Synced' && jobItem.IsMarkedForRemoval) {
html += '<br/>';
html += globalize.translate('SyncJobItemStatusSyncedMarkForRemoval');
}
html += '</div>';
html += '<div class="secondary" style="padding-top:5px;">';
html += '<div style="background:#e0e0e0;height:4px;"><div style="background:#52B54B;width:' + (jobItem.Progress || 0) + '%;height:100%;"></div></div>';
html += '</div>';
html += '</div>';
var moreIcon = appHost.moreIcon === 'dots-horiz' ? '&#xE5D3;' : '&#xE5D4;';
if (hasActions) {
html += '<button type="button" is="paper-icon-button-light" class="btnJobItemMenu autoSize"><i class="md-icon">' + moreIcon + '</i></button>';
} else {
html += '<button type="button" is="paper-icon-button-light" class="btnJobItemMenu autoSize" disabled><i class="md-icon">' + moreIcon + '</i></button>';
}
html += '</div>';
return html;
}
function renderJobItems(context, items, apiClient) {
var html = '';
html += '<h1>' + globalize.translate('HeaderItems') + '</h1>';
html += '<div class="paperList">';
var index = 0;
html += items.map(function (i) {
return getJobItemHtml(i, apiClient, index++);
}).join('');
html += '</div>';
var elem = context.querySelector('.jobItems');
elem.innerHTML = html;
imageLoader.lazyChildren(elem);
}
function parentWithClass(elem, className) {
while (!elem.classList || !elem.classList.contains(className)) {
elem = elem.parentNode;
if (!elem) {
return null;
}
}
return elem;
}
function showJobItemMenu(elem, jobId, apiClient) {
var context = parentWithClass(elem, 'page');
var listItem = parentWithClass(elem, 'listItem');
var jobItemId = listItem.getAttribute('data-itemid');
var status = listItem.getAttribute('data-status');
var remove = listItem.getAttribute('data-remove').toLowerCase() == 'true';
var menuItems = [];
if (status == 'Failed') {
menuItems.push({
name: globalize.translate('ButtonQueueForRetry'),
id: 'retry'
});
}
else if (status == 'Cancelled') {
menuItems.push({
name: globalize.translate('ButtonReenable'),
id: 'retry'
});
}
else if (status == 'Queued' || status == 'Transferring' || status == 'Converting' || status == 'ReadyToTransfer') {
menuItems.push({
name: globalize.translate('ButtonCancelItem'),
id: 'cancel'
});
}
else if (status == 'Synced' && remove) {
menuItems.push({
name: globalize.translate('ButtonUnmarkForRemoval'),
id: 'unmarkforremoval'
});
}
else if (status == 'Synced') {
menuItems.push({
name: globalize.translate('ButtonMarkForRemoval'),
id: 'markforremoval'
});
}
require(['actionsheet'], function (actionsheet) {
actionsheet.show({
items: menuItems,
positionTo: elem,
callback: function (id) {
switch (id) {
case 'cancel':
cancelJobItem(context, jobId, jobItemId, apiClient);
break;
case 'retry':
retryJobItem(context, jobId, jobItemId, apiClient);
break;
case 'markforremoval':
markForRemoval(context, jobId, jobItemId, apiClient);
break;
case 'unmarkforremoval':
unMarkForRemoval(context, jobId, jobItemId, apiClient);
break;
default:
break;
}
}
});
});
}
function cancelJobItem(context, jobId, jobItemId, apiClient) {
// Need a timeout because jquery mobile will not show a popup while another is in the act of closing
loading.show();
apiClient.ajax({
type: "DELETE",
url: apiClient.getUrl('Sync/JobItems/' + jobItemId)
}).then(function () {
loadJob(context, jobId, apiClient);
});
}
function markForRemoval(context, jobId, jobItemId, apiClient) {
apiClient.ajax({
type: "POST",
url: apiClient.getUrl('Sync/JobItems/' + jobItemId + '/MarkForRemoval')
}).then(function () {
loadJob(context, jobId, apiClient);
});
}
function unMarkForRemoval(context, jobId, jobItemId, apiClient) {
apiClient.ajax({
type: "POST",
url: apiClient.getUrl('Sync/JobItems/' + jobItemId + '/UnmarkForRemoval')
}).then(function () {
loadJob(context, jobId, apiClient);
});
}
function retryJobItem(context, jobId, jobItemId, apiClient) {
apiClient.ajax({
type: "POST",
url: apiClient.getUrl('Sync/JobItems/' + jobItemId + '/Enable')
}).then(function () {
loadJob(context, jobId, apiClient);
});
}
function fillJobValues(context, job, editOptions) {
var txtSyncJobName = context.querySelector('#txtSyncJobName');
if (txtSyncJobName) {
txtSyncJobName.value = job.Name;
}
var selectProfile = context.querySelector('#selectProfile');
if (selectProfile) {
selectProfile.value = job.Profile || '';
}
var selectQuality = context.querySelector('#selectQuality');
if (selectQuality) {
selectQuality.value = job.Quality || '';
}
var chkUnwatchedOnly = context.querySelector('#chkUnwatchedOnly');
if (chkUnwatchedOnly) {
chkUnwatchedOnly.checked = job.UnwatchedOnly;
}
var chkSyncNewContent = context.querySelector('#chkSyncNewContent');
if (chkSyncNewContent) {
chkSyncNewContent.checked = job.SyncNewContent;
}
var txtItemLimit = context.querySelector('#txtItemLimit');
if (txtItemLimit) {
txtItemLimit.value = job.ItemLimit;
}
var txtBitrate = context.querySelector('#txtBitrate');
if (job.Bitrate) {
txtBitrate.value = job.Bitrate / 1000000;
} else {
txtBitrate.value = '';
}
var target = editOptions.Targets.filter(function (t) {
return t.Id == job.TargetId;
})[0];
var targetName = target ? target.Name : '';
var selectSyncTarget = context.querySelector('#selectSyncTarget');
if (selectSyncTarget) {
selectSyncTarget.value = targetName;
}
}
var _jobOptions;
function loadJob(context, id, apiClient) {
loading.show();
apiClient.getJSON(apiClient.getUrl('Sync/Jobs/' + id)).then(function (job) {
apiClient.getJSON(apiClient.getUrl('Sync/Options', {
UserId: job.UserId,
ItemIds: (job.RequestedItemIds && job.RequestedItemIds.length ? job.RequestedItemIds.join('') : null),
ParentId: job.ParentId,
Category: job.Category,
TargetId: job.TargetId
})).then(function (options) {
_jobOptions = options;
renderJob(context, job, options);
loading.hide();
});
});
apiClient.getJSON(apiClient.getUrl('Sync/JobItems', {
JobId: id,
AddMetadata: true
})).then(function (result) {
renderJobItems(context, result.Items, apiClient);
loading.hide();
});
}
function loadJobInfo(context, job, jobItems, apiClient) {
//renderJob(page, job, _jobOptions);
renderJobItems(context, jobItems, apiClient);
loading.hide();
}
function saveJob(context, id, apiClient) {
loading.show();
apiClient.getJSON(apiClient.getUrl('Sync/Jobs/' + id)).then(function (job) {
require(['syncDialog'], function (syncDialog) {
syncDialog.setJobValues(job, context);
apiClient.ajax({
url: apiClient.getUrl('Sync/Jobs/' + id),
type: 'POST',
data: JSON.stringify(job),
contentType: "application/json"
}).then(function () {
loading.hide();
dialogHelper.close(context);
});
});
});
}
function onHelpLinkClick(e) {
shell.openUrl(this.href);
e.preventDefault();
return false;
}
function startListening(apiClient, jobId) {
var startParams = "0,1500";
startParams += "," + jobId;
if (apiClient.isWebSocketOpen()) {
apiClient.sendWebSocketMessage("SyncJobStart", startParams);
}
}
function stopListening(apiClient) {
if (apiClient.isWebSocketOpen()) {
apiClient.sendWebSocketMessage("SyncJobStop", "");
}
}
function bindEvents(context, jobId, apiClient) {
context.querySelector('.jobItems').addEventListener('click', function (e) {
var btnJobItemMenu = dom.parentWithClass(e.target, 'btnJobItemMenu');
if (btnJobItemMenu) {
showJobItemMenu(btnJobItemMenu, jobId, apiClient);
}
});
}
function showEditor(options) {
var apiClient = connectionManager.getApiClient(options.serverId);
var id = options.jobId;
var dlgElementOptions = {
removeOnClose: true,
scrollY: false,
autoFocus: false
};
if (layoutManager.tv) {
dlgElementOptions.size = 'fullscreen';
} else {
dlgElementOptions.size = 'medium';
}
var dlg = dialogHelper.createDialog(dlgElementOptions);
dlg.classList.add('formDialog');
var html = '';
html += '<div class="formDialogHeader">';
html += '<button is="paper-icon-button-light" class="btnCancel autoSize" tabindex="-1"><i class="md-icon">&#xE5C4;</i></button>';
html += '<h3 class="formDialogHeaderTitle">';
html += globalize.translate('sharedcomponents#Sync');
html += '</h3>';
html += '<a href="https://github.com/MediaBrowser/Wiki/wiki/Sync" target="_blank" class="clearLink lnkHelp" style="margin-top:0;display:inline-block;vertical-align:middle;margin-left:auto;"><button is="emby-button" type="button" class="button-accent-flat button-flat"><i class="md-icon">info</i><span>' + globalize.translate('sharedcomponents#Help') + '</span></button></a>';
html += '</div>';
html += '<div class="formDialogContent smoothScrollY" style="padding-top:2em;">';
html += '<div class="dialogContentInner dialog-content-centered">';
html += '<form class="syncJobForm" style="margin: auto;">';
html += '<div class="syncJobFormContent"></div>';
html += '<div class="jobItems"></div>';
html += '<div class="formDialogFooter">';
html += '<button is="emby-button" type="submit" class="raised button-submit block formDialogFooterItem"><span>' + globalize.translate('sharedcomponents#Save') + '</span></button>';
html += '</div>';
html += '</form>';
html += '</div>';
html += '</div>';
dlg.innerHTML = html;
dlg.querySelector('.lnkHelp').addEventListener('click', onHelpLinkClick);
var submitted = false;
dlg.querySelector('form').addEventListener('submit', function (e) {
saveJob(dlg, id, apiClient);
e.preventDefault();
return false;
});
dlg.querySelector('.btnCancel').addEventListener('click', function () {
dialogHelper.close(dlg);
});
if (layoutManager.tv) {
scrollHelper.centerFocus.on(dlg.querySelector('.formDialogContent'), false);
}
function onSyncJobMessage(e, apiClient, msg) {
loadJobInfo(dlg, msg.Job, msg.JobItems, apiClient);
}
loadJob(dlg, id, apiClient);
bindEvents(dlg, id, apiClient);
var promise = dialogHelper.open(dlg);
startListening(apiClient, id);
events.on(serverNotifications, "SyncJob", onSyncJobMessage);
return promise.then(function () {
stopListening(apiClient);
events.off(serverNotifications, "SyncJob", onSyncJobMessage);
if (layoutManager.tv) {
scrollHelper.centerFocus.off(dlg.querySelector('.formDialogContent'), false);
}
if (submitted) {
return Promise.resolve();
}
return Promise.reject();
});
}
return {
show: showEditor
};
});

View file

@ -0,0 +1,350 @@
define(['serverNotifications', 'events', 'loading', 'connectionManager', 'imageLoader', 'dom', 'globalize', 'listViewStyle'], function (serverNotifications, events, loading, connectionManager, imageLoader, dom, globalize) {
'use strict';
function onSyncJobsUpdated(e, apiClient, data) {
var listInstance = this;
renderList(listInstance, data);
}
function refreshList(listInstance, jobs) {
for (var i = 0, length = jobs.length; i < length; i++) {
var job = jobs[i];
refreshJob(listInstance, job);
}
}
function cancelJob(listInstance, id) {
require(['confirm'], function (confirm) {
var msg = listInstance.options.isLocalSync ?
globalize.translate('ConfirmRemoveDownload') :
globalize.translate('CancelSyncJobConfirmation');
confirm(msg).then(function () {
loading.show();
var apiClient = getApiClient(listInstance);
apiClient.ajax({
url: apiClient.getUrl('Sync/Jobs/' + id),
type: 'DELETE'
}).then(function () {
fetchData(listInstance);
});
});
});
}
function refreshJob(listInstance, job) {
var listItem = listInstance.options.element.querySelector('.listItem[data-id=\'' + job.Id + '\']');
if (!listItem) {
return;
}
var progress = job.Progress || 0;
var statusIcon = listItem.querySelector('.statusIcon');
if (progress === 0) {
statusIcon.innerHTML = 'file_download';
statusIcon.classList.add('md-icon');
statusIcon.classList.remove('status-text-icon');
statusIcon.classList.add('zeroProgressStatus');
} else if (progress >= 100) {
statusIcon.innerHTML = 'check';
statusIcon.classList.add('md-icon');
statusIcon.classList.remove('status-text-icon');
statusIcon.classList.remove('zeroProgressStatus');
} else {
statusIcon.classList.remove('md-icon');
statusIcon.classList.remove('zeroProgressStatus');
statusIcon.classList.add('status-text-icon');
statusIcon.innerHTML = (Math.round(progress)) + '%';
}
}
function getSyncJobHtml(listInstance, job) {
var html = '';
html += '<div class="listItem" data-id="' + job.Id + '" data-status="' + job.Status + '">';
var progress = job.Progress || 0;
if (progress === 0) {
html += '<i class="md-icon listItemIcon statusIcon zeroProgressStatus">file_download</i>';
} else if (progress >= 100) {
html += '<i class="md-icon listItemIcon statusIcon">check</i>';
} else {
html += '<i class="listItemIcon statusIcon status-text-icon">' + (Math.round(progress)) + '%</i>';
}
var textLines = [];
if (job.ParentName) {
textLines.push(job.ParentName);
}
textLines.push(job.Name);
if (job.ItemCount == 1) {
textLines.push(globalize.translate('ValueItemCount', job.ItemCount));
} else {
textLines.push(globalize.translate('ValueItemCountPlural', job.ItemCount));
}
if (textLines >= 3) {
html += '<div class="listItemBody three-line">';
} else {
html += '<div class="listItemBody two-line">';
}
for (var i = 0, length = textLines.length; i < length; i++) {
if (i == 0) {
html += '<h3 class="listItemBodyText">';
html += textLines[i];
html += '</h3>';
} else {
html += '<div class="listItemBodyText secondary">';
html += textLines[i];
html += '</div>';
}
}
html += '</div>';
html += '<button type="button" is="paper-icon-button-light" class="btnJobMenu listItemButton"><i class="md-icon">more_vert</i></button>';
html += '</div>';
return html;
}
function renderList(listInstance, jobs) {
if ((new Date().getTime() - listInstance.lastDataLoad) < 60000) {
refreshList(listInstance, jobs);
return;
}
listInstance.lastDataLoad = new Date().getTime();
var html = '';
var lastTargetName = '';
var isLocalSync = listInstance.options.isLocalSync;
var showTargetName = !isLocalSync;
var hasOpenSection = false;
for (var i = 0, length = jobs.length; i < length; i++) {
var job = jobs[i];
if (showTargetName) {
var targetName = job.TargetName || 'Unknown';
if (targetName != lastTargetName) {
if (lastTargetName) {
html += '</div>';
html += '<br/>';
html += '<br/>';
html += '<br/>';
hasOpenSection = false;
}
lastTargetName = targetName;
html += '<div class="detailSectionHeader">';
html += '<div>' + targetName + '</div>';
html += '</div>';
html += '<div class="itemsContainer vertical-list">';
hasOpenSection = true;
}
}
html += getSyncJobHtml(listInstance, job);
}
if (hasOpenSection) {
html += '</div>';
}
var elem = listInstance.options.element;
if (!html) {
if (isLocalSync) {
html = '<div style="padding:1em .25em;">' + globalize.translate('MessageDownloadsFound') + '</div>';
} else {
html = '<div style="padding:1em .25em;">' + globalize.translate('MessageNoSyncJobsFound') + '</div>';
}
}
elem.innerHTML = html;
imageLoader.lazyChildren(elem);
}
function fetchData(listInstance) {
listInstance.lastDataLoad = 0;
loading.show();
var options = {};
var apiClient = getApiClient(listInstance);
if (listInstance.options.userId) {
options.UserId = listInstance.options.userId;
}
if (listInstance.options.isLocalSync) {
options.TargetId = apiClient.deviceId();
} else {
options.ExcludeTargetIds = apiClient.deviceId();
}
return apiClient.getJSON(ApiClient.getUrl('Sync/Jobs', options)).then(function (response) {
renderList(listInstance, response.Items);
loading.hide();
});
}
function startListening(listInstance) {
var startParams = "0,1500";
var apiClient = getApiClient(listInstance);
if (listInstance.options.userId) {
startParams += "," + listInstance.options.userId;
}
if (listInstance.options.isLocalSync) {
startParams += "," + apiClient.deviceId();
}
if (apiClient.isWebSocketOpen()) {
apiClient.sendWebSocketMessage("SyncJobsStart", startParams);
}
}
function stopListening(listInstance) {
var apiClient = getApiClient(listInstance);
if (apiClient.isWebSocketOpen()) {
apiClient.sendWebSocketMessage("SyncJobsStop", "");
}
}
function getApiClient(listInstance) {
return connectionManager.getApiClient(listInstance.options.serverId);
}
function showJobMenu(listInstance, elem) {
var item = dom.parentWithClass(elem, 'listItem');
var jobId = item.getAttribute('data-id');
var status = item.getAttribute('data-status');
var menuItems = [];
if (status == 'Cancelled') {
menuItems.push({
name: globalize.translate('ButtonDelete'),
id: 'delete'
});
} else {
var txt = listInstance.options.isLocalSync ?
globalize.translate('RemoveDownload') :
globalize.translate('ButtonCancelSyncJob');
menuItems.push({
name: globalize.translate(txt),
id: 'cancel'
});
}
require(['actionsheet'], function (actionsheet) {
actionsheet.show({
items: menuItems,
positionTo: elem,
callback: function (id) {
switch (id) {
case 'delete':
cancelJob(listInstance, jobId);
break;
case 'cancel':
cancelJob(listInstance, jobId);
break;
default:
break;
}
}
});
});
}
function onElementClick(e) {
var listInstance = this;
var btnJobMenu = dom.parentWithClass(e.target, 'btnJobMenu');
if (btnJobMenu) {
showJobMenu(this, btnJobMenu);
return;
}
var listItem = dom.parentWithClass(e.target, 'listItem');
if (listItem) {
var jobId = listItem.getAttribute('data-id');
// edit job
events.trigger(listInstance, 'jobedit', [jobId, listInstance.options.serverId]);
}
}
function syncJobList(options) {
this.options = options;
var onSyncJobsUpdatedHandler = onSyncJobsUpdated.bind(this);
this.onSyncJobsUpdatedHandler = onSyncJobsUpdatedHandler;
events.on(serverNotifications, 'SyncJobs', onSyncJobsUpdatedHandler);
var onClickHandler = onElementClick.bind(this);
options.element.addEventListener('click', onClickHandler);
this.onClickHandler = onClickHandler;
fetchData(this);
startListening(this);
}
syncJobList.prototype.destroy = function () {
stopListening(this);
var onSyncJobsUpdatedHandler = this.onSyncJobsUpdatedHandler;
this.onSyncJobsUpdatedHandler = null;
events.off(serverNotifications, 'SyncJobs', onSyncJobsUpdatedHandler);
var onClickHandler = this.onClickHandler;
this.onClickHandler = null;
this.options.element.removeEventListener('click', onClickHandler);
this.options = null;
};
return syncJobList;
});

View file

@ -69,8 +69,10 @@
syncToggle.prototype.refresh = function(item) {
this.options.item = item;
updateSyncStatus(this.options.container, item);
if (this.options) {
this.options.item = item;
updateSyncStatus(this.options.container, item);
}
};
syncToggle.prototype.destroy = function () {

View file

@ -1,4 +1,4 @@
define(['connectionManager', 'globalize', 'dom', 'paper-icon-button-light', 'material-icons', 'emby-button', 'css!./userdatabuttons'], function (connectionManager, globalize, dom) {
define(['connectionManager', 'globalize', 'dom', 'itemHelper', 'paper-icon-button-light', 'material-icons', 'emby-button', 'css!./userdatabuttons'], function (connectionManager, globalize, dom, itemHelper) {
'use strict';
var userDataMethods = {
@ -86,6 +86,10 @@ define(['connectionManager', 'globalize', 'dom', 'paper-icon-button-light', 'mat
var itemId = item.Id;
if (itemHelper.isLocalItem(item)) {
return html;
}
var btnCssClass = "btnUserData";
if (cssClass) {