Initial events CRUD

This commit is contained in:
Andrew Radev 2015-07-14 21:00:02 +03:00
parent f173f42834
commit 4963c74925
7 changed files with 159 additions and 2 deletions

View File

@ -1,4 +1,10 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
def require_current_conference
if not current_conference?
redirect_to '/', alert: 'No conference selected'
end
end
# Prevent CSRF attacks by raising an exception. # Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead. # For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception protect_from_forgery with: :exception

View File

@ -1,9 +1,50 @@
module Management module Management
class EventsController < ManagementController class EventsController < ManagementController
before_action :require_current_conference
def index def index
# TODO (2015-07-14) Scoped by conference? Why no conference_id
@events = Event.all
end end
def show def show
@event = Event.find(params[:id])
end
def edit
@event = Event.find(params[:id])
end
def update
@event = Event.find(params[:id])
if @event.update_attributes(event_params)
flash[:notice] = 'Event was successfully updated.'
redirect_to [:management, @event]
else
render action: 'edit'
end
end
def destroy
@event = Event.find(params[:id])
@event.destroy
redirect_to action: :index
end
private
def event_params
params.require(:event).permit(
:title,
:subtitle,
:length,
:language,
:abstract,
:description,
:notes
)
end end
end end
end end

View File

@ -1,2 +1,38 @@
module ApplicationHelper module ApplicationHelper
def action_buttons(record, actions = [:index, :show, :edit, :destroy])
klass = record.class
output = ''
if actions.include? :index
output += link_to(icon(:list), [:management, klass], {
title: t('actions.index.button', models: klass.model_name.human(count: 2)),
class: 'btn btn-info'
})
end
if actions.include? :show
output += link_to(icon(:eye), [:management, record], {
title: t('actions.view.button', model: klass.model_name.human),
class: 'btn btn-info'
})
end
if actions.include? :edit
output += link_to(icon(:edit), [:edit, :management, record], {
title: t('actions.edit.button', model: klass.model_name.human),
class: 'btn btn-primary'
})
end
if actions.include? :destroy
output += link_to(icon(:trash), [:management, record], {
method: :delete,
data: {confirm: t('actions.are_you_sure')},
title: t('actions.edit.button', model: klass.model_name.human),
class: 'btn btn-danger'
})
end
output.html_safe
end
end end

View File

@ -0,0 +1,22 @@
.row
.col-lg-12
= simple_nested_form_for [:management, @event], wrapper: :horizontal_form, html: { class: 'form-horizontal' } do |f|
.panel.panel-primary
.panel-heading
h1.panel-title
= t 'views.user.info'
= link_to icon(:eye), [:management, @event], class: 'btn btn-xs btn-info pull-right'
.panel-body
.row
.col-lg-12
= f.input :title
= f.input :subtitle
= f.input :length
= f.input :language, collection: %w(en bg)
= f.input :abstract
= f.input :description
= f.input :notes
.panel-footer.text-right
= f.submit class: 'btn btn-primary'

View File

@ -1 +1,26 @@
p Hello .row
.col-lg-12
.panel.panel-default
.panel-heading
h2.panel-title= Event.model_name.human(count: 2).mb_chars.capitalize
.panel-body
table.table.table-striped.table-hover.record-table
thead
tr
th = Event.human_attribute_name :title
th = Event.human_attribute_name :subtitle
th = Event.human_attribute_name :length
th = Event.human_attribute_name :language
th.actions
tbody
- @events.each do |event|
tr
td= event.title
td= event.subtitle
td #{event.length} minutes
td= event.language
td.actions
div.btn-group.btn-group-sm
= action_buttons(event, [:show, :edit, :destroy])

View File

@ -1 +1,25 @@
p Hello .row
.col-lg-12
.panel.panel-default
.panel-heading
h2= @event.title
br
h3= @event.subtitle
h4 #{Event.human_attribute_name :length}: #{@event.length}m, #{Event.human_attribute_name :language}: #{@event.language}
.panel-body
h3= Event.human_attribute_name :abstract
p= simple_format @event.abstract
h3= Event.human_attribute_name :description
p= simple_format @event.description
h3= Event.human_attribute_name :notes
p= simple_format @event.notes
h3 TODO Author?
.panel-footer
div.btn-group.btn-group-sm
= action_buttons(@event, [:index, :edit, :destroy])

View File

@ -24,6 +24,9 @@ bg:
bg: БГ bg: БГ
en: EN en: EN
actions: actions:
index:
button: Виж всички %{models}
title: Всички %{models}
create: create:
button: Създай %{model} button: Създай %{model}
title: Създаване на %{model} title: Създаване на %{model}