egov_utils 1.5.0.alpha2 → 1.5.0.alpha4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d41aad5c6d41d126b0bf8c535c3ee7b93ae029fb941aaf56a2fa50122e81c86f
4
- data.tar.gz: 85b31bd2904bf438a71671b591bd163c15fc5c40901f32760b3631aa138d77ba
3
+ metadata.gz: 4e9f48c4a226521a80af25765e7eeb2b133c0112300560d9cb2f37cec56f34e2
4
+ data.tar.gz: 87565bb066e01ac9605fdc5ad1f3308ef9fcfbaa7c5f132b54c07427e4d0fad1
5
5
  SHA512:
6
- metadata.gz: ce7a35bd5dce15d5b01e16ba0c9c55af05885572339881fed1c81cb170c8e0af73d3c368f9fd78ae20ef8f743f22bf7cfb8ed28a0436681cb82d2e02a85a7f91
7
- data.tar.gz: b6e660e7e2fca843d0e06887b18c8659cdb0c316d59982b75cf5f0637fee5dd30a140c605664e054163392e850f20d4a3fea19d3c5a9aa7c29b5ac0db7a677c5
6
+ metadata.gz: bc7af836fdcab121db08350c450908e2df069f784d9283fdc407d8fef509b079bcccb215e5f8212e2f944cdcaebea49eecc3eca97afcf0f91741620a6c2e2262
7
+ data.tar.gz: 23587f1c431273f0f1d4161ddb2f865fb54094845e3f35d424041222a77cc37a8f5de3c8f1408d50262f9f66c45832d255d67c29418ed519be25138786612b93
@@ -0,0 +1,11 @@
1
+ module EgovUtils
2
+ class TownsController < ApplicationController
3
+ def index
4
+ selected = EgovUtils::Address.towns.lazy.select do |town|
5
+ /\A#{params[:term]}/i.match?(town.name)
6
+ end.first(10)
7
+
8
+ render json: { towns: selected.map(&:to_h) }
9
+ end
10
+ end
11
+ end
@@ -18,6 +18,7 @@ module EgovUtils
18
18
  District = Struct.new(:id, :name, :region_id)
19
19
  Region = Struct.new(:id, :name)
20
20
  Country = Struct.new(:iso_id, :code2, :code3, :name)
21
+ Town = Struct.new(:id, :name, :district_name)
21
22
 
22
23
  CZ_ISO_CODE = '203'
23
24
 
@@ -51,6 +52,15 @@ module EgovUtils
51
52
  @regions
52
53
  end
53
54
 
55
+ def self.towns
56
+ @towns ||= begin
57
+ towns = File.read(EgovUtils::Engine.root.join('config', 'obec.json'))
58
+ JSON.parse(towns).map do |town|
59
+ Town.new(*town.slice('code', 'name', 'district_name').values)
60
+ end
61
+ end
62
+ end
63
+
54
64
  def self.region_for_district(district_name)
55
65
  district = districts.detect{|d| d[:name] == district_name }
56
66
  regions.detect{|r| r[:id] == district[:region_id] } if district
@@ -11,14 +11,12 @@ module EgovUtils
11
11
  enum person_type: { natural: 1, legal: 16 }
12
12
 
13
13
  validates :person_entity, presence: true
14
- before_validation :set_residence_from_remote_id
14
+ before_validation :set_person_from_remote_id
15
15
 
16
16
  accepts_nested_attributes_for :residence, :natural_person, :legal_person
17
17
 
18
18
  delegate :fullname, :fullname=, to: :person_entity
19
19
 
20
- attr_accessor :remote_id
21
-
22
20
  def initialize(attributes = {})
23
21
  if attributes&.fetch(:remote_id, nil).present?
24
22
  super(attributes.slice(:remote_id, :person_type))
@@ -61,10 +59,9 @@ module EgovUtils
61
59
 
62
60
  private
63
61
 
64
- def set_residence_from_remote_id
62
+ def set_person_from_remote_id
65
63
  return unless remote_id.present?
66
64
 
67
- # binding.pry
68
65
  attributes =
69
66
  if person_type == 'natural'
70
67
  Iszr::NaturalPeople::SearchByRemoteId.run!(remote_id:)
