-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathapp.jsx
199 lines (171 loc) · 7.12 KB
/
app.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import React from 'react'
import { render } from 'react-dom'
import { Provider } from 'react-redux'
import { BrowserRouter, Switch, Route } from 'react-router-dom'
import moment from 'moment'
import { DWKitForm } from "./../../scripts/optimajet-form.js"
import {ApplicationRouter, NotificationComponent, FormContent,
FlowContent, WorkflowContent, Thunks, Store, Actions, SignalRConnector, StateBindedForm, API} from './../../scripts/optimajet-app.js'
import {CustomControls, CustomControlsRender} from './controls/CustomControlsInit.jsx';
import {CustomUserForms} from './controls/CustomUserForms.jsx';
window.DWKitFormSettings = {
externalControlList: CustomControls,
externalControlRender: CustomControlsRender
};
Store.getState().settings.userForms = CustomUserForms;
Store.dispatch(Actions.app.impersonateduseridfromurl());
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
pagekey: 0,
resourcesLoaded: false
};
//API.setAuth("cookie");
Store.dispatch(Thunks.userinfo.fetch(() => {
this.state.user = Store.getState().app.user;
if (location.pathname === '/' && this.state.user.isAnonymous && !this.state.user.defaultForm) {
Store.signinRedirect();
}
this.loadResources();
}));
window.DWKitApp = this;
window.DWKitApp.API = API;
window.DWKitApp.Store = Store;
}
render(){
let state = Store.getState();
let [header, sidebar, footer] = ["header", "sidebar", "footer"];
if (!this.state.user || !this.state.resourcesLoaded){
return null;
}
let currentEmployee = state.app.impersonatedUserId ? state.app.impersonatedUserId : this.state.user.id;
let bindedFormData = {
currentUser: this.state.user.name,
currentEmployee: currentEmployee
};
if (this.state.user.isAnonymous) {
[header, sidebar, footer] = ["AnonymousHeader", "AnonymousSidebar", "AnonymousFooter"];
}
return <div className="dwkit-wrapper" key={this.state.pagekey}>
<Provider store={Store}>
<StateBindedForm formName={header} stateDataPath="app.extra" data={bindedFormData} />
</Provider>
<div className="dwkit-container">
<Provider store={Store}>
<StateBindedForm className="dwkit-sidebar-container" formName={sidebar} stateDataPath="app.extra" data={bindedFormData} />
</Provider>
<div className="dwkit-content">
<Provider store={Store}>
<BrowserRouter>
<div className="dwkit-content-form">
<ApplicationRouter onReload={this.onRefresh.bind(this, true)} onRefresh={this.onRefresh.bind(this, false)} />
<NotificationComponent
onFetchStarted={this.onFetchStarted.bind(this)}
onFetchFinished={this.onFetchFinished.bind(this)}/>
<Switch>
<Route path='/form' component={FormContent} />
<Route path='/flow' component={FlowContent} />
<Route path='/workflow' component={WorkflowContent} />
<Route exact path='/'>
<FormContent formName={this.props.defaultForm ? this.props.defaultForm : this.state.user.defaultForm} />
</Route>
<Route path='/account/logoff' render={() => {
Store.logoff();
return null;
}} />
<Route nomatch render={() => {
//Hack for back button
let url = window.location.href;
window.location.href = url;
return null;
}} />
</Switch>
</div>
</BrowserRouter>
</Provider>
</div>
</div>
<DWKitForm className="dwkit-footer" formName={footer} stateDataPath="app.extra" data={bindedFormData} />
</div>;
}
onFetchStarted() {
Pace.start();
$('body').loadingModal({
text: 'Loading...',
animation: 'foldingCube',
backgroundColor: '#1262E2'});
}
onFetchFinished() {
Pace.stop();
$('body').loadingModal('destroy');
}
onRefresh(reload) {
Store.resetForm(reload);
this.setState({
pagekey: this.state.pagekey + 1
});
if (reload) {
SignalRConnector.Connect(Store);
}
}
loadResources(){
this.loadStaticResources();
var me = this;
var resources = [
"/ui/localization.js",
"/ui/form/businessobjects.js"
];
var count = resources.length;
let updateFunc = function(){
count--;
if(count == 0){
me.setState({
resourcesLoaded: true
})
if (window.DWKitLang && window.DWKitLang.common && window.DWKitLang.common.locale) {
let locale = window.DWKitLang.common.locale;
moment.locale(locale);
}
}
}
resources.forEach(function(item){
API.loadBackendScript(item, {}, updateFunc);
});
if(resources.length == 0){
me.setState({
resourcesLoaded: true
});
}
}
loadStaticResources(){
var appendLinkCss = function(href){
var body = document.getElementsByTagName('body')[0];
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = href;
body.appendChild(link);
};
if(this.state.user.isRTL){
appendLinkCss('/css/dwkit-style.rtl.css');
}
if(this.state.user.theme){
var theme = this.state.user.theme;
$.getJSON("/themes/theme_manifest.json", function(json) {
if(Array.isArray(json.themes)){
json.themes.forEach(function(item){
if(item.name == theme && Array.isArray(item.files)){
item.files.forEach(function(file){
appendLinkCss('/themes/' + file);
});
}
})
}
});
}
}
}
SignalRConnector.Connect(Store);
var contentDiv = document.getElementById('content');
render(<App defaultForm={contentDiv.getAttribute("data-defaultform")} />, contentDiv);