views/layout.haml

Summary

Maintainability
Test Coverage
!!! 5
%html
  %head
    %title 
      SeaBase
    %link{ rel: 'stylesheet', href: '/css/app.css', type: 'text/css' }

    %link{ rel: 'stylesheet', href: 'http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css', type: 'text/css' } 
    %script{ src: 'http://code.jquery.com/jquery-1.9.1.js' }
    %script{ src: 'http://code.jquery.com/ui/1.10.3/jquery-ui.js' }
    %script{ src: 'https://www.google.com/jsapi' }
  %body
    .container
      .header
        %h1{ id: 'title' }
          %a{ href: '/' } SeaBase
          - if current_user
            %span (logged in as #{current_user.name})
        .menu
          %ul
            %li
              %a{ href: '/' } Home
            %li
              %a{ href: '/search' } Search
            %li
              %a{ href: '/blast' } Blast
            %li
              %a{ href: '/export' } Export
            %li
              %a{ href: '/import' } Import
            - if current_user
              - if current_user.admin?
                %li
                  %a{ href: '/news' } News Edit
              %li
                %a{ href: '/logout' } Logout
    .container
      #search
        .ui-widget
          %form{ method: :get, action: '/search', name: :search_form, id: :search_form}
            Search for
            %em Nematostella vectensis 
            transcripts by 
            - scientific_name = session[:scientific_name] || 'Mus musculus'
            %select{ name: 'scientific_name', id: 'scientific_name' }
              %option{ value: 'Homo sapiens', selected: scientific_name == 'Homo sapiens'} Human orthologs 
              %option{ value: 'Mus musculus', selected: scientific_name == 'Mus musculus' } Mouse orthologs
              %option{ value: 'Nematostella vectensis', selected: scientific_name == 'Nematostella vectensis' } Nematostella annotations
            
            Name: 
            %input#term_search{ type: 'text', name: 'term', autofocus: true }
            %input#exact_search{ type: 'hidden', value: 'false', name: 'exact_search' } 
            %input{ type: 'submit', value: 'Search' }

    .container
      = styled_flash

    .container
      #content
        = yield

    .container
      #footer
        %a{ href: 'http://mbl.edu' } Marine Biological Laboratory
        |
        %a{ href: 'https://github.com/EOL/seabase/blob/master/LICENSE' } 
          MIT License
        | 
        %a{ href: 'https://github.com/EOL/seabase/releases' }
          Version
          = Seabase.version

:javascript
  $(function() {
    $("#term_search").autocomplete({
      source: function( request, response ) {
        $.ajax({
          url: "/search.json",
          dataType: "jsonp",
          data: {
            scientific_name: $("#scientific_name option:selected").attr('value'), 
            term: request.term,
            batch_size: 10
          },
          success: function( data ) {
            response( $.map( data, function( item ) {
              return { value: item.name + ':' + item.gene_name + ':' + item.functional_name }
            }));
          },
        });
      },
      minLength: 1,
      select: function(event, ui) {
        $("#exact_search").val('true');
        $("#term_search").val(ui.item.label);
        $("#search_form").submit();
      },
    });
  });

  $(function() {
    $("#scientific_name").change(function() {
      $.ajax({
        url: "/default_ortholog",
        method: "put",
        data: {
          scientific_name: $("#scientific_name option:selected").attr('value') 
        }
      });
    });
  });

  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', '#{Seabase.conf.ga_id}', '#{Seabase.conf.ga_domain}');
  ga('send', 'pageview');