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

80 lines
2.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-10-22 22:11:46 -07:00
'use strict';
2016-08-16 22:29:05 -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
var mySyncJobList = new syncJobList({
isLocalSync: params.mode === 'offline',
serverId: ApiClient.serverId(),
userId: params.mode === 'offline' ? null : ApiClient.getCurrentUserId(),
2016-12-26 10:37:05 -07:00
element: view.querySelector('.syncActivity'),
mode: params.mode
2016-08-16 22:29:05 -07:00
});
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
};
});