diff --git a/app/models/domain.rb b/app/models/domain.rb index 1e9aba969..99b3e5cbe 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -36,7 +36,7 @@ class Domain < ActiveRecord::Base validates :name_dirty, domain_name: true, uniqueness: true validates :period, numericality: { only_integer: true } - validates :owner_contact, presence: true + validates :owner_contact, :registrar, presence: true validate :validate_period validate :validate_nameservers_count @@ -44,25 +44,6 @@ class Domain < ActiveRecord::Base validate :validate_tech_contacts_uniqueness, if: :new_record? validate :validate_admin_contacts_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) value.strip! @@ -82,30 +63,6 @@ class Domain < ActiveRecord::Base end ### 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 sg = SettingGroup.domain_validation 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 } next unless existing.length > 1 validated << ns.hostname - errors.add(:'nameservers.hostname', 'duplicate') + errors.add(:nameservers, :invalid) if errors[:nameservers].blank? ns.errors.add(:hostname, :taken) end end @@ -146,7 +103,7 @@ class Domain < ActiveRecord::Base existing = contacts.select { |x| x.contact_id == dc.contact_id } next unless existing.length > 1 validated << dc - errors.add(:'domain_contacts.contact', 'duplicate') + errors.add(:domain_contacts, :invalid) if errors[:domain_contacts].blank? dc.errors.add(:contact, :taken) end end @@ -194,6 +151,16 @@ class Domain < ActiveRecord::Base !errors.keys.any? { |x| x.match(/#{name.to_s}/) } 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 def to_s diff --git a/app/views/admin/domains/_form.haml b/app/views/admin/domains/_form.haml index 5f82c322e..5dd5c5611 100644 --- a/app/views/admin/domains/_form.haml +++ b/app/views/admin/domains/_form.haml @@ -1,14 +1,9 @@ = form_for([:admin, @domain]) do |f| - .row - .col-md-12 - = render 'admin/shared/errors', object: f.object - - if f.object.errors.any? - %hr .row .col-md-12 / Nav 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} %a{"data-toggle" => "tab", :href => "#general-tab", :role => "tab"}= t('shared.general') - li_class = @domain.associations_valid?(:nameservers) ? nil : 'error-tab' diff --git a/app/views/admin/domains/form_partials/_contacts.haml b/app/views/admin/domains/form_partials/_contacts.haml index 341e68eac..44543bcb3 100644 --- a/app/views/admin/domains/form_partials/_contacts.haml +++ b/app/views/admin/domains/form_partials/_contacts.haml @@ -1,3 +1,6 @@ += render 'admin/shared/errors_array', errors: @domain.errors[:domain_contacts] +- if @domain.errors[:domain_contacts].any? + %hr #domain_contacts = f.fields_for :domain_contacts do |contact_fields| .panel.panel-default diff --git a/app/views/admin/domains/form_partials/_general.haml b/app/views/admin/domains/form_partials/_general.haml index 0f8e185f5..68fe07cf3 100644 --- a/app/views/admin/domains/form_partials/_general.haml +++ b/app/views/admin/domains/form_partials/_general.haml @@ -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 .col-md-6 .form-group diff --git a/app/views/admin/domains/form_partials/_nameservers.haml b/app/views/admin/domains/form_partials/_nameservers.haml index 12770e2a9..aa9d7f831 100644 --- a/app/views/admin/domains/form_partials/_nameservers.haml +++ b/app/views/admin/domains/form_partials/_nameservers.haml @@ -1,3 +1,6 @@ += render 'admin/shared/errors_array', errors: @domain.errors[:nameservers] +- if @domain.errors[:nameservers].any? + %hr #nameservers = f.fields_for :nameservers do |ns_fields| .panel.panel-default diff --git a/app/views/admin/domains/form_partials/_statuses.haml b/app/views/admin/domains/form_partials/_statuses.haml index 1d78704c2..951c009fb 100644 --- a/app/views/admin/domains/form_partials/_statuses.haml +++ b/app/views/admin/domains/form_partials/_statuses.haml @@ -1,3 +1,6 @@ += render 'admin/shared/errors_array', errors: @domain.errors[:domain_statuses] +- if @domain.errors[:domain_statuses].any? + %hr #domain_statuses = f.fields_for :domain_statuses do |status_fields| .panel.panel-default diff --git a/app/views/admin/shared/_errors_array.haml b/app/views/admin/shared/_errors_array.haml new file mode 100644 index 000000000..464c94d61 --- /dev/null +++ b/app/views/admin/shared/_errors_array.haml @@ -0,0 +1,4 @@ +- if errors.any? + - errors.each do |err| + = err + %br