This commit is contained in:
Martin Lensment 2014-09-16 18:02:26 +03:00
parent 660eef414e
commit 1dc2a7e23f
6 changed files with 4 additions and 143 deletions

View file

@ -1,48 +0,0 @@
class Admin::AdminContactsController < ApplicationController
before_action :set_domain
before_action :set_contact, only: [:destroy]
def new; end
def create
contact = Contact.find_by(id: params[:contact_id])
unless contact
flash.now[:alert] = I18n.t('shared.contact_was_not_found')
render 'new' and return
end
if @domain.admin_contacts.exists?(contact)
flash.now[:alert] = I18n.t('shared.contact_already_exists')
render 'new' and return
end
@domain.admin_contacts << contact
flash[:notice] = I18n.t('shared.contact_added')
redirect_to [:admin, @domain]
end
def destroy
unless @domain.can_remove_admin_contact?
flash[:alert] = @domain.errors[:admin_contacts].first
redirect_to [:admin, @domain] and return
end
if @domain.admin_contacts.delete(@contact)
flash[:notice] = I18n.t('shared.contact_detached')
else
flash[:alert] = I18n.t('shared.failed_to_detach_contact')
end
redirect_to [:admin, @domain]
end
private
def set_domain
@domain = Domain.find(params[:domain_id])
end
def set_contact
@contact = Contact.find(params[:id])
end
end

View file

@ -32,7 +32,7 @@ class Admin::DomainContactsController < ApplicationController
@domain.deleting_tech_contact = true if @domain_contact.tech?
if @domain.save
flash[:notice] = I18n.t('shared.contact_deleted')
flash[:notice] = I18n.t('shared.contact_detached')
else
flash[:alert] = @domain.errors.first[1]
end

View file

@ -1,44 +0,0 @@
class Admin::TechContactsController < ApplicationController
before_action :set_domain
before_action :set_contact, only: [:destroy]
def new; end
def create
contact = Contact.find_by(id: params[:contact_id])
unless contact
flash.now[:alert] = I18n.t('shared.contact_was_not_found')
render 'new' and return
end
if @domain.tech_contacts.exists?(contact)
flash.now[:alert] = I18n.t('shared.contact_already_exists')
render 'new' and return
end
@domain.tech_contacts << contact
flash[:notice] = I18n.t('shared.contact_added')
redirect_to [:admin, @domain]
end
def destroy
if @domain.tech_contacts.delete(@contact)
flash[:notice] = I18n.t('shared.contact_detached')
else
flash[:alert] = I18n.t('shared.failed_to_detach_contact')
end
redirect_to [:admin, @domain]
end
private
def set_domain
@domain = Domain.find(params[:domain_id])
end
def set_contact
@contact = Contact.find(params[:id])
end
end

View file

@ -51,6 +51,9 @@ class Domain < ActiveRecord::Base
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!
write_attribute(:name, SimpleIDN.to_unicode(value))
@ -87,12 +90,6 @@ class Domain < ActiveRecord::Base
errors.add(:nameservers, :greater_than_or_equal_to, { count: min })
end
def can_remove_admin_contact?
return true if admin_contacts.length > 1
errors.add(:admin_contacts, :less_than_or_equal_to, { count: 1 })
false
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

View file

@ -1,22 +0,0 @@
.row
.col-sm-6
%h2.text-center-xs
= "#{t('shared.new_admin_contact')}"
.col-sm-6
%h2.text-right.text-center-xs
= link_to(t('shared.back_to_domain'), [:admin, @domain], class: 'btn btn-default')
%hr
= form_tag(admin_domain_admin_contacts_path(@domain)) do |f|
.row
.col-md-12
.form-group.has-feedback
.form-group.has-feedback
= label_tag :tech_contact
= text_field_tag(:domain_contact, params[:domain_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
= hidden_field_tag(:contact_id, params[:contact_id], class: 'js-contact-id')
.row
.col-md-12.text-right
= button_tag(t('shared.save'), class: 'btn btn-primary')

View file

@ -1,22 +0,0 @@
.row
.col-sm-6
%h2.text-center-xs
= "#{t('shared.new_tech_contact')}"
.col-sm-6
%h2.text-right.text-center-xs
= link_to(t('shared.back_to_domain'), [:admin, @domain], class: 'btn btn-default')
%hr
= form_tag(admin_domain_tech_contacts_path(@domain)) do |f|
.row
.col-md-12
.form-group.has-feedback
.form-group.has-feedback
= label_tag :domain_contact, t('shared.tech_contact')
= text_field_tag(:domain_contact, params[:domain_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
= hidden_field_tag(:contact_id, params[:contact_id], class: 'js-contact-id')
.row
.col-md-12.text-right
= button_tag(t('shared.save'), class: 'btn btn-primary')