jellyfin-web/dashboard-ui/scripts/mysync.js
2016-08-16 14:54:08 -04:00

75 lines
2.0 KiB
JavaScript

define(['loading', 'apphost', 'localsync'], function (loading, appHost) {
return function (view, params) {
var interval;
function isLocalSyncManagement() {
return appHost.supports('sync') && params.mode == 'offline';
}
function refreshSyncStatus(page) {
if (isLocalSyncManagement()) {
var status = LocalSync.getSyncStatus();
page.querySelector('.labelSyncStatus').innerHTML = Globalize.translate('LabelLocalSyncStatusValue', status);
if (status == 'Active') {
loading.show();
} else {
loading.hide();
}
if (status == "Active") {
page.querySelector('.btnSyncNow').classList.add('hide');
}
else {
page.querySelector('.btnSyncNow').classList.remove('hide');
}
}
}
function syncNow(page) {
LocalSync.sync();
require(['toast'], function (toast) {
toast(Globalize.translate('MessageSyncStarted'));
});
refreshSyncStatus(page);
}
view.querySelector('.btnSyncNow').addEventListener('click', function () {
syncNow(view);
});
if (isLocalSyncManagement()) {
view.querySelector('.localSyncStatus').classList.remove('hide');
} else {
view.querySelector('.localSyncStatus').classList.add('hide');
}
view.addEventListener('viewbeforeshow', function () {
var page = this;
refreshSyncStatus(page);
interval = setInterval(function () {
refreshSyncStatus(page);
}, 5000);
});
view.addEventListener('viewbeforehide', function () {
var page = this;
loading.hide();
if (interval) {
clearInterval(interval);
interval = null;
}
});
};
});