2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
class Admin::BroadcastMessagesController < Admin::ApplicationController
|
2018-03-17 18:26:18 +05:30
|
|
|
include BroadcastMessagesHelper
|
|
|
|
|
2016-01-19 16:12:03 +05:30
|
|
|
before_action :finder, only: [:edit, :update, :destroy]
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
feature_category :navigation
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2014-09-02 18:07:02 +05:30
|
|
|
def index
|
2018-03-17 18:26:18 +05:30
|
|
|
@broadcast_messages = BroadcastMessage.order(ends_at: :desc).page(params[:page])
|
2016-01-19 16:12:03 +05:30
|
|
|
@broadcast_message = BroadcastMessage.new
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2016-01-19 16:12:03 +05:30
|
|
|
|
|
|
|
def edit
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@broadcast_message = BroadcastMessage.new(broadcast_message_params)
|
|
|
|
|
|
|
|
if @broadcast_message.save
|
2019-07-07 11:18:12 +05:30
|
|
|
redirect_to admin_broadcast_messages_path, notice: _('Broadcast Message was successfully created.')
|
2014-09-02 18:07:02 +05:30
|
|
|
else
|
|
|
|
render :index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-19 16:12:03 +05:30
|
|
|
def update
|
|
|
|
if @broadcast_message.update(broadcast_message_params)
|
2019-07-07 11:18:12 +05:30
|
|
|
redirect_to admin_broadcast_messages_path, notice: _('Broadcast Message was successfully updated.')
|
2016-01-19 16:12:03 +05:30
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def destroy
|
2016-01-19 16:12:03 +05:30
|
|
|
@broadcast_message.destroy
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
respond_to do |format|
|
2015-10-24 18:46:33 +05:30
|
|
|
format.html { redirect_back_or_default(default: { action: 'index' }) }
|
2016-06-02 11:05:42 +05:30
|
|
|
format.js { head :ok }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
def preview
|
2022-06-21 17:19:12 +05:30
|
|
|
@broadcast_message = BroadcastMessage.new(broadcast_message_params)
|
|
|
|
render partial: 'admin/broadcast_messages/preview'
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
protected
|
|
|
|
|
2016-01-19 16:12:03 +05:30
|
|
|
def finder
|
|
|
|
@broadcast_message = BroadcastMessage.find(params[:id])
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def broadcast_message_params
|
2016-01-19 16:12:03 +05:30
|
|
|
params.require(:broadcast_message).permit(%i(
|
|
|
|
color
|
2022-06-21 17:19:12 +05:30
|
|
|
theme
|
2016-01-19 16:12:03 +05:30
|
|
|
ends_at
|
|
|
|
message
|
|
|
|
starts_at
|
2020-01-01 13:55:28 +05:30
|
|
|
target_path
|
|
|
|
broadcast_type
|
2020-04-08 14:13:33 +05:30
|
|
|
dismissable
|
2022-05-07 20:08:51 +05:30
|
|
|
), target_access_levels: []).reverse_merge!(target_access_levels: [])
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|