-
Notifications
You must be signed in to change notification settings - Fork 753
/
App.jsx
229 lines (203 loc) · 8.67 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import React, { Component } from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import { PersonaBarPageHeader, PersonaBarPage} from "@dnnsoftware/dnn-react-common";
import {
visiblePanel as VisiblePanelActions,
siteInfo
} from "../actions";
import Body from "./body";
import HtmlEditorManager from "./moreSettings/htmlEditorManager";
import LanguageVerifier from "./languageSettings/languageVerifier";
import LanguagePack from "./languageSettings/languagePack";
import LocalizedContent from "./languageSettings/localizedContent";
import TranslatePageContent from "./translatePageContent/translatePageContent";
import EditLanguagePanel from "./editLanguagePanel";
import SiteLanguageSelector from "./siteLanguageSelector";
import utilities from "utils";
import resx from "../resources";
const Pages = {
Default: 0,
HtmlEditorManager: 1,
LanguageVerifier: 2,
LanguageEditor: 3,
LanguagePack: 4,
LocalizedContent: 5,
TranslatePageContent: 6
};
class App extends Component {
constructor() {
super();
this.state = {
portalId: utilities.settings.portalId,
cultureCode: utilities.settings.cultureCode,
referrer: utilities.settings.referrer,
referrerText: utilities.settings.referrerText,
backToReferrerFunc: this.backToReferrer.bind(this, utilities.settings.backToReferrerFunc),
bodyShowing: true
};
this.changePortalId = this.changePortalId.bind(this);
this.changeCultureCode = this.changeCultureCode.bind(this);
this.changePortalIdCultureCode = this.changePortalIdCultureCode.bind(this);
}
backToReferrer(callback) {
if (typeof callback === "function") {
callback();
}
this.setState({
referrer: "",
referrerText: "",
backToReferrerFunc: null
});
}
changePortalId(portalId) {
const { props, state } = this;
if (portalId === undefined || portalId === state.portalId) return;
this.setState({
bodyShowing: true,
portalId
}, () => {
props.dispatch(siteInfo.updatePortalId(portalId));
});
}
changeCultureCode(cultureCode) {
const { state } = this;
if (cultureCode === undefined || cultureCode === state.cultureCode) return;
this.setState({
bodyShowing: false
}, () => {
this.setState({
bodyShowing: true,
cultureCode
});
});
}
changePortalIdCultureCode(portalId, cultureCode) {
let { props } = this;
if (portalId === undefined && cultureCode === undefined) return;
else if (portalId === undefined) {
this.changeCultureCode(cultureCode);
}
else if (cultureCode === undefined) {
this.changePortalId(portalId);
}
else {
this.setState({
bodyShowing: false
}, () => {
this.setState({
bodyShowing: true,
portalId,
cultureCode
}, () => props.dispatch(siteInfo.updatePortalId(portalId))
);
});
}
}
updateReferrerInfo(event) {
this.setState({
referrer: event.referrer,
referrerText: event.referrerText,
backToReferrerFunc: this.backToReferrer.bind(this, event.backToReferrerFunc)
});
}
componentDidMount() {
const {state, props} = this;
// // Listen for the event.
document.addEventListener("portalIdChanged", (e) => {
this.changePortalId(e.portalId);
this.updateReferrerInfo(e);
}, false);
document.addEventListener("cultureCodeChanged", (e) => {
this.changeCultureCode(e.cultureCode);
this.updateReferrerInfo(e);
}, false);
document.addEventListener("portalIdCultureCodeChanged", (e) => {
this.changePortalIdCultureCode(e.portalId, e.cultureCode);
this.updateReferrerInfo(e);
}, false);
}
openPersonaBarPage(pageNumber) {
const {props} = this;
props.dispatch(VisiblePanelActions.selectPanel(pageNumber));
}
closePersonaBarPage() {
const {props} = this;
props.dispatch(VisiblePanelActions.selectPanel(Pages.Default));
}
render() {
const {props, state} = this;
return (
<div className="siteSettings-app">
<SiteLanguageSelector
portalId={state.portalId}
cultureCode={state.cultureCode}
referrer={state.referrer}
referrerText={state.referrerText}
backToReferrerFunc={state.backToReferrerFunc}
/>
<PersonaBarPage isOpen={props.selectedPage === 0}>
<PersonaBarPageHeader title={resx.get("nav_SiteSettings")}>
</PersonaBarPageHeader>
<Body
portalId={state.portalId}
showing={state.bodyShowing}
referrer={state.referrer}
referrerText={state.referrerText}
backToReferrerFunc={state.backToReferrerFunc}
openLanguagePack={this.openPersonaBarPage.bind(this, Pages.LanguagePack)}
openLanguageVerifier={this.openPersonaBarPage.bind(this, Pages.LanguageVerifier)}
openHtmlEditorManager={this.openPersonaBarPage.bind(this, Pages.HtmlEditorManager)}
openLocalizedContent={this.openPersonaBarPage.bind(this, Pages.LocalizedContent)}
cultureCode={state.cultureCode}
/>
</PersonaBarPage>
<PersonaBarPage isOpen={props.selectedPage === Pages.HtmlEditorManager}>
<PersonaBarPageHeader title={resx.get("nav_SiteSettings")}>
</PersonaBarPageHeader>
{props.selectedPage === Pages.HtmlEditorManager &&
<HtmlEditorManager portalId={state.portalId} closeHtmlEditorManager={this.closePersonaBarPage.bind(this)} />
}
</PersonaBarPage>
<PersonaBarPage isOpen={props.selectedPage === Pages.LanguageVerifier}>
<PersonaBarPageHeader title={resx.get("ResourceFileVerifier")}>
</PersonaBarPageHeader>
<LanguageVerifier portalId={state.portalId} closeLanguageVerifier={this.closePersonaBarPage.bind(this)} />
</PersonaBarPage>
{props.selectedPage === Pages.LanguageEditor && <PersonaBarPage isOpen={props.selectedPage === Pages.LanguageEditor}>
<PersonaBarPageHeader title={resx.get("LanguageEditor.Header")} />
<EditLanguagePanel portalId={state.portalId} backToSiteSettings={this.closePersonaBarPage.bind(this)} />
</PersonaBarPage>}
<PersonaBarPage isOpen={props.selectedPage === Pages.LanguagePack}>
<PersonaBarPageHeader title={resx.get("CreateLanguagePack")} />
<LanguagePack closeLanguagePack={this.closePersonaBarPage.bind(this)} />
</PersonaBarPage>
<PersonaBarPage isOpen={props.selectedPage === Pages.LocalizedContent}>
<PersonaBarPageHeader title={resx.get("EnableLocalizedContent")} />
<LocalizedContent portalId={state.portalId} closePersonaBarPage={this.closePersonaBarPage.bind(this)} isOpen={props.selectedPage === Pages.LocalizedContent} />
</PersonaBarPage>
<PersonaBarPage isOpen={props.selectedPage === Pages.TranslatePageContent}>
<PersonaBarPageHeader title={resx.get("TranslatePageContent")} />
{props.selectedPage === Pages.TranslatePageContent &&
<TranslatePageContent cultureCode={state.cultureCode} closePersonaBarPage={this.closePersonaBarPage.bind(this)} portalId={state.portalId} />
}
</PersonaBarPage>
</div>
);
}
}
App.propTypes = {
dispatch: PropTypes.func.isRequired,
selectedPage: PropTypes.number,
siteInfo: PropTypes.object,
cultureCode: PropTypes.string,
portalId: PropTypes.number
};
function mapStateToProps(state) {
return {
selectedPage: state.visiblePanel.selectedPage,
selectedPageVisibleIndex: state.visiblePanel.selectedPageVisibleIndex,
siteInfo: state.siteInfo
};
}
export default connect(mapStateToProps)(App);