Skip to content
Snippets Groups Projects
Commit cc077c15 authored by CupCakeArmy's avatar CupCakeArmy
Browse files

Can Modify Users

parent a0345250
No related branches found
No related tags found
No related merge requests found
......@@ -17,40 +17,98 @@
}
</style>
<script type="text/javascript">
var users = {
showInTable: ['firstname', 'lastname', 'email', 'membership'],
curUserData: null,
};
tools.ui.menu({
'Add User': {
callback: function() {
console.log('noice');
}
'<span class="glyphicon glyphicon-user" aria-hidden="true"></span>': {
callback: function() {}
},
'<span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span>': {
callback: function() {}
},
'<span class="users-cur-page" aria-hidden="true">0</span>': {
callback: function() {}
},
'<span class="glyphicon glyphicon-arrow-right" aria-hidden="true"></span>': {
callback: function() {}
},
'<span class="glyphicon glyphicon-search" aria-hidden="true"></span>': {
callback: function() {}
}
});
function inspectUser() {
var newUserData = {};
$('.users-user-edit-table tr').each(function() {
newUserData[$(this).children('td:nth-child(1)').html()] = $(this).children('td:nth-child(2)').html();
});
var changed = false,
curUserDataChanged = {};
for (var i in newUserData) {
if (newUserData[i] != String(curUserData[i])) {
changed = true;
curUserDataChanged[i] = newUserData[i];
}
}
if (changed) {
amivcore.users.PATCH({
id: curUserData.id,
header: {
'If-Match': $('.users-user-edit-table').attr('data-etag')
},
data: curUserDataChanged
}, function(){
tools.log('User Updated', 's');
tools.getTool('users');
});
}
}
function showDetails() {
console.log($(this).attr('data-id'));
amivcore.users.GET({
id: $(this).attr('data-id')
}, function(ret) {
curUserData = ret;
var tmp = '<table class="table table-hover users-user-edit-table" data-etag="' + ret['_etag'] + '"><tbody>';
for (var cur in ret)
if (cur.charAt(0) != '_')
tmp += '<tr><td>' + cur + '</td><td contenteditable>' + ret[cur] + '</td></tr>'
tmp += '</tbody></table>';
tools.modal({
head: ret.firstname + ' ' + ret.lastname,
body: tmp,
button: 'OK',
success: inspectUser,
cancel: function() {
console.log('Canceled');
}
});
});;
}
var showInTable = ['firstname', 'lastname', 'email', 'membership'],
curData = null;
amivcore.users.GET({
data: {
'max_results': '50'
//'max_results': '50'
}
}, function(ret) {
if (!ret || ret['_items'].length == 0) {
if (ret === undefined || ret['_items'].length == 0) {
tools.log('No Data', 'w');
return;
}
curData = ret['_items'];
showInTable.forEach(function(i) {
users.showInTable.forEach(function(i) {
$('.users-table thead tr').append('<th>' + i + '</th>');
});
for (var n in ret['_items']) {
var tmp = '';
showInTable.forEach(function(i) {
users.showInTable.forEach(function(i) {
tmp += '<td>' + ret['_items'][n][i] + '</td>';
});
$('.users-table tbody').append('<tr data-id="' + ret['_items'][n]['id'] + '">' + tmp + '</tr>');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment