-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_view.php
240 lines (226 loc) · 9.18 KB
/
account_view.php
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
230
231
232
233
234
235
236
237
238
239
240
<?php
defined('EMONCMS_EXEC') or die('Restricted access');
global $path;
?>
<style>
/*.content-container {
max-width: 980px;
}*/
</style>
<script src="<?php echo $path; ?>Lib/vue.min.js"></script>
<div id="app">
<h2><?php echo _("My Accounts"); ?></h2>
<div class="input-prepend input-append" style="float:right">
<button class="btn" id="open-add-user-modal"><i class="icon icon-plus"></i> <?php echo _("Add new user"); ?></button>
</div>
<div class="input-prepend" style="float:right">
<span class="add-on">Filter</span>
<input type="text" v-model="filterKey" style="width:120px; margin-right:20px" />
</div>
<p><b><?php echo _("Number of users:"); ?></b> {{accounts.length}}</p>
<br>
<div v-if="accounts.length==0" class="alert alert-warning"><?php echo _("Multi user management. Click on add new user to create a new user or to add an existing user."); ?></div>
<table class="table table-striped" v-else>
<tr>
<th><?php echo _("Edit"); ?></th>
<th @click="sort('id', 'asc')" style="cursor:pointer"><?php echo _("Id"); ?></th>
<th @click="sort('username', 'asc')" style="cursor:pointer"><?php echo _("Username"); ?></th>
<th @click="sort('location', 'asc')" style="cursor:pointer"><?php echo _("Location"); ?></th>
<th @click="sort('email', 'asc')" style="cursor:pointer"><?php echo _("Email"); ?></th>
<th @click="sort('access', 'asc')" style="cursor:pointer"><?php echo _("User Login"); ?></th>
<th @click="sort('feeds', 'asc')" style="cursor:pointer"><?php echo _("Feeds"); ?></th>
<th></th>
</tr>
<tr v-for="(user,index) in fAccounts">
<td><a class="btn btn-info btn-sm" :href="path+'account/switch?userid='+user.id">view</a></td>
<td>{{ user.id }}</td>
<td>{{ user.username }}</td>
<td>{{ user.location }}</td>
<td>{{ user.email }}</td>
<td @click="change_access(index)" style="cursor:pointer" title="Click to change access level">
<span class="label label-inverse" v-if="user.access==0">Disabled</span>
<span class="label label-warning" v-if="user.access==1">Read only</span>
<span class="label label-success" v-if="user.access==2">Write access</span>
</td>
<td><b>{{ user.feeds }}</b></td>
<td @click="unlink(index)" style="cursor:pointer"><i class="icon-trash"></i></td>
</tr>
</table>
<div id="addNewUserModal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="addNewUserModalLabel" aria-hidden="true" data-backdrop="static" style="width:300px">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="addNewUserModalLabel">Add new user</h3>
</div>
<div class="modal-body">
<p>
<lable>Username:</label><br>
<input v-model="add_username" type="text" style="width:250px" />
</p>
<p>
<lable>Password:</label><br>
<input v-model="add_password" type="text" style="width:250px" />
</p>
<p>
<lable>Email:</label><br>
<input v-model="add_email" type="text" style="width:250px" />
</p>
<p>
<lable>Timezone:</label><br>
<input v-model="add_timezone" type="text" style="width:250px" />
</p>
<div class="alert alert-error" v-if="add_error" style="margin-bottom:0px">{{ add_error }}</div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><?php echo _('Close'); ?></button>
<button class="btn btn-info" @click="add_account"><?php echo _('Add user'); ?></button>
</div>
</div>
</div>
<script>
// Vue app
var app = new Vue({
el: '#app',
data: {
accounts: [],
user: {},
add_username: "",
add_password: "",
add_email: "",
add_timezone: "",
add_error: false,
currentSortColumn: 'id',
currentSortDir: 'desc',
filterKey: ''
},
mounted: function() {
this.getAccounts();
this.getUser();
},
methods: {
getAccounts: function() {
// using jquery ajax
$.ajax({
url: path + "account/list.json",
dataType: 'json',
success: function(result) {
app.accounts = result;
}
});
},
getUser: function() {
// using jquery ajax
$.ajax({
url: path + "user/get.json",
dataType: 'json',
success: function(result) {
app.user = result;
app.add_email = app.user.email;
app.add_timezone = app.user.timezone;
}
});
},
add_account: function() {
$.ajax({
type: "POST",
url: path + "account/add.json",
dataType: 'json',
data: {
username: encodeURIComponent(app.add_username),
password: encodeURIComponent(app.add_password),
email: encodeURIComponent(app.add_email),
timezone: encodeURIComponent(app.add_timezone)
},
success: function(result) {
if (result.success) {
app.getAccounts();
$('#addNewUserModal').modal('hide');
} else {
app.add_error = result.message;
}
}
});
},
change_access: function(index) {
var userid = app.accounts[index].id;
var access = app.accounts[index].access;
access ++;
if (access > 2) access = 0;
$.ajax({
type: "POST",
url: path + "account/setaccess.json",
dataType: 'json',
data: {
userid: userid,
access: access
},
success: function(result) {
app.accounts[index].access = access;
}
});
},
unlink: function(index) {
var userid = app.accounts[index].id;
// ask for confirmation
if (!confirm("Are you sure you want to unlink this user? Original user will not be deleted")) return;
$.ajax({
type: "POST",
url: path + "account/unlink.json",
dataType: 'json',
data: {
userid: userid
},
success: function(result) {
app.getAccounts();
}
});
},
sort: function(column, starting_order) {
if (this.currentSortColumn != column) {
this.currentSortDir = starting_order;
this.currentSortColumn = column;
} else {
if (this.currentSortDir == 'desc') {
this.currentSortDir = 'asc';
} else {
this.currentSortDir = 'desc';
}
}
this.sort_only(column);
},
sort_only: function(column) {
this.accounts.sort((a, b) => {
let modifier = 1;
if (this.currentSortDir == 'desc') modifier = -1;
if (a[column] < b[column]) return -1 * modifier;
if (a[column] > b[column]) return 1 * modifier;
return 0;
});
},
filterAccounts: function (row) {
if (this.filterKey != '') {
return Object.keys(row).some((key) => {
return String(row[key]).toLowerCase().indexOf(this.filterKey.toLowerCase()) > -1
})
}
return true;
}
},
filters: {
access: function(value) {
if (value == 0) return "Disabled";
if (value == 1) return "Read only";
if (value == 2) return "Write access";
return "Unknown";
}
},
computed: {
fAccounts: function () {
return this.accounts.filter(this.filterAccounts);
}
}
});
$("#open-add-user-modal").click(function() {
app.add_error = false;
$('#addNewUserModal').modal('show');
});
</script>