Skip to content

Commit

Permalink
Merge pull request #90 from pulibrary/bootstrap_select_dropdown
Browse files Browse the repository at this point in the history
Convert selects to bootstrap-select.
  • Loading branch information
escowles committed Aug 9, 2017
2 parents 62ee664 + 0a05c7e commit ac3c0e7
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ gem 'riiif'
gem 'sidekiq'
gem 'string_rtl'
gem 'valhalla', path: 'valhalla'
source 'https://rails-assets.org' do
gem 'rails-assets-bootstrap-select', '1.12.2'
end
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ PATH

GEM
remote: https://rubygems.org/
remote: https://rails-assets.org/
specs:
aasm (4.12.2)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -490,6 +491,9 @@ GEM
bundler (>= 1.3.0, < 2.0)
railties (= 5.1.1)
sprockets-rails (>= 2.0.0)
rails-assets-bootstrap-select (1.12.2)
rails-assets-jquery (>= 1.8)
rails-assets-jquery (2.2.4)
rails-controller-testing (1.0.2)
actionpack (~> 5.x, >= 5.0.1)
actionview (~> 5.x, >= 5.0.1)
Expand Down Expand Up @@ -727,6 +731,7 @@ DEPENDENCIES
puma
rack-mini-profiler
rails (= 5.1.1)
rails-assets-bootstrap-select (= 1.12.2)!
rails-controller-testing
recipient_interceptor
riiif
Expand Down
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
//= require nestedSortable/jquery.mjs.nestedSortable
//= require openseadragon/openseadragon
//= require openseadragon/jquery
//= require bootstrap-select
//= require bootstrap_select_dropdown
//= require valhalla/valhalla
//= require_tree .
$(document).ready(function() {
Expand Down
53 changes: 53 additions & 0 deletions app/assets/javascripts/bootstrap_select_dropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
$(function (){
// for some strange reason selectpicker prevents the click-event. so just use mouseup
// when clicking on an optgroup "label", toggle it's "children"
$(document).on("mouseup", ".bootstrap-select .dropdown-header", function (){
var $optgroup = $(this),
$ul = $optgroup.closest("ul"),
optgroup = $optgroup.data("optgroup"),

// options that belong to this optgroup
$options = $ul.find("[data-optgroup="+optgroup+"]").not(".selected").not($optgroup);

// show/hide options
if($optgroup.hasClass("closed")) {
$options.show();
} else {
$options.hide();
}

$optgroup.toggleClass("closed");
});

// initially close all optgroups that have the class "closed"
$(document).on("loaded.bs.select", function (){
$(this).find(".dropdown-header.closed").each(function (){
var $optgroup = $(this),
$ul = $optgroup.closest("ul"),
optgroup = $optgroup.data("optgroup"),

// options that belong to this optgroup
$options = $ul.find("[data-optgroup="+optgroup+"]").not(".selected").not($optgroup);

// show/hide options
$options.hide();
});
});
$(document).on("changed.bs.select", function(){
$(this).find(".dropdown-header.closed").each(function(){
var $optgroup = $(this),
$ul = $optgroup.closest("ul"),
optgroup = $optgroup.data("optgroup"),

// options that belong to this optgroup
$options = $ul.find("[data-optgroup="+optgroup+"]").not(".selected").not($optgroup);

// show/hide options
if($optgroup.hasClass("closed")) {
$options.hide();
} else {
$options.show();
}
})
});
});
1 change: 1 addition & 0 deletions app/assets/javascripts/figgy_boot.es6
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default class Initializer {
this.initialize_form()
this.structure_manager = new StructureManager
this.modal_viewer = new ModalViewer
$("select").selectpicker({'liveSearch': true})
}

initialize_form() {
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/rights_note.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* toggle rights note field based on which rights statement is selected */
$(document).ready(function(){
$('.rights-statement').change(rights_note_visibility);
$('select.rights-statement').change(rights_note_visibility);
});

function rights_note_visibility() {
var stmt = $('.rights-statement');
var stmt = $('select.rights-statement');
var note = $('.rights-note');
if ( $.inArray(stmt.val(), stmt.data("notable")) == -1) {
note.val('');
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@
@import 'blacklight/blacklight';
@import "hydra-editor/hydra-editor";
@import "openseadragon/openseadragon";
@import 'bootstrap-select';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= f.input :member_of_collection_ids, collection: @collections, label_method: :title, value_method: :id, input_html: { multiple: f.object.multiple?(key) }, include_blank: true, required: f.object.required?(key) %>
<%= f.input :member_of_collection_ids, collection: @collections, label_method: :title, value_method: :id, input_html: { multiple: f.object.multiple?(key) }, include_blank: false, required: f.object.required?(key) %>
2 changes: 1 addition & 1 deletion spec/controllers/scanned_resources_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
expect(response.body).to have_field "Portion Note"
expect(response.body).to have_field "Navigation Date"
expect(response.body).to have_selector "#scanned_resource_append_id[value='#{parent.id}']", visible: false
expect(response.body).to have_select "Collections", name: "scanned_resource[member_of_collection_ids][]", options: ["", collection.title.first]
expect(response.body).to have_select "Collections", name: "scanned_resource[member_of_collection_ids][]", options: [collection.title.first]
expect(response.body).to have_select "Rights Statement", name: "scanned_resource[rights_statement]", options: [""] + ControlledVocabulary.for(:rights_statement).all.map(&:label)
expect(response.body).to have_select "PDF Type", name: "scanned_resource[pdf_type]", options: ["Color PDF", "Grayscale PDF", "Bitonal PDF", "No PDF"]
expect(response.body).to have_select "Holding Location", name: "scanned_resource[holding_location]", options: [""] + ControlledVocabulary.for(:holding_location).all.map(&:label)
Expand Down

0 comments on commit ac3c0e7

Please sign in to comment.