Skip to content

Commit

Permalink
Added validations via Rails.
Browse files Browse the repository at this point in the history
  • Loading branch information
agileontheweb authored and taitus committed Nov 24, 2017
1 parent 82a2e09 commit 00e50d9
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 61 deletions.
56 changes: 0 additions & 56 deletions app/assets/javascripts/admin/organizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,4 @@ $(function(){
$("#legal_representant_link").show();
});

$(".organization-form").validate({
ignore: [],
errorElement: "small",
rules : {
"organization[name]" : {
required : true
},
"organization[user_attributes][first_name]" : {
required : true
},
"organization[user_attributes][last_name]" : {
required : true
},
"organization[user_attributes][email]" : {
required : true
},
"organization[user_attributes][password]" : {
required : true
},
"organization[user_attributes][password_confirmation]" : {
required : true
}
},

messages : {
"organization[name]" : {
required : "Añade el nombre"
},
"organization[user_attributes][first_name]" : {
required : "Añade el nombre"
},
"organization[user_attributes][last_name]" : {
required : "Añade Apellido"
},
"organization[user_attributes][password]" : {
required : "Añade contraseña"
},
"organization[user_attributes][phones]" : {
required : "Añade telefóno"
},
"organization[user_attributes][email]" : {
required : "Añade Email"
},
"organization[user_attributes][password]" : {
required : "Añade Contraseña"
},
"organization[user_attributes][password_confirmation]" : {
required : "Confirmar Contraseña"
}
},

errorPlacement : function(error, element) {
error.insertAfter(element);
}
});

});
5 changes: 5 additions & 0 deletions app/assets/stylesheets/all.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3232,6 +3232,11 @@ input.error, textarea.error, select.error {
label.error {
color: #f04124; }

span.error_field_rails,
small.error_field_rails {
margin-top: -1rem;
}

.icon-bar {
display: inline-block;
font-size: 0;
Expand Down
9 changes: 9 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ def show_agenda_link(holder)
link_to(holder.full_name, agenda_path(holder.id,holder.full_name.parameterize)).html_safe
end

def form_field_errors(form, field)
if form.object.errors[field].any?
content_tag :span, class: "error error_field_rails" do
field_errors = form.object.errors[field]
field_errors.join(", ")
end
end
end

end
7 changes: 7 additions & 0 deletions app/views/admin/organizations/_agents_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,43 @@
<div class="small-6 columns">
<%= f.label :identifier, t('backend.agents.identifier') %>
<%= f.text_field :identifier %>
<%= form_field_errors(f, :identifier) %>
</div>

<div class="small-6 columns">
<%= f.label :name, t('backend.agents.name') %>
<%= f.text_field :name %>
<%= form_field_errors(f, :name) %>
</div>

<div class="small-6 columns">
<%= f.label :first_surname, t('backend.agents.first_surname') %>
<%= f.text_field :first_surname %>
<%= form_field_errors(f, :first_surname) %>
</div>

<div class="small-6 columns">
<%= f.label :second_surname, t('backend.agents.second_surname') %>
<%= f.text_field :second_surname %>
<%= form_field_errors(f, :second_surname) %>
</div>

<div class="small-6 columns">
<%= f.label :from, t('backend.agents.from') %>
<%= f.date_field :from %>
<%= form_field_errors(f, :from) %>
</div>

<div class="small-6 columns">
<%= f.label :to, t('backend.agents.to') %>
<%= f.date_field :to %>
<%= form_field_errors(f, :to) %>
</div>

<div class="small-12 columns">
<%= f.label :public_assignments, t('backend.agents.public_assignments') %>
<%= f.text_area :public_assignments %>
<%= form_field_errors(f, :public_assignments) %>
</div>

<div class="small-12 columns">
Expand Down
20 changes: 20 additions & 0 deletions app/views/admin/organizations/_data.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,82 +4,102 @@
<div class="small-6 columns">
<%= f.label :identifier, t('backend.identifying_data.identifier') %>
<%= f.text_field :identifier %>
<%= form_field_errors(f, :identifier) %>
</div>
<div class="small-6 columns">
<%= f.label :name, t('backend.identifying_data.name') %>
<%= f.text_field :name %>
<%= form_field_errors(f, :name) %>
</div>
<div class="small-6 columns">
<%= f.label :first_surname, t('backend.identifying_data.first_surname') %>
<%= f.text_field :first_surname %>
<%= form_field_errors(f, :first_surname) %>
</div>
<div class="small-6 columns">
<%= f.label :second_surname, t('backend.identifying_data.second_surname') %>
<%= f.text_field :second_surname %>
<%= form_field_errors(f, :second_surname) %>
</div>
<div class="small-6 columns">
<%= f.label :phones, t('backend.identifying_data.phones') %>
<%= f.text_field :phones %>
<%= form_field_errors(f, :phones) %>
</div>
<div class="small-6 columns">
<%= f.label :email, t('backend.identifying_data.email') %>
<%= f.text_field :email %>
<%= form_field_errors(f, :email) %>
</div>
<div class="small-12 columns">
<%= f.label :category_id, t('backend.identifying_data.category_id') %>
<%= f.select :category_id, options_for_select(Category.all.map{|c| [c.name, c.id]}), prompt: t('backend.none') %>
<%= form_field_errors(f, :category_id) %>
</div>
<div class="small-12 columns">
<%= f.label :web, t('backend.identifying_data.web') %>
<%= f.text_field :web %>
<%= form_field_errors(f, :category_id) %>
</div>
<div class="small-4 columns">
<%= f.label :address_type, t('backend.identifying_data.address_type') %>
<%= f.text_field :address_type %>
<%= form_field_errors(f, :address_type) %>
</div>
<div class="small-8 columns">
<%= f.label :address, t('backend.identifying_data.address') %>
<%= f.text_field :address %>
<%= form_field_errors(f, :address) %>
</div>
<div class="small-3 columns">
<%= f.label :number, t('backend.identifying_data.number') %>
<%= f.text_field :number %>
<%= form_field_errors(f, :number) %>
</div>
<div class="small-3 columns">
<%= f.label :gateway, t('backend.identifying_data.gateway') %>
<%= f.text_field :gateway %>
<%= form_field_errors(f, :gateway) %>
</div>
<div class="small-3 columns">
<%= f.label :stairs, t('backend.identifying_data.stairs') %>
<%= f.text_field :stairs %>
<%= form_field_errors(f, :stairs) %>
</div>
<div class="small-3 columns">
<%= f.label :floor, t('backend.identifying_data.floor') %>
<%= f.text_field :floor %>
<%= form_field_errors(f, :floor) %>
</div>
<div class="small-3 columns">
<%= f.label :door, t('backend.identifying_data.door') %>
<%= f.text_field :door %>
<%= form_field_errors(f, :door) %>
</div>
<div class="small-3 columns">
<%= f.label :postal_code, t('backend.identifying_data.postal_code') %>
<%= f.text_field :postal_code %>
<%= form_field_errors(f, :postal_code) %>
</div>
<div class="small-3 columns">
<%= f.label :town, t('backend.identifying_data.town') %>
<%= f.text_field :town %>
<%= form_field_errors(f, :town) %>
</div>
<div class="small-3 columns">
<%= f.label :province, t('backend.identifying_data.province') %>
<%= f.text_field :province %>
<%= form_field_errors(f, :province) %>
</div>
<div class="small-12 columns">
<%= f.label :description, t('backend.identifying_data.description') %>
<%= f.text_area :description %>
<%= form_field_errors(f, :description) %>
</div>
<div class="small-12 columns">
<%= f.label :registered_lobbies, t('backend.identifying_data.registered_lobbies') %>
<%= f.select :registered_lobbies, Organization.registered_lobbies.keys.to_a %>
<%= form_field_errors(f, :registered_lobbies) %>
</div>
</div>
</fieldset>
5 changes: 3 additions & 2 deletions app/views/admin/organizations/_interest.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
<div class="row">
<div class="small-12 columns">
<%= f.collection_check_boxes(:interest_ids, Interest.all, :id, :name) do |f| %>
<%= f.label class:"small-6 columns" do%>
<%= f.label class:"small-6 columns" do %>
<%= f.check_box %> <span> <%= f.text %> </span>
<%end%>
<% end %>
<% end %>
<%= form_field_errors(f, :interest_ids) %>
</div>
</div>
</fieldset>
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,37 @@
<div class="small-6 columns">
<%= f.label :identifier, t('backend.legal_representant.identifier') %>
<%= f.text_field :identifier %>
<%= form_field_errors(f, :identifier) %>
</div>

<div class="small-6 columns">
<%= f.label :name, t('backend.legal_representant.name') %>
<%= f.text_field :name %>
<%= form_field_errors(f, :name) %>
</div>

<div class="small-6 columns">
<%= f.label :first_surname, t('backend.legal_representant.first_surname') %>
<%= f.text_field :first_surname %>
<%= form_field_errors(f, :first_surname) %>
</div>

<div class="small-6 columns">
<%= f.label :second_surname, t('backend.legal_representant.second_surname') %>
<%= f.text_field :second_surname %>
<%= form_field_errors(f, :second_surname) %>
</div>

<div class="small-6 columns">
<%= f.label :phones, t('backend.legal_representant.phones') %>
<%= f.text_field :phones %>
<%= form_field_errors(f, :phones) %>
</div>

<div class="small-6 columns">
<%= f.label :email, t('backend.legal_representant.email') %>
<%= f.text_field :email %>
<%= form_field_errors(f, :email) %>
</div>

<div class="small-12 columns">
Expand Down
4 changes: 4 additions & 0 deletions app/views/admin/organizations/_lobbies_data.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
<div class="small-6 columns">
<%= f.label :fiscal_year, t('backend.lobbies_data.fiscal_year') %>
<%= f.number_field :fiscal_year %>
<%= form_field_errors(f, :fiscal_year) %>
</div>
<div class="small-6 columns">
<%= f.label :range_fund, t('backend.lobbies_data.range_fund') %>
<%= f.select :range_fund, Organization.range_funds.keys.to_a %>
<%= form_field_errors(f, :range_fund) %>
</div>
<div class="small-12 columns">
<%= f.label :subvention, t('backend.lobbies_data.subvention') %>
<%= f.check_box :subvention %> Si
<%= form_field_errors(f, :subvention) %>
</div>
<div class="small-12 columns">
<%= f.label :contract, t('backend.lobbies_data.subvention') %>
<%= f.check_box :contract %> Si
<%= form_field_errors(f, :contract) %>
</div>
</div>
</fieldset>
1 change: 1 addition & 0 deletions app/views/admin/organizations/_reference.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<legend><%= t('backend.reference.title_fieldset') %></legend>
<%= f.label :reference, t('backend.reference.title') %>
<%= f.text_field :reference %>
<%= form_field_errors(f, :reference) %>
</fieldset>
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,55 @@
<div class="small-6 columns">
<%= f.label :identifier, t('backend.represented_entities.identifier') %>
<%= f.text_field :identifier %>
<%= form_field_errors(f, :identifier) %>
</div>

<div class="small-6 columns">
<%= f.label :name, t('backend.represented_entities.name') %>
<%= f.text_field :name %>
<%= form_field_errors(f, :name) %>
</div>

<div class="small-6 columns">
<%= f.label :first_surname, t('backend.represented_entities.first_surname') %>
<%= f.text_field :first_surname %>
<%= form_field_errors(f, :first_surname) %>
</div>

<div class="small-6 columns">
<%= f.label :second_surname, t('backend.represented_entities.second_surname') %>
<%= f.text_field :second_surname %>
<%= form_field_errors(f, :second_surname) %>
</div>

<div class="small-12 columns">
<%= f.label :from, t('backend.represented_entities.from') %>
<%= f.date_field :from %>
<%= form_field_errors(f, :from) %>
</div>

<div class="small-6 columns">
<%= f.label :fiscal_year, t('backend.represented_entities.fiscal_year') %>
<%= f.number_field :fiscal_year %>
<%= form_field_errors(f, :fiscal_year) %>
</div>

<div class="small-6 columns">
<%= f.label :range_fund, t('backend.represented_entities.range_founds') %>
<%= f.select :range_fund, Organization.range_funds.keys.to_a %>
<%= form_field_errors(f, :range_fund) %>
</div>

<div class="small-12 columns">
<%= f.label :subvention, t('backend.represented_entities.subvention') %>
<%= f.check_box :subvention %> Si
<%= form_field_errors(f, :subvention) %>
</div>

<div class="small-12 columns">
<%= f.label :contract, t('backend.represented_entities.contract') %>
<%= f.check_box :contract %> Si
<%= form_field_errors(f, :contract) %>
</div>

<div class="small-12 columns">
Expand Down
4 changes: 3 additions & 1 deletion app/views/admin/organizations/_terms.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
<small><%= t('backend.terms.denied_public_data') %></small>
<br />
<%= f.check_box :denied_public_data %> Confirmar
<%= form_field_errors(f, :denied_public_data) %>
<% end %>
<%= f.label :denied_public_events do %>
<small><%= t('backend.terms.denied_public_events') %></small>
<br />
<%= f.check_box :denied_public_events %> Confirmar
<%= form_field_errors(f, :denied_public_events) %>
<% end %>

<small><%= t('backend.terms.last_text') %></small>

</div>
</div>
</fieldset>

0 comments on commit 00e50d9

Please sign in to comment.