Domain editing

This commit is contained in:
Martin Lensment 2014-09-15 11:44:26 +03:00
parent 2a4c46e870
commit 4c4edd3747
6 changed files with 56 additions and 34 deletions

View file

@ -1,5 +1,5 @@
class Admin::DomainsController < ApplicationController
before_action :set_domain, only: [:show]
before_action :set_domain, only: [:show, :edit, :update]
def new
@domain = Domain.new
@ -28,6 +28,19 @@ class Admin::DomainsController < ApplicationController
@domain.all_dependencies_valid?
end
def edit
params[:registrar] = @domain.registrar
params[:owner_contact] = @domain.owner_contact_code
end
def update
if @domain.update(domain_params)
redirect_to [:admin, @domain]
else
render 'edit'
end
end
private
def set_domain

View file

@ -0,0 +1,30 @@
= form_for([:admin, @domain]) do |f|
- if @domain.errors.any?
- @domain.errors.each do |attr, err|
= err
%br
.row
.col-md-6
.form-group
= f.label :name
= f.text_field(:name, class: 'form-control')
.form-group
= f.label :period
= f.text_field(:period, class: 'form-control')
.col-md-6
.form-group.has-feedback
= f.label :registrar
= text_field_tag(:domain_registrar, params[:registrar], 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
= f.label :owner_contact
= text_field_tag(:domain_owner_contact, params[:owner_contact], 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')
.row
.col-md-12.text-right
= button_tag(t('shared.save'), class: 'btn btn-primary')

View file

@ -0,0 +1,9 @@
.row
.col-sm-6
%h2.text-center-xs
= "#{t('shared.edit_domain')}"
.col-sm-6
%h2.text-right.text-center-xs
= link_to(t('shared.back_to_domain'), [:admin, @domain], class: 'btn btn-default')
%hr
= render 'form'

View file

@ -1,34 +1,3 @@
%h2= t('shared.new_domain')
%hr
= form_for([:admin, @domain]) do |f|
- if @domain.errors.any?
- @domain.errors.each do |attr, err|
= err
%br
.row
.col-md-6
.form-group
= f.label :name
= f.text_field(:name, class: 'form-control')
.form-group
= f.label :period
= f.text_field(:period, class: 'form-control')
.col-md-6
.form-group.has-feedback
= f.label :registrar
= text_field_tag(:domain_registrar, params[:registrar], 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
= f.label :owner_contact
= text_field_tag(:domain_owner_contact, params[:owner_contact], 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')
.row
.col-md-12.text-right
= button_tag(t('shared.save'), class: 'btn btn-primary')
= render 'form'

View file

@ -4,7 +4,7 @@
= "#{t('shared.domain_details')}"
.col-sm-6
%h2.text-right.text-center-xs
= link_to(t('shared.edit'), root_path, class: 'btn btn-primary')
= link_to(t('shared.edit'), edit_admin_domain_path(@domain), class: 'btn btn-primary')
= link_to(t('shared.delete'), root_path, method: :delete, data: { confirm: t('shared.are_you_sure') }, class: 'btn btn-danger')
%hr

View file

@ -205,3 +205,4 @@ en:
failed_to_add_nameserver: 'Failed to add nameserver!'
nameserver_added: 'Nameserver added!'
back_to_domain: 'Back to domain'
edit_domain: 'Edit domain'