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
|
class Admin::ContactsController < AdminController
|
||||||
# TODO created_by and updated_by ids
|
before_action :set_contact, only: [:show]
|
||||||
before_action :set_contact, only: [:show, :destroy, :edit, :update]
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@q = Contact.search(params[:q])
|
@q = Contact.search(params[:q])
|
||||||
@contacts = @q.result.page(params[:page])
|
@contacts = @q.result.page(params[:page])
|
||||||
end
|
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
|
def search
|
||||||
render json: Contact.search_by_query(params[:q])
|
render json: Contact.search_by_query(params[:q])
|
||||||
end
|
end
|
||||||
|
@ -53,9 +15,4 @@ class Admin::ContactsController < AdminController
|
||||||
def set_contact
|
def set_contact
|
||||||
@contact = Contact.find(params[:id])
|
@contact = Contact.find(params[:id])
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -1,7 +1,62 @@
|
||||||
class Client::ContactsController < ClientController
|
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
|
# TODO: Add Registrar to Contacts and search only contacts that belong to this domain
|
||||||
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
|
||||||
|
|
||||||
|
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
|
end
|
||||||
|
|
|
@ -18,10 +18,8 @@
|
||||||
= sort_link(@q, 'code', t('shared.code'))
|
= sort_link(@q, 'code', t('shared.code'))
|
||||||
%th{class: 'col-xs-2'}
|
%th{class: 'col-xs-2'}
|
||||||
= sort_link(@q, 'ident', t('shared.identity_code'))
|
= 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'))
|
= sort_link(@q, 'email', t('shared.email'))
|
||||||
%th{class: 'col-xs-1'}
|
|
||||||
= t('shared.action')
|
|
||||||
%tbody
|
%tbody
|
||||||
- @contacts.each do |x|
|
- @contacts.each do |x|
|
||||||
%tr
|
%tr
|
||||||
|
@ -29,7 +27,6 @@
|
||||||
%td= x.code
|
%td= x.code
|
||||||
%td= x.ident
|
%td= x.ident
|
||||||
%td= x.email
|
%td= x.email
|
||||||
%td= link_to(t('shared.edit'), edit_admin_contact_path(x), class: 'btn btn-primary btn-xs')
|
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
= paginate @contacts
|
= paginate @contacts
|
||||||
|
|
|
@ -1,23 +1,15 @@
|
||||||
#contacts.panel.panel-default
|
#contacts.panel.panel-default
|
||||||
.panel-heading.clearfix
|
.panel-heading= t('shared.domains')
|
||||||
.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-responsive
|
||||||
%table.table.table-hover.table-bordered.table-condensed
|
%table.table.table-hover.table-bordered.table-condensed
|
||||||
%thead
|
%thead
|
||||||
%tr
|
%tr
|
||||||
%th{class: 'col-xs-3'}= t('shared.domain_name')
|
%th{class: 'col-xs-4'}= t('shared.domain_name')
|
||||||
%th{class: 'col-xs-3'}= t('shared.registrar')
|
%th{class: 'col-xs-4'}= t('shared.registrar')
|
||||||
%th{class: 'col-xs-3'}= t('shared.valid_to')
|
%th{class: 'col-xs-4'}= t('shared.valid_to')
|
||||||
%th{class: 'col-xs-3'}= t('shared.action')
|
|
||||||
%tbody
|
%tbody
|
||||||
- @contact.domains_owned.each do |x|
|
- @contact.domains_owned.each do |x|
|
||||||
%tr
|
%tr
|
||||||
%td= link_to(x.name, [:admin, x])
|
%td= link_to(x.name, [:admin, x])
|
||||||
%td= link_to(x.registrar, [:admin, x.registrar])
|
%td= link_to(x.registrar, [:admin, x.registrar])
|
||||||
%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')
|
|
||||||
= 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
|
.row
|
||||||
.col-sm-6
|
.col-sm-12
|
||||||
%h2.text-center-xs
|
%h2.text-center-xs
|
||||||
= "#{t('shared.contact_details')}"
|
= "#{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
|
%hr
|
||||||
.row
|
.row
|
||||||
.col-md-6= render 'admin/contacts/partials/general'
|
.col-md-6= render 'admin/contacts/partials/general'
|
||||||
.col-md-6= render 'admin/contacts/partials/address'
|
.col-md-6= render 'admin/contacts/partials/address'
|
||||||
.row
|
.row
|
||||||
.col-md-12= render 'admin/contacts/partials/domains'
|
.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?
|
- if @contact.errors.any?
|
||||||
- @contact.errors.each do |attr, err|
|
- @contact.errors.each do |attr, err|
|
||||||
= err
|
= err
|
|
@ -4,6 +4,6 @@
|
||||||
= "#{t('shared.edit_contact')}"
|
= "#{t('shared.edit_contact')}"
|
||||||
.col-sm-6
|
.col-sm-6
|
||||||
%h2.text-right.text-center-xs
|
%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
|
%hr
|
||||||
= render 'form'
|
= 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
|
.row
|
||||||
.col-sm-12
|
.col-sm-6
|
||||||
%h2.text-center-xs= t('shared.domains')
|
%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
|
%hr
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
|
@ -12,17 +15,14 @@
|
||||||
= sort_link(@q, 'name')
|
= sort_link(@q, 'name')
|
||||||
%th{class: 'col-xs-2'}
|
%th{class: 'col-xs-2'}
|
||||||
= sort_link(@q, 'owner_contact_name', t('shared.owner'))
|
= 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'))
|
= sort_link(@q, 'valid_to', t('shared.valid_to'))
|
||||||
%th{class: 'col-xs-1'}
|
|
||||||
= t('shared.action')
|
|
||||||
%tbody
|
%tbody
|
||||||
- @domains.each do |x|
|
- @domains.each do |x|
|
||||||
%tr
|
%tr
|
||||||
%td= link_to(x, client_domain_path(x))
|
%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= l(x.valid_to, format: :short)
|
||||||
%td= link_to(t('shared.edit'), edit_client_domain_path(x), class: 'btn btn-primary btn-xs')
|
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
= paginate @domains
|
= paginate @domains
|
||||||
|
|
|
@ -30,8 +30,6 @@
|
||||||
%ul.dropdown-menu{role: "menu"}
|
%ul.dropdown-menu{role: "menu"}
|
||||||
%li
|
%li
|
||||||
= link_to t('shared.domain_list'), client_domains_path
|
= link_to t('shared.domain_list'), client_domains_path
|
||||||
%li
|
|
||||||
= link_to t('shared.register_new_domain'), new_client_domain_path
|
|
||||||
%li
|
%li
|
||||||
= link_to t('shared.transfer_domain'), new_client_domain_transfer_path
|
= link_to t('shared.transfer_domain'), new_client_domain_transfer_path
|
||||||
|
|
||||||
|
@ -41,9 +39,7 @@
|
||||||
%span.caret
|
%span.caret
|
||||||
%ul.dropdown-menu{role: "menu"}
|
%ul.dropdown-menu{role: "menu"}
|
||||||
%li
|
%li
|
||||||
= link_to t('shared.check'), '#'
|
= link_to t('shared.contact_list'), client_contacts_path
|
||||||
%li
|
|
||||||
= link_to t('shared.register'), '#'
|
|
||||||
- if current_user.admin?
|
- if current_user.admin?
|
||||||
%li
|
%li
|
||||||
= link_to 'Admin', admin_root_path
|
= link_to 'Admin', admin_root_path
|
||||||
|
|
|
@ -296,6 +296,8 @@ en:
|
||||||
password_invalid: 'Password invalid!'
|
password_invalid: 'Password invalid!'
|
||||||
domain_was_not_found: 'Domain was not found!'
|
domain_was_not_found: 'Domain was not found!'
|
||||||
domain_list: 'Domain list'
|
domain_list: 'Domain list'
|
||||||
register_new_domain: 'Register new domain'
|
create_new_domain: 'Create new domain'
|
||||||
welcome: 'Welcome!'
|
welcome: 'Welcome!'
|
||||||
edit_statuses: 'Edit statuses'
|
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