Skip to content

Commit

Permalink
Refresh the saved search when you click on "show unapproved only"
Browse files Browse the repository at this point in the history
I was going to do a fade effect for this, but it's really fast, so I don't think there's a need.
  • Loading branch information
philc committed Sep 13, 2011
1 parent c649b57 commit f1b7876
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 8 additions & 2 deletions app.rb
Expand Up @@ -253,10 +253,16 @@ def replace_shas_with_links(text)
"OK"
end

# Toggles the "unapproved_only" checkbox and renders the first page of the saved search.
#
# TODO(philc): Make this more generic to take in all options related to a saved search.
post "/saved_searches/:id/show_unapproved_commits" do
unapproved_only = JSON.parse(request.body.read)["unapproved_only"] || false
SavedSearch[:id => params[:id].to_i].update(:unapproved_only => unapproved_only)
"OK"
saved_search = SavedSearch[:id => params[:id].to_i]
saved_search.unapproved_only = unapproved_only
saved_search.save
erb :_saved_search, :layout => false,
:locals => { :saved_search => saved_search, :token => nil, :direction => "before" }
end

#handle login complete from openid provider
Expand Down
9 changes: 6 additions & 3 deletions public/commit_search.coffee
Expand Up @@ -190,13 +190,16 @@ window.CommitSearch =
toggleUnapprovedCommits: (event) ->
@beforeSync()
data = { unapproved_only: $(event.target).attr("checked") == "checked" }
id = (Number) $(event.target).parents(".savedSearch").attr("saved-search-id")
savedSearchId = (Number) $(event.target).parents(".savedSearch").attr("saved-search-id")
$.ajax
type: "POST"
contentTypeType: "application/json"
url: "/saved_searches/#{id}/show_unapproved_commits"
url: "/saved_searches/#{savedSearchId}/show_unapproved_commits"
data: jQuery.toJSON(data)
success: => @afterSync()
success: (newSavedSearchHtml) =>
@afterSync()
savedSearchElement = $(".savedSearch[saved-search-id=#{savedSearchId}]")
savedSearchElement.replaceWith $(newSavedSearchHtml)

beforeSync: ->
# The right thing to do here is to queue up this state and re-sync when the current sync callback happens.
Expand Down

0 comments on commit f1b7876

Please sign in to comment.