@@ -10,9 +10,9 @@ module EgovUtils
10
10
  strategy_class.run!(remote_id:)
11
11
  end
12
12
 
13
- def strategy_class
13
+ def fetch_result
14
14
  if Rails.env.production?
15
- EgovUtils::Iszr::Addresses::FetchForNaturalPerson::FromRemoteReposiory
15
+ EgovUtils::Iszr::FindResultByAifo
16
16
  else
17
17
  EgovUtils::Iszr::Addresses::FetchForNaturalPerson::FromSampleData
18
18
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EgovUtils
4
+ module Iszr
5
+ class Client
6
+ def initialize(message)
7
+ @client = Savon.client(wsdl: config['endpoint'], log: true, log_level: :info, ssl_verify_mode: :none)
8
+ @message = message
9
+ end
10
+
11
+ def self.config
12
+ EgovUtils::Settings['iszr']
13
+ end
14
+
15
+ def call
16
+ client.call(
17
+ :get_data,
18
+ message: { 'tns:inputXml' => message }
19
+ )
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :client, :message
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EgovUtils
4
+ module Iszr
5
+ class FindResultByAifo < Request
6
+ string :remote_id
7
+
8
+ private
9
+
10
+ def handle_response!
11
+ EgovUtils::Address.new(
12
+ street: response_body.xpath('//UliceNazev').text,
13
+ house_number: response_body.xpath('//CisloDomovni').text,
14
+ orientation_number: response_body.xpath('//CisloOrientacni').text,
15
+ city: response_body.xpath('//ObecNazev').text,
16
+ postcode: response_body.xpath('//PostaKod').text,
17
+ egov_identifier: response_body.xpath('//AdresniMistoKod').text,
18
+ country: 203,
19
+ district: district.name,
20
+ region: region.name
21
+ )
22
+ end
23
+
24
+ def district
25
+ @district ||= begin
26
+ district =
27
+ EgovUtils::Address.towns.find do
28
+ _1.id == response_body.xpath('//ObecKod').text
29
+ end.district_name
30
+
31
+ EgovUtils::Address.districts.find { _1.name == district }
32
+ end
33
+ end
34
+
35
+ def region
36
+ @region ||=
37
+ EgovUtils::Address.regions.find { _1.id == district.region_id }
38
+ end
39
+
40
+ def body
41
+ Nokogiri::XML::Builder.new do |xml|
42
+ xml[service_id].RobCtiAifo2(
43
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
44
+ 'xsi:schemaLocation' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiAifo2:v1 IszrRobCtiAifo2.xsd',
45
+ 'xmlns:abs' => 'urn:cz:isvs:iszr:schemas:IszrAbstract:v1',
46
+ 'xmlns:E276' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiAifo2:v1',
47
+ 'xmlns:reg' => 'urn:cz:isvs:reg:schemas:RegTypy:v1',
48
+ 'xmlns:rod' => 'urn:cz:isvs:rob:schemas:RobDotazyData:v1',
49
+ 'xmlns:rob' => 'urn:cz:isvs:rob:schemas:RobTypy:v1'
50
+ ) {
51
+ xml['abs'].ZadostInfo {
52
+ xml['reg'].CasZadosti Time.current.iso8601
53
+ xml['reg'].Agenda EgovUtils::Settings['iszr']['agenda']
54
+ xml['reg'].AgendovaRole EgovUtils::Settings['iszr']['agendova_role']
55
+ xml['reg'].Ovm '00025429'
56
+ xml['reg'].Ais EgovUtils::Settings['iszr']['ais']
57
+ xml['reg'].Subjekt '00025429'
58
+ xml['reg'].Uzivatel 'Administrator'
59
+ xml['reg'].DuvodUcel 'ztotozneni'
60
+ xml['reg'].AgendaZadostId SecureRandom.uuid
61
+ }
62
+ xml['abs'].AutorizaceInfo {
63
+ xml['abs'].SeznamUdaju 'Aifo Prijmeni Jmeno DatumNarozeni RUIANCti AdresaPobytu MistoNarozeni'
64
+ }
65
+ xml['abs'].MapaAifo(nacistData: true) {
66
+ xml['reg'].PrevodAifo {
67
+ xml['reg'].LokalniAifo 1
68
+ xml['reg'].GlobalniAifo remote_id
69
+ }
70
+ }
71
+ xml[service_id].Zadost {
72
+ xml[service_id].RobCtiAifo2Data {
73
+ xml['rod'].Aifo 1
74
+ xml['rod'].VyuzitiPoskytnuti 'poskytnuti'
75
+ }
76
+ }
77
+ }
78
+ end
79
+ end
80
+
81
+ def service_id
82
+ 'E276'
83
+ end
84
+ end
85
+ end
86
+ end
@@ -19,31 +19,70 @@ module EgovUtils
19
19
  end
20
20
  end
21
21
 
22
+ def response_error_code
23
+ @response_error_code ||=
24
+ response_body.xpath('//VysledekSubKod').last&.text&.presence
25
+ end
26
+
27
+ def internal_error_code
28
+ return unless response_error_code
29
+
30
+ code = if response_error_code == 'ZAZNAM NENALEZEN'
31
+ "not_found"
32
+ elsif response_error_code == 'PREKROCEN POCET'
33
+ "multiple_records_found"
34
+ end
35
+
36
+ if birth_place.present?
37
+ "extended_search_#{code}"
38
+ else
39
+ code
40
+ end
41
+ end
42
+
43
+ def handle_response!
44
+ if internal_error_code
45
+ errors.add(:base, internal_error_code)
46
+ return
47
+ end
48
+
49
+ EgovUtils::Services::Iszr::NaturalPeople.new(
50
+ firstname: response_body.xpath('//Jmeno').text.capitalize,
51
+ lastname: response_body.xpath('//Prijmeni').text.capitalize,
52
+ birth_date: response_body.xpath('//DatumNarozeni').text,
53
+ birth_place: response_body.xpath('//Lokalita/Nazev').text,
54
+ remote_id: response_body.xpath('//GlobalniAifo').text
55
+ )
56
+
57
+ end
58
+
22
59
  def search_stage_one
23
60
  Nokogiri::XML::Builder.new do |xml|
