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
|
2022-05-20 17:08:53 -04:00
|
|
|
urgency :low
|
2020-10-05 17:08:47 -04:00
|
|
|
|
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
|
2022-04-18 23:09:43 -04:00
|
|
|
@broadcast_message = BroadcastMessage.new(broadcast_message_params)
|
|
|
|
render partial: 'admin/broadcast_messages/preview'
|
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
|
2022-04-18 23:09:43 -04:00
|
|
|
theme
|
2015-12-31 15:56:15 -05:00
|
|
|
ends_at
|
|
|
|
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-03-07 07:16:11 -05:00
|
|
|
), target_access_levels: []).reverse_merge!(target_access_levels: [])
|
2014-06-26 08:00:09 -04:00
|
|
|
end
|
2013-11-12 07:28:12 -05:00
|
|
|
end
|