-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusers.html
202 lines (189 loc) · 7.23 KB
/
users.html
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
<!DOCTYPE HTML>
<html>
<head>
<title>Users</title>
<link rel="stylesheet" type="text/css" href="/libs/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="/libs/bootstrap/css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="/css/style.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="/libs/bootstrap/js/bootstrap.min.js"></script>
<script src="https://cdn.firebase.com/js/client/2.2.9/firebase.js"></script>
<script src="/js/script.js"></script>
<style type="text/css">
.error {color:#cc0000;font-weight:normal;font-style:italic;}
</style>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul id="user-container" class="nav navbar-nav navbar-right">
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</nav>
<div class="row-fluid">
<div class="col-md-2">
<div class="list-group">
<a href="/flashdeals.html" class="list-group-item">Flash Deals</a>
<a href="/marketing-calendar.html" class="list-group-item">Marketing Calendar</a>
<a href="/image-requests.html" class="list-group-item">Image Requests</a>
<a href="/chat-rooms.html" class="list-group-item">Chat Rooms</a>
<a href="/users.html" class="list-group-item active">Users</a>
</div>
</div>
<div class="col-md-5">
<h3>Users</h3>
<div class="btn-toolbar">
<a id="add-user" href="#add-user" class="btn btn-primary btn-sm">Add User</a>
<a id="delete-user" href="#delete-user" class="btn btn-danger btn-sm" data-key="">Delete User</a>
</div>
<br/>
<table id="users-table" class="table table-bordered table-condensed table-hover">
<thead>
<tr>
<th data-key="fullname">Full Name</th>
<th data-key="username">Username</th>
<th data-key="access">Access(es)</th>
<th data-key="status">Status</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<!-- Users Modal -->
<div id="modal-user" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">Delete User</h3>
</div>
<div class="modal-body">
<p>Are you sure you want to d elete user?</p>
</div>
<div class="modal-footer">
<button type="buton" name="Close" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" name="saveUser" class="btn btn-primary" value="Save User" />
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript">
var ref = new Firebase("https://gc-marketing.firebaseio.com");
ref.onAuth(authDataCallback);
var usersRef = ref.child("users");
var cleanText = function(someText) {
return someText.replace(/(\r\n|\n|\r)/gm,"");
}
var authData = ref.getAuth();
console.log(authData);
// console.log(authData);
// Show user in the upper right of the screen
$("#user-container").html('<li><a href=""">'+authData.password.email+'</a></li>');
// If Add User is click, will add dummy username and password.
$("#add-user").click(function() {
usersRef.push({
fullname: "[Enter Full Name]",
email: "[email@example.com]",
access: "[Choose access]"
});
});
// Remove user if Delete User is clicked.
$("#delete-user").click(function() {
var userKey = $(this).data('key');
usersRef.child(userKey).set({});
$("#delete-user").css('display','none');
console.log('Deleted ' + userKey);
});
// Load users value and manipulate data inside users-table
usersRef.on("value",function(snapshot) {
// Add user entity to list.
var html = '';
snapshot.forEach(function(user) {
html+='<tr data-key="'+ user.key() +'">';
html+='<td>'+user.child("fullname").val()+'</td>';
html+='<td>'+user.child("email").val()+'</td>';
html+='<td>'+user.child("access").val()+'</td>';
html+='<td>'+user.child("status").val()+'</td>';
html+='</tr>';
});
$("#users-table tbody").html(html);
// Select row
$("#users-table tr").click(function() {
var key = $(this).data("key");
$("#users-table tr").removeClass('warning');
$(this).addClass('warning');
$("#delete-user").attr("data-key",$(this).data("key"));
var deleteKey = $("#delete-user").data("key");
if (deleteKey) { $("#delete-user").css("display","inline-block"); } else { $("#delete-user").hide(); }
// if (deleteKey) { $("#delete-user").css("display","inline"); } else { $("#delete-user").css("display","none"); }
});
// Edit user-table
$("#users-table tr").dblclick(function() {
var field = $(this).find("td");
var userKey = $(this).attr("data-key");
console.log(userKey);
field.each(function(key,val) {
var editing = $(this).hasClass('cellEditing');
var content = $(this).html();
$(this).addClass('cellEditing');
if (editing==false) {
switch(key) {
case 0: $(this).html('<textarea name="fullname" class="form-control">'+content+'</textarea>');break;
case 1: $(this).html('<textarea name="email" class="form-control">'+content+'</textarea>');break;
case 2: $(this).html('<textarea name="access" class="form-control">'+content+'</textarea>');break;
case 3: $(this).html('<textarea name="status" class="form-control">'+content+'</textarea>');break;
}
}
});
$("td.cellEditing textarea.form-control").focus(function() {
$(this).first().keyup(function(e) {
if (e.which == 13) {
// Set the user access
userData = {
"fullname": cleanText($("textarea[name='fullname']").val()),
"email": cleanText($("textarea[name='email']").val()),
"access": cleanText($("textarea[name='access']").val()),
"status": cleanText($("textarea[name='status']").val()),
}
console.log(userData);
usersRef.child(userKey).update(userData);
}
});
});
});
// Cancel Editing and unselect tr (table row)
$("*").keyup(function(e) {
if (e.keyCode==27) {
var activeInput = $(".cellEditing textarea.form-control");
// return all edits.
activeInput.each(function(key,value) {
var content = $(this).html();
// console.log(key,content)
var editing = $(".cellEditing");
editing.each(function(key,value) {
$(this).html($(this).text());
$(".cellEditing").removeClass("cellEditing");
});
});
// remove selection
$("#delete-user").attr("data-key","").hide();
$("tr.warning").removeClass("warning");
}
});
});
</script>
</body>
</html>