mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 20:18:22 +02:00
Refactor contact forms to client
This commit is contained in:
parent
3e0943189b
commit
7963330aeb
14 changed files with 140 additions and 86 deletions
|
@ -1,49 +1,11 @@
|
|||
class Admin::ContactsController < AdminController
|
||||
# TODO created_by and updated_by ids
|
||||
before_action :set_contact, only: [:show, :destroy, :edit, :update]
|
||||
before_action :set_contact, only: [:show]
|
||||
|
||||
def index
|
||||
@q = Contact.search(params[:q])
|
||||
@contacts = @q.result.page(params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
@contact = Contact.new
|
||||
@contact.build_address
|
||||
end
|
||||
|
||||
def create
|
||||
@contact = Contact.new(contact_params)
|
||||
@contact.generate_code
|
||||
if @contact.save
|
||||
flash[:notice] = I18n.t('shared.contact_added')
|
||||
redirect_to [:admin, @contact]
|
||||
else
|
||||
flash[:alert] = I18n.t('shared.failed_to_create_contact')
|
||||
render "new"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @contact.destroy_and_clean
|
||||
flash[:notice] = I18n.t('shared.contact_deleted')
|
||||
redirect_to admin_contacts_path
|
||||
else
|
||||
flash[:alert] = I18n.t('shared.failed_to_delete_contact')
|
||||
redirect_to [:admin, @contact]
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @contact.update_attributes(contact_params)
|
||||
flash[:notice] = I18n.t('shared.contact_updated')
|
||||
redirect_to [:admin, @contact]
|
||||
else
|
||||
flash[:alert] = I18n.t('shared.failed_to_update_contact')
|
||||
redirect_to [:admin, @contact]
|
||||
end
|
||||
end
|
||||
|
||||
def search
|
||||
render json: Contact.search_by_query(params[:q])
|
||||
end
|
||||
|
@ -53,9 +15,4 @@ class Admin::ContactsController < AdminController
|
|||
def set_contact
|
||||
@contact = Contact.find(params[:id])
|
||||
end
|
||||
|
||||
def contact_params
|
||||
params.require(:contact).permit( :email, :phone, :fax, :ident_type, :ident, :auth_info, :name, :org_name,
|
||||
address_attributes: [:city, :street, :zip, :street2, :street3, :country_id])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,62 @@
|
|||
class Client::ContactsController < ClientController
|
||||
before_action :set_contact, only: [:show, :destroy, :edit, :update]
|
||||
|
||||
def index
|
||||
@q = Contact.search(params[:q]) if current_user.admin?
|
||||
@q = current_user.registrar.contacts.search(params[:q]) unless current_user.admin?
|
||||
@contacts = @q.result.page(params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
@contact = Contact.new
|
||||
@contact.build_address
|
||||
end
|
||||
|
||||
def create
|
||||
@contact = Contact.new(contact_params)
|
||||
@contact.generate_code
|
||||
if @contact.save
|
||||
flash[:notice] = I18n.t('shared.contact_added')
|
||||
redirect_to [:client, @contact]
|
||||
else
|
||||
flash[:alert] = I18n.t('shared.failed_to_create_contact')
|
||||
render "new"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @contact.destroy_and_clean
|
||||
flash[:notice] = I18n.t('shared.contact_deleted')
|
||||
redirect_to client_contacts_path
|
||||
else
|
||||
flash[:alert] = I18n.t('shared.failed_to_delete_contact')
|
||||
redirect_to [:client, @contact]
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @contact.update_attributes(contact_params)
|
||||
flash[:notice] = I18n.t('shared.contact_updated')
|
||||
redirect_to [:client, @contact]
|
||||
else
|
||||
flash[:alert] = I18n.t('shared.failed_to_update_contact')
|
||||
redirect_to [:client, @contact]
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: Add Registrar to Contacts and search only contacts that belong to this domain
|
||||
def search
|
||||
render json: Contact.search_by_query(params[:q])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_contact
|
||||
@contact = Contact.find(params[:id])
|
||||
end
|
||||
|
||||
def contact_params
|
||||
params.require(:contact).permit( :email, :phone, :fax, :ident_type, :ident, :auth_info, :name, :org_name,
|
||||
address_attributes: [:city, :street, :zip, :street2, :street3, :country_id])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,10 +18,8 @@
|
|||
= sort_link(@q, 'code', t('shared.code'))
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'ident', t('shared.identity_code'))
|
||||
%th{class: 'col-xs-1'}
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'email', t('shared.email'))
|
||||
%th{class: 'col-xs-1'}
|
||||
= t('shared.action')
|
||||
%tbody
|
||||
- @contacts.each do |x|
|
||||
%tr
|
||||
|
@ -29,7 +27,6 @@
|
|||
%td= x.code
|
||||
%td= x.ident
|
||||
%td= x.email
|
||||
%td= link_to(t('shared.edit'), edit_admin_contact_path(x), class: 'btn btn-primary btn-xs')
|
||||
.row
|
||||
.col-md-12
|
||||
= paginate @contacts
|
||||
|
|
|
@ -1,23 +1,15 @@
|
|||
#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')
|
||||
.panel-heading= t('shared.domains')
|
||||
.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')
|
||||
%th{class: 'col-xs-4'}= t('shared.domain_name')
|
||||
%th{class: 'col-xs-4'}= t('shared.registrar')
|
||||
%th{class: 'col-xs-4'}= t('shared.valid_to')
|
||||
%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')
|
||||
|
|
|
@ -1,21 +1,10 @@
|
|||
.row
|
||||
.col-sm-6
|
||||
.col-sm-12
|
||||
%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'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
= form_for([:admin, @contact]) do |f|
|
||||
= form_for([:client, @contact]) do |f|
|
||||
- if @contact.errors.any?
|
||||
- @contact.errors.each do |attr, err|
|
||||
= err
|
|
@ -4,6 +4,6 @@
|
|||
= "#{t('shared.edit_contact')}"
|
||||
.col-sm-6
|
||||
%h2.text-right.text-center-xs
|
||||
= link_to(t('shared.back_to_contact'), [:admin, @contact], class: 'btn btn-default')
|
||||
= link_to(t('shared.back_to_contact'), [:client, @contact], class: 'btn btn-default')
|
||||
%hr
|
||||
= render 'form'
|
32
app/views/client/contacts/index.haml
Normal file
32
app/views/client/contacts/index.haml
Normal file
|
@ -0,0 +1,32 @@
|
|||
.row
|
||||
.col-sm-6
|
||||
%h2.text-center-xs= t('shared.contacts')
|
||||
= render 'admin/contacts/partials/search'
|
||||
.col-sm-6
|
||||
%h2.text-right.text-center-xs
|
||||
= link_to(t('shared.create_new_contact'), new_client_contact_path, class: 'btn btn-primary')
|
||||
%hr
|
||||
.row
|
||||
.col-md-12
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'name', t('shared.name'))
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'code', t('shared.code'))
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'ident', t('shared.identity_code'))
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'email', t('shared.email'))
|
||||
%tbody
|
||||
- @contacts.each do |x|
|
||||
%tr
|
||||
%td= link_to(x, [:client, x])
|
||||
%td= x.code
|
||||
%td= x.ident
|
||||
%td= x.email
|
||||
.row
|
||||
.col-md-12
|
||||
= paginate @contacts
|
19
app/views/client/contacts/partials/_domains.haml
Normal file
19
app/views/client/contacts/partials/_domains.haml
Normal file
|
@ -0,0 +1,19 @@
|
|||
#contacts.panel.panel-default
|
||||
.panel-heading.clearfix
|
||||
.pull-left
|
||||
= t('shared.domains')
|
||||
.pull-right
|
||||
= link_to(t('shared.create_new_domain'), new_client_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-4'}= t('shared.domain_name')
|
||||
%th{class: 'col-xs-4'}= t('shared.registrar')
|
||||
%th{class: 'col-xs-4'}= t('shared.valid_to')
|
||||
%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)
|
15
app/views/client/contacts/show.haml
Normal file
15
app/views/client/contacts/show.haml
Normal file
|
@ -0,0 +1,15 @@
|
|||
.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_client_contact_path(@contact), class: 'btn btn-primary')
|
||||
= link_to(t('shared.delete'), client_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 'client/contacts/partials/domains'
|
|
@ -1,6 +1,9 @@
|
|||
.row
|
||||
.col-sm-12
|
||||
.col-sm-6
|
||||
%h2.text-center-xs= t('shared.domains')
|
||||
.col-sm-6
|
||||
%h2.text-right.text-center-xs
|
||||
= link_to(t('shared.create_new_domain'), new_client_domain_path, class: 'btn btn-primary')
|
||||
%hr
|
||||
.row
|
||||
.col-md-12
|
||||
|
@ -12,17 +15,14 @@
|
|||
= sort_link(@q, 'name')
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'owner_contact_name', t('shared.owner'))
|
||||
%th{class: 'col-xs-1'}
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'valid_to', t('shared.valid_to'))
|
||||
%th{class: 'col-xs-1'}
|
||||
= t('shared.action')
|
||||
%tbody
|
||||
- @domains.each do |x|
|
||||
%tr
|
||||
%td= link_to(x, client_domain_path(x))
|
||||
%td= link_to(x.owner_contact, '#')
|
||||
%td= link_to(x.owner_contact, [:client, x.owner_contact])
|
||||
%td= l(x.valid_to, format: :short)
|
||||
%td= link_to(t('shared.edit'), edit_client_domain_path(x), class: 'btn btn-primary btn-xs')
|
||||
.row
|
||||
.col-md-12
|
||||
= paginate @domains
|
||||
|
|
|
@ -30,8 +30,6 @@
|
|||
%ul.dropdown-menu{role: "menu"}
|
||||
%li
|
||||
= link_to t('shared.domain_list'), client_domains_path
|
||||
%li
|
||||
= link_to t('shared.register_new_domain'), new_client_domain_path
|
||||
%li
|
||||
= link_to t('shared.transfer_domain'), new_client_domain_transfer_path
|
||||
|
||||
|
@ -41,9 +39,7 @@
|
|||
%span.caret
|
||||
%ul.dropdown-menu{role: "menu"}
|
||||
%li
|
||||
= link_to t('shared.check'), '#'
|
||||
%li
|
||||
= link_to t('shared.register'), '#'
|
||||
= link_to t('shared.contact_list'), client_contacts_path
|
||||
- if current_user.admin?
|
||||
%li
|
||||
= link_to 'Admin', admin_root_path
|
||||
|
|
|
@ -296,6 +296,8 @@ en:
|
|||
password_invalid: 'Password invalid!'
|
||||
domain_was_not_found: 'Domain was not found!'
|
||||
domain_list: 'Domain list'
|
||||
register_new_domain: 'Register new domain'
|
||||
create_new_domain: 'Create new domain'
|
||||
welcome: 'Welcome!'
|
||||
edit_statuses: 'Edit statuses'
|
||||
contact_list: 'Contact list'
|
||||
create_new_contact: 'Create new contact'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue