snappymail/dev/Settings/Admin/About.js

91 lines
2.2 KiB
JavaScript
Raw Normal View History

2014-08-21 23:08:34 +08:00
/* global RL_COMMUNITY */
2016-07-16 05:29:42 +08:00
import ko from 'ko';
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
import {i18n, trigger as translatorTrigger} from 'Common/Translator';
import {appSettingsGet, settingsGet} from 'Storage/Settings';
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
import AppStore from 'Stores/Admin/App';
import CoreStore from 'Stores/Admin/Core';
import {getApp} from 'Helper/Apps/Admin';
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
class AboutAdminSettings
2016-06-30 08:02:45 +08:00
{
2016-07-16 05:29:42 +08:00
constructor() {
this.version = ko.observable(appSettingsGet('version'));
this.access = ko.observable(!!settingsGet('CoreAccess'));
this.errorDesc = ko.observable('');
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
this.coreReal = CoreStore.coreReal;
this.coreChannel = CoreStore.coreChannel;
this.coreType = CoreStore.coreType;
this.coreUpdatable = CoreStore.coreUpdatable;
this.coreAccess = CoreStore.coreAccess;
this.coreChecking = CoreStore.coreChecking;
this.coreUpdating = CoreStore.coreUpdating;
this.coreWarning = CoreStore.coreWarning;
this.coreVersion = CoreStore.coreVersion;
this.coreRemoteVersion = CoreStore.coreRemoteVersion;
this.coreRemoteRelease = CoreStore.coreRemoteRelease;
this.coreVersionCompare = CoreStore.coreVersionCompare;
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
this.community = RL_COMMUNITY || AppStore.community();
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
this.coreRemoteVersionHtmlDesc = ko.computed(() => {
translatorTrigger();
return i18n('TAB_ABOUT/HTML_NEW_VERSION', {'VERSION': this.coreRemoteVersion()});
});
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
this.statusType = ko.computed(() => {
let type = '';
const
versionToCompare = this.coreVersionCompare(),
isChecking = this.coreChecking(),
isUpdating = this.coreUpdating(),
isReal = this.coreReal();
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
if (isChecking)
{
type = 'checking';
}
else if (isUpdating)
{
type = 'updating';
}
else if (isReal && 0 === versionToCompare)
{
type = 'up-to-date';
}
else if (isReal && -1 === versionToCompare)
{
type = 'available';
}
else if (!isReal)
{
type = 'error';
this.errorDesc('Cannot access the repository at the moment.');
}
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
return type;
});
}
onBuild() {
if (this.access() && !this.community)
2016-06-30 08:02:45 +08:00
{
getApp().reloadCoreData();
2016-06-30 08:02:45 +08:00
}
2014-08-21 23:08:34 +08:00
}
2016-07-16 05:29:42 +08:00
updateCoreData() {
if (!this.coreUpdating() && !this.community)
{
getApp().updateCoreData();
2016-07-16 05:29:42 +08:00
}
2016-06-30 08:02:45 +08:00
}
2016-07-16 05:29:42 +08:00
}
2014-08-21 23:08:34 +08:00
2016-07-16 03:54:37 +08:00
export {AboutAdminSettings, AboutAdminSettings as default};