mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Display correct errors on different tabs
This commit is contained in:
parent
93930a1243
commit
df5f987551
7 changed files with 32 additions and 52 deletions
|
@ -36,7 +36,7 @@ class Domain < ActiveRecord::Base
|
||||||
|
|
||||||
validates :name_dirty, domain_name: true, uniqueness: true
|
validates :name_dirty, domain_name: true, uniqueness: true
|
||||||
validates :period, numericality: { only_integer: true }
|
validates :period, numericality: { only_integer: true }
|
||||||
validates :owner_contact, presence: true
|
validates :owner_contact, :registrar, presence: true
|
||||||
|
|
||||||
validate :validate_period
|
validate :validate_period
|
||||||
validate :validate_nameservers_count
|
validate :validate_nameservers_count
|
||||||
|
@ -44,25 +44,6 @@ class Domain < ActiveRecord::Base
|
||||||
validate :validate_tech_contacts_uniqueness, if: :new_record?
|
validate :validate_tech_contacts_uniqueness, if: :new_record?
|
||||||
validate :validate_admin_contacts_uniqueness, if: :new_record?
|
validate :validate_admin_contacts_uniqueness, if: :new_record?
|
||||||
validate :validate_domain_statuses_uniqueness, if: :new_record?
|
validate :validate_domain_statuses_uniqueness, if: :new_record?
|
||||||
# validates_associated :nameservers
|
|
||||||
|
|
||||||
attr_accessor :adding_admin_contact
|
|
||||||
validate :validate_admin_contacts_max_count, if: :adding_admin_contact
|
|
||||||
|
|
||||||
attr_accessor :deleting_admin_contact
|
|
||||||
validate :validate_admin_contacts_min_count, if: :deleting_admin_contact
|
|
||||||
|
|
||||||
attr_accessor :adding_nameserver
|
|
||||||
validate :validate_nameserver_max_count, if: :adding_nameserver
|
|
||||||
|
|
||||||
attr_accessor :deleting_nameserver
|
|
||||||
validate :validate_nameserver_min_count, if: :deleting_nameserver
|
|
||||||
|
|
||||||
attr_accessor :adding_tech_contact
|
|
||||||
validate :validate_tech_contacts_max_count, if: :adding_tech_contact
|
|
||||||
|
|
||||||
attr_accessor :deleting_tech_contact
|
|
||||||
validate :validate_tech_contacts_min_count, if: :deleting_tech_contact
|
|
||||||
|
|
||||||
def name=(value)
|
def name=(value)
|
||||||
value.strip!
|
value.strip!
|
||||||
|
@ -82,30 +63,6 @@ class Domain < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
### VALIDATIONS ###
|
### VALIDATIONS ###
|
||||||
def validate_admin_contacts_max_count
|
|
||||||
return if admin_contacts_count < 4
|
|
||||||
errors.add(:admin_contacts, :out_of_range)
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate_admin_contacts_min_count
|
|
||||||
return if admin_contacts_count > 2
|
|
||||||
errors.add(:admin_contacts, :out_of_range)
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate_nameserver_max_count
|
|
||||||
sg = SettingGroup.domain_validation
|
|
||||||
max = sg.setting(:ns_max_count).value.to_i
|
|
||||||
return if nameservers.length <= max
|
|
||||||
errors.add(:nameservers, :less_than_or_equal_to, { count: max })
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate_nameserver_min_count
|
|
||||||
sg = SettingGroup.domain_validation
|
|
||||||
min = sg.setting(:ns_min_count).value.to_i
|
|
||||||
return if nameservers.reject(&:marked_for_destruction?).length >= min
|
|
||||||
errors.add(:nameservers, :greater_than_or_equal_to, { count: min })
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate_nameservers_count
|
def validate_nameservers_count
|
||||||
sg = SettingGroup.domain_validation
|
sg = SettingGroup.domain_validation
|
||||||
min, max = sg.setting(:ns_min_count).value.to_i, sg.setting(:ns_max_count).value.to_i
|
min, max = sg.setting(:ns_min_count).value.to_i, sg.setting(:ns_max_count).value.to_i
|
||||||
|
@ -125,7 +82,7 @@ class Domain < ActiveRecord::Base
|
||||||
existing = nameservers.select { |x| x.hostname == ns.hostname }
|
existing = nameservers.select { |x| x.hostname == ns.hostname }
|
||||||
next unless existing.length > 1
|
next unless existing.length > 1
|
||||||
validated << ns.hostname
|
validated << ns.hostname
|
||||||
errors.add(:'nameservers.hostname', 'duplicate')
|
errors.add(:nameservers, :invalid) if errors[:nameservers].blank?
|
||||||
ns.errors.add(:hostname, :taken)
|
ns.errors.add(:hostname, :taken)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -146,7 +103,7 @@ class Domain < ActiveRecord::Base
|
||||||
existing = contacts.select { |x| x.contact_id == dc.contact_id }
|
existing = contacts.select { |x| x.contact_id == dc.contact_id }
|
||||||
next unless existing.length > 1
|
next unless existing.length > 1
|
||||||
validated << dc
|
validated << dc
|
||||||
errors.add(:'domain_contacts.contact', 'duplicate')
|
errors.add(:domain_contacts, :invalid) if errors[:domain_contacts].blank?
|
||||||
dc.errors.add(:contact, :taken)
|
dc.errors.add(:contact, :taken)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -194,6 +151,16 @@ class Domain < ActiveRecord::Base
|
||||||
!errors.keys.any? { |x| x.match(/#{name.to_s}/) }
|
!errors.keys.any? { |x| x.match(/#{name.to_s}/) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def general_tab_errors
|
||||||
|
collect_errors_with_keys([:name_dirty, :period, :period_unit, :registrar, :owner_contact])
|
||||||
|
end
|
||||||
|
|
||||||
|
def collect_errors_with_keys(keys)
|
||||||
|
res = []
|
||||||
|
errors.each { |attr, err| res << err if keys.include?(attr) }
|
||||||
|
res
|
||||||
|
end
|
||||||
|
|
||||||
## SHARED
|
## SHARED
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
= form_for([:admin, @domain]) do |f|
|
= form_for([:admin, @domain]) do |f|
|
||||||
.row
|
|
||||||
.col-md-12
|
|
||||||
= render 'admin/shared/errors', object: f.object
|
|
||||||
- if f.object.errors.any?
|
|
||||||
%hr
|
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
/ Nav tabs
|
/ Nav tabs
|
||||||
%ul.nav.nav-tabs{:role => "tablist", id: 'tabs'}
|
%ul.nav.nav-tabs{:role => "tablist", id: 'tabs'}
|
||||||
- li_class = @domain.parent_valid? ? nil : 'error-tab'
|
- li_class = @domain.general_tab_errors.empty? ? nil : 'error-tab'
|
||||||
%li.active{class: li_class}
|
%li.active{class: li_class}
|
||||||
%a{"data-toggle" => "tab", :href => "#general-tab", :role => "tab"}= t('shared.general')
|
%a{"data-toggle" => "tab", :href => "#general-tab", :role => "tab"}= t('shared.general')
|
||||||
- li_class = @domain.associations_valid?(:nameservers) ? nil : 'error-tab'
|
- li_class = @domain.associations_valid?(:nameservers) ? nil : 'error-tab'
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
= render 'admin/shared/errors_array', errors: @domain.errors[:domain_contacts]
|
||||||
|
- if @domain.errors[:domain_contacts].any?
|
||||||
|
%hr
|
||||||
#domain_contacts
|
#domain_contacts
|
||||||
= f.fields_for :domain_contacts do |contact_fields|
|
= f.fields_for :domain_contacts do |contact_fields|
|
||||||
.panel.panel-default
|
.panel.panel-default
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
.row
|
||||||
|
.col-md-12
|
||||||
|
= render 'admin/shared/errors_array', errors: @domain.general_tab_errors
|
||||||
|
- if @domain.general_tab_errors.any?
|
||||||
|
%hr
|
||||||
.row
|
.row
|
||||||
.col-md-6
|
.col-md-6
|
||||||
.form-group
|
.form-group
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
= render 'admin/shared/errors_array', errors: @domain.errors[:nameservers]
|
||||||
|
- if @domain.errors[:nameservers].any?
|
||||||
|
%hr
|
||||||
#nameservers
|
#nameservers
|
||||||
= f.fields_for :nameservers do |ns_fields|
|
= f.fields_for :nameservers do |ns_fields|
|
||||||
.panel.panel-default
|
.panel.panel-default
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
= render 'admin/shared/errors_array', errors: @domain.errors[:domain_statuses]
|
||||||
|
- if @domain.errors[:domain_statuses].any?
|
||||||
|
%hr
|
||||||
#domain_statuses
|
#domain_statuses
|
||||||
= f.fields_for :domain_statuses do |status_fields|
|
= f.fields_for :domain_statuses do |status_fields|
|
||||||
.panel.panel-default
|
.panel.panel-default
|
||||||
|
|
4
app/views/admin/shared/_errors_array.haml
Normal file
4
app/views/admin/shared/_errors_array.haml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
- if errors.any?
|
||||||
|
- errors.each do |err|
|
||||||
|
= err
|
||||||
|
%br
|
Loading…
Add table
Add a link
Reference in a new issue