2018-09-14 01:42:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
|
|
|
2020-10-05 17:08:47 -04:00
|
|
|
feature_category :navigation
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
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
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2015-12-31 17:55:14 -05:00
|
|
|
|
|
|
|
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
|
2019-03-21 09:31:05 -04:00
|
|
|
redirect_to admin_broadcast_messages_path, notice: _('Broadcast Message was successfully created.')
|
2013-11-12 07:28:12 -05:00
|
|
|
else
|
|
|
|
render :index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-31 17:55:14 -05:00
|
|
|
def update
|
|
|
|
if @broadcast_message.update(broadcast_message_params)
|
2019-03-21 09:31:05 -04:00
|
|
|
redirect_to admin_broadcast_messages_path, notice: _('Broadcast Message was successfully updated.')
|
2015-12-31 17:55:14 -05:00
|
|
|
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
|
2019-12-02 10:06:36 -05:00
|
|
|
target_path
|
2019-12-10 10:07:52 -05:00
|
|
|
broadcast_type
|
2020-03-04 19:07:49 -05:00
|
|
|
dismissable
|
2022-02-17 10:18:08 -05:00
|
|
|
))
|
2014-06-26 08:00:09 -04:00
|
|
|
end
|
2013-11-12 07:28:12 -05:00
|
|
|
end
|