Skip to content

Commit

Permalink
Add missing fields on organizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
taitus committed Jan 6, 2018
1 parent ed12ecf commit daba4de
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 13 deletions.
24 changes: 24 additions & 0 deletions app/assets/javascripts/admin/organizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ $(function(){
$('#validate_link').toggleClass('success');
});

if ($("#organization_own_lobby_activity_true").is(":checked")) {
$('#lobbies-data-content').show();
};

$("#organization_own_lobby_activity_false").click(function(){
$('#lobbies-data-content').hide();
});

$("#organization_own_lobby_activity_true").click(function(){
$('#lobbies-data-content').show();
});

if ($("#organization_foreign_lobby_activity_true").is(":checked")) {
$("#represented-entities-content").show();
};

$("#organization_foreign_lobby_activity_false").click(function(){
$("#represented-entities-content").hide();
});

$("#organization_foreign_lobby_activity_true").click(function(){
$("#represented-entities-content").show();
});

});

function restore_legal_representant(e){
Expand Down
1 change: 1 addition & 0 deletions app/controllers/admin/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def organization_params
:fiscal_year, :range_fund, :subvention, :contract, :country,
:certain_term, :code_of_conduct_term, :gift_term, :lobby_term,
:inscription_date, :modification_date, :canceled_at,
:own_lobby_activity, :foreign_lobby_activity,
legal_representant_attributes: [:identifier, :name, :first_surname, :second_surname, :phones, :email, :_destroy],
user_attributes: [:id, :first_name, :last_name, :role, :email, :active, :phones, :password, :password_confirmation],
represented_entities_attributes: [:id, :identifier, :name, :first_surname, :second_surname,
Expand Down
18 changes: 16 additions & 2 deletions app/views/admin/organizations/_lobby_data.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
<fieldset>
<legend><%= t('backend.lobbies_data.title_fieldset') %></legend>

<div class="row">
<div class="small-12 columns">
<%= f.label :own_lobby_activity, t('backend.lobbies_data.own_lobby_activity') %>
<%= f.radio_button :own_lobby_activity, true %>
<%= t('backend.lobbies_data.own_lobby_activity_yes') %>
&nbsp;
<%= f.radio_button :own_lobby_activity, false %>
<%= t('backend.lobbies_data.own_lobby_activity_no') %>
<%= form_field_errors(f, :own_lobby_activity) %>
</div>
</div>

<div class="row hide" id="lobbies-data-content">

<div class="small-12 medium-6 columns">
<%= f.label :fiscal_year, t('backend.lobbies_data.fiscal_year') %>
<%= f.number_field :fiscal_year, min: 0 %>
Expand All @@ -18,7 +32,7 @@
<%= f.label :subvention, t('backend.lobbies_data.subvention') %>
<%= f.radio_button :subvention, true %>
<%= t('backend.lobbies_data.subvention_yes') %>
<br>
&nbsp;
<%= f.radio_button :subvention, false %>
<%= t('backend.lobbies_data.subvention_no') %>
<%= form_field_errors(f, :subvention) %>
Expand All @@ -27,7 +41,7 @@
<%= f.label :contract, t('backend.lobbies_data.contract') %>
<%= f.radio_button :contract, true %>
<%= t('backend.lobbies_data.contract_yes') %>
<br>
&nbsp;
<%= f.radio_button :contract, false %>
<%= t('backend.lobbies_data.contract_no') %>
<%= form_field_errors(f, :contract) %>
Expand Down
11 changes: 11 additions & 0 deletions app/views/admin/organizations/_represented_entities.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<fieldset>
<legend><%= t('backend.represented_entities.title_fieldset') %></legend>
<div class="row">
<div class="small-12 columns">
<%= f.label :foreign_lobby_activity, t('backend.lobbies_data.foreign_lobby_activity') %>
<%= f.radio_button :foreign_lobby_activity, true %>
<%= t('backend.lobbies_data.foreign_lobby_activity_yes') %>
&nbsp;
<%= f.radio_button :foreign_lobby_activity, false %>
<%= t('backend.lobbies_data.foreign_lobby_activity_no') %>
<%= form_field_errors(f, :foreign_lobby_activity) %>
</div>
</div>
<div class="row hide" id="represented-entities-content">
<div id="nested-represented-entities">
<%= f.fields_for :represented_entities do |represented_entities_builder| %>
<%= render 'represented_entities_fields', f: represented_entities_builder %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<%= f.label :subvention, t('backend.represented_entities.subvention') %>
<%= f.radio_button :subvention, true %>
<%= t('backend.lobbies_data.subvention_yes') %>
<br>
&nbsp;
<%= f.radio_button :subvention, false %>
<%= t('backend.lobbies_data.subvention_no') %>
<%= form_field_errors(f, :subvention) %>
Expand All @@ -66,7 +66,7 @@
<%= f.label :contract, t('backend.represented_entities.contract') %>
<%= f.radio_button :contract, true %>
<%= t('backend.lobbies_data.contract_yes') %>
<br>
&nbsp;
<%= f.radio_button :contract, false %>
<%= t('backend.lobbies_data.contract_no') %>
<%= form_field_errors(f, :contract) %>
Expand Down
14 changes: 14 additions & 0 deletions app/views/admin/organizations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@
</p>
</div>

<div class="small-12 columns mb10">
<p>
<strong>Lobby por cuenta propia</strong>
<%= t(@organization.own_lobby_activity.to_s) %>
</p>
</div>

<div class="small-12 columns mb10">
<p>
<strong>Lobby por cuenta ajena</strong>
<%= t(@organization.foreign_lobby_activity.to_s) %>
</p>
</div>

</div>
</fieldset>

Expand Down
12 changes: 11 additions & 1 deletion app/views/organizations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@
<% end %>
<% end %>
</p>

<p>
<strong>Lobby por cuenta propia</strong>
<%= t(@organization.own_lobby_activity.to_s) %>
</p>

<p>
<strong>Lobby por cuenta ajena</strong>
<%= t(@organization.foreign_lobby_activity.to_s) %>
</p>
</div>
</li>

Expand All @@ -162,7 +172,7 @@
</div>

<div class="content active">
<% if @organization.fiscal_year.present? || @organization.range_fund.present? %>
<% if @organization.own_lobby_activity %>
<p>
<strong><%= t('organizations.show.fiscal_year') %> </strong>
<%= @organization.fiscal_year.present? ? @organization.fiscal_year : "Sin año" %>
Expand Down
6 changes: 6 additions & 0 deletions config/locales/organizations.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ es:
contract: "¿Ha celebrado contratos y/o convenios con el Ayuntamiento de Madrid, sus organismos autónomos, sociedades mercantiles o consorcios en los que participe?"
contract_yes: ""
contract_no: "No"
own_lobby_activity_yes: ""
own_lobby_activity_no: "No"
own_lobby_activity: "Lobby por cuenta propia"
foreign_lobby_activity_yes: ""
foreign_lobby_activity_no: "No"
foreign_lobby_activity: "Lobby por cuenta ajena"

represented_entities:
add_represented_entities: "Añadir Entidades/personas a las que se representa"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddOwnLobbyActivityAndForeignLobbyActivityToOrganizations < ActiveRecord::Migration
def change
add_column :organizations, :own_lobby_activity, :boolean, default: false
add_column :organizations, :foreign_lobby_activity, :boolean, default: false
end
end
14 changes: 8 additions & 6 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180104194733) do
ActiveRecord::Schema.define(version: 20180106204752) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -237,17 +237,17 @@
t.string "phones"
t.string "email"
t.integer "category_id"
t.string "description", default: ""
t.string "description", default: ""
t.string "web"
t.integer "registered_lobbies"
t.integer "fiscal_year"
t.integer "range_fund"
t.boolean "subvention", default: false
t.boolean "contract", default: false
t.boolean "subvention", default: false
t.boolean "contract", default: false
t.boolean "certain_term"
t.boolean "code_of_conduct_term"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "inscription_reference"
t.datetime "inscription_date"
t.integer "entity_type"
Expand All @@ -266,6 +266,8 @@
t.boolean "lobby_term"
t.string "address_number_type"
t.date "termination_date"
t.boolean "own_lobby_activity", default: false
t.boolean "foreign_lobby_activity", default: false
end

add_index "organizations", ["category_id"], name: "index_organizations_on_category_id", using: :btree
Expand Down
8 changes: 6 additions & 2 deletions spec/features/admin/organizations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@
fill_in :organization_user_attributes_email, with: "user@email.com"
fill_in :organization_user_attributes_password, with: "password"
fill_in :organization_user_attributes_password_confirmation, with: "password"
choose("organization_foreign_lobby_activity_true")

click_on "Añadir Entidades/personas a las que se representa"

Expand All @@ -539,6 +540,7 @@
fill_in :organization_user_attributes_email, with: "user@email.com"
fill_in :organization_user_attributes_password, with: "password"
fill_in :organization_user_attributes_password_confirmation, with: "password"
choose("organization_foreign_lobby_activity_true")

click_on "Añadir Entidades/personas a las que se representa"

Expand All @@ -564,15 +566,17 @@

scenario 'Display remove button after add represented entity', :js do
visit new_admin_organization_path

choose("organization_foreign_lobby_activity_true")
expect(page).not_to have_selector "#new_represented_entity .remove_fields"

click_on "Añadir Entidades/personas a las que se representa"

expect(page).to have_selector "#new_represented_entity .remove_fields"
end

scenario 'Display remove button after add more than one represented entity', :js do
visit new_admin_organization_path
choose("organization_foreign_lobby_activity_true")

expect(page).not_to have_selector "#new_represented_entity .remove_fields"
click_on "Añadir Entidades/personas a las que se representa"
Expand Down Expand Up @@ -943,7 +947,7 @@
end

scenario 'Update to blank represented entity fields', :js do
organization = create(:organization)
organization = create(:organization, foreign_lobby_activity: true)
create(:represented_entity, organization: organization)
visit edit_admin_organization_path(organization)

Expand Down

0 comments on commit daba4de

Please sign in to comment.