[common] added common notifications controller
This commit is contained in:
parent
43bf279535
commit
a77aa2fc91
|
@ -1,5 +1,6 @@
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { resetUsers } from '../store/actions/actions.js'
|
import { resetUsers } from '../store/actions/actions.js'
|
||||||
|
import Notifications from '../../utils/notifications.js'
|
||||||
|
|
||||||
const Collaboration = () => {
|
const Collaboration = () => {
|
||||||
const onChangeEditUsers = (users) => {
|
const onChangeEditUsers = (users) => {
|
||||||
|
@ -7,18 +8,21 @@ const Collaboration = () => {
|
||||||
store.dispatch(resetUsers(Object.values(users)));
|
store.dispatch(resetUsers(Object.values(users)));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Common.Notifications.on('engineCreated', api => {
|
||||||
|
// this.api = api;
|
||||||
|
api.asc_registerCallback('asc_onAuthParticipantsChanged', onChangeEditUsers);
|
||||||
|
api.asc_registerCallback('asc_onParticipantsChanged', onChangeEditUsers);
|
||||||
|
// this.api.asc_registerCallback('asc_onAddComment', _.bind(this.onApiAddComment, this));
|
||||||
|
// this.api.asc_registerCallback('asc_onAddComments', _.bind(this.onApiAddComments, this));
|
||||||
|
// this.api.asc_registerCallback('asc_onChangeCommentData', _.bind(this.onApiChangeCommentData, this));
|
||||||
|
// this.api.asc_registerCallback('asc_onRemoveComment', _.bind(this.onApiRemoveComment, this));
|
||||||
|
// this.api.asc_registerCallback('asc_onRemoveComments', _.bind(this.onApiRemoveComments, this));
|
||||||
|
// this.api.asc_registerCallback('asc_onShowComment', _.bind(this.apiShowComments, this));
|
||||||
|
// this.api.asc_registerCallback('asc_onHideComment', _.bind(this.apiHideComments, this));
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
setApi(api) {
|
setApi(api) {
|
||||||
this.api = api;
|
|
||||||
this.api.asc_registerCallback('asc_onAuthParticipantsChanged', onChangeEditUsers);
|
|
||||||
this.api.asc_registerCallback('asc_onParticipantsChanged', onChangeEditUsers);
|
|
||||||
// this.api.asc_registerCallback('asc_onAddComment', _.bind(this.onApiAddComment, this));
|
|
||||||
// this.api.asc_registerCallback('asc_onAddComments', _.bind(this.onApiAddComments, this));
|
|
||||||
// this.api.asc_registerCallback('asc_onChangeCommentData', _.bind(this.onApiChangeCommentData, this));
|
|
||||||
// this.api.asc_registerCallback('asc_onRemoveComment', _.bind(this.onApiRemoveComment, this));
|
|
||||||
// this.api.asc_registerCallback('asc_onRemoveComments', _.bind(this.onApiRemoveComments, this));
|
|
||||||
// this.api.asc_registerCallback('asc_onShowComment', _.bind(this.apiShowComments, this));
|
|
||||||
// this.api.asc_registerCallback('asc_onHideComment', _.bind(this.apiHideComments, this));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
25
apps/common/mobile/utils/notifications.js
Normal file
25
apps/common/mobile/utils/notifications.js
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
export default class Notifications {
|
||||||
|
constructor() {
|
||||||
|
this._events = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
on(event, callback) {
|
||||||
|
!this._events[event] && (this._events[event] = []);
|
||||||
|
this._events[event].push(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
off(event, callback) {
|
||||||
|
if ( this._events[event] && this._events[event].includes(callback) ) {
|
||||||
|
this._events[event].splice(this._events[event].indexOf(callback), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trigger(event/*, args*/) {
|
||||||
|
if ( this._events[event] ) {
|
||||||
|
this._events[event].forEach(callback => {
|
||||||
|
callback.apply(this, Array.prototype.slice.call(arguments, 1));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ import routes from '../js/routes';
|
||||||
import '../../../../common/Gateway.js';
|
import '../../../../common/Gateway.js';
|
||||||
import '../../../../common/main/lib/util/utils.js';
|
import '../../../../common/main/lib/util/utils.js';
|
||||||
import { CollaborationController } from '../../../../common/mobile/lib/controller/Collaboration.jsx';
|
import { CollaborationController } from '../../../../common/mobile/lib/controller/Collaboration.jsx';
|
||||||
|
import Notifications from '../../../../common/mobile/utils/notifications.js'
|
||||||
|
|
||||||
export default class extends React.Component {
|
export default class extends React.Component {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -48,6 +49,11 @@ export default class extends React.Component {
|
||||||
username: '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Common.Notifications = new Notifications();
|
||||||
|
|
||||||
|
Common.Controllers = {};
|
||||||
|
Common.Controllers.Collaboration = new CollaborationController();
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
@ -244,10 +250,7 @@ export default class extends React.Component {
|
||||||
Common.Gateway.on('opendocument', loadDocument);
|
Common.Gateway.on('opendocument', loadDocument);
|
||||||
Common.Gateway.appReady();
|
Common.Gateway.appReady();
|
||||||
|
|
||||||
Common.Controllers = {};
|
Common.Notifications.trigger('engineCreated', this.api);
|
||||||
Common.Controllers.Collaboration = new CollaborationController();
|
|
||||||
Common.Controllers.Collaboration.setApi(this.api, "");
|
|
||||||
|
|
||||||
}, error => {
|
}, error => {
|
||||||
console.log('promise failed ' + error);
|
console.log('promise failed ' + error);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue