Refactoring Admin menu #384

This commit is contained in:
Chrisbr 2014-07-30 12:03:16 +02:00
parent 518e1cc62b
commit d1f5b1e3cc
30 changed files with 865 additions and 190 deletions

View file

@ -0,0 +1,2 @@
class Admin::ConferenceBasicsController < Admin::ConferenceController
end

View file

@ -0,0 +1,2 @@
class Admin::ConferenceContactsController < Admin::ConferenceController
end

View file

@ -72,8 +72,8 @@ class Admin::ConferenceController < ApplicationController
end
def update
@conference = Conference.find_by(short_title: params[:id])
short_title = @conference.short_title
@conference = Conference.find_by(short_title: params[:conference_id])
old_short_title = @conference.short_title
@conference.assign_attributes(params[:conference])
notify_on_conf_dates_updates = (@conference.start_date_changed? || @conference.end_date_changed?)\
&& @conference.email_settings.send_on_updated_conference_dates\
@ -85,13 +85,22 @@ class Admin::ConferenceController < ApplicationController
&& !@conference.email_settings.updated_conference_registration_dates_subject.blank?\
&& @conference.email_settings.updated_conference_registration_dates_template
# Change :return_to if short_title changed
if @conference.short_title_changed?
session[:return_to] =
session[:return_to].gsub! old_short_title, params[:conference][:short_title] unless
session[:return_to].blank?
end
if @conference.update_attributes(params[:conference])
Mailbot.delay.conference_date_update_mail(@conference) if notify_on_conf_dates_updates
Mailbot.delay.conference_registration_date_update_mail(@conference) if notify_on_conf_reg_dates_updates
redirect_to(edit_admin_conference_path(id: @conference.short_title),
redirect_to(session[:return_to],
notice: 'Conference was successfully updated.') && return unless session[:return_to].blank?
redirect_to(admin_conference_path(id: @conference.short_title),
notice: 'Conference was successfully updated.')
else
redirect_to(edit_admin_conference_path(id: short_title),
redirect_to(:back,
alert: 'Updating conference failed. ' \
"#{@conference.errors.full_messages.join('. ')}.")
end
@ -165,8 +174,7 @@ class Admin::ConferenceController < ApplicationController
end
def edit
@conferences = Conference.all
@conference = Conference.find_by(short_title: params[:id])
@conference = Conference.find_by(short_title: params[:conference_id])
respond_to do |format|
format.html
format.json { render json: @conference.to_json }

View file

@ -0,0 +1,63 @@
class Admin::PhotosController < ApplicationController
before_action :set_conference
before_action :set_photo, only: [:edit, :update, :destroy]
# GET /admin/photos
def index
@photos = @conference.photos.all
end
# GET /admin/photos/new
def new
@photo = @conference.photos.build
end
# GET /admin/photos/1/edit
def edit
end
# POST /admin/photos
def create
@photo = @conference.photos.build(photo_params)
if @photo.save
redirect_to admin_conference_photos_path, notice: 'Photo was successfully created.'
else
flash[:alert] = "A error prohibited this Photo from being saved: #{@photo.errors.full_messages.join('. ')}."
render :new
end
end
# PATCH/PUT /admin/photos/1
def update
if @photo.update(photo_params)
redirect_to admin_conference_photos_path, notice: 'Photo was successfully updated.'
else
flash[:alert] = "A error prohibited this Photo from being saved: #{@photo.errors.full_messages.join('. ')}."
render :edit
end
end
# DELETE /admin/photos/1
def destroy
@photo.destroy
redirect_to admin_conference_photos_path, notice: 'Photo was successfully destroyed.'
end
private
# Use callbacks to share common setup or constraints between actions.
def set_conference
@conference = Conference.find_by(short_title: params[:conference_id])
end
# Use callbacks to share common setup or constraints between actions.
def set_photo
@photo = Photo.find_by(id: params[:id])
end
# Only allow a trusted parameter "white list" through.
def photo_params
params[:photo]
end
end