jellyfin-web/dashboard-ui/scripts/mysync.js

110 lines
3.3 KiB
JavaScript
Raw Normal View History

2016-08-20 23:59:36 -07:00
define(['apphost', 'globalize', 'syncJobList', 'events', 'localsync', 'emby-button', 'paper-icon-button-light'], function (appHost, globalize, syncJobList, events, localSync) {
2016-08-16 22:29:05 -07:00
function initSupporterInfo(view, params) {
view.querySelector('.btnSyncSupporter').addEventListener('click', function () {
2016-10-14 09:22:04 -07:00
requirejs(["registrationServices"], function (registrationServices) {
2016-08-16 22:29:05 -07:00
registrationServices.validateFeature('sync');
});
});
view.querySelector('.supporterPromotion .mainText').innerHTML = globalize.translate('HeaderSyncRequiresSupporterMembership');
var apiClient = ApiClient;
apiClient.getPluginSecurityInfo().then(function (regInfo) {
if (regInfo.IsMBSupporter) {
view.querySelector('.supporterPromotionContainer').classList.add('hide');
} else {
view.querySelector('.supporterPromotionContainer').classList.remove('hide');
}
}, function () {
view.querySelector('.supporterPromotionContainer').classList.remove('hide');
});
}
2015-08-12 14:39:02 -07:00
2016-08-16 11:54:08 -07:00
return function (view, params) {
2015-08-12 14:39:02 -07:00
2016-08-16 11:54:08 -07:00
var interval;
2015-08-12 14:39:02 -07:00
2016-08-16 11:54:08 -07:00
function isLocalSyncManagement() {
return appHost.supports('sync') && params.mode == 'offline';
}
2015-08-12 14:39:02 -07:00
2016-08-16 11:54:08 -07:00
function refreshSyncStatus(page) {
2015-08-12 14:39:02 -07:00
2016-08-16 11:54:08 -07:00
if (isLocalSyncManagement()) {
2016-06-19 09:53:53 -07:00
2016-08-19 15:56:32 -07:00
var status = localSync.getSyncStatus();
2015-08-12 14:39:02 -07:00
2016-08-16 11:54:08 -07:00
if (status == "Active") {
page.querySelector('.btnSyncNow').classList.add('hide');
}
else {
page.querySelector('.btnSyncNow').classList.remove('hide');
}
}
}
2015-08-12 14:39:02 -07:00
2016-08-16 11:54:08 -07:00
function syncNow(page) {
2015-08-12 14:39:02 -07:00
2016-08-19 15:56:32 -07:00
localSync.sync();
2016-08-16 11:54:08 -07:00
require(['toast'], function (toast) {
toast(Globalize.translate('MessageSyncStarted'));
});
refreshSyncStatus(page);
}
2015-08-12 14:39:02 -07:00
2016-06-19 09:53:53 -07:00
view.querySelector('.btnSyncNow').addEventListener('click', function () {
syncNow(view);
2015-08-12 14:39:02 -07:00
});
2016-08-16 11:54:08 -07:00
if (isLocalSyncManagement()) {
2015-10-01 23:14:04 -07:00
2016-06-19 09:53:53 -07:00
view.querySelector('.localSyncStatus').classList.remove('hide');
2015-10-01 23:14:04 -07:00
2016-06-19 09:53:53 -07:00
} else {
view.querySelector('.localSyncStatus').classList.add('hide');
}
2015-08-12 14:39:02 -07:00
2016-08-16 22:29:05 -07:00
initSupporterInfo(view, params);
var mySyncJobList = new syncJobList({
isLocalSync: params.mode === 'offline',
serverId: ApiClient.serverId(),
userId: params.mode === 'offline' ? null : ApiClient.getCurrentUserId(),
element: view.querySelector('.syncActivity')
});
events.on(mySyncJobList, 'jobedit', function (e, jobId, serverId) {
Dashboard.navigate('mysyncjob.html?id=' + jobId);
});
2016-06-19 09:53:53 -07:00
view.addEventListener('viewbeforeshow', function () {
2015-08-12 14:39:02 -07:00
2016-08-16 22:29:05 -07:00
refreshSyncStatus(view);
2015-08-12 14:39:02 -07:00
2016-08-16 22:29:05 -07:00
if (appHost.supports('sync')) {
interval = setInterval(function () {
refreshSyncStatus(view);
}, 5000);
}
2016-06-19 09:53:53 -07:00
});
2015-08-12 14:39:02 -07:00
2016-06-19 09:53:53 -07:00
view.addEventListener('viewbeforehide', function () {
2015-08-12 14:39:02 -07:00
2016-06-19 09:53:53 -07:00
if (interval) {
clearInterval(interval);
interval = null;
}
});
2016-08-16 22:29:05 -07:00
view.addEventListener('viewdestroy', function () {
mySyncJobList.destroy();
});
2016-06-19 09:53:53 -07:00
};
});