1
0
Fork 0

more functionality for usermanagement

This commit is contained in:
gschwab 2014-02-19 13:13:16 +01:00
parent da7d64bba9
commit 67464b2145
6 changed files with 84 additions and 19 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -1,5 +1,5 @@
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true */
/*global window, Backbone, $, window */
/*global window, Backbone, $,_, window */
window.ArangoUsers = Backbone.Collection.extend({
model: window.Users,
@ -71,6 +71,20 @@ window.ArangoUsers = Backbone.Collection.extend({
result.push(object);
});
return result;
},
whoAmI: function() {
if (this.currentUser) {
return this.currentUser;
}
var result;
$.ajax("whoAmI", {async:false}).done(
function(data) {
result = data.name;
}
);
this.currentUser = result;
return this.currentUser;
}
});

View File

@ -9,10 +9,24 @@
<img src="<%=img%>" id="userimage" height="23" width="23" /> <b class="caret"></b>
</a>
<ul class="user-dropdown-menu" id="user_dropdown">
<li class="dropdown-header"><%=prename%> <%=lastname%></li>
<li class="dropdown-header" style="text-transform: none">
<%
if(username === null) {
%>-<%
} else {
if (name) {%>
<%=name%> (<%=username%>)
<% } else {%>
<%=username%>
<%}
}
%>
<% if(username !== null) { %>
<li class="dropdown-item">
<a id="user" class="tab" href="#user">User profile</a>
</li>
<% } %>
<li class="dropdown-item">
<a id="userManagement" class="internalLink" href="#userManagement">User management</a>
</li>

View File

@ -19,7 +19,8 @@
current: window.currentDB
});
this.userBarView = new window.UserBarView({
collection: this.options.notificationCollection
collection: this.options.notificationCollection,
userCollection: window.activeUser
});
this.statisticBarView = new window.StatisticBarView({});
},

View File

@ -19,6 +19,7 @@
this.collection.bind("add", this.renderNotifications.bind(this));
this.collection.bind("remove", this.renderNotifications.bind(this));
this.collection.bind("reset", this.renderNotifications.bind(this));
this.userCollection = this.options.userCollection;
},
notificationItem: templateEngine.createTemplate("notificationItem.ejs"),
@ -94,11 +95,32 @@
},
render: function (el) {
var username = this.userCollection.whoAmI(),
img = null,
name = null,
active = false,
currentUser = null;
if (username !== null) {
this.userCollection.fetch({async:false});
currentUser = this.userCollection.findWhere({user: username});
currentUser.set({loggedIn : true});
name = currentUser.get("name");
img = currentUser.get("img");
active = currentUser.get("active");
}
if (!img) {
img = "img/arangodblogoAvatar.png";
}
if (!name) {
name = "";
}
this.$el = el;
this.$el.html(this.template.render({
img : "https://s.gravatar.com/avatar/9c53a795affc3c3c03801ffae90e2e11?s=80",
prename : "Floyd",
lastname : "Pepper",
img : img,
name : name,
username : username,
active : active,
notifications : this.collection
}));

View File

@ -14,7 +14,7 @@
"click #submitCreateUser" : "submitCreateUser",
"click #userManagementTable .icon_arangodb_roundminus" : "removeUser",
"click #submitDeleteUser" : "submitDeleteUser",
// "click .editUser" : "editUser",
"click .editUser" : "editUser",
"click #submitEditUser" : "submitEditUser"
},
@ -34,14 +34,28 @@
renderTable: function () {
this.collection.forEach(function(user) {
var deleteButton =
'<span class="arangoicon icon_arangodb_roundminus" data-original-title="Delete user"></span>';
if(user.get("loggedIn")) {
deleteButton = '';
}
var username = user.get("user"),
name = user.get("name"),
img = user.get("img"),
active = user.get("active");
if (!img) {
img = " ";
}
if (!name) {
name = " ";
}
$("#userManagementTable tbody").append(
'<tr class="editUser" id="' + user.get("user") + '">' +
'<td><a>' + user.get("user") + '</a></td>' +//username
'<td><a>' + "" + '</a></td>' +//avatar
'<td><a>' + "" + '</a></td>' +//name
'<td><a>' + user.get("active") + '</a></td>' +//active
'<td><span class="arangoicon icon_arangodb_roundminus"' +
'data-original-title="Delete user"></span></td>' +
'<tr class="editUser" id="' + username + '">' +
'<td><a>' + username + '</a></td>' +//username
'<td><a>' + img + '</a></td>' +//avatar
'<td><a>' + name + '</a></td>' +//name
'<td><a>' + active + '</a></td>' +//active
'<td>' + deleteButton + '</td>' +
'</tr>'
);
});
@ -136,7 +150,7 @@
editUser : function(e) {
this.userToEdit = $(e.currentTarget).attr("id");
console.log(this.userToEdit);
// console.log(this.userToEdit);
$('#editUserModal').modal('show');
var user = this.collection.findWhere({user: this.userToEdit});
$('#editUsername').html(user.get("user"));
@ -145,14 +159,14 @@
},
submitEditUser : function() {
console.log("submitEditUser");
// console.log("submitEditUser");
var self = this;
var userName = this.userToEdit;
var name = $('#editName').val();
var status = $('#editStatus').is(':checked');
console.log(userName);
console.log(name);
console.log(status);
// console.log(userName);
// console.log(name);
// console.log(status);
if (!this.validateStatus(status)) {
$('#editStatus').closest("th").css("backgroundColor", "red");
return;