petitions

This commit is contained in:
Nicolas Bally 2013-06-28 20:35:32 +02:00
parent 7befa4610e
commit 1e33360cc6
33 changed files with 547 additions and 15 deletions

View File

@ -1,6 +1,7 @@
/*
*= require_self
*= require shared/formtastic
*/

View File

@ -0,0 +1,64 @@
# -*- encoding : utf-8 -*-
class Admin::PetitionsController < ApplicationController
layout "admin"
before_filter :authenticate_admin!
def index
@petitions = Petition.all
end
def show
@petition = Petition.find(params[:id])
end
def new
@petition = Petition.new
end
def edit
@petition = Petition.find(params[:id])
end
def create
@petition = Petition.new(params[:petition])
if @petition.save
redirect_to admin_petitions_url, notice: 'La pétition a été crée.'
else
render action: "new"
end
end
def update
@petition = Petition.find(params[:id])
if @petition.update_attributes(params[:petition])
redirect_to admin_petitions_url, notice: 'Les infos sur la pétition ont été mise à jour.'
else
render action: "edit"
end
end
def destroy
@petition = Petition.find(params[:id])
@petition.destroy
redirect_to admin_petitions_url
end
end

View File

@ -0,0 +1,50 @@
# -*- encoding : utf-8 -*-
class PetitionsController < ApplicationController
before_filter :authenticate_admin!
def show
@petition = Petition.find_by_slug(params[:id])
@signator = @petition.signators.new(:country => "France")
@title = "Le Pic Vert - "+@petition.name
end
def new
@petition = Petition.new
end
def edit
@petition = Petition.find(params[:id])
end
def create
@signator = PetitionSignator.new(params[:petition_signator])
@petition = @signator.petition
@title = "Le Pic Vert - "+@petition.name
if @signator.save
PetitionMails.confirmation(@signator).deliver
render action: "create"
else
render action: "show"
end
end
def confirm
@signator = PetitionSignator.find_by_token(params[:id])
@petition = @signator.petition
@title = "Le Pic Vert - "+@petition.name
@signator.enabled = true
@signator.save!
end
end

View File

@ -9,8 +9,11 @@ class SurveySetsController < ApplicationController
end
def new
@survey = SurveyType.find_by_slug(params[:slug])
@survey_set = @survey.to_survey_set
@title = "Le Pic Vert - Sondage : "+@survey_set.survey_type.name
end
def edit
@ -18,7 +21,11 @@ class SurveySetsController < ApplicationController
end
def create
@survey_set = SurveySet.new(params[:survey_set])
@title = "Le Pic Vert - Sondage : "+@survey_set.survey_type.name
if @survey_set.save
redirect_to thank_survey_set_path(:slug => @survey_set.survey_type.slug)
else
@ -27,10 +34,13 @@ class SurveySetsController < ApplicationController
end
def show
@survey = SurveyType.find_by_slug(params[:slug])
end
def thank
@survey = SurveyType.find_by_slug(params[:slug])
@title = "Le Pic Vert - Sondage : "+@survey.name
end
end

View File

@ -0,0 +1,19 @@
# -*- encoding : utf-8 -*-
class PetitionMails < ActionMailer::Base
layout 'mail'
default from: "Le Pic Vert <contact@lepicvert.asso.fr>"
def confirmation(signator)
@signator = signator
@email = @signator.email
@title = "Important : pour valider votre signature."
mail(:to => @email, :from => @from, :subject => @title)
end
end

14
app/models/petition.rb Normal file
View File

@ -0,0 +1,14 @@
class Petition < ActiveRecord::Base
attr_accessible :description, :enabled, :name, :slug
has_many :signators, :class_name => "PetitionSignator"
def signators_number
self.signators.count
end
def confirmed_signators_number
self.signators.where(:enabled => true).count
end
end

View File