24
- xml['e05'].RobCtiPodleUdaju(
61
+ xml[service_id].RobCtiPodleUdaju2(
25
62
  'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
26
- 'xsi:schemaLocation' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiPodleUdaju:v1 IszrRobCtiPodleUdaju.xsd',
63
+ 'xsi:schemaLocation' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiPodleUdaju2:v1 IszrRobCtiPodleUdaju2.xsd',
27
64
  'xmlns:abs' => 'urn:cz:isvs:iszr:schemas:IszrAbstract:v1',
28
- 'xmlns:e05' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiPodleUdaju:v1',
65
+ 'xmlns:E278' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiPodleUdaju2:v1',
29
66
  'xmlns:reg' => 'urn:cz:isvs:reg:schemas:RegTypy:v1',
30
67
  'xmlns:rod' => 'urn:cz:isvs:rob:schemas:RobDotazyData:v1',
31
68
  'xmlns:rob' => 'urn:cz:isvs:rob:schemas:RobTypy:v1'
32
69
  ) {
33
70
  xml['abs'].ZadostInfo {
34
- xml['reg'].CasZadosti Time.current
35
- xml['reg'].Agenda 'A482'
36
- xml['reg'].AgendovaRole 'CTENAR'
71
+ xml['reg'].CasZadosti Time.current.iso8601
72
+ xml['reg'].Agenda EgovUtils::Settings['iszr']['agenda']
73
+ xml['reg'].AgendovaRole EgovUtils::Settings['iszr']['agendova_role']
37
74
  xml['reg'].Ovm '00025429'
38
- xml['reg'].Ais '124'
39
- xml['reg'].Uzivatel 'Uzivatel156'
40
- xml['reg'].AgendaZadostId '5a7b9af0-f759-4632-ab96-7bb06df1b98c'
75
+ xml['reg'].Ais EgovUtils::Settings['iszr']['ais']
76
+ xml['reg'].Subjekt '00025429'
77
+ xml['reg'].Uzivatel 'Administrator'
78
+ xml['reg'].DuvodUcel 'ztotozneni'
79
+ xml['reg'].AgendaZadostId SecureRandom.uuid
41
80
  }
42
81
  xml['abs'].AutorizaceInfo {
43
- xml['abs'].SeznamUdaju 'Aifo Prijmeni Jmeno AdresaPobytu DorucovaciAdresa DatumNarozeni MistoNarozeni DatumUmrti DatumPravniMociUmrti MistoUmrti DatovaSchrankaROB Doklad Obcanstvi'
82
+ xml['abs'].SeznamUdaju 'Aifo Prijmeni Jmeno DatumNarozeni RUIANCti AdresaPobytu MistoNarozeni'
44
83
  }
45
- xml['e05'].Zadost {
46
- xml['e05'].RobCtiPodleUdajuData {
84
+ xml[service_id].Zadost {
85
+ xml[service_id].RobCtiPodleUdaju2Data {
47
86
  xml['rod'].DatumNarozeni birth_date
48
87
  xml['rod'].Jmeno firstname
49
88
  xml['rod'].Prijmeni lastname
@@ -55,32 +94,36 @@ module EgovUtils
55
94
 
56
95
  def search_stage_two
57
96
  Nokogiri::XML::Builder.new do |xml|
58
- xml['e05'].RobCtiPodleUdaju(
97
+ xml[service_id].RobCtiPodleUdaju2(
59
98
  'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
60
- 'xsi:schemaLocation' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiPodleUdaju:v1 IszrRobCtiPodleUdaju.xsd',
99
+ 'xsi:schemaLocation' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiPodleUdaju2:v1 IszrRobCtiPodleUdaju2.xsd',
61
100
  'xmlns:abs' => 'urn:cz:isvs:iszr:schemas:IszrAbstract:v1',
62
- 'xmlns:e05' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiPodleUdaju:v1',
101
+ 'xmlns:E278' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiPodleUdaju2:v1',
63
102
  'xmlns:reg' => 'urn:cz:isvs:reg:schemas:RegTypy:v1',
64
103
  'xmlns:rod' => 'urn:cz:isvs:rob:schemas:RobDotazyData:v1',
65
104
  'xmlns:rob' => 'urn:cz:isvs:rob:schemas:RobTypy:v1'
66
105
  ) {
67
106
  xml['abs'].ZadostInfo {
68
- xml['reg'].CasZadosti Time.current
69
- xml['reg'].Agenda 'A482'
70
- xml['reg'].AgendovaRole 'CTENAR'
107
+ xml['reg'].CasZadosti Time.current.iso8601
108
+ xml['reg'].Agenda EgovUtils::Settings['iszr']['agenda']
109
+ xml['reg'].AgendovaRole EgovUtils::Settings['iszr']['agendova_role']
71
110
  xml['reg'].Ovm '00025429'
72
- xml['reg'].Ais '124'
73
- xml['reg'].Uzivatel 'Uzivatel156'
74
- xml['reg'].AgendaZadostId '5a7b9af0-f759-4632-ab96-7bb06df1b98c'
111
+ xml['reg'].Ais EgovUtils::Settings['iszr']['ais']
112
+ xml['reg'].Subjekt '00025429'
113
+ xml['reg'].Uzivatel 'Administrator'
114
+ xml['reg'].DuvodUcel 'ztotozneni'
115
+ xml['reg'].AgendaZadostId SecureRandom.uuid
75
116
  }
76
117
  xml['abs'].AutorizaceInfo {
77
- xml['abs'].SeznamUdaju 'Aifo Prijmeni Jmeno AdresaPobytu DorucovaciAdresa DatumNarozeni MistoNarozeni DatumUmrti DatumPravniMociUmrti MistoUmrti DatovaSchrankaROB Doklad Obcanstvi'
118
+ xml['abs'].SeznamUdaju 'Aifo Prijmeni Jmeno DatumNarozeni RUIANCti AdresaPobytu MistoNarozeni'
78
119
  }
79
- xml['e05'].Zadost {
80
- xml['e05'].RobCtiPodleUdajuData {
81
- xml['rod'].MistoNarozeni birth_place
120
+ xml[service_id].Zadost {
121
+ xml[service_id].RobCtiPodleUdaju2Data {
82
122
  xml['rod'].DatumNarozeni birth_date
83
123
  xml['rod'].Jmeno firstname
124
+ xml['rod'].MistoNarozeni {
125
+ xml['rob'].NarozeniCr birth_place
126
+ }
84
127
  xml['rod'].Prijmeni lastname
85
128
  }
86
129
  }
@@ -89,7 +132,7 @@ module EgovUtils
89
132
  end
90
133
 
91
134
  def service_id
92
- 'E05'
135
+ 'E278'
93
136
  end
94
137
  end
95
138
  end
@@ -2,7 +2,7 @@ module EgovUtils
2
2
  module Iszr
3
3
  class Request < ActiveInteraction::Base
4
4
  def execute
5
- envelope.to_xml
5
+ handle_response!
6
6
  end
7
7
 
8
8
  private
@@ -19,7 +19,7 @@ module EgovUtils
19
19
  }
20
20
  xml.SenderDetails {
21
21
  xml.Authentication(type: 'clear') {
22
- xml.ISId '124'
22
+ xml.ISId EgovUtils::Settings['iszr']['ais']
23
23
  }
24
24
  }
25
25
  }
@@ -31,6 +31,24 @@ module EgovUtils
31
31
  def encoded_body(body)
32
32
  Base64.encode64(body.to_xml)
33
33
  end
34
+
35
+ def response
36
+ @response ||= Client.new(envelope.to_xml).call
37
+ end
38
+
39
+ def response_body
40
+ @response_body ||= begin
41
+ body = Nokogiri::XML(
42
+ response.body[:get_data_response][:get_data_result]
43
+ ).xpath("//Body").text
44
+
45
+ Nokogiri::XML(Base64.decode64(body)).remove_namespaces!
46
+ end
47
+ end
48
+
49
+ def handle_response!
50
+ response_body
51
+ end
34
52
  end
35
53
  end
36
54
  end
@@ -1,6 +1,4 @@
1
1
  .person-form
2
- .row
3
- .col-12= form.select :person_type, enum_values_for_select(person.class, :person_type), {}, class: 'person-type-toggle'
4
2
  .natural_person.row
5
3
  = form.fields_for(:natural_person, person.natural_person || EgovUtils::NaturalPerson.new) do |fields|
6
4
  .col-12.col-md-2= fields.text_field(:title)
@@ -9,11 +7,11 @@
9
7
  .col-12.col-md-2= fields.text_field(:higher_title)
10
8
  .col-12.col-md-6= fields.date_field(:birth_date, min: Date.new(1920, 1, 1), max: Date.today, data: {'date-view-mode' => 'decades', 'date-use-current' => false, 'date-view-date' => Date.new(1950, 1, 1).to_s })
11
9
  .col-12.col-sm-6= fields.text_field(:birth_place)
12
- .legal_person.row
13
- = form.fields_for(:legal_person, person.legal_person || EgovUtils::LegalPerson.new) do |fields|
14
- .col-12= fields.text_field(:name)
15
- .col-12.col-sm-6= fields.text_field(:ico)
16
- .col-12.col-sm-6= fields.select2 :legal_form, list_values_for_select(azahara_attribute_for(EgovUtils::LegalPerson, 'legal_form'))
10
+ -# .legal_person.row
11
+ -# = form.fields_for(:legal_person, person.legal_person || EgovUtils::LegalPerson.new) do |fields|
12
+ -# .col-12= fields.text_field(:name)
13
+ -# .col-12.col-sm-6= fields.text_field(:ico)
14
+ -# .col-12.col-sm-6= fields.select2 :legal_form, list_values_for_select(azahara_attribute_for(EgovUtils::LegalPerson, 'legal_form'))
17
15
  .row
18
16
  .col-12
19
17
  = form.fields_for(:residence, person.residence || EgovUtils::Address.new) do |fields|
@@ -1,36 +1,49 @@
1
- .person-form
2
- .row
3
- .col-12= form.select :person_type, enum_values_for_select(person.class, :person_type), {}, class: 'person-type-toggle'
4
- .natural-person-row.identification-form.natural_person.row
5
- .col-12
6
- .card
7
- .card-header Ztotožnění fyzické osoby
8
- .card-body
9
- .form
10
- .form-group
11
- = label_tag 'firstname', 'Jméno'
12
- = text_field_tag :firstname, {}, class: 'form-control'
13
- .form-group
14
- = label_tag 'lastname', 'Příjmení'
15
- = text_field_tag :lastname, {}, class: 'form-control'
16
- .form-group
17
- = label_tag 'birth_date', 'Datum narození'
18
- = date_field_tag :birth_date, {}, class: 'form-control'
19
- = link_to 'Vyhledat', {}, class: 'btn btn-primary'
20
- .legal-person-row.identification-form.legal_person.row
21
- .col-12
22
- .card
23
- .card-header Ztotožnění právnické osoby
24
- .card-body
25
- .form
26
- .form-group
27
- = label_tag 'ico', 'IČO'
28
- = text_field_tag :ico, {}, class: 'form-control'
29
- = link_to 'Vyhledat', nil, class: 'btn btn-primary'
30
- = form.hidden_field :remote_id
1
+ %div{id: key}
2
+ .person-form
3
+ .row
4
+ .col-12= form.select :person_type, enum_values_for_select(person.class, :person_type), {}, class: 'person-type-toggle'
5
+ .natural-person-row.identification-form.natural_person.row
6
+ .col-12
7
+ .card
8
+ .card-header Ztotožnění fyzické osoby
9
+ .card-body
10
+ .form
11
+ .form-group
12
+ = label_tag 'firstname', 'Jméno'
13
+ = text_field_tag :firstname, {}, class: 'form-control'
14
+ .form-group
15
+ = label_tag 'lastname', 'Příjmení'
16
+ = text_field_tag :lastname, {}, class: 'form-control'
17
+ .form-group
18
+ = label_tag 'birth_date', 'Datum narození'
19
+ = date_field_tag :birth_date, {}, class: 'form-control'
20
+ = link_to 'Vyhledat', {}, class: 'btn btn-primary'
21
+ .legal_person
22
+ .row
23
+ = form.fields_for(:legal_person, person.legal_person || EgovUtils::LegalPerson.new) do |fields|
24
+ .col-12= fields.text_field(:name)
25
+ .col-12.col-sm-6= fields.text_field(:ico)
26
+ .col-12.col-sm-6= fields.select2 :legal_form, list_values_for_select(azahara_attribute_for(EgovUtils::LegalPerson, 'legal_form'))
27
+ .row
28
+ .col-12
29
+ = form.fields_for(:residence, person.residence || EgovUtils::Address.new) do |fields|
30
+ = render 'egov_utils/addresses/form', form: fields, address: fields.object
31
+
32
+ -# .legal-person-row.identification-form.legal_person.row
33
+ -# .col-12
34
+ -# .card
35
+ -# .card-header Ztotožnění právnické osoby
36
+ -# .card-body
37
+ -# .form
38
+ -# .form-group
39
+ -# = label_tag 'ico', 'IČO'
40
+ -# = text_field_tag :ico, {}, class: 'form-control'
41
+ -# = link_to 'Vyhledat', nil, class: 'btn btn-primary'
42
+ = form.hidden_field :remote_id
31
43
 
32
44
  :javascript
33
- $('.natural-person-row a').on('click', function(e) {
45
+ var key = "#{key}";
46
+ $('body').on('click', `\#${key} .natural-person-row a`, function(e) {
34
47
  e.preventDefault();
35
48
  $this = $(this);
36
49
  $npr = $this.closest('.natural-person-row');
@@ -39,9 +52,11 @@
39
52
  firstname: $npr.find('input[name=firstname]').val(),
40
53
  lastname: $npr.find('input[name=lastname]').val(),
41
54
  birth_date: $npr.find('input[name=birth_date]').val(),
42
- birth_place: $npr.find('input[name=birth_place]').val()
55
+ birth_place: $npr.find('select[name=birth_place]').val()
43
56
  }
44
57
 
58
+ selected_birth_place = $npr.find('select[name=birth_place] option:selected').text().split('(')[0].trim();
59
+
45
60
  $.ajax({
46
61
  url: '/internals/iszr/search',
47
62
  data: {
@@ -66,21 +81,58 @@
66
81
 
67
82
  if(error_kind == 'not_found') {
68
83
  $icon = $('<i>').addClass('fa').addClass('fa-times');
69
- $error_div = $('<div>').addClass('alert').addClass('alert-danger').append($icon).append(' Nenalezeno');
70
- $this.closest('.card-body').prepend($error_div);
84
+ $error_div = $('<div>').addClass('alert').addClass('alert-danger').append($icon).append(' Dle zadaných údajů nebyla nalezena žádná osoba, pokračujte, prosím, ručním zadáním údajů');
85
+
86
+ $new_person_form = $this.closest('.new-person-form');
87
+ $old_person_form = $new_person_form.siblings('.old-person-form');
88
+
89
+ $old_person_form.prepend($error_div);
90
+ $new_person_form.addClass('hidden').hide();
91
+ $old_person_form.removeClass('hidden').show();
92
+
93
+ eGovUtilities.initPeople($old_person_form);
94
+
95
+ // Fill in the form with the data
96
+ $old_person_form.find("input[name*='[firstname]']").val(form_data.firstname);
97
+ $old_person_form.find("input[name*='[lastname]']").val(form_data.lastname);
98
+ $old_person_form.find("input[name*='[birth_place]']").val(selected_birth_place);
99
+ $old_person_form.find("input[name*='[birth_date]']").val(form_data.birth_date);
71
100
  }
72
101
  else if(error_kind == 'multiple_results_found') {
73
102
  $form_group = $('<div>').addClass('form-group');
74
103
  $label = $('<label>').attr('for', 'birth_place').text('Místo narození');
75
- $input = $('<input>').attr('type', 'text').attr('name', 'birth_place').addClass('form-control');
104
+ $input = $('<select>').attr('name', 'birth_place').addClass('form-control');
76
105
  $form_group.append($label).append($input);
106
+ $input.select2({
107
+ ajax: {
108
+ url: '/internals/towns',
109
+ data: function (params) {
110
+ var query = {
111
+ term: params.term
112
+ }
113
+
114
+ return query;
115
+ },
116
+ processResults: function(data) {
117
+ return {
118
+ results: data.towns.map(function(val) {
119
+ return {
120
+ id: val.id,
121
+ text: `${val.name} (okr. ${val.district_name})`
122
+ }
123
+ })
124
+ }
125
+ }
126
+ }
127
+ });
128
+
77
129
  $npr.find('.card-body .form .btn').before($form_group);
78
130
 
79
131
  $icon = $('<i>').addClass('fa').addClass('fa-times');
80
132
  $error_div = $('<div>').addClass('alert').addClass('alert-danger').append($icon).append(' Nalezeno více osob, zadejte místo narození');
81
133
  $npr.find('.card-body').prepend($error_div);
82
134
  }
83
- else if(error_kind == 'extended_search_multiple_records_found') {
135
+ else if(error_kind == 'extended_search_multiple_records_found' || error_kind == 'extended_search_not_found') {
84
136
  $icon = $('<i>').addClass('fa').addClass('fa-times');
85
137
  $error_div = $('<div>').addClass('alert').addClass('alert-danger').append($icon).append(' Nalezeno více osob, pokračujte, prosím, ručním zadáním údajů');
86
138
 
@@ -92,13 +144,13 @@
92
144
  // Fill in the form with the data
93
145
  $('.old-person-form').find("input[name*='[firstname]']").val(form_data.firstname);
94
146
  $('.old-person-form').find("input[name*='[lastname]']").val(form_data.lastname);
95
- $('.old-person-form').find("input[name*='[birth_place]']").val(form_data.birth_place);
147
+ $('.old-person-form').find("input[name*='[birth_place]']").val(selected_birth_place);
96
148
  $('.old-person-form').find("input[name*='[birth_date]']").val(form_data.birth_date);
97
149
  }
98
150
  }
99
151
  });
100
152
  });
101
- $('.legal-person-row a').on('click', function(e) {
153
+ $('body').on('click', '.legal-person-row a', function(e) {
102
154
  e.preventDefault();
103
155
  $this = $(this);
104
156
  $lpr = $this.closest('.legal-person-row');
@@ -3,6 +3,7 @@
3
3
  = bootstrap_form_tag(url: egov_utils.users_path, method: :get, layout: :inline) do |f|
4
4
  .form-group
5
5
  = f.text_field :search, value: params[:search], label: false, placeholder: t('label_search'), skip_label: true
6
+ = f.hidden_field :default_scope, value: params[:default_scope]
6
7
  = f.submit 'Vyhledat', class: 'btn btn-primary btn-sm'
7
8
 
8
9
  %table.table.table-striped