Skip to content

Commit

Permalink
Merge pull request #716 from sparc-request/ac-organization-filter-sor…
Browse files Browse the repository at this point in the history
…ting-bug

fixing issue with organization filter/sorting.  also caused problems …
  • Loading branch information
amcates committed Oct 26, 2016
2 parents 9d29aed + b43ac69 commit 0d37d91
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
39 changes: 23 additions & 16 deletions app/assets/javascripts/dashboard/protocols.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ $(document).ready ->
url: "/dashboard/protocols/#{protocol_id}/archive.js"
data: { protocol_id: protocol_id }

$(document).on 'submit', '#filterrific-no-ajax-auto-submit', ->
$('#filterrific_sorted_by').val("#{$('.protocol-sort').data('sort-name')} #{$('.protocol-sort').data('sort-order')}")

$(document).on 'click', '#save_filters_link', ->
data = {} #Grab form values

Expand Down Expand Up @@ -156,24 +159,28 @@ $(document).ready ->

# Protocol Table Sorting
$(document).on 'click', '.protocol-sort', ->
search_query = $('#search_query').val()
show_archived = $('#show_archived').val()
with_status = $('#with_status').val()
with_organization = $('#with_organization').val()
with_owner = $('#with_owner').val()
admin_filter = $('#admin_filter').val()
sorted_by = "#{$(this).data('sort-name')} #{$(this).data('sort-order')}"
page = $('#page').val() || 1
data =
'page': page
'filterrific':
'search_query': search_query
'show_archived': show_archived
'with_status': with_status
'with_organization': with_organization
'with_owner': with_owner
'admin_filter': admin_filter
'sorted_by': sorted_by

data = {} #Grab form values

# REVIEW this is not fetching values from multiselects
$.each $('form#filterrific-no-ajax-auto-submit').serializeArray(), (i, field) ->
data[field.name] = field.value

data["page"] = page
data["filterrific[sorted_by]"] = sorted_by

# manually enter those in
if data["filterrific[with_status][]"].length
data["filterrific[with_status][]"] = $("#filterrific_with_status").val()

if data["filterrific[with_organization][]"] && data["filterrific[with_organization][]"].length
data["filterrific[with_organization][]"] = $("#filterrific_with_organization").val()

if data["filterrific[with_owner][]"] && data["filterrific[with_owner][]"].length
data["filterrific[with_owner][]"] = $("#filterrific_with_owner").val()

$.ajax
type: 'get'
url: "/dashboard/protocols.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
.clearfix

= form_for_filterrific filterrific, remote: true, html: { id: 'filterrific-no-ajax-auto-submit', autocomplete: 'off' } do |form|
= form.hidden_field :sorted_by
.panel-body
#protocol_filter_form_display
.form-group.row
Expand All @@ -54,7 +55,7 @@
= filterrific.select_options[:with_organization].each do |org_type, orgs|
%optgroup{ label: org_type }
- orgs.each do |name, id|
%option{ value: id, selected: filterrific.with_organization && filterrific.with_organization.include?(id.to_s), data: {content: name} }
%option{ value: id, selected: filterrific.with_organization && filterrific.with_organization.include?(id), data: {content: name} }
- if admin
%hr
.form-group.row
Expand Down

0 comments on commit 0d37d91

Please sign in to comment.