To be continued : Add position form (autocomplete)
This commit is contained in:
parent
559135472e
commit
f16db07eb6
5 changed files with 30 additions and 13 deletions
|
|
@ -2,6 +2,8 @@ class AutocompleteController < ApplicationController
|
|||
|
||||
autocomplete :subject, :title, full: true, extra_data: [:presentation]
|
||||
|
||||
autocomplete :public_figure, :name, full: true
|
||||
|
||||
def autocomplete_position_title
|
||||
term = params[:term]
|
||||
subject_id = params[:subject_id]
|
||||
|
|
|
|||
|
|
@ -4,4 +4,14 @@ class Position < ActiveRecord::Base
|
|||
validates :subject_id, presence: true
|
||||
validates :title, presence: true
|
||||
validates :description, presence: true
|
||||
validate :at_least_one_statement
|
||||
|
||||
private
|
||||
|
||||
def at_least_one_statement
|
||||
if statements.size < 1
|
||||
errors.add("Il faut au moins une prise de position pour cette position")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -49,17 +49,17 @@
|
|||
|
||||
<%= f.fields_for @new_statement.evidences.build do |e| %>
|
||||
|
||||
<%= e.label :url, "Lien internet ..." %>
|
||||
<%= e.text_field :url, placeholder: "http://" %>
|
||||
<%= e.label :file, "... ou pièce jointe" %>
|
||||
<%= e.file_field :file, accept: 'image/jpeg,image/gif,image/png,application/pdf,audio/mpeg3,audio/x-mpeg3,video/avi,video/quicktime,audio/wav' %>
|
||||
<%= e.label :title, "Intitulé de la preuve" %>
|
||||
<%= e.text_field :title, placeholder: "Explicitez la référence" %>
|
||||
<%= e.label :fact_date, "Date des faits" %>
|
||||
<%= e.text_field :fact_date, placeholder: "jj/mm/yyyy", class: "Datepicker" %>
|
||||
<%= e.label :url, "Lien internet ..." %>
|
||||
<%= e.text_field :url, placeholder: "http://" %>
|
||||
<%= e.label :file, "... ou pièce jointe" %>
|
||||
<%= e.file_field :file, accept: 'image/jpeg,image/gif,image/png,application/pdf,audio/mpeg3,audio/x-mpeg3,video/avi,video/quicktime,audio/wav' %>
|
||||
<%= e.label :title, "Intitulé de la preuve" %>
|
||||
<%= e.text_field :title, placeholder: "Explicitez la référence" %>
|
||||
<%= e.label :fact_date, "Date des faits" %>
|
||||
<%= e.text_field :fact_date, placeholder: "jj/mm/yyyy", class: "Datepicker" %>
|
||||
|
||||
<% end %>
|
||||
<%= label_tag "Sujet" %>
|
||||
<%= label_tag "Sujet" %>
|
||||
<%= autocomplete_field_tag 'Subject', '',
|
||||
autocomplete_autocomplete_subject_title_path,
|
||||
id_element: '#statement_subject_id',
|
||||
|
|
@ -72,7 +72,6 @@
|
|||
}
|
||||
%>
|
||||
|
||||
<%= label_tag t "Position" %>
|
||||
<%= f.label :position_id, "Position prise" %>
|
||||
<%= f.select :position_id, {} %>
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
<%= render partial: "position", collection:@subject.positions, as: :position %>
|
||||
|
||||
|
||||
<% if false && logged_in? && allowed_to?(:add_position) && allowed_to?(:add_statement) %>
|
||||
<% if logged_in? && allowed_to?(:add_position) && allowed_to?(:add_statement) %>
|
||||
<li id="new-position">
|
||||
<%= form_for(@new_position) do |f| %>
|
||||
<%= render 'shared/error_messages', object: f.object %>
|
||||
|
|
@ -32,7 +32,12 @@
|
|||
|
||||
<!-- Il est obligatoire d'ajouter une première prise de position pour valider une nouvelle position, donc on la met tout de suite dans le même formulaire -->
|
||||
<p>Qui a pris cette position ?</p>
|
||||
|
||||
<%= autocomplete_field_tag 'PublicFigure', '',
|
||||
autocomplete_autocomplete_public_figure_name_path,
|
||||
id_element: '#position_public_figure_id',
|
||||
class: "Autocomplete"
|
||||
%>
|
||||
<%= f.hidden_field :public_figure_id, value: ""%>
|
||||
|
||||
<%= f.submit "Ajouter", class: "btn btn-primary" %>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ Rails.application.routes.draw do
|
|||
# AUTOCOMPLETE
|
||||
get 'autocomplete/autocomplete_subject_title'
|
||||
get 'autocomplete/autocomplete_position_title'
|
||||
get 'autocomplete/autocomplete_public_figure_name'
|
||||
|
||||
get 'a-propos', to: 'static_pages#a_propos', as: 'a_propos'
|
||||
get 'contact', to: 'static_pages#contact', as: 'contact'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue