ncbo/bioportal_web_ui

View on GitHub
app/views/shared/_ontology_picker.html.erb

Summary

Maintainability
Test Coverage
<%custom_ontologies ||= nil%>
<%selected_ontologies ||= []%>
<%init_ontology_picker(custom_ontologies, selected_ontologies)%>
<%form_object ||= :ontology%>
<%form_attribute ||= "ontologyId"%>
<%sel_text ||= "Select ontologies"%>
<%@select_id = "#{form_object}_#{form_attribute}"%>

<script type="text/javascript">
jQuery(window).ready(function(){
  jQuery("#<%=@select_id%>").chosen({search_contains: true, width: '100%'});

  // Unbind the click handler from the ontology list
  jQuery("#<%=@select_id%>_chzn").bind("focus", hideChosenResults);
  jQuery("#<%=@select_id%>_chzn").bind("keydown", showChosenResults);
});

var showChosenResults = function(){
  if (!jQuery("#<%=@select_id%>_chzn_o_0").closest("div.chzn-drop").is(":visible")) {
    jQuery("#<%=@select_id%>_chzn_o_0").closest("div.chzn-drop").show();
  }
}

var hideChosenResults = function(){
  if (jQuery("#<%=@select_id%>_chzn_o_0").closest("div.chzn-drop").is(":visible")) {
    jQuery("#<%=@select_id%>_chzn_o_0").closest("div.chzn-drop").hide();
  }
}
</script>


<div id="ontology_picker_container" style="margin-bottom: 1em; width: 432px;">
  <h2 id="ontology_picker_head" style="margin-bottom: 3px;">
    <%=sel_text%>
  </h2>

  <div id="<%=@select_id%>_container">
    <%=select form_object, form_attribute, options_for_select(@onts_for_select, selected_ontologies), { }, :multiple => 'true', "data-placeholder".to_sym => "Start typing to select ontologies or leave blank to use all", :style => "width: 432px;" %>
  </div>

  <div style="float: right; font-size: smaller;">
    <a id="ont_select_clear" href="javascript:void(0)">clear selection</a>
    &nbsp;&nbsp;&nbsp;
    <a id="ont_select_adv_href" href="javascript:void(0)">select from list</a>
  </div>

  <%=render_advanced_picker(custom_ontologies, selected_ontologies)%>
</div>