kennethkalmer/powerdns-on-rails

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

Summary

Maintainability
Test Coverage
%div{ :style => "display:none" }
  #new-step=t :help_macro_step_new
  #edit-macro=t :help_macro_edit
  #delete-macro=t :help_macro_delete
  #edit-step=t :help_macro_step_edit
  #delete-step=t :help_macro_step_delete
  #actions=t :help_macro_actions
  #content-field=t :help_macro_content_field
  #name-field=t :help_macro_name_field

%h1.underline
  = @macro.name
   
  = link_to edit_macro_path( @macro ) do
    = info_icon( 'brick_edit.png', 'edit-macro' )

%table.grid
  %tr
    %td= t :label_macro_name
    %td  
    %td= @macro.name
  %tr
    %td.top= t :label_macro_description
    %td  
    %td= @macro.description
  %tr
    %td= t :label_macro_owner
    %td  
    %td= @macro.user.nil? ? '-' : link_to(@macro.user.login, user_path(@macro.user))
  %tr
    %td= t :label_macro_active
    %td  
    %td= @macro.active? ? t(:generic_yes) : t(:generic_no)

%p  

%h1.underline=t :title_macro_steps

%table#steps-table.gridwide
  %tr
    %td.small=t :label_macro_step_position
    %td.small=t :label_macro_step_action
    %td.small=t :label_macro_step_type
    %td.small=t :label_macro_step_name
    %td.small=t :label_macro_step_priority
    %td.small=t :label_macro_step_content
  = render :partial => @macro.macro_steps

%p  

= link_to_function info_icon('table_add.png', 'new-step'), "displayRecordForm()"
= link_to_function t(:label_macro_step_create_new), "displayRecordForm()"

#record-form-div{ :style => 'display:none' }
  = form_for( [@macro, @macro.macro_steps.build], :remote => true, :html => { :id => 'record-form' } ) do |f|
    = f.hidden_field( :macro_id )
    %table.grid
      %tr.all
        %td= t :label_macro_step_position
        %td= f.text_field :position, :size => 5
      %tr.all
        %td= t :label_macro_step_action
        %td
          = f.select :action, MacroStep.valid_actions.map { |a| [ a.humanize, a ] }
          = info_icon( 'help.png', 'actions' )
      %tr.all
        %td= t :label_domain_record_type
        %td
          = f.select :record_type, Macro.record_types.map { |t| [t,t] }
      %tr.all
        %td= t :label_domain_record_host
        %td
          = f.text_field :name
          = info_icon( 'help.png', 'name-field' )
      %tr.rt-mx.rt-srv{ :style => 'display :none' }
        %td= t :label_domain_record_priority
        %td= f.text_field :prio, :size => 6
      %tr.all
        %td= t :label_domain_record_data
        %td
          = f.text_field :content
          = info_icon( 'help.png', 'content-field' )
      %tr.all
        %td.right= link_to_function t(:generic_cancel), "hideAll()"
        %td= submit_tag t(:generic_save)

:javascript
  // Blatantly copied from record templates, needs to be unified
  function hideAll() {
    $('#record-form-div').hide();
  }
  function displayRecordForm() {
    $('#record-form-div').show();
  }
  function editRecordTemplate(i){
    $('#show_macro_step_' + i).hide();
    $('#edit_macro_step_' + i).show();
  }
  function hideRecordTemplate(i) {
    $('#show_macro_step_' + i).show();
    $('#edit_macro_step_' + 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();
    });
  }