Adding nameservers to domain

This commit is contained in:
Martin Lensment 2014-09-09 11:13:42 +03:00
parent 24e7beed5b
commit c24c8c7181
10 changed files with 69 additions and 8 deletions

View file

@ -1,7 +1,16 @@
$(".js-registrars-typeahead").typeahead $(".js-registrars-typeahead").typeahead
source: (query, process) -> source: (query, process) ->
$.get "/admin/registrars/search", {query: query}, (data) -> $.get "/admin/registrars/search", {query: query}, (data) ->
process data map = {}
registrars = []
$.each data, (i, registrar) ->
map[registrar.id] = registrar
registrars.push registrar.display
process registrars
updater: (item) ->
$('input[name="domain[registrar_id]"]').val()
$(".js-contacts-typeahead").typeahead $(".js-contacts-typeahead").typeahead
source: (query, process) -> source: (query, process) ->

View file

@ -5,6 +5,9 @@ class Admin::DomainsController < ApplicationController
@domain = Domain.new @domain = Domain.new
end end
def create
end
def index def index
@q = Domain.search(params[:q]) @q = Domain.search(params[:q])
@domains = @q.result.page(params[:page]) @domains = @q.result.page(params[:page])
@ -15,4 +18,8 @@ class Admin::DomainsController < ApplicationController
def set_domain def set_domain
@domain = Domain.find(params[:id]) @domain = Domain.find(params[:id])
end end
def domain_params
params.require(:domain).permit(:name, :period, :registrar, :owner_contact)
end
end end

View file

@ -0,0 +1,21 @@
class Admin::NameserversController < ApplicationController
def new
@domain = Domain.find_by(params[:id])
@nameserver = @domain.nameservers.build
end
def create
@domain = Domain.find(params[:domain_id])
if @domain.nameservers.create(nameserver_params)
redirect_to [:admin, @domain]
else
render 'new'
end
end
private
def nameserver_params
params.require(:nameserver).permit(:hostname, :ipv4, :ipv6)
end
end

View file

@ -1,7 +1,5 @@
class Admin::RegistrarsController < ApplicationController class Admin::RegistrarsController < ApplicationController
def search def search
r = Registrar.arel_table render json: Registrar.search_by_query(params[:query])
query_string = "%#{params[:query]}%"
render json: Registrar.where(r[:name].matches(query_string)).pluck(:name)
end end
end end

View file

@ -7,4 +7,11 @@ class Registrar < ActiveRecord::Base
def to_s def to_s
name name
end end
class << self
def search_by_query(query)
res = Registrar.search(name_or_reg_no_cont: query).result
res.reduce([]) { |o, v| o << { id: v[:id], display: "#{v[:name]} (#{v[:reg_no]})" } }
end
end
end end

View file

@ -12,7 +12,11 @@
.col-md-6 .col-md-6
.form-group .form-group
= f.label :registrar = f.label :registrar
= f.text_field(:registrar, class: 'form-control js-registrars-typeahead', placeholder: t('shared.registrar_name')) = f.text_field(:registrar, class: 'form-control js-registrars-typeahead', placeholder: t('shared.registrar_name'), autocomplete: 'off')
= f.hidden_field(:registrar_id)
.form-group .form-group
= f.label :owner_contact = f.label :owner_contact
= f.text_field(:owner_contact, class: 'form-control js-contacts-typeahead', placeholder: t('shared.contact_code')) = f.text_field(:owner_contact, class: 'form-control js-contacts-typeahead', placeholder: t('shared.contact_code'), autocomplete: 'off')
.row
.col-md-12.text-right
= button_tag(t('shared.save'), class: 'btn btn-primary')

View file

@ -1,5 +1,9 @@
.panel.panel-default .panel.panel-default
.panel-heading= t('shared.nameservers') .panel-heading.clearfix
.pull-left
= t('shared.nameservers')
.pull-right
= link_to(t('shared.add'), new_admin_domain_nameserver_path(@domain), 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
@ -17,3 +21,7 @@
%td %td
= link_to(t('shared.edit'), root_path, class: 'btn btn-primary btn-xs') = link_to(t('shared.edit'), root_path, class: 'btn btn-primary btn-xs')
= link_to(t('shared.delete'), root_path, method: :delete, data: { confirm: t('shared.are_you_sure') }, class: 'btn btn-danger btn-xs') = link_to(t('shared.delete'), root_path, method: :delete, data: { confirm: t('shared.are_you_sure') }, class: 'btn btn-danger btn-xs')
%tfoot
%tr
%td{colspan: 4}
Nameservers count must be between %{min}-%{max}

View file

@ -0,0 +1,3 @@
= form_for([:admin, @domain, @nameserver]) do |f|
= f.text_field :hostname
= f.button 'save'

View file

@ -184,3 +184,4 @@ en:
new_domain: 'New domain' new_domain: 'New domain'
registrar_name: 'Registrar name' registrar_name: 'Registrar name'
contact_code: 'Contact code' contact_code: 'Contact code'
add: 'Add'

View file

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