web-apps/apps/spreadsheeteditor/mobile/src/store/appOptions.js

113 lines
6.6 KiB
JavaScript
Raw Normal View History

import {action, observable, makeObservable} from 'mobx';
import { LocalStorage } from '../../../../common/mobile/utils/LocalStorage';
export class storeAppOptions {
constructor() {
makeObservable(this, {
2021-03-27 13:33:27 +00:00
isEdit: observable,
canViewComments: observable,
setConfigOptions: action,
2021-04-29 16:08:58 +00:00
setPermissionOptions: action,
lostEditingRights: observable,
2021-05-17 11:55:21 +00:00
changeEditingRights: action,
2021-12-18 10:40:59 +00:00
canBranding: observable,
2021-05-17 11:55:21 +00:00
isDocReady: observable,
changeDocReady: action
});
}
isEdit = false;
config = {};
2021-06-05 10:05:28 +00:00
2021-03-27 13:33:27 +00:00
canViewComments = false;
2021-06-05 10:05:28 +00:00
changeCanViewComments(value) {
this.canViewComments = value;
}
2021-12-18 10:40:59 +00:00
canBranding = undefined;
2021-04-29 16:08:58 +00:00
lostEditingRights = false;
changeEditingRights (value) {
this.lostEditingRights = value;
}
2021-05-17 11:55:21 +00:00
isDocReady = false;
changeDocReady (value) {
this.isDocReady = value;
}
2021-04-24 14:57:44 +00:00
setConfigOptions (config, _t) {
this.config = config;
2021-04-24 14:57:44 +00:00
this.customization = config.customization;
this.canRenameAnonymous = !((typeof (this.customization) == 'object') && (typeof (this.customization.anonymous) == 'object') && (this.customization.anonymous.request===false));
this.guestName = (typeof (this.customization) == 'object') && (typeof (this.customization.anonymous) == 'object') &&
(typeof (this.customization.anonymous.label) == 'string') && this.customization.anonymous.label.trim()!=='' ?
Common.Utils.String.htmlEncode(this.customization.anonymous.label) : _t.textGuest;
const value = this.canRenameAnonymous ? LocalStorage.getItem("guest-username") : null;
this.user = Common.Utils.fillUserInfo(config.user, config.lang, value ? (value + ' (' + this.guestName + ')' ) : _t.textAnonymous, LocalStorage.getItem("guest-id") || ('uid-' + Date.now()));
this.user.anonymous && LocalStorage.setItem("guest-id", this.user.id);
2021-04-24 14:57:44 +00:00
config.user = this.user;
this.isDesktopApp = config.targetApp == 'desktop';
this.canCreateNew = !!config.createUrl && !this.isDesktopApp;
this.canOpenRecent = config.recent !== undefined && !this.isDesktopApp;
this.templates = config.templates;
this.recent = config.recent;
this.createUrl = config.createUrl;
this.lang = config.lang;
this.location = (typeof (config.location) == 'string') ? config.location.toLowerCase() : '';
this.region = (typeof (config.region) == 'string') ? config.region.toLowerCase() : config.region;
this.sharingSettingsUrl = config.sharingSettingsUrl;
this.fileChoiceUrl = config.fileChoiceUrl;
this.isEditDiagram = config.mode == 'editdiagram';
this.isEditMailMerge = config.mode == 'editmerge';
this.mergeFolderUrl = config.mergeFolderUrl;
this.canAnalytics = false;
this.canRequestClose = config.canRequestClose;
this.canBackToFolder = (config.canBackToFolder!==false) && (typeof (config.customization) == 'object') && (typeof (config.customization.goback) == 'object')
&& (!!(config.customization.goback.url) || config.customization.goback.requestClose && this.canRequestClose);
this.canBack = this.canBackToFolder === true;
this.canPlugins = false;
2021-07-01 23:06:34 +00:00
AscCommon.UserInfoParser.setParser(true);
AscCommon.UserInfoParser.setCurrentName(this.user.fullname);
}
2021-06-09 12:18:04 +00:00
setPermissionOptions (document, licType, params, permissions, isSupportEditFeature) {
2021-06-25 15:14:24 +00:00
if (params.asc_getRights() !== Asc.c_oRights.Edit)
permissions.edit = false;
2021-12-20 09:17:16 +00:00
this.canBranding = params.asc_getCustomization();
this.canBrandingExt = params.asc_getCanBranding() && (typeof this.customization == 'object');
this.canAutosave = true;
this.canAnalytics = params.asc_getIsAnalyticsEnable();
this.canLicense = (licType === Asc.c_oLicenseResult.Success || licType === Asc.c_oLicenseResult.SuccessLimit);
this.isLightVersion = params.asc_getIsLight();
this.canCoAuthoring = !this.isLightVersion;
this.isOffline = Common.EditorApi.get().asc_isOffline();
this.canRequestEditRights = this.config.canRequestEditRights;
this.canEdit = permissions.edit !== false && // can edit or review
2021-06-09 12:18:04 +00:00
(this.config.canRequestEditRights || this.config.mode !== 'view') && isSupportEditFeature; // if mode=="view" -> canRequestEditRights must be defined
// (!this.isReviewOnly || this.canLicense) && // if isReviewOnly==true -> canLicense must be true
this.isEdit = (this.canLicense || this.isEditDiagram || this.isEditMailMerge) && permissions.edit !== false && this.config.mode !== 'view' && true;
this.canComments = this.canLicense && (permissions.comment === undefined ? this.isEdit : permissions.comment) && (this.config.mode !== 'view');
this.canComments = this.canComments && !((typeof (this.customization) == 'object') && this.customization.comments===false);
this.canViewComments = this.canComments || !((typeof (this.customization) == 'object') && this.customization.comments===false);
this.canEditComments = this.isOffline || !(typeof (this.customization) == 'object' && this.customization.commentAuthorOnly);
2021-07-06 14:13:55 +00:00
this.canDeleteComments= this.isOffline || !permissions.deleteCommentAuthorOnly;
this.canChat = this.canLicense && !this.isOffline && !((typeof (this.customization) == 'object') && this.customization.chat === false);
this.canPrint = (permissions.print !== false);
this.isRestrictedEdit = !this.isEdit && this.canComments;
this.trialMode = params.asc_getLicenseMode();
2022-02-04 21:48:02 +00:00
const type = /^(?:(pdf|djvu|xps|oxps))$/.exec(document.fileType);
this.canDownloadOrigin = permissions.download !== false && (type && typeof type[1] === 'string');
this.canDownload = permissions.download !== false && (!type || typeof type[1] !== 'string');
2021-07-06 14:13:55 +00:00
this.canUseReviewPermissions = this.canLicense && (!!permissions.reviewGroups || this.customization
&& this.customization.reviewPermissions && (typeof (this.customization.reviewPermissions) == 'object'));
this.canUseCommentPermissions = this.canLicense && !!permissions.commentGroups;
this.canUseReviewPermissions && AscCommon.UserInfoParser.setReviewPermissions(permissions.reviewGroups, this.customization.reviewPermissions);
this.canUseCommentPermissions && AscCommon.UserInfoParser.setCommentPermissions(permissions.commentGroups);
}
}