Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Javascript to handle users finished. Added check to make sure approve…
…d users are not stuck on the approval page. Same for suspended
- Loading branch information
Showing
7 changed files
with
104 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,71 @@ | ||
$(document).ready -> | ||
$(document).on("click", ".waiting-for-approval-users .action.approve", {action : "approve"}, act_on_user) | ||
$(document).on("click", ".approved-users .action.suspend", {action : "suspend"}, act_on_user) | ||
$(document).on("click", ".approved-users .action.activate", {action : "activate"}, act_on_user) | ||
$(document).on("click", ".waiting-for-approval-users .action.approve", {action : "approve" }, act_on_user) | ||
$(document).on("click", ".approved-users .action.suspend", {action : "suspend" }, act_on_user) | ||
$(document).on("click", ".approved-users .action.activate", {action : "activate" }, act_on_user) | ||
return | ||
|
||
act_on_user = (obj)-> | ||
user_id = $(this).closest("tr").data("user-id") | ||
$el = $(this) | ||
$row = $el.closest("tr") | ||
|
||
user_id = $row.data("user-id") | ||
action_taken = obj.data.action | ||
|
||
request = $.post '/admin/update_user', | ||
user_id: user_id | ||
action_taken: action_taken | ||
|
||
request.success (data) -> | ||
alert("done") | ||
# We will set the new and old css actions depending on the action that was taken because this method | ||
# is used by 3 different buttons | ||
if action_taken == "suspend" | ||
old_btn_class = "suspend" | ||
old_css_class = "btn-danger" | ||
new_btn_class = "btn-success" | ||
new_css_class = "activate" | ||
else | ||
# Approve and activate will be almost the same except for the original css class | ||
if action_taken == "activate" | ||
old_css_class = "activate" | ||
else | ||
old_css_class = "approve" | ||
|
||
old_btn_class = "btn-success" | ||
new_btn_class = "btn-danger" | ||
new_css_class = "suspend" | ||
|
||
btn_text = _.str.titleize(new_css_class) | ||
|
||
$row.find("td.status").text(_.str.titleize(data.status)) | ||
|
||
# Change the look of the buttons by removing and adding classes | ||
$el.text(btn_text).removeClass("#{old_btn_class} #{old_css_class}").addClass("#{new_btn_class} #{new_css_class}") | ||
|
||
# Check if the user was an approval. If so, move the user out of the waiting for approval table and add it to the approved table | ||
if action_taken == "approve" | ||
$row.remove() | ||
$(".approved-users table").show().append($row) | ||
|
||
toggleTableIfNeeded $(".waiting-for-approval-users") | ||
toggleTableIfNeeded $(".approved-users") | ||
|
||
return | ||
|
||
request.error (data, textStatus, jqXHR) -> | ||
alert('error') | ||
|
||
return | ||
return | ||
|
||
# Toggles a table and the container that says there are no users if needed | ||
toggleTableIfNeeded = ($container)-> | ||
$table = $container.find("table") | ||
$no_user_el = $container.find(".js-no-users") | ||
|
||
if $table.find("tbody tr").length == 0 | ||
$table.hide() | ||
$no_user_el.show() | ||
else | ||
$table.show() | ||
$no_user_el.hide() | ||
|
||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<table <%= inline_style_hidden(users.empty?)%> class="table table-striped table-bordered" cellspacing="0" cellpadding="0" border="0"> | ||
<thead> | ||
<tr> | ||
<th class="username">Username</th> | ||
<th class="first_name">First Name</th> | ||
<th class="last_name">Last Name</th> | ||
<th class="email">Email</th> | ||
<th class="statu">Status</th> | ||
<th class="action">Action</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% users.each do |user| %> | ||
<tr class="<%= cycle('odd', 'even')%>" data-user-id="<%= user.id%>"> | ||
<td class="username"> | ||
<%= user.username %> | ||
</td> | ||
<td class="first_name"> | ||
<%= user.first_name %> | ||
</td> | ||
<td class="last_name"> | ||
<%= user.last_name %> | ||
</td> | ||
<td class="email"> | ||
<%= user.email %> | ||
</td> | ||
<td class="status"> | ||
<%= user_status(user) %> | ||
</td> | ||
<td class="action"> | ||
<%= user_action(user) %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<div class="js-no-users" <%= inline_style_hidden(users.any?)%> >There are no users. Invite others to join Kandan!</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters