Cleanups, design improvements

This commit is contained in:
Martin Lensment 2014-09-10 18:10:07 +03:00
parent eac302bafb
commit 8c309c2b0f
9 changed files with 68 additions and 34 deletions

View file

@ -1,4 +1,8 @@
class Admin::NameserversController < ApplicationController class Admin::NameserversController < ApplicationController
# TODO: Refactor this to domain_nameservers controller!
before_action :set_domain
before_action :set_nameserver, only: [:edit, :update, :destroy]
def new def new
@domain = Domain.find(params[:domain_id]) @domain = Domain.find(params[:domain_id])
@nameserver = @domain.nameservers.build @nameserver = @domain.nameservers.build
@ -15,6 +19,19 @@ class Admin::NameserversController < ApplicationController
end end
end end
def edit
@domain = Domain.find(params[:domain_id])
@nameserver = Nameserver.find(params[:id])
end
def update
if @nameserver.update(nameserver_params) && @domain.valid?
redirect_to [:admin, @domain]
else
render 'edit'
end
end
def destroy def destroy
# TODO: Refactor this # TODO: Refactor this
@nameserver = Nameserver.find(params[:id]) @nameserver = Nameserver.find(params[:id])
@ -25,6 +42,14 @@ class Admin::NameserversController < ApplicationController
private private
def set_domain
@domain = Domain.find(params[:domain_id])
end
def set_nameserver
@nameserver = Nameserver.find(params[:id])
end
def nameserver_params def nameserver_params
params.require(:nameserver).permit(:hostname, :ipv4, :ipv6) params.require(:nameserver).permit(:hostname, :ipv4, :ipv6)
end end

View file

@ -1,4 +1,9 @@
%h2= t('shared.domains') .row
.col-sm-6
%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

View file

@ -1,7 +1,6 @@
%h2= t('shared.new_domain') %h2= t('shared.new_domain')
%hr %hr
= form_for([:admin, @domain]) do |f| = form_for([:admin, @domain]) do |f|
= @domain.errors.inspect
- if @domain.errors.any? - if @domain.errors.any?
- @domain.errors.each do |attr, err| - @domain.errors.each do |attr, err|
= err = err

View file

@ -20,8 +20,8 @@
%td= x.ipv4 %td= x.ipv4
%td= x.ipv6 %td= x.ipv6
%td %td
= link_to(t('shared.edit'), root_path, class: 'btn btn-primary btn-xs') = link_to(t('shared.edit'), edit_admin_domain_nameserver_path(@domain, x), class: 'btn btn-primary btn-xs')
= link_to(t('shared.delete'), [:admin, x], method: :delete, data: { confirm: t('shared.are_you_sure') }, class: 'btn btn-danger btn-xs') = link_to(t('shared.delete'), admin_domain_nameserver_path(@domain, x), method: :delete, data: { confirm: t('shared.are_you_sure') }, class: 'btn btn-danger btn-xs')
- if @domain.errors.messages[:nameservers] - if @domain.errors.messages[:nameservers]
%tfoot %tfoot
- @domain.errors.messages[:nameservers].each do |x| - @domain.errors.messages[:nameservers].each do |x|

View file

@ -0,0 +1,28 @@
= form_for([:admin, @domain, @nameserver]) do |f|
= render 'admin/shared/errors', object: @domain
= render 'admin/shared/errors', object: f.object
- if @domain.errors.any?
%hr
.row
.col-md-6
.form-group
= label_tag t('shared.domain')
= text_field_tag :domain, @domain.name, disabled: true, class: 'form-control'
.col-md-6
.form-group
= f.label :hostname
= f.text_field(:hostname, class: 'form-control', autocomplete: 'off')
.row
.col-md-6
.form-group
= f.label :ipv4
= f.text_field(:ipv4, class: 'form-control', autocomplete: 'off')
.col-md-6
.form-group
= f.label :ipv6
= f.text_field(:ipv6, class: 'form-control', autocomplete: 'off')
.row
.col-md-12.text-right
= button_tag(t('shared.save'), class: 'btn btn-primary')

View file

@ -0,0 +1,3 @@
%h2= t('shared.edit_nameserver')
%hr
= render 'form'

View file

@ -1,30 +1,3 @@
%h2= t('shared.new_nameserver') %h2= t('shared.new_nameserver')
%hr %hr
= form_for([:admin, @domain, @nameserver]) do |f| = render 'form'
= render 'admin/shared/errors', object: @domain
= render 'admin/shared/errors', object: f.object
- if @domain.errors.any?
%hr
.row
.col-md-6
.form-group
= label_tag t('shared.domain')
= text_field_tag :domain, @domain.name, disabled: true, class: 'form-control'
.col-md-6
.form-group
= f.label :hostname
= f.text_field(:hostname, class: 'form-control', autocomplete: 'off')
.row
.col-md-6
.form-group
= f.label :ipv4
= f.text_field(:ipv4, class: 'form-control', autocomplete: 'off')
.col-md-6
.form-group
= f.label :ipv6
= f.text_field(:ipv6, class: 'form-control', autocomplete: 'off')
.row
.col-md-12.text-right
= button_tag(t('shared.save'), class: 'btn btn-primary')

View file

@ -190,3 +190,5 @@ en:
contact_code: 'Contact code' contact_code: 'Contact code'
add: 'Add' add: 'Add'
domain: 'Domain' domain: 'Domain'
new_nameserver: 'New nameserver'
edit_nameserver: 'Edit nameserver'

View file

@ -7,8 +7,7 @@ Rails.application.routes.draw do
namespace(:admin) do namespace(:admin) do
resources :domains do resources :domains do
resources :nameservers, shallow: true resources :nameservers
end end
resources :setting_groups resources :setting_groups
resources :registrars do resources :registrars do