Status attaching

This commit is contained in:
Martin Lensment 2014-09-16 10:51:24 +03:00
parent d286a67cc0
commit a72560c3d3
7 changed files with 117 additions and 4 deletions

View file

@ -0,0 +1,57 @@
class Admin::DomainStatusesController < ApplicationController
before_action :set_domain
before_action :set_domain_status, only: [:edit, :update, :destroy]
def new
@domain_status = @domain.domain_statuses.build(value: DomainStatus::OK)
end
def create
@domain_status = @domain.domain_statuses.build(domain_status_params)
if @domain.save
flash[:notice] = I18n.t('shared.status_added')
redirect_to [:admin, @domain]
else
flash.now[:alert] = I18n.t('shared.failed_to_add_status')
render 'new'
end
end
def edit; end
def update
if @domain_status.update(domain_status_params)
flash[:notice] = I18n.t('shared.status_updated')
redirect_to [:admin, @domain]
else
flash.now[:alert] = I18n.t('shared.failed_to_update_status')
render 'edit'
end
end
def destroy
if @domain_status.destroy
flash[:notice] = I18n.t('shared.status_deleted')
else
flash[:alert] = I18n.t('shared.failed_to_delete_status')
end
redirect_to [:admin, @domain]
end
private
def set_domain
@domain = Domain.find(params[:domain_id])
end
def set_domain_status
@domain_status = DomainStatus.find(params[:id])
end
def domain_status_params
params.require(:domain_status).permit(:value, :description)
end
end

View file

@ -0,0 +1,18 @@
= form_for([:admin, @domain, @domain_status]) 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
= f.label :value
= f.select :value, options_for_select(DomainStatus::STATUSES, @domain_status.value), {}, {class: 'form-control'}
.col-md-6
.form-group
= f.label :description
= f.text_field :description, 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,9 @@
.row
.col-sm-6
%h2.text-center-xs
= "#{t('shared.edit_domain_status')}"
.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

@ -0,0 +1,9 @@
.row
.col-sm-6
%h2.text-center-xs
= "#{t('shared.new_domain_status')}"
.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,5 +1,10 @@
.panel.panel-default
.panel-heading= t('shared.statuses')
- panel_class = @domain.errors.messages[:domain_statuses] ? 'panel-danger' : 'panel-default'
.panel{class: panel_class}
.panel-heading.clearfix
.pull-left
= t('shared.statuses')
.pull-right
= link_to(t('shared.add'), new_admin_domain_domain_status_path(@domain), class: 'btn btn-primary btn-xs')
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead
@ -13,5 +18,10 @@
%td= x.value
%td= x.description
%td
= 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.edit'), edit_admin_domain_domain_status_path(@domain, x), class: 'btn btn-primary btn-xs')
= link_to(t('shared.delete'), admin_domain_domain_status_path(@domain, x), method: :delete, data: { confirm: t('shared.are_you_sure') }, class: 'btn btn-danger btn-xs')
- if @domain.errors.messages[:domain_statuses]
%tfoot
- @domain.errors.messages[:domain_statuses].each do |x|
%tr
%td{colspan: 4}= x

View file

@ -95,6 +95,7 @@ en:
auth_info:
wrong_pw: 'Authentication error'
domain_statuses:
invalid: 'Status is invalid'
not_found: 'Status was not found'
taken: 'Status already exists on this domain'
domain:
@ -215,3 +216,11 @@ en:
new_admin_contact: 'New admin contact'
contact_detached: 'Contact detached!'
failed_to_detach_contact: 'Failed to detach contact!'
new_domain_status: 'New domain status'
status_added: 'Status added!'
failed_to_add_status: 'Failed to add status!'
edit_domain_status: 'Edit domain status'
status_updated: 'Status updated!'
failed_to_update_status: 'Failed to update status!'
status_deleted: 'Status deleted!'
failed_to_delete_status: 'Failed to delete status!'

View file

@ -10,6 +10,7 @@ Rails.application.routes.draw do
resources :nameservers
resources :tech_contacts
resources :admin_contacts
resources :domain_statuses
end
resources :setting_groups