DocSpace-buildtools/web/ASC.Web.Common/src/store/SettingsStore.js

134 lines
3.7 KiB
JavaScript
Raw Normal View History

2021-02-02 09:55:14 +00:00
import { action, computed, makeObservable, observable } from "mobx";
import api from "../api";
import { LANGUAGE } from "../constants";
const desktop = window["AscDesktopEditor"] !== undefined;
2021-02-02 09:55:14 +00:00
// const desktopEncryption =
// desktop && typeof window.AscDesktopEditor.cloudCryptoCommand === "function";
// const lang = localStorage[LANGUAGE]
// ? localStorage
// .getItem(LANGUAGE)
// .split("-")
// .find((el) => el[0])
// : "en";
class SettingsStore {
2021-02-02 09:55:14 +00:00
currentProductId = "";
culture = "en-US";
cultures = [];
trustedDomains = [];
trustedDomainsType = 1;
timezone = "UTC";
timezones = [];
utcOffset = "00:00:00";
utcHoursOffset = 0;
defaultPage = "/products/files";
homepage = ""; //config.homepage;
datePattern = "M/d/yyyy";
datePatternJQ = "00/00/0000";
dateTimePattern = "dddd, MMMM d, yyyy h:mm:ss tt";
datepicker = {
datePattern: "mm/dd/yy",
dateTimePattern: "DD: mm dd: yy h:mm:ss tt",
timePattern: "h:mm tt",
};
2021-02-02 09:55:14 +00:00
organizationName = "ONLYOFFICE";
greetingSettings = "Web Office Applications";
enableAdmMess = false;
urlLicense = "https://gnu.org/licenses/gpl-3.0.html";
urlSupport = "https://helpdesk.onlyoffice.com/";
logoUrl = "images/nav.logo.opened.react.svg";
customNames = {
id: "Common",
userCaption: "User",
usersCaption: "Users",
groupCaption: "Group",
groupsCaption: "Groups",
userPostCaption: "Title",
regDateCaption: "Registration Date",
groupHeadCaption: "Head",
guestCaption: "Guest",
guestsCaption: "Guests",
};
isDesktopClient = desktop;
//isDesktopEncryption: desktopEncryption;
isEncryptionSupport = false;
encryptionKeys = null;
isTabletView = false;
hashSettings = null;
constructor() {
2021-02-02 09:55:14 +00:00
makeObservable(this, {
currentProductId: observable,
culture: observable,
cultures: observable,
trustedDomains: observable,
trustedDomainsType: observable,
timezone: observable,
timezones: observable,
utcOffset: observable,
utcHoursOffset: observable,
defaultPage: observable,
homepage: observable,
datePattern: observable,
datePatternJQ: observable,
dateTimePattern: observable,
datepicker: observable,
organizationName: observable,
greetingSettings: observable,
enableAdmMess: observable,
urlLicense: observable,
urlSupport: observable,
urlAuthKeys: computed,
logoUrl: observable,
customNames: observable,
isDesktopClient: observable,
isEncryptionSupport: observable,
encryptionKeys: observable,
isTabletView: observable,
hashSettings: observable,
getSettings: action,
getCurrentCustomSchema: action,
getPortalSettings: action,
});
}
2021-02-02 09:55:14 +00:00
get urlAuthKeys() {
const splitted = this.culture.split("-");
const lang = splitted.length > 0 ? splitted[0] : "en";
return `https://helpcenter.onlyoffice.com/${lang}/installation/groups-authorization-keys.aspx`;
}
2021-02-02 09:55:14 +00:00
getSettings = async () => {
const newSettings = await api.settings.getSettings();
2021-02-02 09:55:14 +00:00
Object.keys(newSettings).map((key) => {
if (this[key]) {
this[key] = newSettings[key];
2021-02-02 09:55:14 +00:00
if (key === "culture" && !localStorage.getItem(LANGUAGE)) {
localStorage.setItem(LANGUAGE, newSettings[key]);
}
} else if (key === "passwordHash") {
this.hashSettings = newSettings[key];
}
});
2021-02-02 09:55:14 +00:00
return newSettings;
};
2021-02-02 09:55:14 +00:00
getCurrentCustomSchema = async (id) => {
this.customNames = await api.settings.getCurrentCustomSchema(id);
};
2021-02-02 09:55:14 +00:00
getPortalSettings = async () => {
const origSettings = await this.getSettings();
if (origSettings.nameSchemaId) {
this.getCurrentCustomSchema(origSettings.nameSchemaId);
}
};
}
export default SettingsStore;