mirror of
https://github.com/internetee/registry.git
synced 2025-07-20 09:46:09 +02:00
Refactor
This commit is contained in:
parent
168e6d2a01
commit
660eef414e
8 changed files with 55 additions and 18 deletions
|
@ -3,13 +3,20 @@ class Admin::DomainContactsController < ApplicationController
|
|||
before_action :set_domain_contact, only: [:destroy]
|
||||
|
||||
def new
|
||||
@domain_contact = @domain.domain_contacts.build
|
||||
@domain_contact = @domain.domain_contacts.build(contact_type: params[:type])
|
||||
end
|
||||
|
||||
def create
|
||||
@domain.adding_admin_contact = true
|
||||
@domain_contact = @domain.domain_contacts.build(domain_contact_params)
|
||||
|
||||
unless @domain_contact.contact
|
||||
flash.now[:alert] = I18n.t('shared.contact_was_not_found')
|
||||
render 'new' and return
|
||||
end
|
||||
|
||||
@domain.adding_admin_contact = true if @domain_contact.admin?
|
||||
@domain.adding_admin_contact = true if @domain_contact.tech?
|
||||
|
||||
if @domain.save
|
||||
flash[:notice] = I18n.t('shared.contact_added')
|
||||
redirect_to [:admin, @domain]
|
||||
|
@ -20,13 +27,14 @@ class Admin::DomainContactsController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
@domain.deleting_admin_contact = true
|
||||
@domain.domain_contacts.select { |x| x == @domain_contact }[0].mark_for_destruction
|
||||
@domain.deleting_admin_contact = true if @domain_contact.admin?
|
||||
@domain.deleting_tech_contact = true if @domain_contact.tech?
|
||||
|
||||
if @domain.save
|
||||
flash[:notice] = I18n.t('shared.contact_deleted')
|
||||
else
|
||||
flash[:alert] = I18n.t('shared.fail')
|
||||
flash[:alert] = @domain.errors.first[1]
|
||||
end
|
||||
|
||||
redirect_to [:admin, @domain]
|
||||
|
|
|
@ -6,8 +6,6 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
has_many :domain_contacts, dependent: :delete_all, autosave: true
|
||||
|
||||
accepts_nested_attributes_for :domain_contacts, allow_destroy: true
|
||||
|
||||
has_many :tech_contacts, -> do
|
||||
where(domain_contacts: { contact_type: DomainContact::TECH })
|
||||
end, through: :domain_contacts, source: :contact
|
||||
|
@ -50,6 +48,9 @@ class Domain < ActiveRecord::Base
|
|||
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
|
||||
|
||||
def name=(value)
|
||||
value.strip!
|
||||
write_attribute(:name, SimpleIDN.to_unicode(value))
|
||||
|
|
|
@ -6,6 +6,17 @@ class DomainContact < ActiveRecord::Base
|
|||
ADMIN = 'admin'
|
||||
TYPES = [TECH, ADMIN]
|
||||
|
||||
# TODO: Fix EPP problems
|
||||
validates :contact, uniqueness: { scope: [:domain_id, :contact_type] }
|
||||
|
||||
scope :admin, -> { where(contact_type: ADMIN) }
|
||||
scope :tech, -> { where(contact_type: TECH) }
|
||||
|
||||
def admin?
|
||||
contact_type == ADMIN
|
||||
end
|
||||
|
||||
def tech?
|
||||
contact_type == TECH
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,6 +7,11 @@
|
|||
= link_to(t('shared.back_to_domain'), [:admin, @domain], class: 'btn btn-default')
|
||||
%hr
|
||||
= form_for([:admin, @domain, @domain_contact]) do |f|
|
||||
= render 'admin/shared/errors', object: @domain
|
||||
/ = render 'admin/shared/errors', object: f.object
|
||||
|
||||
- if @domain.errors.any?
|
||||
%hr
|
||||
.row
|
||||
.col-md-6
|
||||
.form-group
|
||||
|
@ -14,7 +19,7 @@
|
|||
= f.select :contact_type, options_for_select(DomainContact::TYPES, @domain_contact.contact_type), {}, {class: 'form-control'}
|
||||
.col-md-6
|
||||
.form-group.has-feedback
|
||||
= f.label :contact
|
||||
= label_tag :contact
|
||||
= text_field_tag(:contact, params[:contact], class: 'form-control js-contact-typeahead', placeholder: t('shared.contact_code'), autocomplete: 'off')
|
||||
%span.glyphicon.glyphicon-ok.form-control-feedback.js-typeahead-ok.hidden
|
||||
%span.glyphicon.glyphicon-remove.form-control-feedback.js-typeahead-remove
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
.pull-left
|
||||
= t('shared.admin_contacts')
|
||||
.pull-right
|
||||
= link_to(t('shared.add'), new_admin_domain_admin_contact_path(@domain), class: 'btn btn-primary btn-xs')
|
||||
= link_to(t('shared.add'), new_admin_domain_domain_contact_path(@domain, type: DomainContact::ADMIN), class: 'btn btn-primary btn-xs')
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
%thead
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
.pull-left
|
||||
= t('shared.tech_contacts')
|
||||
.pull-right
|
||||
= link_to(t('shared.add'), new_admin_domain_tech_contact_path(@domain), class: 'btn btn-primary btn-xs')
|
||||
= link_to(t('shared.add'), new_admin_domain_domain_contact_path(@domain, type: DomainContact::TECH), class: 'btn btn-primary btn-xs')
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
%thead
|
||||
|
@ -13,13 +13,13 @@
|
|||
%th{class: 'col-xs-5'}= t('shared.email')
|
||||
%th{class: 'col-xs-3'}= t('shared.action')
|
||||
%tbody
|
||||
- @domain.tech_contacts.each do |x|
|
||||
- @domain.domain_contacts.tech.each do |x|
|
||||
%tr
|
||||
%td= link_to(x, root_path)
|
||||
%td= x.email
|
||||
%td= link_to(x.contact, root_path)
|
||||
%td= x.contact.email
|
||||
%td
|
||||
= link_to(t('shared.edit'), root_path, class: 'btn btn-primary btn-xs')
|
||||
= link_to(t('shared.detach'), admin_domain_tech_contact_path(@domain, x), method: :delete, data: { confirm: t('shared.are_you_sure') }, class: 'btn btn-warning btn-xs')
|
||||
= link_to(t('shared.detach'), admin_domain_domain_contact_path(@domain, x), method: :delete, data: { confirm: t('shared.are_you_sure') }, class: 'btn btn-warning btn-xs')
|
||||
- if @domain.errors.messages[:tech_contacts]
|
||||
%tfoot
|
||||
- @domain.errors.messages[:tech_contacts].each do |x|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue