[mobile] added LocalStorage utility
This commit is contained in:
parent
cf14a2d56d
commit
ade1f81420
80
apps/common/mobile/utils/LocalStorage.js
Normal file
80
apps/common/mobile/utils/LocalStorage.js
Normal file
|
@ -0,0 +1,80 @@
|
|||
|
||||
class LocalStorage {
|
||||
constructor() {
|
||||
Common.Gateway.on('internalcommand', data => {
|
||||
if (data.type == 'localstorage') {
|
||||
this._store = data.keys;
|
||||
}
|
||||
});
|
||||
|
||||
this._store = {};
|
||||
|
||||
try {
|
||||
this._isAllowed = !!window.localStorage;
|
||||
} catch (e) {
|
||||
this._isAllowed = false;
|
||||
}
|
||||
}
|
||||
|
||||
get id() {
|
||||
return this._storeName;
|
||||
}
|
||||
|
||||
set id(name) {
|
||||
this._storeName = name;
|
||||
}
|
||||
|
||||
set keysFilter(value) {
|
||||
this._filter = value;
|
||||
}
|
||||
|
||||
get keysFilter() {
|
||||
return this._filter;
|
||||
}
|
||||
|
||||
sync() {
|
||||
if ( !this._isAllowed )
|
||||
Common.Gateway.internalMessage('localstorage', {cmd:'get', keys:this._filter});
|
||||
}
|
||||
|
||||
save() {
|
||||
if ( !this._isAllowed )
|
||||
Common.Gateway.internalMessage('localstorage', {cmd:'set', keys:this._store});
|
||||
}
|
||||
|
||||
setItem(name, value, just) {
|
||||
if ( this._isAllowed ) {
|
||||
try {
|
||||
localStorage.setItem(name, value);
|
||||
} catch (error){}
|
||||
} else {
|
||||
this._store[name] = value;
|
||||
|
||||
if ( just===true ) {
|
||||
Common.Gateway.internalMessage('localstorage', {cmd:'set', keys: {name: value}});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getItem(name) {
|
||||
if ( this._isAllowed )
|
||||
return localStorage.getItem(name);
|
||||
else return this._store[name]===undefined ? null : this._store[name];
|
||||
};
|
||||
|
||||
setBool(name, value, just) {
|
||||
this.setItem(name, value ? 1 : 0, just);
|
||||
}
|
||||
|
||||
getBool(name, defValue) {
|
||||
const value = this.getItem(name);
|
||||
return (value !== null) ? (parseInt(value) != 0) : !!defValue;
|
||||
}
|
||||
|
||||
itemExists(name) {
|
||||
return this.getItem(name) !== null;
|
||||
}
|
||||
}
|
||||
|
||||
const instance = new LocalStorage();
|
||||
export {instance as LocalStorage};
|
|
@ -1,5 +1,6 @@
|
|||
import React, { Component } from "react";
|
||||
import { ApplicationSettings } from "../../view/settings/ApplicationSettings";
|
||||
import { LocalStorage } from '../../../../../common/mobile/utils/LocalStorage';
|
||||
|
||||
class ApplicationSettingsController extends Component {
|
||||
constructor(props) {
|
||||
|
@ -8,10 +9,11 @@ class ApplicationSettingsController extends Component {
|
|||
}
|
||||
|
||||
setUnitMeasurement(value) {
|
||||
const api = Common.EditorApi.get();
|
||||
value = (value !== null) ? parseInt(value) : Common.Utils.Metric.getDefaultMetric();
|
||||
Common.Utils.Metric.setCurrentMetric(value);
|
||||
// Common.localStorage.setItem("de-mobile-settings-unit", value);
|
||||
LocalStorage.setItem("de-mobile-settings-unit", value);
|
||||
|
||||
const api = Common.EditorApi.get();
|
||||
api.asc_SetDocumentUnits((value == Common.Utils.Metric.c_MetricUnits.inch) ? Asc.c_oAscDocumentUnits.Inch : ((value == Common.Utils.Metric.c_MetricUnits.pt) ? Asc.c_oAscDocumentUnits.Point : Asc.c_oAscDocumentUnits.Millimeter));
|
||||
}
|
||||
|
||||
|
@ -23,14 +25,15 @@ class ApplicationSettingsController extends Component {
|
|||
}
|
||||
|
||||
switchNoCharacters(value) {
|
||||
Common.localStorage.setItem("de-mobile-no-characters", value);
|
||||
|
||||
const api = Common.EditorApi.get();
|
||||
// Common.localStorage.setItem("de-mobile-no-characters", value);
|
||||
api.put_ShowParaMarks(value);
|
||||
}
|
||||
|
||||
switchShowTableEmptyLine(value) {
|
||||
Common.localStorage.setItem("de-mobile-hidden-borders", value);
|
||||
const api = Common.EditorApi.get();
|
||||
// Common.localStorage.setItem("de-mobile-hidden-borders", state);
|
||||
api.put_ShowTableEmptyLine(value);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,11 @@ import React from 'react';
|
|||
|
||||
import {App,Panel,Views,View,Popup,Page,Navbar,Toolbar,NavRight,Link,Block,BlockTitle,List,ListItem,ListInput,ListButton,BlockFooter} from 'framework7-react';
|
||||
|
||||
import routes from '../js/routes';
|
||||
|
||||
import '../../../../common/Gateway.js';
|
||||
import '../../../../common/main/lib/util/utils.js';
|
||||
|
||||
import routes from '../js/routes';
|
||||
|
||||
import Notifications from '../../../../common/mobile/utils/notifications.js'
|
||||
import {MainController} from '../controller/Main';
|
||||
import {Device} from '../../../../common/mobile/utils/device'
|
||||
|
|
Loading…
Reference in a new issue