[DE mobile] Add set app options

This commit is contained in:
JuliaSvinareva 2020-12-03 23:30:06 +03:00
parent 6e28a6674e
commit 44a6b8ef07
3 changed files with 101 additions and 19 deletions

View file

@ -3,7 +3,7 @@ import React, {Component} from 'react'
import {inject} from "mobx-react";
import CollaborationController from '../../../../common/mobile/lib/controller/Collaboration.jsx'
@inject("storeDocumentSettings", "storeFocusObjects", "storeTextSettings", "storeParagraphSettings", "storeTableSettings", "storeDocumentInfo")
@inject("storeAppOptions", "storeDocumentSettings", "storeFocusObjects", "storeTextSettings", "storeParagraphSettings", "storeTableSettings", "storeDocumentInfo")
class MainController extends Component {
constructor(props) {
super(props)
@ -36,11 +36,13 @@ class MainController extends Component {
};
const loadConfig = data => {
let me = this;
console.log('load config');
me.editorConfig = Object.assign({}, this.editorConfig, data.config);
me.appOptions.user = Common.Utils.fillUserInfo(me.editorConfig.user, me.editorConfig.lang, "Local.User"/*me.textAnonymous*/);
this.editorConfig = Object.assign({}, this.editorConfig, data.config);
this.props.storeAppOptions.setConfigOptions(this.editorConfig);
this.editorConfig.lang && this.api.asc_setLocale(this.editorConfig.lang);
};
const loadDocument = data => {
@ -52,10 +54,11 @@ class MainController extends Component {
if (data.doc) {
this.permissions = Object.assign(this.permissions, data.doc.permissions);
let _permissions = Object.assign({}, data.doc.permissions),
_user = new Asc.asc_CUserInfo();
_user.put_Id(this.appOptions.user.id);
_user.put_FullName(this.appOptions.user.fullname);
const _permissions = Object.assign({}, data.doc.permissions);
const _userOptions = this.props.storeAppOptions.user;
const _user = new Asc.asc_CUserInfo();
_user.put_Id(_userOptions.id);
_user.put_FullName(_userOptions.fullname);
docInfo = new Asc.asc_CDocInfo();
docInfo.put_Id(data.doc.key);
@ -105,20 +108,23 @@ class MainController extends Component {
};
const onEditorPermissions = params => {
let me = this;
const licType = params.asc_getLicenseType();
me.appOptions.canLicense = (licType === Asc.c_oLicenseResult.Success || licType === Asc.c_oLicenseResult.SuccessLimit);
// me.appOptions.canEdit = (me.permissions.edit !== false || me.permissions.review === true) && // can edit or review
// (me.editorConfig.canRequestEditRights || me.editorConfig.mode !== 'view') && // if mode=="view" -> canRequestEditRights must be defined
// (!me.appOptions.isReviewOnly || me.appOptions.canLicense) && // if isReviewOnly==true -> canLicense must be true
// me.isSupportEditFeature();
// me.appOptions.isEdit = me.appOptions.canLicense && me.appOptions.canEdit && me.editorConfig.mode !== 'view';
// check licType
// me.api.asc_setViewMode(!me.appOptions.isEdit);
me.api.asc_setViewMode(false);
me.api.asc_LoadDocument();
me.api.Resize();
this.appOptions.canLicense = (licType === Asc.c_oLicenseResult.Success || licType === Asc.c_oLicenseResult.SuccessLimit);
this.props.storeAppOptions.setPermissionOptions(this.document, licType, params, this.permissions);
//Common.Utils.UserInfoParser.setParser(me.appOptions.canUseReviewPermissions);
//me.api.asc_setViewMode(!me.appOptions.isEdit && !me.appOptions.isRestrictedEdit);
//me.appOptions.isRestrictedEdit && this.appOptions.canComments && me.api.asc_setRestriction(Asc.c_oAscRestrictionType.OnlyComments);
//me.appOptions.isRestrictedEdit && me.appOptions.canFillForms && me.api.asc_setRestriction(Asc.c_oAscRestrictionType.OnlyForms);
this.api.asc_setViewMode(false);
this.api.asc_LoadDocument();
this.api.Resize();
};
const _process_array = (array, fn) => {

View file

@ -0,0 +1,74 @@
import {action, observable} from 'mobx';
export class storeAppOptions {
config = {};
@action setConfigOptions (config) {
this.config = config;
this.user = Common.Utils.fillUserInfo(config.user, config.lang, "Local.User"/*me.textAnonymous*/);
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.sharingSettingsUrl = config.sharingSettingsUrl;
this.fileChoiceUrl = config.fileChoiceUrl;
this.mergeFolderUrl = config.mergeFolderUrl;
this.canAnalytics = false;
this.canRequestClose = config.canRequestClose;
this.customization = config.customization;
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;
}
@action setPermissionOptions (document, licType, params, permissions) {
this.review = (permissions.review === undefined) ? (permissions.edit !== false) : permissions.review;
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.isReviewOnly = (permissions.review === true) && (permissions.edit === false);
this.canRequestEditRights = this.config.canRequestEditRights;
this.canEdit = (permissions.edit !== false || permissions.review === true) && // can edit or review
(this.config.canRequestEditRights || this.config.mode !== 'view') && // if mode=="view" -> canRequestEditRights must be defined
(!this.isReviewOnly || this.canLicense) && // if isReviewOnly==true -> canLicense must be true
true/*isSupportEditFeature*/;
this.isEdit = this.canLicense && this.canEdit && this.config.mode !== 'view';
this.canReview = this.canLicense && this.isEdit && (permissions.review===true);
this.canUseHistory = this.canLicense && !this.isLightVersion && this.config.canUseHistory && this.canCoAuthoring && !this.isDesktopApp;
this.canHistoryClose = this.config.canHistoryClose;
this.canUseMailMerge = this.canLicense && this.canEdit && !this.isDesktopApp;
this.canSendEmailAddresses = this.canLicense && this.config.canSendEmailAddresses && this.canEdit && this.canCoAuthoring;
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);
this.canChat = this.canLicense && !this.isOffline && !((typeof (this.customization) == 'object') && this.customization.chat === false);
this.canEditStyles = this.canLicense && this.canEdit;
this.canPrint = (permissions.print !== false);
this.fileKey = document.key;
this.canFillForms = this.canLicense && ((permissions.fillForms===undefined) ? this.isEdit : permissions.fillForms) && (this.config.mode !== 'view');
this.isRestrictedEdit = !this.isEdit && (this.canComments || this.canFillForms);
if (this.isRestrictedEdit && this.canComments && this.canFillForms) // must be one restricted mode, priority for filling forms
this.canComments = false;
this.trialMode = params.asc_getLicenseMode();
const type = /^(?:(pdf|djvu|xps))$/.exec(document.fileType);
this.canDownloadOrigin = permissions.download !== false && (type && typeof type[1] === 'string');
this.canDownload = permissions.download !== false && (!type || typeof type[1] !== 'string');
this.canReader = (!type || typeof type[1] !== 'string');
this.canBranding = params.asc_getCustomization();
this.canBrandingExt = params.asc_getCanBranding() && (typeof this.customization == 'object');
if ( this.isLightVersion ) {
this.canUseHistory = this.canReview = this.isReviewOnly = false;
}
this.canUseReviewPermissions = this.canLicense && this.customization && this.customization.reviewPermissions && (typeof (this.customization.reviewPermissions) == 'object');
}
}

View file

@ -10,8 +10,10 @@ import {storeTableSettings} from "./tableSettings";
import {storeChartSettings} from "./chartSettings";
import {storeDocumentInfo} from "./documentInfo";
import {storeApplicationSettings} from './applicationSettings';
import {storeAppOptions} from "./appOptions";
export const stores = {
storeAppOptions: new storeAppOptions(),
storeFocusObjects: new storeFocusObjects(),
storeDocumentSettings: new storeDocumentSettings(),
users: new storeUsers(),