@@ -2,6 +2,7 @@ $(document).ready ->
2
2
$ (document ).on (" click" , " .waiting-for-approval-users .action.approve" , {action : " approve" }, act_on_user)
3
3
$ (document ).on (" click" , " .approved-users .action.suspend" , {action : " suspend" }, act_on_user)
4
4
$ (document ).on (" click" , " .approved-users .action.activate" , {action : " activate" }, act_on_user)
5
+ $ (document ).on (" click" , " .admin input[type='checkbox']" , {}, toggelAdminOnUser)
5
6
return
6
7
7
8
act_on_user = (obj )->
@@ -52,10 +53,40 @@ act_on_user = (obj)->
52
53
return
53
54
54
55
request .error (data, textStatus, jqXHR) ->
55
- alert (' error ' )
56
+ alert (' Something went wrong while trying to get change user status ' )
56
57
57
58
return
58
59
60
+ toggelAdminOnUser = ()->
61
+ $el = $ (this )
62
+ $row = $el .closest (" tr" )
63
+
64
+ user_id = $row .data (" user-id" )
65
+
66
+ checked = $el .prop (" checked" );
67
+
68
+ full_name = $row .data (" full-name" )
69
+
70
+ # Generate the message based on the check of the user admin flag
71
+ message = if checked then " make #{ full_name} an administrator?" else " remove #{ full_name} from the administrators?"
72
+ message = " Are you sure " + message
73
+
74
+ if (confirm (message) != true )
75
+ $el .prop (" checked" , ! checked);
76
+ return
77
+
78
+ request = $ .post ' /admin/toggle_admin' ,
79
+ user_id : user_id
80
+
81
+ request .success (data) ->
82
+ alert (" #{ full_name} is now an administrator" )
83
+ return
84
+
85
+ request .error (data, textStatus, jqXHR) ->
86
+ alert (" Something went wrong while trying to make #{ full_name} an administrator" )
87
+ $el .prop (" checked" , ! checked);
88
+ return
89
+
59
90
# Toggles a table and the container that says there are no users if needed
60
91
toggleTableIfNeeded = ($container )->
61
92
$table = $container .find (" table" )
0 commit comments