mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Remove domain editing and adding from admin
This commit is contained in:
parent
482d77c319
commit
302f51a4cb
12 changed files with 64 additions and 124 deletions
|
@ -1,27 +1,5 @@
|
||||||
class Admin::DomainsController < AdminController
|
class Admin::DomainsController < AdminController
|
||||||
before_action :set_domain, only: [:show, :edit, :update, :destroy]
|
before_action :set_domain, only: [:show, :edit, :update]
|
||||||
before_action :verify_deletion, only: [:destroy]
|
|
||||||
|
|
||||||
def 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
|
|
||||||
|
|
||||||
build_associations
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
|
||||||
@domain = Domain.new(domain_params)
|
|
||||||
|
|
||||||
if @domain.save
|
|
||||||
flash[:notice] = I18n.t('shared.domain_added')
|
|
||||||
redirect_to [:admin, @domain]
|
|
||||||
else
|
|
||||||
build_associations
|
|
||||||
flash.now[:alert] = I18n.t('shared.failed_to_add_domain')
|
|
||||||
render 'new'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@q = Domain.search(params[:q])
|
@q = Domain.search(params[:q])
|
||||||
|
@ -33,7 +11,7 @@ class Admin::DomainsController < AdminController
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
build_associations
|
@domain.domain_statuses.build if @domain.domain_statuses.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
@ -41,22 +19,12 @@ class Admin::DomainsController < AdminController
|
||||||
flash[:notice] = I18n.t('shared.domain_updated')
|
flash[:notice] = I18n.t('shared.domain_updated')
|
||||||
redirect_to [:admin, @domain]
|
redirect_to [:admin, @domain]
|
||||||
else
|
else
|
||||||
build_associations
|
@domain.domain_statuses.build if @domain.domain_statuses.empty?
|
||||||
flash[:alert] = I18n.t('shared.failed_to_update_domain')
|
flash.now[:alert] = I18n.t('shared.failed_to_update_domain')
|
||||||
render 'edit'
|
render 'edit'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
|
||||||
if @domain.destroy
|
|
||||||
flash[:notice] = I18n.t('shared.domain_deleted')
|
|
||||||
redirect_to admin_domains_path
|
|
||||||
else
|
|
||||||
flash[:alert] = I18n.t('shared.failed_to_delete_domain')
|
|
||||||
redirect_to [:admin, @domain]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_domain
|
def set_domain
|
||||||
|
@ -65,29 +33,7 @@ class Admin::DomainsController < AdminController
|
||||||
|
|
||||||
def domain_params
|
def domain_params
|
||||||
params.require(:domain).permit(
|
params.require(:domain).permit(
|
||||||
:name,
|
|
||||||
:period,
|
|
||||||
:period_unit,
|
|
||||||
:registrar_id,
|
|
||||||
:owner_contact_id,
|
|
||||||
:owner_contact_typeahead,
|
|
||||||
:registrar_typeahead,
|
|
||||||
nameservers_attributes: [:id, :hostname, :ipv4, :ipv6, :_destroy],
|
|
||||||
domain_contacts_attributes: [:id, :contact_type, :contact_id, :value_typeahead, :_destroy],
|
|
||||||
domain_statuses_attributes: [:id, :value, :description, :_destroy]
|
domain_statuses_attributes: [:id, :value, :description, :_destroy]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_associations
|
|
||||||
@domain.nameservers.build if @domain.nameservers.empty?
|
|
||||||
@domain.domain_contacts.build if @domain.domain_contacts.empty?
|
|
||||||
@domain.domain_statuses.build if @domain.domain_statuses.empty?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_deletion
|
|
||||||
return if @domain.can_be_deleted?
|
|
||||||
flash[:alert] = I18n.t('shared.domain_status_prohibits_deleting')
|
|
||||||
redirect_to [:admin, @domain]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
class Client::DomainsController < ClientController
|
class Client::DomainsController < ClientController
|
||||||
include Shared::CommonDomain
|
load_and_authorize_resource
|
||||||
|
before_action :set_domain, only: [:show, :edit, :update, :destroy]
|
||||||
|
before_action :verify_deletion, only: [:destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@q = Domain.search(params[:q]) if current_user.admin?
|
@q = Domain.search(params[:q]) if current_user.admin?
|
||||||
|
@ -29,6 +31,10 @@ class Client::DomainsController < ClientController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
build_associations
|
||||||
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if @domain.update(domain_params)
|
if @domain.update(domain_params)
|
||||||
flash[:notice] = I18n.t('shared.domain_updated')
|
flash[:notice] = I18n.t('shared.domain_updated')
|
||||||
|
@ -49,10 +55,25 @@ class Client::DomainsController < ClientController
|
||||||
:period_unit,
|
:period_unit,
|
||||||
:owner_contact_id,
|
:owner_contact_id,
|
||||||
:owner_contact_typeahead,
|
:owner_contact_typeahead,
|
||||||
:registrar_typeahead,
|
|
||||||
nameservers_attributes: [:id, :hostname, :ipv4, :ipv6, :_destroy],
|
nameservers_attributes: [:id, :hostname, :ipv4, :ipv6, :_destroy],
|
||||||
domain_contacts_attributes: [:id, :contact_type, :contact_id, :value_typeahead, :_destroy],
|
domain_contacts_attributes: [:id, :contact_type, :contact_id, :value_typeahead, :_destroy],
|
||||||
domain_statuses_attributes: [:id, :value, :description, :_destroy]
|
domain_statuses_attributes: [:id, :value, :description, :_destroy]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_domain
|
||||||
|
@domain = Domain.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_associations
|
||||||
|
@domain.nameservers.build if @domain.nameservers.empty?
|
||||||
|
@domain.domain_contacts.build if @domain.domain_contacts.empty?
|
||||||
|
@domain.domain_statuses.build if @domain.domain_statuses.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
def verify_deletion
|
||||||
|
return if @domain.can_be_deleted?
|
||||||
|
flash[:alert] = I18n.t('shared.domain_status_prohibits_deleting')
|
||||||
|
redirect_to [:admin, @domain]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,23 +4,13 @@
|
||||||
%hr
|
%hr
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
/ Nav tabs
|
|
||||||
%ul.nav.nav-tabs{:role => "tablist", id: 'tabs'}
|
%ul.nav.nav-tabs{:role => "tablist", id: 'tabs'}
|
||||||
- li_class = @domain.general_tab_valid? ? nil : 'error-tab'
|
|
||||||
%li.active{class: li_class}
|
|
||||||
%a{"data-toggle" => "tab", :href => "#general-tab", :role => "tab"}= t('shared.general')
|
|
||||||
- li_class = @domain.statuses_tab_valid? ? nil : 'error-tab'
|
- li_class = @domain.statuses_tab_valid? ? nil : 'error-tab'
|
||||||
%li{class: li_class}
|
%li{class: li_class}
|
||||||
%a{"data-toggle" => "tab", :href => "#statuses-tab", :role => "tab"}= t('shared.statuses')
|
%a{"data-toggle" => "tab", :href => "#statuses-tab", :role => "tab"}= t('shared.statuses')
|
||||||
/ Tab panes
|
/ Tab panes
|
||||||
.tab-content{style:'margin-top: 20px;'}
|
.tab-content{style:'margin-top: 20px;'}
|
||||||
#general-tab.tab-pane.active
|
#general-tab.tab-pane.active
|
||||||
= render 'admin/domains/form_partials/general', f: f
|
|
||||||
%hr
|
|
||||||
= render 'admin/domains/form_partials/contacts', f: f
|
|
||||||
%hr
|
|
||||||
= render 'admin/domains/form_partials/nameservers', f: f
|
|
||||||
#statuses-tab.tab-pane
|
|
||||||
= render 'admin/domains/form_partials/statuses', f: f
|
= render 'admin/domains/form_partials/statuses', f: f
|
||||||
.row
|
.row
|
||||||
.col-md-12.text-right
|
.col-md-12.text-right
|
||||||
|
@ -30,15 +20,3 @@
|
||||||
$(function() {
|
$(function() {
|
||||||
$('#tabs a:first').tab('show')
|
$('#tabs a:first').tab('show')
|
||||||
})
|
})
|
||||||
|
|
||||||
$("#domain_contacts").nestedAttributes({
|
|
||||||
bindAddTo: $(".add-domain-contact"),
|
|
||||||
afterAdd: function(item) {
|
|
||||||
item.find('.errors').html('');
|
|
||||||
item.find('.js-contact-id').val('')
|
|
||||||
Autocomplete.bindAdminContactSearch();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Autocomplete.bindAdminContactSearch()
|
|
||||||
Autocomplete.bindAdminRegistrarSearch()
|
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
.row
|
|
||||||
.col-md-6
|
|
||||||
.form-group
|
|
||||||
= f.label :name
|
|
||||||
= f.text_field(:name, class: 'form-control')
|
|
||||||
.form-group
|
|
||||||
= f.label :period
|
|
||||||
.row
|
|
||||||
.col-md-6
|
|
||||||
= f.text_field(:period, class: 'form-control')
|
|
||||||
.col-md-6
|
|
||||||
= f.select :period_unit, options_for_select(['y', 'm', 'd'], @domain.period_unit), {}, {class: 'form-control'}
|
|
||||||
.col-md-6
|
|
||||||
.form-group.has-feedback.js-typeahead-container
|
|
||||||
= f.label :registrar_typeahead
|
|
||||||
= f.text_field(:registrar_typeahead, class: 'form-control js-registrar-typeahead', placeholder: t('shared.registrar_name'), autocomplete: 'off')
|
|
||||||
%span.glyphicon.glyphicon-ok.form-control-feedback.js-typeahead-ok.hidden
|
|
||||||
%span.glyphicon.glyphicon-remove.form-control-feedback.js-typeahead-remove
|
|
||||||
= f.hidden_field(:registrar_id, class: 'js-registrar-id')
|
|
||||||
.form-group.has-feedback.js-typeahead-container
|
|
||||||
= f.label :owner_contact_typeahead
|
|
||||||
= f.text_field(:owner_contact_typeahead, 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
|
|
||||||
= f.hidden_field(:owner_contact_id, class: 'js-contact-id')
|
|
|
@ -1,9 +1,6 @@
|
||||||
.row
|
.row
|
||||||
.col-sm-6
|
.col-sm-12
|
||||||
%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.add'), new_admin_domain_path, class: 'btn btn-primary')
|
|
||||||
%hr
|
%hr
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
|
@ -17,10 +14,8 @@
|
||||||
= sort_link(@q, 'registrar_name', t('shared.registrar'))
|
= sort_link(@q, 'registrar_name', t('shared.registrar'))
|
||||||
%th{class: 'col-xs-2'}
|
%th{class: 'col-xs-2'}
|
||||||
= sort_link(@q, 'owner_contact_international_address_name', t('shared.owner'))
|
= sort_link(@q, 'owner_contact_international_address_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
|
||||||
|
@ -28,7 +23,6 @@
|
||||||
%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, [:admin, x.owner_contact])
|
%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')
|
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
= paginate @domains
|
= paginate @domains
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
%h2= t('shared.new_domain')
|
|
||||||
%hr
|
|
||||||
= render 'form'
|
|
|
@ -4,8 +4,7 @@
|
||||||
= "#{t('shared.domain_details')}"
|
= "#{t('shared.domain_details')}"
|
||||||
.col-sm-6
|
.col-sm-6
|
||||||
%h2.text-right.text-center-xs
|
%h2.text-right.text-center-xs
|
||||||
= link_to(t('shared.edit'), edit_admin_domain_path(@domain), class: 'btn btn-primary')
|
= link_to(t('shared.edit_statuses'), edit_admin_domain_path(@domain), class: 'btn btn-primary')
|
||||||
= link_to(t('shared.delete'), admin_domain_path(@domain), method: :delete, data: { confirm: t('shared.are_you_sure') }, class: 'btn btn-danger')
|
|
||||||
|
|
||||||
%hr
|
%hr
|
||||||
.row
|
.row
|
||||||
|
|
|
@ -17,11 +17,11 @@
|
||||||
#general-tab.tab-pane.active
|
#general-tab.tab-pane.active
|
||||||
= render 'client/domains/form_partials/general', f: f
|
= render 'client/domains/form_partials/general', f: f
|
||||||
%hr
|
%hr
|
||||||
= render 'admin/domains/form_partials/contacts', f: f
|
= render 'client/domains/form_partials/contacts', f: f
|
||||||
%hr
|
%hr
|
||||||
= render 'admin/domains/form_partials/nameservers', f: f
|
= render 'client/domains/form_partials/nameservers', f: f
|
||||||
#statuses-tab.tab-pane
|
#statuses-tab.tab-pane
|
||||||
= render 'admin/domains/form_partials/statuses', f: f
|
= render 'client/domains/form_partials/statuses', f: f
|
||||||
.row
|
.row
|
||||||
.col-md-12.text-right
|
.col-md-12.text-right
|
||||||
= button_tag(t('shared.save'), class: 'btn btn-primary')
|
= button_tag(t('shared.save'), class: 'btn btn-primary')
|
||||||
|
|
29
app/views/client/domains/form_partials/_statuses.haml
Normal file
29
app/views/client/domains/form_partials/_statuses.haml
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#domain_statuses
|
||||||
|
= f.fields_for :domain_statuses do |status_fields|
|
||||||
|
.panel.panel-default
|
||||||
|
.panel-heading.clearfix
|
||||||
|
.pull-left= t('shared.status')
|
||||||
|
.pull-right
|
||||||
|
= link_to(t('shared.add_another'), '#', class: 'btn btn-primary btn-xs add-domain-status')
|
||||||
|
= link_to(t('shared.delete'), '#', class: 'btn btn-danger btn-xs destroy')
|
||||||
|
.panel-body
|
||||||
|
.errors
|
||||||
|
= render 'shared/errors', object: status_fields.object
|
||||||
|
- if status_fields.object.errors.any?
|
||||||
|
%hr
|
||||||
|
.row
|
||||||
|
.col-md-6
|
||||||
|
.form-group
|
||||||
|
= status_fields.label :value
|
||||||
|
= status_fields.select :value, options_for_select(DomainStatus::STATUSES, status_fields.object.value), {include_blank: true}, {class: 'form-control'}
|
||||||
|
.col-md-6
|
||||||
|
.form-group
|
||||||
|
= status_fields.label :description
|
||||||
|
= status_fields.text_field :description, class: 'form-control', autocomplete: 'off'
|
||||||
|
:javascript
|
||||||
|
$("#domain_statuses").nestedAttributes({
|
||||||
|
bindAddTo: $(".add-domain-status"),
|
||||||
|
afterAdd: function(item) {
|
||||||
|
item.find('.errors').html('');
|
||||||
|
}
|
||||||
|
});
|
|
@ -298,3 +298,4 @@ en:
|
||||||
domain_list: 'Domain list'
|
domain_list: 'Domain list'
|
||||||
register_new_domain: 'Register new domain'
|
register_new_domain: 'Register new domain'
|
||||||
welcome: 'Welcome!'
|
welcome: 'Welcome!'
|
||||||
|
edit_statuses: 'Edit statuses'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue