diff --git a/src/bower_components/emby-webcomponents/sync/syncjobeditor.js b/src/bower_components/emby-webcomponents/sync/syncjobeditor.js deleted file mode 100644 index a4666bab72..0000000000 --- a/src/bower_components/emby-webcomponents/sync/syncjobeditor.js +++ /dev/null @@ -1,504 +0,0 @@ -define(['connectionManager', 'serverNotifications', 'events', 'datetime', 'dom', 'imageLoader', 'loading', 'globalize', 'apphost', 'layoutManager', 'scrollHelper', 'dialogHelper', 'listViewStyle', 'paper-icon-button-light', 'emby-button', 'formDialogStyle', 'emby-linkbutton'], function (connectionManager, serverNotifications, events, datetime, dom, imageLoader, loading, globalize, appHost, layoutManager, scrollHelper, dialogHelper) { - 'use strict'; - - function syncNow() { - require(['localsync'], function (localSync) { - localSync.sync(); - }); - } - - function renderJob(context, job, dialogOptions) { - - require(['syncDialog'], function (syncDialog) { - syncDialog.renderForm({ - elem: context.querySelector('.syncJobFormContent'), - dialogOptions: dialogOptions, - dialogOptionsFn: getTargetDialogOptionsFn(dialogOptions), - 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 = ''; - var status = jobItem.Status; - - var nextAction; - - if (status === 'Failed') { - nextAction = 'retry'; - } - else if (status === 'Cancelled') { - nextAction = 'retry'; - } - else if (status === 'Queued' || status === 'Transferring' || status === 'Converting' || status === 'ReadyToTransfer') { - nextAction = 'cancel'; - } - else if (status === 'Synced' && !jobItem.IsMarkedForRemoval) { - nextAction = 'remove'; - } - - var listItemClass = 'listItem listItem-border'; - if (layoutManager.tv && nextAction) { - listItemClass += ' btnJobItemMenu'; - } - - if (layoutManager.tv) { - listItemClass += ' listItem-button'; - } - - var tagName = layoutManager.tv ? 'button' : 'div'; - html += '<' + tagName + ' type="button" class="' + listItemClass + '" data-itemid="' + jobItem.Id + '" data-status="' + jobItem.Status + '" data-action="' + nextAction + '">'; - - var imgUrl; - - if (jobItem.PrimaryImageItemId) { - - imgUrl = apiClient.getImageUrl(jobItem.PrimaryImageItemId, { - type: "Primary", - width: 80, - tag: jobItem.PrimaryImageTag, - minScale: 1.5 - }); - } - - if (imgUrl) { - html += '
'; - } - else { - html += 'sync'; - } - - html += '
'; - - html += '

'; - html += jobItem.ItemName; - html += '

'; - - if (jobItem.Status === 'Failed') { - html += '
'; - } else { - html += '
'; - } - html += globalize.translate('sharedcomponents#SyncJobItemStatus' + jobItem.Status); - if (jobItem.Status === 'Synced' && jobItem.IsMarkedForRemoval) { - html += '
'; - html += globalize.translate('sharedcomponents#RemovingFromDevice'); - } - html += '
'; - - html += '
'; - html += '
'; - html += '
'; - - html += '
'; - - var moreIcon = ''; - - if (!layoutManager.tv) { - - if (nextAction === 'retry') { - html += ''; - } - else if (nextAction === 'cancel') { - html += ''; - } - else if (nextAction === 'remove') { - html += ''; - } - } - - html += ''; - return html; - } - - function renderJobItems(context, items, apiClient) { - - var html = ''; - - html += '

' + globalize.translate('sharedcomponents#Items') + '

'; - - html += '
'; - - var index = 0; - html += items.map(function (i) { - - return getJobItemHtml(i, apiClient, index++); - - }).join(''); - - html += '
'; - - 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 action = elem.getAttribute('data-action'); - var context = parentWithClass(elem, 'formDialog'); - var listItem = parentWithClass(elem, 'listItem'); - var jobItemId = listItem.getAttribute('data-itemid'); - - var menuItems = []; - - if (action === 'retry') { - retryJobItem(context, jobId, jobItemId, apiClient); - } - else if (action === 'cancel' || action === 'remove') { - cancelJobItem(context, jobId, jobItemId, apiClient); - } - } - - function cancelJobItem(context, jobId, jobItemId, apiClient) { - - showRemoveConfirm(function () { - loading.show(); - - apiClient.ajax({ - - type: "DELETE", - url: apiClient.getUrl('Sync/JobItems/' + jobItemId) - - }).then(function () { - - // TODO this should check editor options.mode === 'download' - if (appHost.supports('sync')) { - syncNow(); - } - - loadJob(context, jobId, apiClient); - }); - }); - } - - function retryJobItem(context, jobId, jobItemId, apiClient) { - - showRetryConfirm(function () { - apiClient.ajax({ - - type: "POST", - url: apiClient.getUrl('Sync/JobItems/' + jobItemId + '/Enable') - - }).then(function () { - - // TODO this should check editor options.mode === 'download' - if (appHost.supports('sync')) { - syncNow(); - } - - loadJob(context, jobId, apiClient); - }); - }); - } - - function showRetryConfirm(callback) { - - // TODO Implement this as a retry dialog - require(['confirm'], function (confirm) { - - confirm({ - - text: globalize.translate('sharedcomponents#ConfirmRemoveDownload'), - confirmText: globalize.translate('sharedcomponents#RemoveDownload'), - cancelText: globalize.translate('sharedcomponents#KeepDownload'), - primary: 'cancel' - - }).then(callback); - }); - } - - function showRemoveConfirm(callback) { - - require(['confirm'], function (confirm) { - - confirm({ - - text: globalize.translate('sharedcomponents#ConfirmRemoveDownload'), - confirmText: globalize.translate('sharedcomponents#RemoveDownload'), - cancelText: globalize.translate('sharedcomponents#KeepDownload'), - primary: 'cancel' - - }).then(callback); - }); - } - - function showConfirm(text, callback) { - - require(['confirm'], function (confirm) { - - confirm(text).then(callback); - }); - } - - function fillJobValues(context, job, editOptions) { - - 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 () { - - // TODO this should check editor options.mode === 'download' - if (appHost.supports('sync')) { - syncNow(); - } - - loading.hide(); - dialogHelper.close(context); - }); - }); - }); - - } - - function startListening(apiClient, jobId) { - - var startParams = "0,1500"; - - startParams += "," + jobId; - - apiClient.sendMessage("SyncJobStart", startParams); - } - - function stopListening(apiClient) { - - apiClient.sendMessage("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 += '
'; - html += ''; - html += '

'; - html += globalize.translate('sharedcomponents#Sync'); - html += '

'; - - if (appHost.supports('externallinks')) { - html += 'info' + globalize.translate('sharedcomponents#Help') + ''; - } - - html += '
'; - - html += '
'; - html += '
'; - - html += '
'; - - html += '
'; - - html += '
'; - - html += '
'; - html += ''; - html += '
'; - - html += '
'; - - html += '
'; - html += '
'; - - dlg.innerHTML = html; - - 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 - }; - -}); \ No newline at end of file diff --git a/src/bower_components/emby-webcomponents/sync/syncjoblist.js b/src/bower_components/emby-webcomponents/sync/syncjoblist.js deleted file mode 100644 index 9ae477fb50..0000000000 --- a/src/bower_components/emby-webcomponents/sync/syncjoblist.js +++ /dev/null @@ -1,455 +0,0 @@ -define(['serverNotifications', 'events', 'loading', 'connectionManager', 'imageLoader', 'dom', 'globalize', 'registrationServices', 'layoutManager', 'listViewStyle'], function (serverNotifications, events, loading, connectionManager, imageLoader, dom, globalize, registrationServices, layoutManager) { - 'use strict'; - - function onSyncJobCreated(e, apiClient, data) { - var listInstance = this; - fetchData(listInstance); - } - function onSyncJobUpdated(e, apiClient, data) { - var listInstance = this; - - refreshJob(listInstance, data); - } - function onSyncJobCancelled(e, apiClient, data) { - var listInstance = this; - fetchData(listInstance); - } - - function refreshList(listInstance, jobs) { - for (var i = 0, length = jobs.length; i < length; i++) { - - var job = jobs[i]; - refreshJob(listInstance, job); - } - } - - function syncNow() { - require(['localsync'], function (localSync) { - localSync.sync(); - }); - } - - function cancelJob(listInstance, id) { - - require(['confirm'], function (confirm) { - - var msg = globalize.translate('sharedcomponents#ConfirmRemoveDownload'); - - confirm({ - - text: msg, - primary: 'cancel' - - }).then(function () { - - loading.show(); - var apiClient = getApiClient(listInstance); - - apiClient.ajax({ - - url: apiClient.getUrl('Sync/Jobs/' + id), - type: 'DELETE' - - }).then(function () { - - if (listInstance.options.mode === 'download') { - syncNow(); - } - - fetchData(listInstance); - }); - }); - }); - } - - function refreshJob(listInstance, job) { - - var listItem = listInstance.options.element.querySelector('.listItem[data-id=\'' + job.Id + '\']'); - - if (!listItem) { - return; - } - - listItem.querySelector('.jobStatus').innerHTML = getProgressText(job); - } - - function getProgressText(job) { - - var status = job.Status; - - if (status === 'Completed') { - status = 'Synced'; - } - - var html = globalize.translate('sharedcomponents#SyncJobItemStatus' + status); - - if (job.Status === 'Transferring' || job.Status === 'Converting' || job.Status === 'Completed') { - html += ' '; - - var progress = job.Progress || 0; - if (progress > 0 && progress < 100) { - progress = progress.toFixed(1); - } - html += progress + '%'; - } - - return html; - } - - function getSyncJobHtml(listInstance, job, apiClient) { - - var html = ''; - - var tagName = layoutManager.tv ? 'button' : 'div'; - var typeAttribute = tagName === 'button' ? ' type="button"' : ''; - - var listItemClass = 'listItem listItem-border'; - - if (layoutManager.tv) { - listItemClass += ' listItem-button listItem-focusscale'; - - listItemClass += ' btnJobMenu'; - } - - var canEdit = (job.ItemCount || 1) > 1 || job.Status === 'Queued'; - html += '<' + tagName + typeAttribute + ' class="' + listItemClass + '" data-canedit="' + canEdit + '" data-id="' + job.Id + '" data-status="' + job.Status + '">'; - - var imgUrl; - - if (job.PrimaryImageItemId) { - - imgUrl = apiClient.getImageUrl(job.PrimaryImageItemId, { - type: "Primary", - width: 80, - tag: job.PrimaryImageTag, - minScale: 1.5 - }); - } - - if (imgUrl) { - html += '
'; - html += '
'; - } - else { - html += 'file_download'; - } - - var textLines = []; - - var name = job.Name; - - if (job.ParentName) { - name += ' - ' + job.ParentName; - } - - textLines.push(name); - - if (job.ItemCount === 1) { - //textLines.push(globalize.translate('sharedcomponents#ValueOneItem')); - } else { - textLines.push(globalize.translate('sharedcomponents#ItemCount', job.ItemCount)); - } - - html += '
'; - - for (var i = 0, length = textLines.length; i < length; i++) { - - if (i === 0) { - html += '

'; - html += textLines[i]; - html += '

'; - } else { - html += '
'; - html += textLines[i]; - html += '
'; - } - } - - html += '
'; - html += getProgressText(job); - html += '
'; - - html += '
'; - - if (!layoutManager.tv) { - - if (canEdit) { - html += ''; - } else { - html += ''; - } - } - - html += ''; - - return html; - } - - function renderList(listInstance, jobs, apiClient) { - - if ((new Date().getTime() - listInstance.lastDataLoad) < 60000) { - refreshList(listInstance, jobs); - return; - } - - listInstance.lastDataLoad = new Date().getTime(); - - var html = ''; - var lastTargetName = ''; - - var mode = listInstance.options.mode; - var showTargetName = mode !== 'download'; - - 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 += '
'; - html += '
'; - hasOpenSection = false; - } - - lastTargetName = targetName; - - html += '
'; - html += '
'; - - html += '

' + targetName + '

'; - - html += '
'; - html += '
'; - hasOpenSection = true; - } - } - - html += getSyncJobHtml(listInstance, job, apiClient); - } - - if (hasOpenSection) { - html += '
'; - html += '
'; - } - - var elem = listInstance.options.element.querySelector('.syncJobListContent'); - - if (!html) { - if (mode === 'download') { - html = '
' + globalize.translate('sharedcomponents#MessageNoDownloadsFound') + '
'; - } else { - html = '
' + globalize.translate('sharedcomponents#MessageNoSyncJobsFound') + '
'; - } - } - - 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.mode === 'download') { - options.TargetId = apiClient.deviceId(); - } - - return apiClient.getJSON(apiClient.getUrl('Sync/Jobs', options)).then(function (response) { - - renderList(listInstance, response.Items, apiClient); - loading.hide(); - }); - } - - 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 (item.getAttribute('data-canedit') === 'true') { - menuItems.push({ - name: globalize.translate('sharedcomponents#Edit'), - id: 'edit' - }); - } - - var txt = globalize.translate('sharedcomponents#RemoveDownload'); - - menuItems.push({ - name: 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; - case 'edit': - showJobEditor(listInstance, elem); - break; - default: - break; - } - } - }); - - }); - } - - function onElementClick(e) { - - var listInstance = this; - - var btnJobMenu = dom.parentWithClass(e.target, 'btnJobMenu'); - if (btnJobMenu) { - showJobMenu(listInstance, btnJobMenu); - return; - } - - var btnCancelJob = dom.parentWithClass(e.target, 'btnCancelJob'); - if (btnCancelJob) { - var listItem = dom.parentWithClass(btnCancelJob, 'listItem'); - if (listItem) { - var jobId = listItem.getAttribute('data-id'); - cancelJob(listInstance, jobId); - } - return; - } - - showJobEditor(listInstance, e.target); - } - - function showJobEditor(listInstance, elem) { - - var listItem = dom.parentWithClass(elem, 'listItem'); - if (listItem && listItem.getAttribute('data-canedit') === 'true') { - var jobId = listItem.getAttribute('data-id'); - // edit job - require(['syncJobEditor'], function (syncJobEditor) { - syncJobEditor.show({ - - serverId: listInstance.options.serverId, - jobId: jobId, - mode: listInstance.options.mode - - }).then(function () { - fetchData(listInstance); - }); - }); - } - } - - function syncJobList(options) { - this.options = options; - - var onSyncJobCreatedHandler = onSyncJobCreated.bind(this); - this.onSyncJobCreatedHandler = onSyncJobCreatedHandler; - events.on(serverNotifications, 'SyncJobCreated', onSyncJobCreatedHandler); - - var onSyncJobCancelledHandler = onSyncJobCancelled.bind(this); - this.onSyncJobCancelledHandler = onSyncJobCancelledHandler; - events.on(serverNotifications, 'SyncJobCancelled', onSyncJobCancelledHandler); - - var onSyncJobUpdatedHandler = onSyncJobUpdated.bind(this); - this.onSyncJobUpdatedHandler = onSyncJobUpdatedHandler; - events.on(serverNotifications, 'SyncJobUpdated', onSyncJobUpdatedHandler); - - var onClickHandler = onElementClick.bind(this); - options.element.addEventListener('click', onClickHandler); - this.onClickHandler = onClickHandler; - - options.element.innerHTML = '
'; - - fetchData(this); - - initSupporterInfo(options.element, getApiClient(this)); - } - - function showSupporterInfo(context) { - - var html = ' - - -
-
- -
- - - \ No newline at end of file