Browse Source

Activity-edit to HAML, add managing organizers

Maarten van den Berg 7 years ago
parent
commit
7e7f5bbb45

+ 25 - 0
app/controllers/activities_controller.rb

36
 
36
 
37
   # GET /activities/1/edit
37
   # GET /activities/1/edit
38
   def edit
38
   def edit
39
+    @non_organizers = @activity.participants.where.not(is_organizer: true)
40
+    @organizers = @activity.organizers
41
+
42
+    @non_organizers_options = @non_organizers.map{|p| [p.person.full_name, p.id] }
43
+    @organizers_options     =     @organizers.map{|p| [p.person.full_name, p.id] }
44
+
45
+    @non_organizers_options.sort!
46
+    @organizers_options.sort!
39
   end
47
   end
40
 
48
 
41
   # POST /activities
49
   # POST /activities
58
     end
66
     end
59
   end
67
   end
60
 
68
 
69
+  # Change organizer state for a Participant
70
+  def change_organizer
71
+    @activity = Activity.find(params[:activity_id])
72
+    @participant = @activity.participants.find(params[:participant_id])
73
+    @participant.is_organizer = params[:new_state]
74
+    @participant.save
75
+
76
+    if params[:new_state] == "true"
77
+      message = I18n.t('activities.organizers.added', name: @participant.person.full_name)
78
+    else
79
+      message = I18n.t('activities.organizers.removed', name: @participant.person.full_name)
80
+    end
81
+    flash_message(:success, message)
82
+
83
+    redirect_to edit_group_activity_path(@group, @activity)
84
+  end
85
+
61
   # PATCH/PUT /activities/1
86
   # PATCH/PUT /activities/1
62
   # PATCH/PUT /activities/1.json
87
   # PATCH/PUT /activities/1.json
63
   def update
88
   def update

+ 0 - 8
app/views/activities/edit.html.erb

1
-<h1>
2
-  <%= t 'activity.editing' %>
3
-</h1>
4
-
5
-<%= render 'form', activity: @activity %>
6
-
7
-<%= link_to t(:cancel), group_activity_path(@group, @activity) %> |
8
-<%= link_to t(:back), group_activities_path(@group) %>

+ 38 - 0
app/views/activities/edit.html.haml

1
+%h1
2
+  = t 'activity.editing'
3
+
4
+= render 'form', activity: @activity
5
+
6
+%h2
7
+  = t 'activities.organizers.manage'
8
+.row
9
+  .col-md-6
10
+    %h4
11
+      = t 'activities.organizers.add'
12
+    - if @non_organizers.count > 0
13
+      = form_tag(group_activity_change_organizer_path(@group, @activity), method: 'post') do
14
+        .form-group
15
+          = select_tag(:participant_id, options_for_select(@non_organizers_options))
16
+        .form-group
17
+          = hidden_field_tag(:new_state, true)
18
+          = submit_tag(t('activities.organizers.add'), class: 'btn btn-success')
19
+    - else
20
+      = t 'activities.organizers.no_non_organizers'
21
+
22
+  .col-md-6
23
+    %h4
24
+      = t 'activities.organizers.remove'
25
+    - if @organizers.count > 0
26
+      = form_tag(group_activity_change_organizer_path(@group, @activity), method: 'post') do
27
+        .form-group
28
+          = select_tag(:participant_id, options_for_select(@organizers_options))
29
+        .form-group
30
+          = hidden_field_tag(:new_state, false)
31
+          = submit_tag(t('activities.organizers.remove'), class: 'btn btn-danger')
32
+
33
+    - else
34
+      = t 'activities.organizers.no_organizers'
35
+
36
+= link_to t(:back), group_activity_path(@group, @activity)
37
+|
38
+= link_to t(:overview), group_activities_path(@group)

+ 1 - 0
config/locales/aardbei_en.yml

36
   destroy: "Delete"
36
   destroy: "Delete"
37
   remove: "Remove"
37
   remove: "Remove"
38
   send_email: "Send email"
38
   send_email: "Send email"
39
+  overview: "Overzicht"
39
 
40
 
40
   areyousure: "Are you sure?"
41
   areyousure: "Are you sure?"
41
 
42
 

+ 1 - 0
config/locales/aardbei_nl.yml

15
   destroy: "Verwijderen"
15
   destroy: "Verwijderen"
16
   remove: "Verwijderen"
16
   remove: "Verwijderen"
17
   send_email: "Email versturen"
17
   send_email: "Email versturen"
18
+  overview: "Overzicht"
18
 
19
 
19
   areyousure: "Weet je het zeker?"
20
   areyousure: "Weet je het zeker?"
20
 
21
 

+ 12 - 0
config/locales/activities/en.yml

23
       add_notes: "Add notes"
23
       add_notes: "Add notes"
24
       yourresponse: "Your response"
24
       yourresponse: "Your response"
25
 
25
 
26
+    organizers:
27
+      one: "Organizer"
28
+      other: "Organizers"
29
+      manage: "Manage organizers"
30
+      add: "Add organizer"
31
+      added: "%{name} is now an organizer."
32
+      remove: "Remove organizer"
33
+      removed: "%{name} is no longer an organizer."
34
+
35
+      no_organizers: "This activity has no organizers."
36
+      no_non_organizers: "This activity has no non-organizers."
37
+
26
     state:
38
     state:
27
       need_response: "Need response"
39
       need_response: "Need response"
28
       present: "Present"
40
       present: "Present"

+ 12 - 0
config/locales/activities/nl.yml

23
       add_notes: "Opmerkingen toevoegen"
23
       add_notes: "Opmerkingen toevoegen"
24
       yourresponse: "Jouw antwoord"
24
       yourresponse: "Jouw antwoord"
25
 
25
 
26
+    organizers:
27
+      one: "Organisator"
28
+      other: "Organisatoren"
29
+      manage: "Organisatoren aanpassen"
30
+      add: "Organisator toevoegen"
31
+      added: "%{name} is nu een organisator."
32
+      remove: "Organisator verwijderen"
33
+      removed: "%{name} is nu geen organisator meer."
34
+
35
+      no_organizers: "Deze activiteit heeft geen organisatoren."
36
+      no_non_organizers: "Deze activiteit heeft geen niet-organisatoren."
37
+
26
     state:
38
     state:
27
       need_response: "Nog geen reactie"
39
       need_response: "Nog geen reactie"
28
       present: "Aanwezig"
40
       present: "Aanwezig"

+ 1 - 0
config/routes.rb

38
     end
38
     end
39
 
39
 
40
     resources :activities do
40
     resources :activities do
41
+      post 'change_organizer', to: 'activities#change_organizer'
41
       put 'presence', to: 'activities#presence', on: :member
42
       put 'presence', to: 'activities#presence', on: :member
42
       patch 'presence', to: 'activities#presence', on: :member
43
       patch 'presence', to: 'activities#presence', on: :member
43
     end
44
     end