2013-11-12 07:28:12 -05:00
|
|
|
class Admin::BroadcastMessagesController < Admin::ApplicationController
|
2015-12-31 17:55:14 -05:00
|
|
|
before_action :finder, only: [:edit, :update, :destroy]
|
2013-11-12 07:28:12 -05:00
|
|
|
|
|
|
|
def index
|
2016-02-05 10:01:10 -05:00
|
|
|
@broadcast_messages = BroadcastMessage.reorder("ends_at DESC").page(params[:page])
|
2015-12-31 17:55:14 -05:00
|
|
|
@broadcast_message = BroadcastMessage.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2013-11-12 07:28:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-06-26 08:00:09 -04:00
|
|
|
@broadcast_message = BroadcastMessage.new(broadcast_message_params)
|
2013-11-12 07:28:12 -05:00
|
|
|
|
|
|
|
if @broadcast_message.save
|
|
|
|
redirect_to admin_broadcast_messages_path, notice: 'Broadcast Message was successfully created.'
|
|
|
|
else
|
|
|
|
render :index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-31 17:55:14 -05:00
|
|
|
def update
|
|
|
|
if @broadcast_message.update(broadcast_message_params)
|
|
|
|
redirect_to admin_broadcast_messages_path, notice: 'Broadcast Message was successfully updated.'
|
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-12 08:20:31 -05:00
|
|
|
def destroy
|
2015-12-31 17:55:14 -05:00
|
|
|
@broadcast_message.destroy
|
2013-11-12 08:20:31 -05:00
|
|
|
|
|
|
|
respond_to do |format|
|
2015-10-20 03:28:28 -04:00
|
|
|
format.html { redirect_back_or_default(default: { action: 'index' }) }
|
2013-11-12 08:20:31 -05:00
|
|
|
format.js { render nothing: true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-03 23:01:04 -05:00
|
|
|
def preview
|
|
|
|
@message = broadcast_message_params[:message]
|
|
|
|
end
|
|
|
|
|
2013-11-12 07:28:12 -05:00
|
|
|
protected
|
|
|
|
|
2015-12-31 17:55:14 -05:00
|
|
|
def finder
|
|
|
|
@broadcast_message = BroadcastMessage.find(params[:id])
|
2013-11-12 07:28:12 -05:00
|
|
|
end
|
2014-06-26 08:00:09 -04:00
|
|
|
|
|
|
|
def broadcast_message_params
|
2015-12-31 15:56:15 -05:00
|
|
|
params.require(:broadcast_message).permit(%i(
|
|
|
|
color
|
|
|
|
ends_at
|
|
|
|
font
|
|
|
|
message
|
|
|
|
starts_at
|
|
|
|
))
|
2014-06-26 08:00:09 -04:00
|
|
|
end
|
2013-11-12 07:28:12 -05:00
|
|
|
end
|