From cc672a420b139265028f0425f51701f64171a098 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 21 Jul 2015 19:05:39 +0300 Subject: [PATCH] Preselect default values for new record #2776 --- app/models/depp/contact.rb | 7 ------- app/views/registrar/contacts/form_partials/_address.haml | 5 +++-- app/views/registrar/contacts/form_partials/_general.haml | 6 ++++-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/app/models/depp/contact.rb b/app/models/depp/contact.rb index eb15b192e..9af836d45 100644 --- a/app/models/depp/contact.rb +++ b/app/models/depp/contact.rb @@ -144,13 +144,6 @@ module Depp end end - def initialize(attributes = {}) - super - self.country_code = 'EE' if country_code.blank? - self.ident_type = 'bic' if ident_type.blank? - self.ident_country_code = 'EE' if ident_country_code.blank? - end - def save create_xml = Depp::Contact.epp_xml.create( { diff --git a/app/views/registrar/contacts/form_partials/_address.haml b/app/views/registrar/contacts/form_partials/_address.haml index 8737bffa3..77f868080 100644 --- a/app/views/registrar/contacts/form_partials/_address.haml +++ b/app/views/registrar/contacts/form_partials/_address.haml @@ -30,5 +30,6 @@ .col-md-3.control-label = f.label :country_code, t(:country) + '*' .col-md-7 - = f.select :country_code, - SortedCountry.all_options(f.object.country_code) + - country_selected = f.object.persisted? ? f.object.country_code : 'EE' + = f.select :country_code, SortedCountry.all_options(country_selected), + { include_blank: true } diff --git a/app/views/registrar/contacts/form_partials/_general.haml b/app/views/registrar/contacts/form_partials/_general.haml index 6c0e13448..24e02e435 100644 --- a/app/views/registrar/contacts/form_partials/_general.haml +++ b/app/views/registrar/contacts/form_partials/_general.haml @@ -11,7 +11,8 @@ = Country.new(f.object.ident_country_code).try(:to_s) = " [#{f.object.ident_country_code}]" - else - = f.select(:ident_country_code, SortedCountry.all_options(f.object.ident_country_code), {}, + - country_selected = @contact.persisted? ? '' : 'EE' + = f.select(:ident_country_code, SortedCountry.all_options(country_selected), {}, class: 'js-ident-country-code', required: true) .form-group @@ -23,8 +24,9 @@ = Depp::Contact.type_string(f.object.ident_type) = " [#{f.object.ident_type}]" - else + - type_selected = @contact.persisted? ? '' : 'bic' = f.select(:ident_type, Depp::Contact::SELECTION_TYPES, - { selected: f.object.ident_type }, + { selected: type_selected }, class: 'js-ident-type', required: true) .form-group