(function () { function cancelJob(page, id) { $('.jobMenu', page).on("popupafterclose.deleteuser", function () { $(this).off('popupafterclose.deleteuser'); var msg = Globalize.translate('CancelSyncJobConfirmation'); Dashboard.confirm(msg, Globalize.translate('HeaderCancelSyncJob'), function (result) { if (result) { Dashboard.showLoadingMsg(); ApiClient.ajax({ url: ApiClient.getUrl('Sync/Jobs/' + id), type: 'DELETE' }).done(function () { reloadData(page); }); } }); }).popup('close'); } function getSyncTargetName(targets, id) { var target = targets.filter(function (t) { return t.Id == id; })[0]; return target ? target.Name : 'Unknown Device'; } function getSyncJobHtml(page, job, cardBoxCssClass, syncJobPage) { var html = ''; html += "
"; html += '
'; html += '"; html += '
'; var textLines = []; if (job.ParentName) { textLines.push(job.ParentName); } textLines.push(job.Name); if (job.ItemCount == 1) { textLines.push(job.ItemCount + ' item'); } else { textLines.push(job.ItemCount + ' items'); } if (!job.ParentName) { textLines.push(' '); } html += '
'; html += ''; html += "
"; for (var i = 0, length = textLines.length; i < length; i++) { html += "
"; html += textLines[i]; html += "
"; } // cardFooter html += "
"; // cardBox html += "
"; // card html += "
"; return html; } function loadData(page, jobs, targets) { var html = ''; var lastTargetName = ''; var cardBoxCssClass = 'cardBox visualCardBox'; var barCssClass = 'detailSectionHeader'; var syncJobPage = 'syncjob.html'; if ($(page).hasClass('mySyncPage')) { syncJobPage = 'mysyncjob.html'; } for (var i = 0, length = jobs.length; i < length; i++) { var job = jobs[i]; var targetName = getSyncTargetName(targets, job.TargetId); if (targetName != lastTargetName) { if (lastTargetName) { html += '
'; html += '
'; html += '
'; } lastTargetName = targetName; html += '

' + targetName + '

'; } html += getSyncJobHtml(page, job, cardBoxCssClass, syncJobPage); } var elem = $('.syncActivity', page).html(html).trigger('create'); $('.btnJobMenu', elem).on('click', function () { showJobMenu(this); }); if (!jobs.length) { elem.html('
' + Globalize.translate('MessageNoSyncJobsFound') + '
'); } } function showJobMenu(elem) { var card = $(elem).parents('.card'); var page = $(elem).parents('.page'); var id = card.attr('data-id'); $('.jobMenu', page).popup("close").remove(); var html = '
'; html += ''; html += '
'; page.append(html); var flyout = $('.jobMenu', page).popup({ positionTo: elem || "window" }).trigger('create').popup("open").on("popupafterclose", function () { $(this).off("popupafterclose").remove(); }); $('.btnCancelJob', flyout).on('click', function () { cancelJob(page, this.getAttribute('data-id')); }); } function reloadData(page) { Dashboard.showLoadingMsg(); var options = {}; Dashboard.getCurrentUser().done(function (user) { if ($(page).hasClass('mySyncPage')) { options.UserId = Dashboard.getCurrentUserId(); } var promise1 = ApiClient.getJSON(ApiClient.getUrl('Sync/Jobs', options)); var promise2 = ApiClient.getJSON(ApiClient.getUrl('Sync/Targets', options)); $.when(promise1, promise2).done(function (response1, response2) { loadData(page, response1[0].Items, response2[0]); Dashboard.hideLoadingMsg(); }); }); } $(document).on('pageshow', ".syncActivityPage", function () { var page = this; reloadData(page); // on here $('.btnSync', page).taskButton({ mode: 'on', progressElem: $('.syncProgress', page), taskKey: 'SyncPrepare' }); }).on('pagehide', ".syncActivityPage", function () { var page = this; // off here $('.btnSync', page).taskButton({ mode: 'off' }); }); })();