1
+ SUSPEND_ACTION = " suspend"
2
+ SUSPEND_BTN_CSS = " btn-danger"
3
+ ACTIVATE_ACTION = " activate"
4
+ ACTIVATE_APPROVE_BTN_CSS = " btn-success"
5
+ APPROVE_ACTION = " approve"
6
+
1
7
$ (document ).ready ->
2
- $ (document ).on (" click" , " .waiting-for-approval-users .action.approve" , {action : " approve " }, act_on_user)
3
- $ (document ).on (" click" , " .approved-users .action.suspend" , {action : " suspend " }, act_on_user)
4
- $ (document ).on (" click" , " .approved-users .action.activate" , {action : " activate " }, act_on_user)
8
+ $ (document ).on (" click" , " .waiting-for-approval-users .action.approve" , {action : APPROVE_ACTION }, act_on_user)
9
+ $ (document ).on (" click" , " .approved-users .action.suspend" , {action : SUSPEND_ACTION }, act_on_user)
10
+ $ (document ).on (" click" , " .approved-users .action.activate" , {action : ACTIVATE_ACTION }, act_on_user)
5
11
$ (document ).on (" click" , " .admin input[type='checkbox']" , {}, toggelAdminOnUser)
6
12
return
7
13
@@ -19,21 +25,21 @@ act_on_user = (obj)->
19
25
request .success (data) ->
20
26
# We will set the new and old css actions depending on the action that was taken because this method
21
27
# is used by 3 different buttons
22
- if action_taken == " suspend "
23
- old_btn_class = " suspend "
24
- old_css_class = " btn-danger "
25
- new_btn_class = " btn-success "
26
- new_css_class = " activate "
28
+ if action_taken == SUSPEND_ACTION
29
+ old_btn_class = SUSPEND_ACTION
30
+ old_css_class = SUSPEND_BTN_CSS
31
+ new_btn_class = ACTIVATE_APPROVE_BTN_CSS
32
+ new_css_class = ACTIVATE_ACTION
27
33
else
28
34
# Approve and activate will be almost the same except for the original css class
29
- if action_taken == " activate "
30
- old_css_class = " activate "
35
+ if action_taken == ACTIVATE_ACTION
36
+ old_css_class = ACTIVATE_ACTION
31
37
else
32
- old_css_class = " approve "
38
+ old_css_class = APPROVE_ACTION
33
39
34
- old_btn_class = " btn-success "
35
- new_btn_class = " btn-danger "
36
- new_css_class = " suspend "
40
+ old_btn_class = ACTIVATE_APPROVE_BTN_CSS
41
+ new_btn_class = SUSPEND_BTN_CSS
42
+ new_css_class = SUSPEND_ACTION
37
43
38
44
btn_text = _ .str .titleize (new_css_class)
39
45
@@ -43,7 +49,7 @@ act_on_user = (obj)->
43
49
$el .text (btn_text).removeClass (" #{ old_btn_class} #{ old_css_class} " ).addClass (" #{ new_btn_class} #{ new_css_class} " )
44
50
45
51
# 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
46
- if action_taken == " approve "
52
+ if action_taken == APPROVE_ACTION
47
53
$row .remove ()
48
54
$ (" .approved-users table" ).show ().append ($row)
49
55
0 commit comments