app/views/media_resources/edit/fields/_meta_datum_copyright.html.haml

Summary

Maintainability
Test Coverage
:ruby

  copyright_roots = Copyright.roots
  current = (meta_datum.nil? ? nil : meta_datum.value) || Copyright.default

%input.value-target{:name => "resource[meta_data_attributes][#{@i}][value]", :type => "hidden", :value => current}

%select.block.copyright-roots{:id => "resource[meta_data_attributes][#{@i}][value]"}
  
  / # parent copyright options
  - copyright_roots.each do |copyright|
    
    = render partial: "media_resources/edit/fields/meta_datum_copyright/option", 
             locals: {:copyright => copyright, :selected => current.root}

/   # child copyright options
- copyright_roots.each do |copyright|

  - unless copyright.leaf?

    %select.block.copyright-children.hidden{:"data-parent-id" => copyright.id}
      
      - copyright.children.each do |child|

        - if child.leaf? # if it's just an option…

          = render :partial => "media_resources/edit/fields/meta_datum_copyright/option", 
                   :locals => {:copyright => child, :selected => current}

        - else # if it's a "grouped" option…

          %optgroup{:label => child.label}

            - child.children.each do |leaf|

              = render :partial => "media_resources/edit/fields/meta_datum_copyright/option", 
                       :locals => {:copyright => leaf, :selected => current}