@ -0,0 +1,19 @@
class PetitionSignator < ActiveRecord::Base
belongs_to :petition
attr_accessor :email_confirmation
attr_accessible :address, :address2, :city, :enabled, :token, :country, :cp, :email, :email_confirmation, :firstname, :name, :petition_id
validates :email, :presence => true, :confirmation => true, :uniqueness => { :scope => :petition_id }
validates :name, :presence => true
validates :firstname, :presence => true
validates :address, :presence => true
validates :cp, :presence => true
validates :city, :presence => true
validates :country, :presence => true
before_create do
self.token = (Digest::MD5.hexdigest "#{SecureRandom.hex(10)}-#{DateTime.now.to_s}")
end
end

View File

@ -0,0 +1,28 @@
=form_for [:admin, @petition] do |f|
=f.submit "sauvegarder", :class => "btn"
%p
Nom :
=f.text_field :name
%p
Permalink :
=f.text_field :slug
%p
=f.text_area :description, :class => "redactor_content", :style => "height:600px;width:100%;max-width:100%"
:javascript
$('.redactor_content').redactor({
fixed: true,
lang: 'fr',
buttons : ['html', '|', 'formatting', '|', 'bold', 'italic', 'deleted','underline','|', 'alignleft', 'aligncenter', 'alignright', 'justify', '|', 'unorderedlist', 'orderedlist', 'outdent', 'indent', '|', 'table', 'link', '|','fontcolor', 'backcolor','|', 'horizontalrule'],
});
=f.submit "sauvegarder", :class => "btn"

View File

@ -0,0 +1,6 @@
%h1 Modifier l'url
= render 'form'
= link_to 'Show', @tiny_url
= link_to 'Back', tiny_urls_path

View File

@ -0,0 +1,25 @@
= link_to i(:plus)+' Ajouter une petition', new_admin_petition_path, :class => "btn"
%h1 Liste des petitions en ligne
%table.stat_table.table.table-striped
%tr
%th Nom
%th Url
%th Nbr sign.
%th
- @petitions.each do |petition|
%tr
%td= petition.name
%td=link_to petition_url(:id => petition.slug),petition_url(:id => petition.slug)
%td
=petition.confirmed_signators_number
="("+(petition.signators_number-petition.confirmed_signators_number).to_s+" en attente)" if petition.signators_number-petition.confirmed_signators_number > 0
%td
= link_to i(:"eye-open"), [:admin, petition]
= link_to i(:pencil), edit_admin_petition_path(petition)
= link_to i(:trash), [:admin, petition], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cette petition ? Les signatures seront également supprimées.' }

View File

@ -0,0 +1,6 @@
%h1 Ajouter une url
= render 'form'
= link_to 'Back', tiny_urls_path

View File

@ -0,0 +1,39 @@
%h1=@petition.name
.alert.alert-info
Adresse publique de la pétition :
=link_to petition_url(:id => @petition.slug),petition_url(:id => @petition.slug)
=raw @petition.description
%hr
%h1
Liste des signataires
%p
%span.badge.badge-success=@petition.confirmed_signators_number
=raw "- "+raw(content_tag("span", (@petition.signators_number-@petition.confirmed_signators_number).to_s, :class => "badge badge-warning"))+" en attente" if @petition.signators_number-@petition.confirmed_signators_number > 0
%table.table.table.table-striped.table-bordered
%tr
%th Nom
%th Prénom
%th Adresse
%th Adresse suite
%th Ville
%th Pays
%th Email
%th
-@petition.signators.each do |signator|
%tr{:class => (signator.enabled ? "success" : "warning")}
%td=signator.name
%td=signator.firstname
%td=signator.address
%td=signator.address2
%td
=signator.cp
=signator.city
%td=signator.country
%td=signator.email
%td

View File

@ -26,7 +26,7 @@
%li.dropdown
%a{:href => "#", :class => "dropdown-toggle", :data => {:toggle => "dropdown"}}
=image_tag (current_admin.file? ? current_admin.file.square.url : ""), :class => "avatar", :style => "height:15px;"
=image_tag (current_admin.file? ? current_admin.file.square.url : ""), :class => "img img-rounded", :style => "height:15px;"
=current_admin.firstname
=current_admin.name
%b.caret
@ -51,6 +51,7 @@
%li=link_to "gestion newsletters", newsletters_path
%li.divider
%li=link_to "Sondages", admin_surveys_path
%li=link_to "Petitions", admin_petitions_path

View File

@ -1,7 +1,7 @@
!!!
%html
%head
%title Le Pic Vert - Votre avis sur les sorties du Pic Vert
%title= @title || "Le Pic Vert."
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags

View File

@ -0,0 +1,28 @@
%p
Bonjour
=@signator.firstname+","
%p
Vous venez de signer "
=@signator.petition.name
='",'
merci pour votre soutient.
%p
Pour que votre signature soit bien prise en compte, merci de cliquer sur ce lien, où de le copier dans la barre d'adresse de votre navigateur :
%p{:style => "text-align:center"}
=link_to confirm_petition_url(:id => @signator.token),confirm_petition_url(:id => @signator.token)
%p
%strong Association Le Pic Vert
%br
24 place de la Mairie
%br
38140 Réaumont
%p
Tel : 04 76 91 34 33
Site internet : www.lepicvert.asso.fr
Mail : contact@lepicvert.asso.fr

View File

@ -0,0 +1,32 @@
.answer_p
=f.check_box :is_checked, :class => "checkboxe_#{answer.survey_item.id}"
-checkboxe_class = "checkboxe_#{answer.survey_item.id}"
=f.label :is_checked, answer.label_text
=f.text_field :content if answer.field_type == 2
-if 1 == 2
%script
= raw '$("input[type=checkbox][class='+checkboxe_class+']").click(function() {'
= raw 'var bol = $("input[type=checkbox][class='+checkboxe_class+']:checked").length >= 1000;'
= raw '$("input[type=checkbox][class='+checkboxe_class+']").not(":checked").attr("disabled",bol);'
});

View File

@ -0,0 +1,21 @@
%h2 Ajouter ma signature.
=semantic_form_for @signator, :url => petitions_path, :method => :post do |f|
=f.hidden_field :petition_id
=f.inputs do
=f.input :name, :label => "Nom :"
=f.input :firstname, :label => "Prénom :"
=f.input :address, :label => "Adresse :"
=f.input :address2, :label => "Adresse (suite) :"
=f.input :cp, :label => "Code postal :"
=f.input :city, :label => "Ville :"
=f.input :country, :label => "Pays :", :as => :string
=f.input :email, :label => "Email :"
=f.input :email_confirmation, :label => "Email (confirmation) :"
%p=f.submit "Envoyer ma signature", :style => "margin-bottom:1em;"
%p
Attention, afin de valider votre signature il faut absolument cliquer sur le lien de validation que vous allez recevoir dans un mail envoyé à l'adresse email que vous avez indiquée.

View File

@ -0,0 +1,31 @@
.question=item.title
-if item.questions_type == 1
.answer_p
=f.radio_button :boolean_content, true
=f.label :boolean_content_true, "oui"
=f.radio_button :boolean_content, false
=f.label :boolean_content_false, "non"
-elsif item.questions_type == 2
.answer_p
-if item.text_presentation == 2
=f.text_area :content, :class => "large"
-else
=f.text_field :content, :class => "large"
-elsif item.questions_type == 3
= f.fields_for(:answer_sets) do |f|
=f.hidden_field :survey_item_answer_id
=render :partial => "survey_sets/answer_set", :locals => {:f => f, :answer => f.object.survey_item_answer}
-elsif item.questions_type == 4
-item.answers.each do |answer|
.answer_p{:style =>( "display:inline;" if item.display_type == 1)}
=f.radio_button :content, answer.label_text
=f.label :content, answer.label_text, :value => answer.label_text

View File

@ -0,0 +1,5 @@
%h1 Votre signature a bien été validée !
%p Merci d'avoir agi pour la protection de la nature.
%p N'hésitez pas à diffuser le lien pour cette action :
%p{:style => "text-align:center;"}=link_to petition_url(@petition.slug), petition_url(@petition.slug)

View File

