Gros nettoyage des formulaires, en utilisant des fieldset pour regrouper les éléments

This commit is contained in:
echarp 2014-08-09 18:59:11 +02:00
parent 514115b000
commit d085e37c8a
23 changed files with 218 additions and 184 deletions

View File

@ -122,7 +122,7 @@ GEM
lumberjack (~> 1.0)
pry (>= 0.9.12)
thor (>= 0.18.1)
guard-brakeman (0.8.1)
guard-brakeman (0.8.2)
brakeman (>= 2.1.1)
guard (>= 1.1.0)
guard-bundler (2.0.0)
@ -189,7 +189,7 @@ GEM
multi_json (1.10.1)
mysql2 (0.3.16)
orm_adapter (0.5.0)
parser (2.2.0.pre.3)
parser (2.2.0.pre.4)
ast (>= 1.1, < 3.0)
slop (~> 3.4, >= 3.4.5)
polyamorous (1.0.0)
@ -297,7 +297,7 @@ GEM
polyglot (>= 0.3.1)
turbolinks (2.2.2)
coffee-rails
tzinfo (1.2.1)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (2.5.3)
execjs (>= 0.3.0)

View File

@ -25,7 +25,7 @@ ActiveAdmin.register_page 'Dashboard' do
end
end
panel 'ActiveAdmin' do
para %(Currently deployed: #{`git describe --tags --abbrev=0`},
para %(Actuellement déployé:
#{link_to(`git rev-parse --short HEAD`,
"https://gitorious.org/agenda-du-libre-rails/agenda-du-libre-rails/commit/
#{`git rev-parse HEAD`}")})

View File

@ -34,29 +34,34 @@ a:link, a:visited
a:hover, a:active, a:focus
color: #2E97FF
#flash_messages
left: 0
width: 100%
z-index: 1000
position: absolute
margin-top: -2.5em
.flash
color: white
border: solid 1px #007ba0
margin: 1em auto
padding: 0.5em 1.1em
max-width: 40em
font-size: x-large
text-align: justify
background-color: #008cba
@include box-shadow(0 0 0.3em gray)
@include border-radius(3px)
&.notice
border-color: #3a945b
background-color: #43ac6a
&.alert
border-color: #de2b0f
background-color: #f04124
#flash_messages .flash
color: white
border: solid 1px #007ba0
margin: 1em auto
padding: 0.5em 1.1em
max-width: 50em
font-size: x-large
text-align: justify
background-color: #008cba
@include box-shadow(0 0 0.3em gray)
@include border-radius(3px)
&.notice
border-color: #3a945b
background-color: #43ac6a
&.alert
border-color: #de2b0f
background-color: #f04124
h3.warning
color: white
margin: 0
padding: 1em
display: inline-block
text-align: center
border-color: #de2b0f
background-color: #f04124
@include box-shadow(0 0 0.3em gray)
@include border-radius(1em)
.fa:before
font-style: normal
@ -94,7 +99,7 @@ header.top
padding-top: 10px
letter-spacing: 2px
h2
font-size: 0.8em
font-size: 1.2em
font-style: italic
font-weight: normal
margin-bottom: 22px
@ -128,6 +133,21 @@ main
hr
margin: 10px 20px
fieldset
border: none
margin: 1em auto
padding: 1em
@include box-shadow(1px 1px 5px gray)
@include border-radius(0.4em)
legend
float: left
color: gray
padding: 0 1em
margin-top: -1.6em
background-color: white
h2
margin-top: 0
label
text-align: right
padding-right: 0.4em
@ -149,6 +169,10 @@ input, textarea, select, a.button
&:focus
background-color: #F0F8FF
@include box-shadow(1px 1px 4px gray)
&[type=radio]
@include box-shadow(none)
&[type=radio] + label
text-align: left
&[type=submit], &.button
color: black
border: none

View File

@ -20,14 +20,13 @@ header.calendar-header
a
margin: 0
a
margin: 0 0.3em
font-weight: normal
&.month_selector
display: block
font-weight: bolder
margin-bottom: -2.1em
&.year_selector
margin: 0
&:first-child, &:last-child
margin: 0 0.3em
.events, .event
.city:after
@ -120,6 +119,14 @@ a#banner
margin-left: 5%
padding-left: 2px
body.events.show main
padding: 1em
max-width: 60em
@include box-shadow(1px 1px 5px gray)
@include border-radius(0.4em)
h2
margin-top: 1em
sidebar#lug-list
float: right
width: 16em
@ -127,6 +134,7 @@ sidebar#lug-list
margin: 0 1.2em
padding: 5px
font-size: 0.7em
margin-right: -4em
background-color: #D6ECFF
@include box-shadow(4px 4px 1em gray)
@include border-radius(10px)

View File

@ -1,7 +1,7 @@
h2.warning
color: red
.events.edit, .events.update, .events.cancel, .moderations, .notes
.moderations, .notes
table.list
min-width: 90%
margin-top: 15px
@ -31,18 +31,3 @@ h2.warning
padding: 0.2em
display: inline-block
font-weight: normal
main > h3
font-size: inherit
line-height: 1.3em
font-weight: normal
margin-left: 5em
margin-right: 5em
background-color: #CCC
.box
width: 70%
margin: auto
padding: 1em
margin-bottom: 10px
background-color: #CCC

View File

@ -2,26 +2,21 @@
# This is a central part to this project
class EventsController < ApplicationController
before_action :set_events, only: [:index]
before_action :set_event, only: [:show, :edit, :update, :cancel, :destroy]
before_action :check_secret, only: [:edit, :update, :cancel, :destroy]
before_action :set_event, only:
[:show, :edit, :preview, :update, :cancel, :destroy]
before_action :check_secret, only:
[:edit, :preview, :update, :cancel, :destroy]
before_action :set_mailer_host
def index
respond_to do |format|
format.html do
if params[:year]
# Whole year calendar
@events = @events.year params[:year].to_i
else
@events = @events.month params[:start_date].try(:to_date) || Date.today
end
end
format.html
format.rss do
@events = @events.future.includes :related_city
@events = @events.future_30.includes :related_city
@events = @events.limit params[:daylimit] if params[:daylimit]
end
format.ics { @events = @events.last_year.order :id }
format.xml { @events = @events.order :id }
format.xml { @events = @events.includes(:related_region).order :id }
end
end
@ -32,11 +27,17 @@ class EventsController < ApplicationController
@event.end_time ||= Time.now.change(min: 0) + 1.day + 2.hour
end
# POST /events/preview
def preview_create
@event = Event.new event_params
@event.valid?
render action: :new
end
# POST /events
# POST /events.json
def create
@event = Event.new event_params
preview && return if params[:visu]
respond_to do |format|
if @event.save && send_creation_mails
@ -49,11 +50,16 @@ class EventsController < ApplicationController
end
end
# PATCH/PUT /events/1/preview
def preview
@event.attributes = event_params
@event.valid?
render action: :edit
end
# PATCH/PUT /events/1
# PATCH/PUT /events/1.json
def update
preview_update && return if params[:visu]
@older_event = Event.new @event.attributes
respond_to do |format|
if @event.update(event_params) && send_update_mails
@ -83,13 +89,6 @@ class EventsController < ApplicationController
@events = @events.region params[:region] \
if params[:region].present? && params[:region] != 'all'
@events = @events.tag(params[:tag]) if params[:tag]
if params[:year]
# Whole year calendar
@events = @events.year params[:year].to_i
else
@events = @events.month params[:start_date].try(:to_date) || Date.today
end
end
# Use callbacks to share common setup or constraints between actions.
@ -110,8 +109,9 @@ class EventsController < ApplicationController
:locality, :url, :contact, :submitter, :tags
end
# Check that you can only edit an existing event if you know its secret
def check_secret
redirect_to :root, notice: t(:forbidden, scope: [:events, :edit]) \
redirect_to :root, alert: t(:forbidden, scope: [:events, :edit]) \
unless params[:secret] == @event.secret
end
@ -131,15 +131,4 @@ class EventsController < ApplicationController
# Send an update mail to moderators
ModerationMailer.update(@older_event, @event, nil).deliver
end
def preview
@event.valid?
render action: :new
end
def preview_update
@event.attributes = event_params
@event.valid?
render action: :edit
end
end

View File

@ -4,21 +4,21 @@ require 'differ'
class ModerationsController < ApplicationController
before_action :authenticate_user!
before_action :set_moderation, :set_mailer_host, only:
[:show, :edit, :update, :validate, :accept, :refuse, :destroy]
[:show, :edit, :preview, :update, :validate, :accept, :refuse, :destroy]
def index
@events = Event.unmoderated
end
def preview
@moderation.attributes = moderation_params
@moderation.valid?
render action: :edit
end
# PATCH/PUT /moderations/1
# PATCH/PUT /moderations/1.json
def update
if params[:visu]
@moderation.attributes = moderation_params
render action: 'edit'
return
end
@older_mod = Event.new @event.attributes
respond_to do |format|
if @moderation.update(moderation_params) && send_moderation_mails

View File

@ -2,10 +2,8 @@
module EventsHelper
def set_events_meta
set_meta_tags \
description: "#{t 'layouts.application.subtitle'} \
- #{t '.nb_events', count: @events.size}",
keywords: @events.pluck(:tags)
.join(' ').split.group_by { |i| i }
description: t('layouts.application.subtitle'),
keywords: @events.pluck(:tags).join(' ').split.group_by { |i| i }
.reject { |_k, v| v.size < 2 }.map { |k, _v| k },
DC: {
title: t('layouts.application.title'),

View File

@ -31,13 +31,14 @@ class Event < ActiveRecord::Base
end)
scope :year, (lambda do |year|
where '? <= end_time and start_time <= ?',
Date.new(year, 1, 1).beginning_of_week, Date.new(year, 12, 31)
.end_of_week
Date.new(year, 1, 1).beginning_of_week,
Date.new(year, 12, 31).end_of_week
end)
scope :month, (lambda do |start_date|
start_date ||= Date.today.beginning_of_month
where '? <= end_time and start_time <= ?',
start_date.beginning_of_month.beginning_of_week,
start_date.beginning_of_month.next_month.end_of_week
start_date.beginning_of_week,
start_date.end_of_month.end_of_week
end)
scope :region, -> region { where 'region = ? or locality', region }
scope :tag, -> tag { where 'tags like ?', "%#{tag}%" }

View File

@ -5,16 +5,9 @@
- @event.errors.full_messages.each do |msg|
%p= msg
- unless @event.id
:markdown
#{t '.subtitle'}
#advises
:markdown
#{t '.advises'}
- else
= hidden_field_tag :secret, params[:secret]
- if @event.persisted?
- unless @moderation
= hidden_field_tag :secret, params[:secret]
.field.title
.helper
@ -75,5 +68,5 @@
= f.text_field :tags, size: 70
.actions
= f.submit t('.visualise'), name: :visu
= f.submit t('.visualise'), formaction: :preview
= f.submit t('.save')

View File

@ -1,21 +1,18 @@
%h3
>>>
%h2
%em.fa.fa-trash-o
=t '.title'
.box
- if @event.moderated?
%h3=t '.already_moderated'
- if @event.moderated?
%h3.warning=t '.already_moderated'
%fieldset
= form_for @event, method: :delete do |f|
= hidden_field_tag :secret, params[:secret]
.confirm=t '.confirm'
%br/
%h2=t '.confirm'
= f.submit t('.ok'), name: :yes
= link_to t('.ko'), @event, class: :button
%h3
>>>
=t '.preview'
.box= render file: '/events/show'
%fieldset
%legend=Event.model_name.human
= render file: '/events/show'

View File

@ -1,16 +1,16 @@
%h3
>>>
=t '.preview'
%h2
%em.fa.fa-pencil
=t '.title'
- if @event.moderated?
.box
%h3=t '.warning'
%h3.warning
%em.fa.fa-warning
=t '.warning'
.box= render file: '/events/show'
%fieldset
%legend=t '.preview'
= render file: '/events/show'
%h3
= link_to t('.moderation'), moderations_path
>>>
=t '.edit'
.box= render '/events/form'
%fieldset
%legend=t '.edit'
= render '/events/form'

View File

@ -1,5 +1,3 @@
- set_events_meta
= render '/lugs/search' unless controller.controller_name == 'lugs'
-# Seems necessary, for the time being, to ensure calendar is changing days correctly
@ -17,6 +15,7 @@
- if params[:year]
-# Whole year calendar
- @events = @events.year params[:year].to_i
%header.calendar-header.year
= link_to '<<', year: params[:year].to_i-1, tag: params[:tag], region: params[:region]
= params[:year]
@ -26,9 +25,9 @@
- params[:start_date] = "#{params[:year]}-#{i}-01"
= month_calendar events: @events,
title: ->(start_date) { raw link_to I18n.t('date.month_names')[start_date.month]+' '+params[:year], root_url( start_date: start_date), class: 'month_selector' },
previous_link: ->(param, date_range) { },
next_link: ->(param, date_range) { } do |date, events|
previous_link: nil, next_link: nil,
title: ->(start_date) { raw link_to l(start_date, format: :month),
root_url(start_date: start_date), class: 'month_selector' } do |date, events|
.day_number= date.day
%ul.events
- events.select { |e| e.start_time.to_date <= date and date <= e.end_time.to_date }.sort_by { |e| e.city }.each do |event|
@ -38,10 +37,15 @@
= event.title
- else
-# One month calendar
- @events = @events.month params[:start_date].try :to_date
= month_calendar events: @events,
title: ->(start_date) { raw "#{I18n.t('date.month_names')[start_date.month]} #{link_to start_date.year, root_url(year: start_date.year), class: 'year_selector'}" },
previous_link: ->(param, date_range) { link_to '<<', { param => date_range.first - 1.day, tag: params[:tag], region: params[:region] } },
next_link: ->(param, date_range) { link_to '>>', { param => date_range.last + 1.day, tag: params[:tag], region: params[:region] } } do |date, events|
title: ->(start_date) { raw "#{I18n.t('date.month_names')[start_date.month]} #{link_to start_date.year,
root_url(year: start_date.year)}" },
previous_link: ->(param, date_range) { link_to '<<',
{ param => (date_range.first - 1.day).beginning_of_month, tag: params[:tag], region: params[:region] } },
next_link: ->(param, date_range) { link_to '>>',
{ param => (date_range.last + 1.day).beginning_of_month, tag: params[:tag], region: params[:region] } } do |date, events|
.day_number= date.day
%ul.events
- events.select { |e| e.start_time.to_date <= date and date <= e.end_time.to_date }.sort_by { |e| e.city }.each do |event|
@ -66,3 +70,5 @@
= image_tag 'priorite-logiciel-libre-je-soutiens-april_2_m.png',
width: '374', height: '48',
alt: 'Priorité au Logiciel Libre! Je soutiens l\'April.'
- set_events_meta

View File

@ -2,9 +2,19 @@
%em.fa.fa-pencil
=title t '.title'
- if @event && params[:visu]
%hr/
= render file: '/events/show'
%hr/
- if @event.description
%fieldset
%legend=t '.preview'
= render file: '/events/show'
= render 'form'
- else
:markdown
#{t '.subtitle'}
#advises
:markdown
#{t '.advises'}
%fieldset
%legend=t '.edit'
= render 'form'

View File

@ -1,17 +1,14 @@
%h3
= link_to t('.moderation'), moderations_path
>>>
=t '.preview'
%h2
%em.fa.fa-pencil
=t '.title'
- if @moderation.moderated?
.box
%h3=t '.warning'
%h3.warning=t '.warning'
.box= render file: '/events/show'
%fieldset
%legend=t '.preview'
= render file: '/events/show'
%h3
= link_to t('.moderation'), moderations_path
>>>
=t '.edit'
.box= render '/events/form'
%fieldset
%legend=t '.edit'
= render '/events/form'

View File

@ -1,12 +1,11 @@
%h3
= link_to t('.moderation'), moderations_path
>>>
%h2
%em.fa.fa-thumbs-down
=t '.title'
.box
%h2=t '.question'
%fieldset
= form_tag moderation_path(@moderation), method: :delete do |f|
%h3=t '.question'
.field.closer(title="#{t '.reason_r_1_long'}")
= radio_button_tag :reason, :r_1, params[:event] == 'reason_r_1'
= label_tag :reason_r_1, t('.reason_r_1')
@ -24,10 +23,12 @@
= label_tag :reason_r_4, t('.reason_r_4')
.field
= label_tag :reason_text, t('.reason_text')
= label_tag :reason_text, t('.reason')
= text_area_tag :reason_text, nil, cols: 40, rows: 5
= submit_tag t '.ok'
= link_to t('.ko'), moderations_url, class: :button
.box= render file: '/events/show'
%fieldset
%legend=Event.model_name.human
= render file: '/events/show'

View File

@ -1,9 +1,8 @@
%h3
= link_to t('.moderation'), moderations_path
>>>
%h2
%em.fa.fa-thumbs-up
=t '.title'
.box
%fieldset
- if @event.locality?
%h2.warning=t '.warning'
%h2=t '.question'
@ -12,4 +11,6 @@
= f.submit t('.ok'), name: :yes
= link_to t('.ko'), moderations_url, class: :button
.box= render file: '/events/show'
%fieldset
%legend=Event.model_name.human
= render file: '/events/show'

View File

@ -9,7 +9,6 @@
- if params[:envoiParMail]
= hidden_field_tag :envoiParMail, params[:envoiParMail]
%h2=t '.title'
%p=t 'title', scope: [:note_mailer, :create]
%p=t 'body', scope: [:note_mailer, :create], subject: @note.event.title, contents: @note.contents
@ -19,11 +18,11 @@
- if params[:envoiParMail]
:markdown
#{t 'edit_link', scope: [:note_mailer, :create]}
#{t 'edit_link', scope: [:note_mailer, :notify]}
#{ edit_moderation_url @note.event}
#{edit_moderation_url @note.event}
#{t 'signature', scope: [:note_mailer, :create]}
#{t 'signature', scope: [:note_mailer, :notify]}
.actions
= f.submit t('.save')

View File

@ -1,7 +1,14 @@
%h3
= link_to t('.back'), moderations_path
%h2
- if params[:envoiParMail]
%em.fa.fa-bullhorn
- else
%em.fa.fa-paperclip
=t '.title'
.box= render 'form'
%fieldset
%legend=t '.title'
= render 'form'
.box= render file: '/events/show'
%fieldset
%legend=t '.event'
= render file: '/events/show'

View File

@ -133,17 +133,22 @@ fr:
infos: Informations
new:
title: Soumettre un événement
preview: Prévisualisation
edit: Édition
create:
ok: Votre événement a bien été ajouté à la liste des événements en
attente de modération. Il apparaîtra en ligne dès qu'un modérateur
l'aura validé.
edit:
title: Éditer un événement
preview: Prévisualisation de l'événement
warning: Attention, cet événement est déjà modéré. Toute modification
sera immédiatement visible sur le site.
forbidden: Vous n'êtes pas authorisé à modifier cet événement
edit: Édition de l'événement
preview: Prévisualisation
edit: Édition
preview:
warning: Attention, cet événement est déjà modéré. Toute modification
sera immédiatement visible sur le site.
update:
ok: Votre événement a été mis à jour
form:
@ -211,11 +216,12 @@ Exemple: `%{daylimit}`"
askInfos: Demander des infos
createNote: Ajouter une note
edit:
title: Éditer un événement
moderation: Modération
preview: Prévisualisation de l'événement
warning: Attention, cet événement est déjà modéré. Toute modification
sera immédiatement visible sur le site.
edit: Édition de l'événement
preview: Prévisualisation
edit: Édition
update:
ok: Événement mis à jour
validate:
@ -228,6 +234,7 @@ Exemple: `%{daylimit}`"
ok: Événement accepté
refuse:
title: Rejet de l'événement
motif: Motif
question: Quel motif souhaitez-vous associer au rejet de cet événement?
ok: Rejeter
ko: Annuler
@ -262,12 +269,13 @@ Exemple: `%{daylimit}`"
new:
back: Modération
title: Ajout d'une note de modération
event: Événements à modérer
create:
sendByMailWrap: "<p>Demande d'informations complémentaires:</p>
<pre>%{contents}</pre>"
ok: La note a bien été ajoutée, merci!
form:
title: Rédaction du message
save: Envoyer
ok: Enregistrer
ko: Annuler

View File

@ -6,9 +6,12 @@ Rails.application.routes.draw do
resources :users
resources :events do
get :cancel, on: :member
post :preview, on: :collection, to: 'events#preview_create'
patch :preview, on: :member
end
resources :moderations do
resources :notes, only: [:new, :create]
patch :preview, on: :member
get :validate, :refuse, on: :member
put :accept, on: :member
end

View File

@ -21,7 +21,7 @@ class EventsControllerTest < ActionController::TestCase
test 'should preview event' do
assert_no_difference 'Event.count' do
post :create, visu: 'visualise', event: {
patch :preview_create, event: {
title: @event.title,
start_time: @event.start_time,
end_time: @event.end_time,

View File

@ -11,6 +11,13 @@ class ModerationsControllerTest < ActionController::TestCase
sign_in users(:one)
end
test 'should preview event' do
patch :preview, id: @moderation, event: {
title: 'hello world',
related_region: regions(:region_one)
}
end
test 'should edit event' do
put :update, id: @moderation, event: {
title: 'hello world',