ncbo/bioportal_web_ui

View on GitHub
app/views/ontologies/_form.html.haml

Summary

Maintainability
Test Coverage
- button_text ||= "Create ontology"
- title_text ||= "Submit New Ontology"

:css
  div.ontologyFormError {
    color: red;
    padding-top: 3px;
  }

- unless @errors.nil?
  .enable-lists{:style => "color:red;"}
    %strong Errors On Form
    %ul
      - if @errors[:error].instance_of? OpenStruct
        - errors = @errors[:error].to_h
        - errors.delete :links
        - errors.delete :context
        - errors.to_h.each do |errors_field, error|
          - next if error.nil?
          <style>#ontology_#{errors_field} { border: thin solid red; }</style>
          %li
            - if error.instance_of? OpenStruct
              - error_hash = error.to_h
              - error_hash.delete :links
              - error_hash.delete :context
              - error_hash.each do |error_type, e|
                = "#{error_type} : #{e}"
            - else
              = errors_field
      - else
        -# A generic fallback
        = @errors.to_json

%div{:style => "width:500px"}
  %span.asterik{:style => "float:right;"} * fields are required
  %h1 #{title_text}
%table#new_ontology.form{:width => "50%"}
  %tr
    %th
      Name:
      %span.asterik *
    %td.top
      = f.text_field :name, value: @ontology.name
  %tr
    %th
      Acronym:
      %span.asterik *
    %td
      - acronym_enabled = @ontology.acronym.nil? || ! @errors.nil?
      = f.text_field(:acronym, value: @ontology.acronym, :disabled => ! acronym_enabled, data: { acronyms: acronyms(@ontologies) })
      %ul#acronym_errors.enable-lists{style: "color: red; padding: 3px;"}
  %tr
    %th
      Administrators:
      %span.asterik *
    %td
      = f.select(:administeredBy, @user_select_list, {selected: @ontology.administeredBy || session[:user].id}, {multiple: true, :"data-placeholder" => "Select administrators"})
  %tr
    %th
      Viewing Restrictions
    %td
      - view_restiction_options = [["Public", "public"], ["Private", "private"]]
      - selected = @ontology.private? ? "private" : ""
      - selected = @ontology.licensed? ? "licensed" : selected
      - display_private = @ontology.private? ? "" : "hidden"
      - display_licensed = @ontology.licensed? ? "" : "hidden"
      = f.select :viewingRestriction, view_restiction_options, { :selected => selected }
      #viewingRestrictionsPrivate.viewing_restriction_types{:style => "padding: .5em; border: thin solid #C1DAD7; margin: .5em .5em .5em 0;", class: display_private}
        %h3 Add or remove accounts that are allowed to view classes in this ontology using the account name
        = f.select(:acl, @user_select_list, {include_blank: true, selected: @ontology.acl}, {multiple: true, :"data-placeholder" => "Select users who have access"})
      #viewingRestrictionsLicensed.viewing_restriction_types{:style => "padding: .5em; border: thin solid #C1DAD7; margin: .5em .5em .5em 0;", class: display_licensed}
        %b License Text:
        The text below explains what licensing information you want to collect before allowing access. We will display this text and record the user's response when the user attempts to access your ontology.
        - disabled = @ontology.licensed? ? {} : {:disabled => "true"}
        = f.text_area :licenseInformation, { :rows => 5, :class => "viewing_restriction_disabled", :style => "width: 90%;" }.merge(disabled)

  %tr
    %th
      Categories:
    %td
      - cat_select = @categories.sort{|a,b| a.name <=> b.name}.map{|c| [c.name, c.id]}
      = f.hidden_field(:hasDomain, {value: "", id: "ontology_hasDomain_empty_select_hack", name: "ontology[hasDomain][]"})
      = f.select(:hasDomain, cat_select, {selected: @ontology.hasDomain}, {multiple: true, :"data-placeholder" => "Select category (domain)"})

  %tr
    %th
      View:
    %td
      = f.check_box :isView, checked: @ontology.view?
      = f.label :isView, "This ontology is a view of:"
      #viewOf_picker{style: "padding-top: .3em;"}
        - single_picker_locals = {:picker_id => "ontology_viewOf", placeholder: "Select an ontology to create a view on", field_name: "viewOf", disabled: !@ontology.view?, selected: @ontology.viewOf}
        = render :partial => "shared/ontology_picker_single", :locals => single_picker_locals

  %tr
    %td{:align => "right", :colspan => "2"}
      = f.label :subscribe_notifications, "Subscribe to email notifications for new notes"
      = f.check_box :subscribe_notifications
  %tr
    %td{:align => "right", :colspan => "2"}
      = submit_tag "Cancel", formnovalidate: "formnovalidate"
      = submit_tag button_text