2013-11-12 07:28:12 -05:00
|
|
|
class Admin::BroadcastMessagesController < Admin::ApplicationController
|
2018-02-05 09:59:48 -05:00
|
|
|
include BroadcastMessagesHelper
|
|
|
|
|
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
|
2017-08-15 06:27:37 -04:00
|
|
|
@broadcast_messages = BroadcastMessage.order(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' }) }
|
2016-03-15 21:16:25 -04:00
|
|
|
format.js { head :ok }
|
2013-11-12 08:20:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-03 23:01:04 -05:00
|
|
|
def preview
|
2018-02-05 09:59:48 -05:00
|
|
|
broadcast_message = BroadcastMessage.new(broadcast_message_params)
|
|
|
|
render json: { message: render_broadcast_message(broadcast_message) }
|
2016-02-03 23:01:04 -05:00
|
|
|
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
|