diff --git a/app/controllers/admin/domain_statuses_controller.rb b/app/controllers/admin/domain_statuses_controller.rb new file mode 100644 index 000000000..830608b8e --- /dev/null +++ b/app/controllers/admin/domain_statuses_controller.rb @@ -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 diff --git a/app/views/admin/domain_statuses/_form.haml b/app/views/admin/domain_statuses/_form.haml new file mode 100644 index 000000000..137670f7d --- /dev/null +++ b/app/views/admin/domain_statuses/_form.haml @@ -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') diff --git a/app/views/admin/domain_statuses/edit.haml b/app/views/admin/domain_statuses/edit.haml new file mode 100644 index 000000000..12f77956b --- /dev/null +++ b/app/views/admin/domain_statuses/edit.haml @@ -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' diff --git a/app/views/admin/domain_statuses/new.haml b/app/views/admin/domain_statuses/new.haml new file mode 100644 index 000000000..272e36b7b --- /dev/null +++ b/app/views/admin/domain_statuses/new.haml @@ -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' diff --git a/app/views/admin/domains/partials/_statuses.haml b/app/views/admin/domains/partials/_statuses.haml index aab1721ad..121b79899 100644 --- a/app/views/admin/domains/partials/_statuses.haml +++ b/app/views/admin/domains/partials/_statuses.haml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index f95e70976..66c6d4d33 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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!' diff --git a/config/routes.rb b/config/routes.rb index 72f71747e..9d6d5892c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,6 +10,7 @@ Rails.application.routes.draw do resources :nameservers resources :tech_contacts resources :admin_contacts + resources :domain_statuses end resources :setting_groups