Add contact show

This commit is contained in:
Martin Lensment 2014-09-18 18:01:32 +03:00
parent 1777a0e572
commit 2d2a12b7d0
12 changed files with 131 additions and 6 deletions

View file

@ -1,4 +1,5 @@
class Admin::ContactsController < ApplicationController class Admin::ContactsController < ApplicationController
before_action :set_contact, only: [:show]
def index def index
@q = Contact.search(params[:q]) @q = Contact.search(params[:q])
@ -8,4 +9,10 @@ class Admin::ContactsController < ApplicationController
def search def search
render json: Contact.search_by_query(params[:q]) render json: Contact.search_by_query(params[:q])
end end
private
def set_contact
@contact = Contact.find(params[:id])
end
end end

View file

@ -3,15 +3,19 @@ class Admin::DomainsController < ApplicationController
before_action :verify_deletion, only: [:destroy] before_action :verify_deletion, only: [:destroy]
def new def new
@domain = Domain.new owner_contact = Contact.find(params[:owner_contact_id]) if params[:owner_contact_id]
@domain = Domain.new(owner_contact: owner_contact)
params[:domain_owner_contact] = owner_contact
end end
def create def create
@domain = Domain.new(domain_params) @domain = Domain.new(domain_params)
if @domain.save if @domain.save
flash[:notice] = I18n.t('shared.domain_added')
redirect_to [:admin, @domain] redirect_to [:admin, @domain]
else else
flash.now[:alert] = I18n.t('shared.failed_to_add_domain')
render 'new' render 'new'
end end
end end
@ -27,7 +31,7 @@ class Admin::DomainsController < ApplicationController
def edit def edit
params[:registrar] = @domain.registrar params[:registrar] = @domain.registrar
params[:owner_contact] = @domain.owner_contact_code params[:domain_owner_contact] = @domain.owner_contact
end end
def update def update

View file

