define(['serverNotifications', 'events', 'loading', 'connectionManager', 'imageLoader', 'dom', 'globalize', 'registrationServices', 'listViewStyle'], function (serverNotifications, events, loading, connectionManager, imageLoader, dom, globalize, registrationServices) {
'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('sharedcomponents#ConfirmRemoveDownload') :
globalize.translate('sharedcomponents#CancelSyncJobConfirmation');
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 () {
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 += '
';
var progress = job.Progress || 0;
if (progress === 0) {
html += 'file_download';
} else if (progress >= 100) {
html += 'check';
} else {
html += '' + (Math.round(progress)) + '%';
}
var textLines = [];
if (job.ParentName) {
textLines.push(job.ParentName);
}
textLines.push(job.Name);
if (job.ItemCount === 1) {
textLines.push(globalize.translate('sharedcomponents#ValueOneItem'));
} else {
textLines.push(globalize.translate('sharedcomponents#ItemCount', job.ItemCount));
}
if (textLines >= 3) {
html += '
';
} else {
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 += '';
html += '
';
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 += '
';
html += ' ';
hasOpenSection = false;
}
lastTargetName = targetName;
html += '
';
html += '
' + targetName + '
';
html += '
';
html += '
';
hasOpenSection = true;
}
}
html += getSyncJobHtml(listInstance, job);
}
if (hasOpenSection) {
html += '
';
}
var elem = listInstance.options.element.querySelector('.syncJobListContent');
if (!html) {
if (isLocalSync) {
html = '