kennethkalmer/powerdns-on-rails

View on GitHub
app/views/templates/show.html.haml

Summary

Maintainability
Test Coverage
%div{ :style => "display: none;" }
  #new-template= t :help_template_zone_new
  #edit-template= t :help_template_zone_edit
  #delete-template= t :help_template_zone_delete
  #new-record-template= t :help_template_record_add
  #edit-record-template= t :help_template_record_edit
  #delete-record-template= t :help_template_record_delete
  #help-primary-ns= t :help_domain_primary_ns
  #help-contact= t :help_domain_contact
  #help-refresh= t :help_domain_refresh
  #help-retry= t :help_domain_retry
  #help-expire= t :help_domain_expire
  #help-minimum= t :help_domain_minimum

%h1.underline
  = @zone_template.name
   
  = link_to info_icon( 'database_edit.png', 'edit-template' ), edit_zone_template_path(@zone_template)

%table.grid
  %tr
    %td= t :label_template_zone_name
    %td= @zone_template.name
  %tr
    %td= t :label_template_zone_ttl
    %td= @zone_template.ttl
  %tr
    %td= t :label_template_zone_type
    %td= @zone_template.type.humanize
  %tr
    %td= t :label_template_zone_owner
    %td
      - if @zone_template.user
        = @zone_template.user.login
      - else
        \-

%p  

%h1.underline= t :title_template_records

- unless @zone_template.has_soa?
   
  #soa-warning.generic-warning
    = image_tag('table_error.png')
    = t :message_template_cannot_use_no_soa
   

%table#record-table.gridwide
  %tr
    %td.small= t :label_domain_record_host
    %td.small= t :label_domain_record_ttl
    %td.small= t :label_domain_record_type
    %td.small= t :label_domain_record_priority
    %td.small= t :label_domain_record_data
    %td
  = render :partial => "record_template", :collection => @zone_template.record_templates

%p  

= link_to_function info_icon('table_add.png', 'new-record-template'), "displayRecordForm()"
= link_to_function t(:label_template_record_create_new), "displayRecordForm()"

#record-form-div{ :style => 'display:none' }
  = form_for( RecordTemplate.new, :remote => true, :html => { :id => 'record-form' } ) do |f|
    = hidden_field( :zone_template, :id )
    %table.grid
      %tr.all
        %td= t :label_template_record_type
        %td
          = f.select :record_type, RecordTemplate.record_types.map { |t| [t,t] }
        %td  
      %tr.all
        %td= t :label_template_record_host
        %td= f.text_field :name
        %td  
      %tr.all
        %td= t :label_template_record_ttl
        %td= f.text_field :ttl, :size => 6
        %td  
      %tr.rt-mx.rt-srv{ :style => 'display :none' }
        %td= t :label_template_record_priority
        %td= f.text_field :prio, :size => 6
        %td  
      %tr.all
        %td= t :label_template_record_data
        %td= f.text_field :content
        %td  
      %tr.rt-soa{ :style => 'display :none' }
        %td= t :label_template_record_primary_ns
        %td= f.text_field :primary_ns
        %td= help_icon('help-primary-ns')
      %tr.rt-soa{ :style => 'display :none' }
        %td= t :label_template_record_contact
        %td= f.text_field :contact
        %td= help_icon('help-contact')
      %tr.rt-soa{ :style => 'display :none' }
        %td= t :label_template_record_refresh
        %td
          = f.text_field :refresh, :size => 6
          = help_icon('help-refresh')
        %td  
      %tr.rt-soa{ :style => 'display :none' }
        %td= t :label_template_record_retry
        %td
          = f.text_field :retry, :size => 6
          = help_icon('help-retry')
        %td  
      %tr.rt-soa{ :style => 'display :none' }
        %td= t :label_template_record_expire
        %td
          = f.text_field :expire, :size => 6
          = help_icon('help-expire')
        %td  
      %tr.rt-soa{ :style => 'display :none' }
        %td= t :label_template_record_minimum
        %td
          = f.text_field :minimum, :size => 6
          = help_icon('help-minimum')
        %td  
      %tr.all
        %td.right= link_to_function t(:generic_cancel), "hideAll()"
        %td= submit_tag t(:generic_save)

:javascript
  function hideAll() {
    $('#record-form-div').hide();
  }
  function displayRecordForm() {
    $('#record-form-div').show();
  }
  function editRecordTemplate(i){
    $('#show_record_template_' + i).hide();
    soa = $('#show-soa_record_template_' + i);
    if (soa)
      soa.hide();
    $('#edit_record_template_' + i).show();
  }
  function hideRecordTemplate(i) {
    $('#show_record_template_' + i).show();
    soa = $('#show-soa_record_template_' + i);
    if (soa)
      soa.show();
    $('#edit_record_template_' + i).hide();
  }
  function toggleRecordFields(v){
    t = 'rt-' + v.toLowerCase();
    $('#record-form-div tr').each(function(){
      if($(this).hasClass(t) || $(this).hasClass('all'))
        $(this).show();
      else
        $(this).hide();
    });
  }