-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
153 lines (133 loc) · 4.36 KB
/
index.js
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
import React from 'react';
import ReactDOM from 'react-dom';
import Cookies from 'universal-cookie';
import Container from './components/Container'
import HeadContainer from './components/HeadContainer'
class App extends React.Component {
constructor() {
super();
const cookies = new Cookies();
var user = cookies.get('user');
var module = "Dashboard";
if(!user)
{
user = null;
module = "web";
}
this.state = {
user: user,
association : null,
authorizedModules: [],
currentModule: module
};
this.loginUser = this.loginUser.bind(this);
this.logoutUser = this.logoutUser.bind(this);
this.handleSelectAssociation = this.handleSelectAssociation.bind(this);
}
loginUser(user)
{
const cookies = new Cookies();
cookies.set('user', user);
this.setState({
user : user
});
}
logoutUser()
{
const cookies = new Cookies();
cookies.remove('user');
this.setState({
user : null,
currentModule: "Dashboard"
});
}
handleSelectAssociation(associationId)
{
var path = "user/menurole";
$.ajax({
url: path,
type: 'Post',
data: { associationId: associationId},
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization",this.state.user._token);
}.bind(this),
success: function (data)
{
var authorizedModules = data.accessModules;
this.setState({
association: associationId,
authorizedModules: authorizedModules
});
}.bind(this),
error: function (error)
{
this.setState({
association: associationId,
authorizedModules: []
});
console.log(error);
// Put whatever you need to do if the query fails here.
}.bind(this)
});
}
createPopUpMessage(popupTitle,text,alert = 0,type = 0) // this will create a popup
{
var popupClass = 'popup_panel_message_content';
if(alert == 1)
{
popupClass = 'popup_panel_alert_content';
}else{
popupClass = 'popup_panel_message_content';
}
var popupContainer = $( '<div id="message_panel" class="popup_message_panel">');
var popup = $( '<div id="message" class="'+popupClass+'">');
var title = $( '<div class="col-lg-12"><h3 class="text-center">'+popupTitle+'</h3></div>');
var message = $( '<div class="col-lg-12">'+text+'</div>');
var buttonsContainerRow = $( '<div class="eow"></div>');
var buttonsContainer = $( '<div class="col-lg-12 button_container"></div>');
popupContainer.append(popup);
popup.append(title);
popup.append(message);
popup.append(buttonsContainerRow);
buttonsContainerRow.append(buttonsContainer);
$( "body" ).append(popupContainer);
if(type == 0)
{
var buttonOK = $( '<button class="btn btn-edit">Ok</button>');
buttonOK.click(function (e) {
popupContainer.remove();
})
buttonsContainer.append(buttonOK);
}else if(type== 1){
var buttonYes = $( '<button class="btn btn-edit">Yes</button>');
var buttonNo = $( '<button class="btn btn-edit">No</button>');
buttonsContainer.append(buttonYes);
buttonsContainer.append(" ");
buttonsContainer.append(buttonNo);
buttonNo.click(function (e) {
popupContainer.remove();
})
buttonYes.click(function (e) {
popupContainer.remove();
})
return buttonYes;
}
return null;
}
changeModule(newModule){
this.setState({
currentModule : newModule
});
console.log('Change Module Handler ' + newModule);
return;
}
render() {
return (
<div>
<HeadContainer changeModule={this.changeModule.bind(this)} user={this.state.user} logoutUser={this.logoutUser}/>
<Container changeModule={this.changeModule.bind(this)} authorizedModules={this.state.authorizedModules} handleSelectAssociation={this.handleSelectAssociation} currentModule={this.state.currentModule} user={this.state.user} createPopUpMessage={this.createPopUpMessage} loginUser={this.loginUser}/>
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById("app"));