@ -26,6 +26,11 @@ class Contact < ActiveRecord::Base
validates :code, uniqueness: { message: :epp_id_taken } validates :code, uniqueness: { message: :epp_id_taken }
delegate :name, to: :international_address delegate :name, to: :international_address
delegate :country, to: :address, prefix: true
delegate :city, to: :address, prefix: true
delegate :street, to: :address, prefix: true
delegate :zip, to: :address, prefix: true
delegate :org_name, to: :address, prefix: true
IDENT_TYPE_ICO = 'ico' IDENT_TYPE_ICO = 'ico'
IDENT_TYPES = [ IDENT_TYPES = [
@ -75,7 +80,7 @@ class Contact < ActiveRecord::Base
# Find a way to use self.domains with contact # Find a way to use self.domains with contact
def domains_owned def domains_owned
Domain.find_by(owner_contact_id: id) Domain.where(owner_contact_id: id)
end end
def relations_with_domain? def relations_with_domain?

View file

@ -1,2 +1,5 @@
class Country < ActiveRecord::Base class Country < ActiveRecord::Base
def to_s
name
end
end end

View file

@ -0,0 +1,19 @@
.panel.panel-default
.panel-heading
%h3.panel-title= t('shared.address')
.panel-body
%dl.dl-horizontal
%dt= t('shared.country')
%dd= @contact.address_country
%dt= t('shared.city')
%dd= @contact.address_city
%dt= t('shared.street')
%dd= @contact.address_street
%dt= t('shared.zip')
%dd= @contact.address_zip
%dt= t('shared.org_name')
%dd= @contact.address_org_name

View file

@ -0,0 +1,23 @@
#contacts.panel.panel-default
.panel-heading.clearfix
.pull-left
= t('shared.domains')
.pull-right
= link_to(t('shared.add'), new_admin_domain_path(owner_contact_id: @contact), class: 'btn btn-primary btn-xs')
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead
%tr
%th{class: 'col-xs-3'}= t('shared.domain_name')
%th{class: 'col-xs-3'}= t('shared.registrar')
%th{class: 'col-xs-3'}= t('shared.valid_to')
%th{class: 'col-xs-3'}= t('shared.action')
%tbody
- @contact.domains_owned.each do |x|
%tr
%td= link_to(x.name, [:admin, x])
%td= link_to(x.registrar, [:admin, x.registrar])
%td= l(x.valid_to, format: :short)
%td
= link_to(t('shared.edit'), edit_admin_domain_path(x), class: 'btn btn-primary btn-xs')
= link_to(t('shared.delete'), admin_domain_path(x), method: :delete, data: { confirm: t('shared.are_you_sure') }, class: 'btn btn-danger btn-xs')

View file

@ -0,0 +1,29 @@
.panel.panel-default
.panel-heading
%h3.panel-title= t('shared.general')
.panel-body
%dl.dl-horizontal
%dt= t('shared.name')
%dd= @contact.name
%dt= t('shared.code')
%dd= @contact.code
%dt= t('shared.ident')
%dd= @contact.ident
%dt= t('shared.ident_type')
%dd= @contact.ident_type
%dt= t('shared.email')
%dd= @contact.email
%dt= t('shared.phone')
%dd= @contact.phone
- if @contact.fax
%dt= t('shared.fax')
%dd= @contact.fax
%dt= t('shared.password')
%dd= @contact.auth_info

View file

@ -0,0 +1,21 @@
.row
.col-sm-6
%h2.text-center-xs
= "#{t('shared.contact_details')}"
.col-sm-6
%h2.text-right.text-center-xs
= link_to(t('shared.edit'), edit_admin_contact_path(@contact), class: 'btn btn-primary')
= link_to(t('shared.delete'), admin_contact_path(@contact), method: :delete, data: { confirm: t('shared.are_you_sure') }, class: 'btn btn-danger')
%hr
.row
.col-md-6= render 'admin/contacts/partials/general'
.col-md-6= render 'admin/contacts/partials/address'
.row
.col-md-12= render 'admin/contacts/partials/domains'
/ .row
/ .col-md-12= render 'admin/contacts/partials/addresses'
/ .row
/ .col-md-12= render 'admin/contacts/partials/tech_contacts'
/ .row
/ .col-md-12= render 'admin/contacts/partials/admin_contacts'

View file

@ -3,6 +3,8 @@
- @domain.errors.each do |attr, err| - @domain.errors.each do |attr, err|
= err = err
%br %br
- if @domain.errors.any?
%hr
.row .row
.col-md-6 .col-md-6
@ -25,7 +27,7 @@
= f.hidden_field(:registrar_id, class: 'js-registrar-id') = f.hidden_field(:registrar_id, class: 'js-registrar-id')
.form-group.has-feedback .form-group.has-feedback
= f.label :owner_contact = f.label :owner_contact
= text_field_tag(:domain_owner_contact, params[:owner_contact], class: 'form-control js-contact-typeahead', placeholder: t('shared.contact_code'), autocomplete: 'off') = text_field_tag(:domain_owner_contact, params[:domain_owner_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-ok.form-control-feedback.js-typeahead-ok.hidden
%span.glyphicon.glyphicon-remove.form-control-feedback.js-typeahead-remove %span.glyphicon.glyphicon-remove.form-control-feedback.js-typeahead-remove
= f.hidden_field(:owner_contact_id, class: 'js-contact-id') = f.hidden_field(:owner_contact_id, class: 'js-contact-id')

View file

@ -26,7 +26,7 @@
%tr %tr
%td= link_to(x, admin_domain_path(x)) %td= link_to(x, admin_domain_path(x))
%td= link_to(x.registrar, root_path) if x.registrar %td= link_to(x.registrar, root_path) if x.registrar
%td= link_to(x.owner_contact, root_path) %td= link_to(x.owner_contact, [:admin, x.owner_contact])
%td= l(x.valid_to, format: :short) %td= l(x.valid_to, format: :short)
%td= link_to(t('shared.edit'), edit_admin_domain_path(x), class: 'btn btn-primary btn-xs') %td= link_to(t('shared.edit'), edit_admin_domain_path(x), class: 'btn btn-primary btn-xs')
.row .row

View file

@ -4,7 +4,7 @@
.panel-body .panel-body
%dl.dl-horizontal %dl.dl-horizontal
%dt= t('shared.name') %dt= t('shared.name')
%dd= link_to(@domain.owner_contact, root_path) %dd= link_to(@domain.owner_contact, [:admin, @domain.owner_contact])
%dt= t('shared.code') %dt= t('shared.code')
%dd= @domain.owner_contact_code %dd= @domain.owner_contact_code

View file

@ -244,3 +244,15 @@ en:
domain_deleted: 'Domain deleted!' domain_deleted: 'Domain deleted!'
failed_to_delete_domain: 'Failed to delete domain!' failed_to_delete_domain: 'Failed to delete domain!'
email: 'Email' email: 'Email'
fax: 'Fax'
contact_details: 'Contact details'
ident: 'Ident'
ident_type: 'Ident type'
address: 'Address'
country: 'Country'
city: 'City'
street: 'Street'
zip: 'Zip'
org_name: 'Organisation name'
failed_to_add_domain: 'Failed to add domain!'
domain_added: 'Domain added!'