2014-08-06 14:47:47 +02:00
|
|
|
# Events, particulary during moderation, can have notes associated to them
|
2014-06-23 23:39:42 +02:00
|
|
|
class NotesController < ApplicationController
|
2014-11-05 21:25:18 +01:00
|
|
|
before_action :set_event, only: [:new, :create]
|
|
|
|
before_action :create_note, :set_mailer_host, only: [:create]
|
2014-06-23 23:39:42 +02:00
|
|
|
|
|
|
|
# GET /moderations/id/new
|
|
|
|
def new
|
|
|
|
@note = @moderation.notes.new
|
|
|
|
end
|
2014-03-06 21:49:30 +01:00
|
|
|
|
|
|
|
def create
|
2014-06-23 23:39:42 +02:00
|
|
|
respond_to do |format|
|
2014-08-06 14:47:47 +02:00
|
|
|
if @note.save && send_mails
|
2014-06-23 23:39:42 +02:00
|
|
|
format.html { redirect_to moderations_url, notice: t('.ok') }
|
2014-08-06 14:47:47 +02:00
|
|
|
format.json { render action: :show, status: :created, location: @event }
|
2014-06-23 23:39:42 +02:00
|
|
|
else
|
2014-11-05 21:25:18 +01:00
|
|
|
format.html { render action: :new }
|
2014-06-23 23:39:42 +02:00
|
|
|
format.json { render json: @note.errors, status: :unprocessable_entity }
|
|
|
|
end
|
2014-03-06 21:49:30 +01:00
|
|
|
end
|
|
|
|
end
|
2014-02-18 09:28:04 +01:00
|
|
|
|
|
|
|
private
|
2014-06-23 23:39:42 +02:00
|
|
|
|
2014-08-06 14:47:47 +02:00
|
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
|
|
def set_event
|
|
|
|
@event = Event.find params[:moderation_id]
|
|
|
|
@moderation = @event
|
|
|
|
end
|
2014-02-18 09:28:04 +01:00
|
|
|
|
2014-11-05 21:25:18 +01:00
|
|
|
def create_note
|
|
|
|
@note = @moderation.notes.new note_params.merge author: current_user
|
|
|
|
end
|
|
|
|
|
2014-08-06 14:47:47 +02:00
|
|
|
# Never trust parameters from the scary internet, only allow the white list
|
|
|
|
# through.
|
|
|
|
def note_params
|
|
|
|
params.require(:note).permit :contents
|
|
|
|
end
|
|
|
|
|
|
|
|
# Useful to manage absolute url in mails
|
|
|
|
def set_mailer_host
|
|
|
|
ActionMailer::Base.default_url_options[:host] = request.host_with_port
|
|
|
|
end
|
|
|
|
|
|
|
|
def send_mails
|
|
|
|
if params[:envoiParMail] == 'oui'
|
|
|
|
# Send an update mail to its author
|
|
|
|
NoteMailer.notify(@note).deliver
|
|
|
|
@note.contents = t '.sendByMailWrap', contents: @note.contents
|
|
|
|
@note.save
|
2014-02-18 09:28:04 +01:00
|
|
|
end
|
2014-08-06 14:47:47 +02:00
|
|
|
NoteMailer.create(@note).deliver
|
|
|
|
end
|
2014-02-18 09:28:04 +01:00
|
|
|
end
|