@ -0,0 +1,7 @@
%p Merci beaucoup pour votre soutien
%h1 ... encore une petite étape pour valider votre signature :
%p Pour valider votre signature, il faut cliquer sur le lien que vous venez de recevoir dans votre boite mail. Sans validation de votre part, votre signature ne sera pas prise en compte.

View File

@ -0,0 +1,6 @@
%h1=@petition.name
=raw @petition.description
%hr
=render :partial => "form"

View File

@ -1,6 +0,0 @@
<h1>Editing tiny_url</h1>
<%= render 'form' %>
<%= link_to 'Show', @tiny_url %> |
<%= link_to 'Back', tiny_urls_path %>

View File

@ -0,0 +1,6 @@
%h1 Modifier l'url
= render 'form'
= link_to 'Show', @tiny_url
= link_to 'Back', tiny_urls_path

View File

@ -1,5 +0,0 @@
<h1>New tiny_url</h1>
<%= render 'form' %>
<%= link_to 'Back', tiny_urls_path %>

View File

@ -0,0 +1,6 @@
%h1 Ajouter une url
= render 'form'
= link_to 'Back', tiny_urls_path

View File

@ -9,6 +9,7 @@ Survey::Application.routes.draw do
root :to => "dashboard#index"
resources :admins
resources :surveys
resources :petitions
end
@ -84,8 +85,15 @@ Survey::Application.routes.draw do
match 'sondages/:slug.:f' => 'survey_sets#new', :as => :new_survey_set, :f => "html"
match 'sondages/:slug/resultats.:f' => 'survey_sets#show', :as => :survey_set, :f => "html"
match 'petitions/:id.:f' => 'petitions#show', :as => :petition, :f => "html"
resources :petitions do
member do
get :confirm
end
end
resources :survey_sets do
collection do
get 'thanks'

View File

@ -0,0 +1,12 @@
class CreatePetitions < ActiveRecord::Migration
def change
create_table :petitions do |t|
t.string :name
t.text :description
t.string :slug
t.boolean :enabled
t.timestamps
end
end
end

View File

@ -0,0 +1,20 @@
class CreatePetitionSignators < ActiveRecord::Migration
def change
create_table :petition_signators do |t|
t.references :petition
t.string :firstname
t.string :name
t.string :address
t.string :address2
t.string :cp
t.string :city
t.string :country
t.string :email
t.boolean :enabled
t.string :token
t.timestamps
end
add_index :petition_signators, :petition_id
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130319095715) do
ActiveRecord::Schema.define(:version => 20130628154116) do
create_table "admins", :force => true do |t|
t.string "email", :default => "", :null => false
@ -191,6 +191,33 @@ ActiveRecord::Schema.define(:version => 20130319095715) do
t.datetime "updated_at"
end
create_table "petition_signators", :force => true do |t|
t.integer "petition_id"
t.string "firstname"
t.string "name"
t.string "address"
t.string "address2"
t.string "cp"
t.string "city"
t.string "country"
t.string "email"
t.boolean "enabled"
t.string "token"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "petition_signators", ["petition_id"], :name => "index_petition_signators_on_petition_id"
create_table "petitions", :force => true do |t|
t.string "name"
t.text "description"
t.string "slug"
t.boolean "enabled"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "question_sets", :force => true do |t|
t.integer "survey_item_id"
t.integer "survey_set_id"

25
test/fixtures/petition_signators.yml vendored Normal file
View File

@ -0,0 +1,25 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
petition:
firstname: MyString
name: MyString
address: MyString
address2: MyString
cp: MyString
city: MyString
country: MyString
email: MyString
confirmed: false
two:
petition:
firstname: MyString
name: MyString
address: MyString
address2: MyString
cp: MyString
city: MyString
country: MyString
email: MyString
confirmed: false

13
test/fixtures/petitions.yml vendored Normal file
View File

@ -0,0 +1,13 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
name: MyString
description: MyText
slug: MyString
enabled: false
two:
name: MyString
description: MyText
slug: MyString
enabled: false

View File

@ -0,0 +1,7 @@
require 'test_helper'
class PetitionSignatorTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class PetitionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end