jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/sync/syncjobeditor.js

506 lines
16 KiB
JavaScript
Raw Normal View History

2016-12-24 12:15:27 -07:00
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) {
2016-10-22 22:11:46 -07:00
'use strict';
2014-12-30 23:24:49 -07:00
2016-12-24 12:15:27 -07:00
function renderJob(context, job, dialogOptions) {
2016-02-17 21:57:19 -07:00
require(['syncDialog'], function (syncDialog) {
syncDialog.renderForm({
2016-12-24 12:15:27 -07:00
elem: context.querySelector('.syncJobFormContent'),
2016-02-17 21:57:19 -07:00
dialogOptions: dialogOptions,
dialogOptionsFn: getTargetDialogOptionsFn(dialogOptions),
showName: true,
readOnlySyncTarget: true
}).then(function () {
2016-12-24 12:15:27 -07:00
fillJobValues(context, job, dialogOptions);
2016-02-17 21:57:19 -07:00
});
2015-03-14 21:17:35 -07:00
});
}
2014-12-30 23:24:49 -07:00
2015-03-14 21:17:35 -07:00
function getTargetDialogOptionsFn(dialogOptions) {
2014-12-30 23:24:49 -07:00
2015-03-14 21:17:35 -07:00
return function (targetId) {
2014-12-30 23:24:49 -07:00
2016-06-11 10:10:06 -07:00
return Promise.resolve(dialogOptions);
2015-03-14 21:17:35 -07:00
};
2014-12-30 23:24:49 -07:00
}
2016-12-24 00:41:25 -07:00
function getJobItemHtml(jobItem, apiClient, index) {
2014-12-30 23:24:49 -07:00
var html = '';
2016-07-02 11:46:05 -07:00
html += '<div class="listItem" data-itemid="' + jobItem.Id + '" data-status="' + jobItem.Status + '" data-remove="' + jobItem.IsMarkedForRemoval + '">';
2014-12-30 23:24:49 -07:00
2016-12-27 01:07:18 -07:00
var hasActions = ['Queued', 'Cancelled', 'Failed', 'ReadyToTransfer', 'Transferring', 'Converting', 'Synced'].indexOf(jobItem.Status) !== -1;
2014-12-30 23:24:49 -07:00
var imgUrl;
if (jobItem.PrimaryImageItemId) {
2016-12-24 00:41:25 -07:00
imgUrl = apiClient.getImageUrl(jobItem.PrimaryImageItemId, {
2014-12-30 23:24:49 -07:00
type: "Primary",
width: 80,
tag: jobItem.PrimaryImageTag,
minScale: 1.5
});
}
if (imgUrl) {
2016-07-02 11:46:05 -07:00
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>';
2014-12-30 23:24:49 -07:00
}
2015-08-17 09:52:56 -07:00
else {
2016-07-02 11:46:05 -07:00
html += '<button type="button" is="emby-button" class="blue mini fab autoSize" icon="sync"><i class="md-icon">sync</i></button>';
2015-08-17 09:52:56 -07:00
}
2016-07-02 11:46:05 -07:00
html += '<div class="listItemBody three-line">';
2014-12-30 23:24:49 -07:00
2015-08-17 09:52:56 -07:00
html += '<div>';
2014-12-30 23:24:49 -07:00
html += jobItem.ItemName;
2015-08-17 09:52:56 -07:00
html += '</div>';
2014-12-30 23:24:49 -07:00
2016-12-27 01:07:18 -07:00
if (jobItem.Status === 'Failed') {
2016-07-02 11:46:05 -07:00
html += '<div class="secondary" style="color:red;">';
2015-01-20 21:56:00 -07:00
} else {
2016-07-02 11:46:05 -07:00
html += '<div class="secondary">';
2015-01-20 21:56:00 -07:00
}
2016-12-26 10:37:05 -07:00
html += globalize.translate('sharedcomponents#SyncJobItemStatus' + jobItem.Status);
2016-12-27 01:07:18 -07:00
if (jobItem.Status === 'Synced' && jobItem.IsMarkedForRemoval) {
2015-01-20 21:56:00 -07:00
html += '<br/>';
2016-12-26 10:37:05 -07:00
html += globalize.translate('sharedcomponents#RemovingFromDevice');
2015-01-20 21:56:00 -07:00
}
2015-08-17 09:52:56 -07:00
html += '</div>';
2014-12-30 23:24:49 -07:00
2016-07-02 11:46:05 -07:00
html += '<div class="secondary" style="padding-top:5px;">';
2016-07-02 19:47:39 -07:00
html += '<div style="background:#e0e0e0;height:4px;"><div style="background:#52B54B;width:' + (jobItem.Progress || 0) + '%;height:100%;"></div></div>';
2015-09-21 08:43:10 -07:00
html += '</div>';
2016-07-02 11:46:05 -07:00
html += '</div>';
2014-12-30 23:24:49 -07:00
2016-12-24 00:41:25 -07:00
var moreIcon = appHost.moreIcon === 'dots-horiz' ? '&#xE5D3;' : '&#xE5D4;';
2014-12-30 23:24:49 -07:00
if (hasActions) {
2016-12-24 00:41:25 -07:00
html += '<button type="button" is="paper-icon-button-light" class="btnJobItemMenu autoSize"><i class="md-icon">' + moreIcon + '</i></button>';
2014-12-30 23:24:49 -07:00
} else {
2016-12-24 00:41:25 -07:00
html += '<button type="button" is="paper-icon-button-light" class="btnJobItemMenu autoSize" disabled><i class="md-icon">' + moreIcon + '</i></button>';
2014-12-30 23:24:49 -07:00
}
2016-07-02 11:46:05 -07:00
html += '</div>';
2014-12-30 23:24:49 -07:00
return html;
}
2016-12-24 12:15:27 -07:00
function renderJobItems(context, items, apiClient) {
2014-12-30 23:24:49 -07:00
var html = '';
2016-12-26 10:37:05 -07:00
html += '<h1>' + globalize.translate('sharedcomponents#Items') + '</h1>';
2014-12-30 23:24:49 -07:00
2015-08-17 09:52:56 -07:00
html += '<div class="paperList">';
2014-12-30 23:24:49 -07:00
var index = 0;
html += items.map(function (i) {
2016-12-24 00:41:25 -07:00
return getJobItemHtml(i, apiClient, index++);
2014-12-30 23:24:49 -07:00
}).join('');
2015-08-17 09:52:56 -07:00
html += '</div>';
2014-12-30 23:24:49 -07:00
2016-12-24 12:15:27 -07:00
var elem = context.querySelector('.jobItems');
2016-06-20 18:59:39 -07:00
elem.innerHTML = html;
2016-11-24 23:58:38 -07:00
imageLoader.lazyChildren(elem);
2014-12-30 23:24:49 -07:00
}
2016-07-02 11:46:05 -07:00
function parentWithClass(elem, className) {
while (!elem.classList || !elem.classList.contains(className)) {
elem = elem.parentNode;
if (!elem) {
return null;
}
}
return elem;
}
2016-12-24 00:41:25 -07:00
function showJobItemMenu(elem, jobId, apiClient) {
2014-12-30 23:24:49 -07:00
2016-12-24 12:15:27 -07:00
var context = parentWithClass(elem, 'page');
2016-07-02 11:46:05 -07:00
var listItem = parentWithClass(elem, 'listItem');
var jobItemId = listItem.getAttribute('data-itemid');
var status = listItem.getAttribute('data-status');
2016-12-27 01:07:18 -07:00
var remove = listItem.getAttribute('data-remove').toLowerCase() === 'true';
2014-12-30 23:24:49 -07:00
2015-06-22 08:43:19 -07:00
var menuItems = [];
2014-12-30 23:24:49 -07:00
2016-12-27 01:07:18 -07:00
if (status === 'Failed' || status === 'Cancelled') {
2015-06-22 08:43:19 -07:00
menuItems.push({
2016-12-26 10:37:05 -07:00
name: globalize.translate('sharedcomponents#Retry'),
2016-06-18 22:26:52 -07:00
id: 'retry'
2015-06-22 08:43:19 -07:00
});
2015-01-20 20:54:45 -07:00
}
2016-12-27 01:07:18 -07:00
else if (status === 'Queued' || status === 'Transferring' || status === 'Converting' || status === 'ReadyToTransfer') {
2015-06-22 08:43:19 -07:00
menuItems.push({
2016-12-26 10:37:05 -07:00
name: globalize.translate('sharedcomponents#CancelDownload'),
2016-06-18 22:26:52 -07:00
id: 'cancel'
2015-06-22 08:43:19 -07:00
});
2014-12-30 23:24:49 -07:00
}
2016-12-27 01:07:18 -07:00
else if (status === 'Synced' && remove) {
2015-06-22 08:43:19 -07:00
menuItems.push({
2016-12-26 10:37:05 -07:00
name: globalize.translate('sharedcomponents#KeepOnDevice'),
2016-06-18 22:26:52 -07:00
id: 'unmarkforremoval'
2015-06-22 08:43:19 -07:00
});
2015-01-20 21:56:00 -07:00
}
2016-12-27 01:07:18 -07:00
else if (status === 'Synced') {
2015-06-22 08:43:19 -07:00
menuItems.push({
2016-12-26 10:37:05 -07:00
name: globalize.translate('sharedcomponents#RemoveFromDevice'),
2016-06-18 22:26:52 -07:00
id: 'markforremoval'
2015-06-22 08:43:19 -07:00
});
2015-01-20 21:56:00 -07:00
}
2014-12-30 23:24:49 -07:00
2016-01-30 21:04:00 -07:00
require(['actionsheet'], function (actionsheet) {
2015-06-22 08:43:19 -07:00
2016-01-30 21:04:00 -07:00
actionsheet.show({
2015-06-22 08:43:19 -07:00
items: menuItems,
positionTo: elem,
callback: function (id) {
switch (id) {
case 'cancel':
2016-12-24 12:15:27 -07:00
cancelJobItem(context, jobId, jobItemId, apiClient);
2015-06-22 08:43:19 -07:00
break;
case 'retry':
2016-12-24 12:15:27 -07:00
retryJobItem(context, jobId, jobItemId, apiClient);
2015-06-22 08:43:19 -07:00
break;
case 'markforremoval':
2016-12-24 12:15:27 -07:00
markForRemoval(context, jobId, jobItemId, apiClient);
2015-06-22 08:43:19 -07:00
break;
case 'unmarkforremoval':
2016-12-24 12:15:27 -07:00
unMarkForRemoval(context, jobId, jobItemId, apiClient);
2015-06-22 08:43:19 -07:00
break;
default:
break;
}
}
});
2015-01-20 21:56:00 -07:00
});
2015-01-20 20:54:45 -07:00
}
2016-12-24 12:15:27 -07:00
function cancelJobItem(context, jobId, jobItemId, apiClient) {
2015-01-20 20:54:45 -07:00
// Need a timeout because jquery mobile will not show a popup while another is in the act of closing
2016-12-24 00:41:25 -07:00
loading.show();
2015-01-20 20:54:45 -07:00
2016-12-24 00:41:25 -07:00
apiClient.ajax({
2015-01-20 20:54:45 -07:00
type: "DELETE",
2016-12-24 00:41:25 -07:00
url: apiClient.getUrl('Sync/JobItems/' + jobItemId)
2015-01-20 20:54:45 -07:00
2015-12-14 08:43:03 -07:00
}).then(function () {
2015-01-20 20:54:45 -07:00
2016-12-24 12:15:27 -07:00
loadJob(context, jobId, apiClient);
2015-01-20 20:54:45 -07:00
});
}
2016-12-24 12:15:27 -07:00
function markForRemoval(context, jobId, jobItemId, apiClient) {
2015-01-20 21:56:00 -07:00
2016-12-24 00:41:25 -07:00
apiClient.ajax({
2015-01-20 21:56:00 -07:00
type: "POST",
2016-12-24 00:41:25 -07:00
url: apiClient.getUrl('Sync/JobItems/' + jobItemId + '/MarkForRemoval')
2015-01-20 21:56:00 -07:00
2015-12-14 08:43:03 -07:00
}).then(function () {
2015-01-20 21:56:00 -07:00
2016-12-24 12:15:27 -07:00
loadJob(context, jobId, apiClient);
2015-01-20 21:56:00 -07:00
});
}
2016-12-24 12:15:27 -07:00
function unMarkForRemoval(context, jobId, jobItemId, apiClient) {
2015-01-20 21:56:00 -07:00
2016-12-24 00:41:25 -07:00
apiClient.ajax({
2015-01-20 21:56:00 -07:00
type: "POST",
2016-12-24 00:41:25 -07:00
url: apiClient.getUrl('Sync/JobItems/' + jobItemId + '/UnmarkForRemoval')
2015-01-20 21:56:00 -07:00
2015-12-14 08:43:03 -07:00
}).then(function () {
2015-01-20 21:56:00 -07:00
2016-12-24 12:15:27 -07:00
loadJob(context, jobId, apiClient);
2015-01-20 21:56:00 -07:00
});
}
2016-12-24 12:15:27 -07:00
function retryJobItem(context, jobId, jobItemId, apiClient) {
2015-01-20 20:54:45 -07:00
2016-12-24 00:41:25 -07:00
apiClient.ajax({
2015-01-20 20:54:45 -07:00
type: "POST",
2016-12-24 00:41:25 -07:00
url: apiClient.getUrl('Sync/JobItems/' + jobItemId + '/Enable')
2015-01-20 20:54:45 -07:00
2015-12-14 08:43:03 -07:00
}).then(function () {
2015-01-20 20:54:45 -07:00
2016-12-24 12:15:27 -07:00
loadJob(context, jobId, apiClient);
2014-12-30 23:24:49 -07:00
});
}
2016-12-24 12:15:27 -07:00
function fillJobValues(context, job, editOptions) {
2014-12-30 23:24:49 -07:00
2016-12-24 12:15:27 -07:00
var txtSyncJobName = context.querySelector('#txtSyncJobName');
2015-12-14 08:43:03 -07:00
if (txtSyncJobName) {
txtSyncJobName.value = job.Name;
}
2016-12-24 12:15:27 -07:00
var selectProfile = context.querySelector('#selectProfile');
2016-08-17 22:56:10 -07:00
if (selectProfile) {
selectProfile.value = job.Profile || '';
}
2016-12-24 12:15:27 -07:00
var selectQuality = context.querySelector('#selectQuality');
2016-08-17 22:56:10 -07:00
if (selectQuality) {
selectQuality.value = job.Quality || '';
}
2016-12-24 12:15:27 -07:00
var chkUnwatchedOnly = context.querySelector('#chkUnwatchedOnly');
2016-08-17 22:56:10 -07:00
if (chkUnwatchedOnly) {
chkUnwatchedOnly.checked = job.UnwatchedOnly;
}
2014-12-30 23:24:49 -07:00
2016-12-24 12:15:27 -07:00
var chkSyncNewContent = context.querySelector('#chkSyncNewContent');
2016-08-17 22:56:10 -07:00
if (chkSyncNewContent) {
chkSyncNewContent.checked = job.SyncNewContent;
}
2016-12-24 12:15:27 -07:00
var txtItemLimit = context.querySelector('#txtItemLimit');
2016-08-17 22:56:10 -07:00
if (txtItemLimit) {
txtItemLimit.value = job.ItemLimit;
}
2016-12-24 12:15:27 -07:00
var txtBitrate = context.querySelector('#txtBitrate');
2015-03-15 12:10:27 -07:00
if (job.Bitrate) {
2016-08-17 22:56:10 -07:00
txtBitrate.value = job.Bitrate / 1000000;
2015-03-15 12:10:27 -07:00
} else {
2016-08-17 22:56:10 -07:00
txtBitrate.value = '';
2015-03-15 12:10:27 -07:00
}
2014-12-30 23:24:49 -07:00
var target = editOptions.Targets.filter(function (t) {
2016-12-27 01:07:18 -07:00
return t.Id === job.TargetId;
2014-12-30 23:24:49 -07:00
})[0];
var targetName = target ? target.Name : '';
2016-12-24 12:15:27 -07:00
var selectSyncTarget = context.querySelector('#selectSyncTarget');
2016-08-17 22:56:10 -07:00
if (selectSyncTarget) {
selectSyncTarget.value = targetName;
}
2014-12-30 23:24:49 -07:00
}
2015-02-04 20:01:37 -07:00
var _jobOptions;
2016-12-24 12:15:27 -07:00
function loadJob(context, id, apiClient) {
2014-12-30 23:24:49 -07:00
2016-12-24 00:41:25 -07:00
loading.show();
2014-12-30 23:24:49 -07:00
2016-12-24 00:41:25 -07:00
apiClient.getJSON(apiClient.getUrl('Sync/Jobs/' + id)).then(function (job) {
2014-12-30 23:24:49 -07:00
2016-12-24 00:41:25 -07:00
apiClient.getJSON(apiClient.getUrl('Sync/Options', {
2014-12-30 23:24:49 -07:00
UserId: job.UserId,
ItemIds: (job.RequestedItemIds && job.RequestedItemIds.length ? job.RequestedItemIds.join('') : null),
ParentId: job.ParentId,
Category: job.Category,
TargetId: job.TargetId
2014-12-30 23:24:49 -07:00
2015-12-14 08:43:03 -07:00
})).then(function (options) {
2014-12-30 23:24:49 -07:00
2015-02-04 20:01:37 -07:00
_jobOptions = options;
2016-12-24 12:15:27 -07:00
renderJob(context, job, options);
2016-12-24 00:41:25 -07:00
loading.hide();
2014-12-30 23:24:49 -07:00
});
});
2016-12-24 00:41:25 -07:00
apiClient.getJSON(apiClient.getUrl('Sync/JobItems', {
2014-12-30 23:24:49 -07:00
JobId: id,
AddMetadata: true
2015-12-14 08:43:03 -07:00
})).then(function (result) {
2014-12-30 23:24:49 -07:00
2016-12-24 12:15:27 -07:00
renderJobItems(context, result.Items, apiClient);
2016-12-24 00:41:25 -07:00
loading.hide();
2014-12-30 23:24:49 -07:00
});
}
2016-12-24 12:15:27 -07:00
function loadJobInfo(context, job, jobItems, apiClient) {
2015-02-04 20:01:37 -07:00
//renderJob(page, job, _jobOptions);
2016-12-24 12:15:27 -07:00
renderJobItems(context, jobItems, apiClient);
2016-12-24 00:41:25 -07:00
loading.hide();
2015-02-04 20:01:37 -07:00
}
2016-12-24 12:15:27 -07:00
function saveJob(context, id, apiClient) {
2014-12-30 23:24:49 -07:00
2016-12-24 00:41:25 -07:00
loading.show();
2014-12-30 23:24:49 -07:00
2016-12-24 00:41:25 -07:00
apiClient.getJSON(apiClient.getUrl('Sync/Jobs/' + id)).then(function (job) {
2014-12-30 23:24:49 -07:00
2016-02-17 21:57:19 -07:00
require(['syncDialog'], function (syncDialog) {
2016-12-24 12:15:27 -07:00
syncDialog.setJobValues(job, context);
2014-12-30 23:24:49 -07:00
2016-12-24 00:41:25 -07:00
apiClient.ajax({
2014-12-30 23:24:49 -07:00
2016-12-24 00:41:25 -07:00
url: apiClient.getUrl('Sync/Jobs/' + id),
2016-02-17 21:57:19 -07:00
type: 'POST',
data: JSON.stringify(job),
contentType: "application/json"
2014-12-30 23:24:49 -07:00
2016-02-17 21:57:19 -07:00
}).then(function () {
2014-12-30 23:24:49 -07:00
2016-12-24 00:41:25 -07:00
loading.hide();
2016-12-24 12:15:27 -07:00
dialogHelper.close(context);
2016-02-17 21:57:19 -07:00
});
2014-12-30 23:24:49 -07:00
});
});
}
2016-12-24 12:15:27 -07:00
function onHelpLinkClick(e) {
2015-02-04 20:01:37 -07:00
2016-12-24 12:15:27 -07:00
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);
2016-12-24 00:41:25 -07:00
}
2016-12-24 12:15:27 -07:00
}
2016-12-24 00:41:25 -07:00
2016-12-24 12:15:27 -07:00
function stopListening(apiClient) {
2015-02-04 20:01:37 -07:00
2016-12-24 12:15:27 -07:00
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);
}
2016-06-11 10:10:06 -07:00
});
2016-12-24 12:15:27 -07:00
}
2015-02-04 20:01:37 -07:00
2016-12-24 12:15:27 -07:00
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';
2015-02-04 20:01:37 -07:00
}
2016-12-24 12:15:27 -07:00
var dlg = dialogHelper.createDialog(dlgElementOptions);
2015-02-04 20:01:37 -07:00
2016-12-24 12:15:27 -07:00
dlg.classList.add('formDialog');
2015-02-04 20:01:37 -07:00
2016-12-24 12:15:27 -07:00
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>';
2016-12-24 00:41:25 -07:00
2016-12-24 12:15:27 -07:00
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>';
2015-06-08 22:56:46 -07:00
2016-12-24 12:15:27 -07:00
html += '</div>';
2015-06-08 22:56:46 -07:00
2016-12-24 12:15:27 -07:00
html += '<div class="formDialogContent smoothScrollY" style="padding-top:2em;">';
html += '<div class="dialogContentInner dialog-content-centered">';
2015-06-08 22:56:46 -07:00
2016-12-24 12:15:27 -07:00
html += '<form class="syncJobForm" style="margin: auto;">';
2016-12-24 00:41:25 -07:00
2016-12-24 12:15:27 -07:00
html += '<div class="syncJobFormContent"></div>';
2014-12-30 23:24:49 -07:00
2016-12-24 12:15:27 -07:00
html += '<div class="jobItems"></div>';
2014-12-30 23:24:49 -07:00
2016-12-24 12:15:27 -07:00
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>';
2016-08-17 22:56:10 -07:00
2016-12-24 12:15:27 -07:00
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;
});
2014-12-30 23:24:49 -07:00
2016-12-24 12:15:27 -07:00
dlg.querySelector('.btnCancel').addEventListener('click', function () {
dialogHelper.close(dlg);
2016-06-11 10:10:06 -07:00
});
2014-12-30 23:24:49 -07:00
2016-12-24 12:15:27 -07:00
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);
2014-12-30 23:24:49 -07:00
2016-12-24 12:15:27 -07:00
startListening(apiClient, id);
events.on(serverNotifications, "SyncJob", onSyncJobMessage);
return promise.then(function () {
stopListening(apiClient);
2016-12-24 00:41:25 -07:00
events.off(serverNotifications, "SyncJob", onSyncJobMessage);
2016-12-24 12:15:27 -07:00
if (layoutManager.tv) {
scrollHelper.centerFocus.off(dlg.querySelector('.formDialogContent'), false);
}
if (submitted) {
return Promise.resolve();
}
return Promise.reject();
2016-06-11 10:10:06 -07:00
});
2016-12-24 12:15:27 -07:00
}
return {
show: showEditor
2016-06-11 10:10:06 -07:00
};
2014-12-30 23:24:49 -07:00
});