Commit 00e87004 authored by Robert Speicher's avatar Robert Speicher

Broadcast Messages can now be edited

Closes #3046
parent 540ae3c3
class Admin::BroadcastMessagesController < Admin::ApplicationController class Admin::BroadcastMessagesController < Admin::ApplicationController
before_action :broadcast_messages before_action :finder, only: [:edit, :update, :destroy]
def index def index
@broadcast_message = BroadcastMessage.new @broadcast_messages = BroadcastMessage.reorder("starts_at ASC").page(params[:page])
@broadcast_message = BroadcastMessage.new
end
def edit
end end
def create def create
...@@ -15,8 +19,16 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController ...@@ -15,8 +19,16 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController
end end
end end
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
def destroy def destroy
BroadcastMessage.find(params[:id]).destroy @broadcast_message.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_back_or_default(default: { action: 'index' }) } format.html { redirect_back_or_default(default: { action: 'index' }) }
...@@ -26,8 +38,8 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController ...@@ -26,8 +38,8 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController
protected protected
def broadcast_messages def finder
@broadcast_messages ||= BroadcastMessage.order("starts_at DESC").page(params[:page]) @broadcast_message = BroadcastMessage.find(params[:id])
end end
def broadcast_message_params def broadcast_message_params
......
.broadcast-message-preview .broadcast-message-preview{ style: broadcast_message_style(@broadcast_message) }
= icon('bullhorn') = icon('bullhorn')
%span Your message here %span= @broadcast_message.message || "Your message here"
= form_for [:admin, @broadcast_message], html: { class: 'broadcast-message-form form-horizontal js-requires-input'} do |f| = form_for [:admin, @broadcast_message], html: { class: 'broadcast-message-form form-horizontal js-requires-input'} do |f|
-if @broadcast_message.errors.any? -if @broadcast_message.errors.any?
...@@ -10,18 +10,18 @@ ...@@ -10,18 +10,18 @@
.form-group .form-group
= f.label :message, class: 'control-label' = f.label :message, class: 'control-label'
.col-sm-10 .col-sm-10
= f.text_area :message, class: "form-control", rows: 2, required: true = f.text_area :message, class: "form-control js-quick-submit", rows: 2, required: true
.form-group.js-toggle-colors-container .form-group.js-toggle-colors-container
.col-sm-10.col-sm-offset-2 .col-sm-10.col-sm-offset-2
= link_to 'Customize colors', '#', class: 'js-toggle-colors-link' = link_to 'Customize colors', '#', class: 'js-toggle-colors-link'
.form-group.js-toggle-colors-container.hide .form-group.js-toggle-colors-container.hide
= f.label :color, "Background Color", class: 'control-label' = f.label :color, "Background Color", class: 'control-label'
.col-sm-10 .col-sm-10
= f.color_field :color, value: "#E75E40", class: "form-control" = f.color_field :color, class: "form-control"
.form-group.js-toggle-colors-container.hide .form-group.js-toggle-colors-container.hide
= f.label :font, "Font Color", class: 'control-label' = f.label :font, "Font Color", class: 'control-label'
.col-sm-10 .col-sm-10
= f.color_field :font, value: "#FFFFFF", class: "form-control" = f.color_field :font, class: "form-control"
.form-group .form-group
= f.label :starts_at, class: 'control-label' = f.label :starts_at, class: 'control-label'
.col-sm-10.datetime-controls .col-sm-10.datetime-controls
......
- page_title "Broadcast Messages"
= render 'form'
...@@ -8,24 +8,30 @@ ...@@ -8,24 +8,30 @@
= render 'form' = render 'form'
%br.clearfix
-if @broadcast_messages.any? -if @broadcast_messages.any?
%ul.bordered-list.broadcast-messages %table.table
- @broadcast_messages.each do |broadcast_message| %thead
%li %tr
.pull-right %th Status
- if broadcast_message.starts_at %th Preview
%strong %th Starts
#{broadcast_message.starts_at.to_s(:short)} %th Ends
\... %th &nbsp;
- if broadcast_message.ends_at %tbody
%strong - @broadcast_messages.each do |message|
#{broadcast_message.ends_at.to_s(:short)} %tr
&nbsp; %td
= link_to [:admin, broadcast_message], method: :delete, remote: true, class: 'remove-row btn btn-xs' do = message.status
%i.fa.fa-times.cred %td
= broadcast_message(message)
.message= broadcast_message.message %td
= message.starts_at.to_s(:iso861)
%td
= message.ends_at.to_s(:iso861)
%td
= link_to icon('pencil-square-o'), edit_admin_broadcast_message_path(message), title: 'Edit', class: 'btn btn-xs'
= link_to icon('times'), admin_broadcast_message_path(message), method: :delete, remote: true, title: 'Remove', class: 'js-remove-tr btn btn-xs btn-danger'
= paginate @broadcast_messages = paginate @broadcast_messages
...@@ -219,7 +219,7 @@ Rails.application.routes.draw do ...@@ -219,7 +219,7 @@ Rails.application.routes.draw do
get :test get :test
end end
resources :broadcast_messages, only: [:index, :create, :destroy] resources :broadcast_messages, only: [:index, :edit, :create, :update, :destroy]
resource :logs, only: [:show] resource :logs, only: [:show]
resource :background_jobs, controller: 'background_jobs', only: [:show] resource :background_jobs, controller: 'background_jobs', only: [:show]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment