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

69 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-06-19 09:53:53 -07:00
define(['localsync'], function () {
2015-08-12 14:39:02 -07:00
function refreshSyncStatus(page) {
2016-06-19 09:53:53 -07:00
if (LocalSync.isSupported()) {
2015-08-12 14:39:02 -07:00
2016-06-19 09:53:53 -07:00
var status = LocalSync.getSyncStatus();
2015-08-12 14:39:02 -07:00
2016-06-19 09:53:53 -07:00
page.querySelector('.labelSyncStatus').innerHTML = Globalize.translate('LabelLocalSyncStatusValue', status);
page.querySelector('.syncSpinner').active = status == "Active";
2015-08-12 14:39:02 -07:00
2016-06-19 09:53:53 -07:00
if (status == "Active") {
page.querySelector('.btnSyncNow').classList.add('hide');
2015-08-12 14:39:02 -07:00
}
2016-06-19 09:53:53 -07:00
else {
page.querySelector('.btnSyncNow').classList.remove('hide');
}
}
2015-08-12 14:39:02 -07:00
}
function syncNow(page) {
2016-06-19 09:53:53 -07:00
LocalSync.sync();
require(['toast'], function (toast) {
toast(Globalize.translate('MessageSyncStarted'));
2015-08-12 14:39:02 -07:00
});
2016-06-19 09:53:53 -07:00
refreshSyncStatus(page);
2015-08-12 14:39:02 -07:00
}
2016-06-19 09:53:53 -07:00
return function (view, params) {
2015-08-12 14:39:02 -07:00
2016-06-19 09:53:53 -07:00
var interval;
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-06-19 09:53:53 -07:00
if (LocalSync.isSupported()) {
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');
view.querySelector('.syncSpinner').active = false;
}
2015-08-12 14:39:02 -07:00
2016-06-19 09:53:53 -07:00
view.addEventListener('viewbeforeshow', function () {
var page = this;
2015-08-12 14:39:02 -07:00
refreshSyncStatus(page);
2016-06-19 09:53:53 -07:00
interval = setInterval(function () {
refreshSyncStatus(page);
}, 5000);
});
2015-08-12 14:39:02 -07:00
2016-06-19 09:53:53 -07:00
view.addEventListener('viewbeforehide', function () {
var page = this;
2015-08-12 14:39:02 -07:00
2016-06-19 09:53:53 -07:00
page.querySelector('.syncSpinner').active = false;
2015-08-12 14:39:02 -07:00
2016-06-19 09:53:53 -07:00
if (interval) {
clearInterval(interval);
interval = null;
}
});
};
});