diff --git a/lumi2/static/js/group_edit.js b/lumi2/static/js/group_edit.js
index 1219069..f30673e 100644
--- a/lumi2/static/js/group_edit.js
+++ b/lumi2/static/js/group_edit.js
@@ -1,9 +1,14 @@
$(function() {
+ for (entry of $(".unsortable")) {
+ $(entry).data("sorter", false);
+ }
+
$("table").tablesorter({
theme: 'bootstrap',
headerTemplate: '{content} {icon}',
cssIcon: 'bi-arrow-down-up',
cssIconNone: '',
+ cssIconDisabled: '',
cssIconAsc: 'bi-arrow-up',
cssIconDesc: 'bi-arrow-down',
});
@@ -23,102 +28,50 @@ class UserEntry {
}
onClickLeave() {
- // Deactivate the last remaining member's togglebutton before leaving
- if ($(membersTable).find(".userEntry").length < 2) {
- for (entry of $(membersTable).find(".userEntry")) {
- if ($(entry).id != this.username) {
- $(entry).find(".toggleMembershipButton")[0].prop("disabled", true);
- }
- }
- }
-
this.setButtonAppearanceInProgress();
-
$.ajax({
context: {
"userEntry": this
},
- url: `/api/group/${groupname}`,
- type: "GET",
+ url: `/api/group/${groupname}/member/${this.username}`,
+ type: "DELETE",
dataType: "json",
- }).done(function(groupJson) {
- $.ajax({
- context: {
- "userEntry": this.userEntry,
- },
- url: `/api/group/${groupname}`,
- type: "PUT",
- dataType: "json",
- data: JSON.stringify(groupJson),
- contentType: "application/json",
- })
- .done(function(groupJson) {
- this.userEntry.isMember = false;
- $(this.userEntry.buttonElement).off("click");
- $(this.userEntry.buttonElement).click(() => this.userEntry.onClickJoin());
- $(this.userEntry.rowElement).prependTo($("#tableNonMembers").find("tbody"));
- this.userEntry.setButtonAppearanceJoinGroup();
- })
- .fail(function(xhr, status, errorThrown) {
- console.log(`Error: ${errorThrown}`);
- console.log(`Status: ${status}`);
- console.dir(xhr);
- alert("Sorry, there was a problem sending information to the server.");
-
- this.userEntry.setButtonAppearanceLeaveGroup();
- });
+ }).done(function() {
+ this.userEntry.isMember = false;
+ $(this.userEntry.buttonElement).off("click");
+ $(this.userEntry.buttonElement).click(() => this.userEntry.onClickJoin());
+ $(this.userEntry.rowElement).prependTo($("#tableNonMembers").find("tbody"));
+ this.userEntry.setButtonAppearanceJoinGroup();
+ // TODO check status code!
}).fail(function(xhr, status, errorThrown) {
console.log(`Error: ${errorThrown}`);
console.log(`Status: ${status}`);
alert("Sorry, there was a problem retrieving information from the server.");
-
this.userEntry.setButtonAppearanceLeaveGroup();
});
}
onClickJoin() {
this.setButtonAppearanceInProgress();
-
$.ajax({
context: {
"userEntry": this
},
- url: `/api/group/${groupname}`,
- type: "GET",
+ url: `/api/group/${groupname}/member/${this.username}`,
+ type: "POST",
dataType: "json",
- }).done(function(groupJson) {
- // Add current user to the members array
- groupJson.group.members.push(this.userEntry.username);
- $.ajax({
- context: {
- "userEntry": this.userEntry,
- },
- url: `/api/group/${groupname}`,
- type: "PUT",
- dataType: "json",
- data: JSON.stringify(groupJson),
- contentType: "application/json",
- })
- .done(function(groupJson) {
- this.userEntry.isMember = true;
- $(this.userEntry.buttonElement).off("click");
- $(this.userEntry.buttonElement).click(() => this.userEntry.onClickLeave());
- $(this.userEntry.rowElement).prependTo($("#tableMembers").find("tbody"));
- this.userEntry.setButtonAppearanceLeaveGroup();
- })
- .fail(function(xhr, status, errorThrown) {
- console.log(`Error: ${errorThrown}`);
- console.log(`Status: ${status}`);
- console.dir(xhr);
- alert("Sorry, there was a problem sending information to the server.");
-
- this.userEntry.setButtonAppearanceJoinGroup();
- });
+ }).done(function() {
+ this.userEntry.isMember = true;
+ $(this.userEntry.buttonElement).off("click");
+ $(this.userEntry.buttonElement).click(() => this.userEntry.onClickLeave());
+ $(this.userEntry.rowElement).prependTo($("#tableMembers").find("tbody"));
+ this.userEntry.setButtonAppearanceLeaveGroup();
+ // TODO check status code!
}).fail(function(xhr, status, errorThrown) {
console.log(`Error: ${errorThrown}`);
console.log(`Status: ${status}`);
alert("Sorry, there was a problem retrieving information from the server.");
- this.userEntry.setButtonAppearanceJoinGroup();
+ this.userEntry.setButtonAppearanceLeaveGroup();
});
}
diff --git a/lumi2/static/js/group_list.js b/lumi2/static/js/group_list.js
new file mode 100644
index 0000000..909aa32
--- /dev/null
+++ b/lumi2/static/js/group_list.js
@@ -0,0 +1,10 @@
+$(function() {
+ $("table").tablesorter({
+ theme: 'bootstrap',
+ headerTemplate: '{content} {icon}',
+ cssIcon: 'bi-arrow-down-up',
+ cssIconNone: '',
+ cssIconAsc: 'bi-arrow-up',
+ cssIconDesc: 'bi-arrow-down',
+ });
+});
diff --git a/lumi2/templates/usermanager/group_edit.html b/lumi2/templates/usermanager/group_edit.html
index d89d73b..0fb7854 100644
--- a/lumi2/templates/usermanager/group_edit.html
+++ b/lumi2/templates/usermanager/group_edit.html
@@ -11,7 +11,7 @@
- Other users |
+ Username |
@@ -41,7 +41,7 @@
- {{ groupname }} |
+ Username |
diff --git a/lumi2/templates/usermanager/group_list.html b/lumi2/templates/usermanager/group_list.html
index 76d573c..f37b2da 100644
--- a/lumi2/templates/usermanager/group_list.html
+++ b/lumi2/templates/usermanager/group_list.html
@@ -16,18 +16,17 @@
Group Name |
- Members |
+ Number of Members |
{% for group in groups | sort %}
- {{ group.groupname }}
+ {{ group.groupname }}
|
- {% for user in group.members %}
- {% endfor %}
+ {{ group.members|length }}
|
{% endfor %}
@@ -39,4 +38,5 @@
There are currently no groups.
{% endif %}
+
{% endblock content %}
diff --git a/lumi2/usermanager.py b/lumi2/usermanager.py
index 27ada87..4a314e3 100644
--- a/lumi2/usermanager.py
+++ b/lumi2/usermanager.py
@@ -339,35 +339,6 @@ def group_create():
abort(404)
-@bp.route("/groups/view/")
-def group_view(groupname: str):
- """Displays a form allowing group creation."""
-
- try:
- conn = ldap.get_connection()
- except Exception:
- abort(500)
-
- try:
- group = ldap.get_group(conn, groupname)
- except ldap.EntryNotFoundException:
- conn.unbind()
- abort(404)
-
- conn.unbind()
- # TODO implement
- abort(404)
-
-
-class GroupUpdateForm(FlaskForm):
- updated_members = HiddenField(
- 'Group Members',
- )
- submit = SubmitField(
- 'Apply',
- )
-
-
@bp.route("/groups/update/")
def group_update(groupname: str):
"""Detail and Update view for a group.