Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Recipe list selection in query fixed

  • Loading branch information...
commit 60a0c0dec2928e4a656862f0812bf302b31f2f71 1 parent 4dd82e4
@upstill authored
View
124 app/assets/javascripts/RPquery.js
@@ -8,40 +8,81 @@ function queryChange() {
// Callback to respond to select on list owner,
// triggering immediate response
function queryownerChange() {
- queryheaderHit(this.form);
- queryformHit(this.form, {});
+ // queryheaderHit(this.form);
+ // queryformHit(this.form, {});
+ var ownerItem = $('#rcpquery_owner_id')[0];
+ var newOwner = ownerItem.value;
+ updateRecipeQueryHeader(newOwner);
+ updateRecipeQueryResults({});
}
-function queryListmodeChange() {
- var form = $("form")[0];
- var formstr = $(form).serialize();
- // Add the popup to the rcpquery params in the form
- var div = $('select#rcpquery_listmode_str')[0];
- var divstr = $(div).serialize();
- var datastr = "element=tabnum&" + formstr + "&" + divstr;
- //...and proceed with the form hit as usual
- var resp =
- jQuery.ajax({
+function queryTabOnPaginate(evt) {
+ // Pagination spans have an associated value with the page number
+ page = evt.currentTarget.getAttribute("value")
+ updateRecipeQueryResults({cur_page: page});
+ // queryformHit($("form")[0], {page: page});
+}
+
+function updateRecipeQueryHeader( newowner ) {
+ var query = $.param( {
+ 'rcpquery': { owner_id: newowner },
+ 'element': 'querylist_header'
+ })
+ var queryID = $(".rcpquery_owner_div").attr('value');
+ var resp = jQuery.ajax({
+ url: "/rcpqueries/"+queryID,
+ type: "POST",
+ data: query,
+ dataType: "html",
+ success: queryheaderUpdate
+ });
+}
+
+// Handle a hit on the header (backtome link or list selector) by firing off a query-update request
+function queryheaderHit(form) {
+ var resp = jQuery.ajax({
type: "POST",
url: form.action,
- data: datastr,
+ data: "element=querylist_header&" + $(form).serialize(),
// Submit the data from the form
dataType: "html",
- success: queryresultsUpdate
+ success: queryheaderUpdate
+ });
+}
+
+// Callback for replacing the recipe list header when the update returns
+function queryheaderUpdate(resp, succ, xhr) {
+ // Just slam the HTML--if any--in there. (Nil response => leave unchanged.)
+ if (resp != "") {
+ $('#querylist_header').replaceWith(resp);
+ // Replace the hit-handler
+ $("select#rcpquery_owner_id").change(queryownerChange);
}
- );
}
-// Callback after an update to hit the appropriate recipe tab
-function queryresultsUpdate(resp, succ, xhr) {
- // The response is just the index of the tab to hit
- $("#rcpquery_tabset").tabs('load', Number(resp));
- $("select#rcpquery_listmode_str").change(queryListmodeChange);
+// Update the recipe query list due to a change in state. The change is expressed in
+// the passed-in hash, which gets sent to the server as a query-update request. The
+// returned list gets used to replace the current list.
+function updateRecipeQueryResults( queryparams ) {
+ debugger;
+ var query = $.param({
+ 'rcpquery': queryparams,
+ 'element': "tabnum"
+ })
+ var queryID = $(".rcpquery_owner_div").attr('value');
+ var resp = jQuery.ajax({
+ url: "/rcpqueries/"+queryID,
+ type: "POST",
+ data: query,
+ dataType: "html",
+ success: queryresultsUpdate
+ })
}
// Handle a hit on one of the query fields by POSTing the whole form, then
// (via callback) updating the results list
function queryformHit(form, options) {
+ debugger;
var query = "";
if(options.page) {
query = "page="+page+"&"
@@ -59,26 +100,31 @@ function queryformHit(form, options) {
);
}
-// Handle a hit on the header (backtome link or list selector) by firing off a query-update request
-function queryheaderHit(form) {
- var resp = jQuery.ajax({
+function queryListmodeChange() {
+ var form = $("form")[0];
+ var formstr = $(form).serialize();
+ // Add the popup to the rcpquery params in the form
+ var div = $('select#rcpquery_listmode_str')[0];
+ var divstr = $(div).serialize();
+ var datastr = "element=tabnum&" + formstr + "&" + divstr;
+ //...and proceed with the form hit as usual
+ var resp =
+ jQuery.ajax({
type: "POST",
url: form.action,
- data: "element=querylist_header&" + $(form).serialize(),
+ data: datastr,
// Submit the data from the form
dataType: "html",
- success: queryheaderUpdate
- });
+ success: queryresultsUpdate
+ }
+ );
}
-// Callback for replacing the recipe list header when the update returns
-function queryheaderUpdate(resp, succ, xhr) {
- // Just slam the HTML--if any--in there. (Nil response => leave unchanged.)
- if (resp != "") {
- $('#querylist_header').replaceWith(resp);
- // Replace the hit-handler
- $("select#rcpquery_owner_id").change(queryownerChange);
- }
+// Callback after an update to hit the appropriate recipe tab
+function queryresultsUpdate(resp, succ, xhr) {
+ // The response is just the index of the tab to hit
+ $("#rcpquery_tabset").tabs('load', Number(resp));
+ $("select#rcpquery_listmode_str").change(queryListmodeChange);
}
// Called when a tab loads => fit any pics in their frames and enable clicking
@@ -87,6 +133,10 @@ function queryTabOnLoad() {
wdwFitImages();
$("select#rcpquery_listmode_str").change(queryListmodeChange);
$(".pageclickr").click(queryTabOnPaginate);
+ $(".popup").click(servePopup);
+ // if(popupItem = $('.popup')[0]) {
+ // popupItem.onclick = servePopup;
+ // }
// Activate the tag tokeninput field
$("#rcpquery_tag_tokens").tokenInput("/tags/match.json", {
crossDomain: false,
@@ -105,9 +155,3 @@ function queryTabOnLoad() {
function queryTabOnSelect() {
var x = 2;
}
-
-function queryTabOnPaginate(evt) {
- // Pagination spans have an associated value with the page number
- page = evt.currentTarget.getAttribute("value")
- queryformHit($("form")[0], {page: page});
-}
View
19 app/controllers/rcpqueries_controller.rb
@@ -4,6 +4,7 @@ class RcpqueriesController < ApplicationController
# Get the current query for the current user and a stipulated owner,
# making a new one as necessary
def current_query(owner)
+ debugger
uid = session[:user_id]
# Either we're dealing with an existing query, or not
session[:rcpquery] = nil if session[:rcpquery].class != Fixnum
@@ -31,7 +32,6 @@ def index
# We wake up with optional parameters:
# owner: id of list owner
- # page: page in current query
# Listing recipes doesn't require login, but we do need a user_id
need_login false # ...doesn't require session: sets user_id to guest id if none
@@ -40,7 +40,6 @@ def index
# NB: the list of special user 'guest' sees all public recipes
# Ensure the quality of the query
- session[:querypage] = @rcpquery.cur_page = params[:page] || session[:querypage]
@Title = @rcpquery.title
@navlinks = []
@nav_current = :cookmarks
@@ -54,7 +53,6 @@ def index
# GET /rcpqueries/1.xml
def show
session[:rcpquery] = params[:id].to_i
- session[:querypage] = @rcpquery.cur_page = params[:page] || session[:querypage]
redirect_to rcpqueries_url
# respond_to do |format|
@@ -87,7 +85,6 @@ def create
@rcpquery = current_query session[:user_id]
@rcpquery.update_attributes(params[:rcpquery])
@rcpquery.save
- session[:querypage] = @rcpquery.cur_page = params[:page] || session[:querypage]
@Title = "Query from Create"
redirect_to rcpqueries_url
@@ -106,9 +103,9 @@ def create
# (without such a parameter, it just refreshes the list from the current query)
def relist
# Presumably the params include :status, :querymode and/or :listmode specs
+ debugger
@rcpquery = Rcpquery.fetch_revision(session[:rcpquery], session[:user_id], params)
session[:rcpquery] = @rcpquery.id # In case the model decided on a new query
- session[:querypage] = @rcpquery.cur_page = params[:page] || session[:querypage]
render '_form_rcplist.html.erb', :layout=>false
end
@@ -118,10 +115,10 @@ def relist
# POST /rcpqueries/1.xml
def update
# Respond to a form submission (query params are in params[:rcpquery])
+ debugger
@rcpquery = Rcpquery.fetch_revision(params[:id].to_i, session[:user_id], params[:rcpquery])
session[:rcpquery] = @rcpquery.id
- session[:querypage] = @rcpquery.cur_page = params[:page] || session[:querypage]
@Title = "Query from Update"
element = params[:element].to_sym
case element
@@ -129,7 +126,7 @@ def update
# Just send back the tab number
render :text=>@rcpquery.status_tab.to_s
when :querylist_header
- render '_form_rcplist_header.html.erb', :layout=>false
+ render '_form_rcpquery_header.html.erb', :layout=>false
when :rcplist_body
render '_form_rcplist.html.erb', :layout=>false
end
@@ -139,9 +136,11 @@ def update
# DELETE /rcpqueries/1
# DELETE /rcpqueries/1.xml
def destroy
- @rcpquery = Rcpquery.find(params[:id])
- @rcpquery.destroy
- session[:rcpquery] = session[:querypage] = nil
+ begin
+ Rcpquery.find(params[:id]).destroy
+ rescue # No need to do anything with failure
+ end
+ session[:rcpquery] = nil
redirect_to rcpqueries_url
# respond_to do |format|
View
4 app/helpers/application_helper.rb
@@ -15,6 +15,10 @@ def link_to_remove_fields(name, f)
f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)")
end
+ def recipe_popup( rcp )
+ link_to image_tag("preview.png", title:"Show the Recipe", class: "preview_button"), rcp.url, target: "_blank", class: "popup"
+ end
+
# Create a popup selection list for adding a rating to the tags
def select_to_add_rating(name, f, association, ratings, inex)
# Derive 'fields', the information needed by the 'add_rating' javascript
View
1  app/helpers/rcpqueries_helper.rb
@@ -33,6 +33,7 @@ def pagination_link (text, pagenum)
end
def pagination_links
+ debugger
per_page = @rcpquery.page_length
npages = @rcpquery.npages
cur_page = @rcpquery.cur_page
View
9 app/models/rcpquery.rb
@@ -72,7 +72,7 @@ class Rcpquery < ActiveRecord::Base
attr_reader :tags
attr_reader :tag_tokens
attr_reader :results
- attr_accessor :page_length, :cur_page, :specialtags
+ attr_accessor :page_length, :specialtags
after_initialize :my_init
after_find :my_reinit
@@ -266,12 +266,12 @@ def self.fetch_revision(id, uid, params)
# Current # of results per page
def page_length()
- 25
+ 10
end
def page_length=(length)
end
-
+=begin
# Page we're now on
def cur_page()
@cur_page || 1
@@ -280,6 +280,7 @@ def cur_page()
def cur_page=(p)
@cur_page = p.to_i if p
end
+=end
# How many pages in the current result set?
def npages
@@ -293,7 +294,7 @@ def results_paged
return self.results if npg <= 1
# Clamp current page to last page
- cpg = self.cur_page
+ cpg = self.cur_page || 1
cpg = self.cur_page = npg if cpg > npg
# Now get indices of first and last records on the page
View
7 app/views/rcpqueries/_form_edit.html.erb
@@ -1,7 +1,2 @@
<%= show_errors @rcpquery.errors %>
- <div id="querylist_header">
- <div class="rcpquery_owner_div" >
- <%= select :rcpquery, :owner_id, @rcpquery.selectionlist %>
- </div>
- <h3><%= @rcpquery.title %><%= backtome %></h3>
- </div>
+ <%= render 'form_rcpquery_header' %>
View
6 app/views/rcpqueries/_form_rcpquery_header.html.erb
@@ -0,0 +1,6 @@
+<div id="querylist_header">
+ <div class="rcpquery_owner_div" value="<%= @rcpquery.id.to_s %>">
+ <%= select :rcpquery, :owner_id, @rcpquery.selectionlist %>
+ </div>
+ <h3><%= @rcpquery.title %><%= backtome %></h3>
+</div>
View
3  app/views/recipes/_form_edit.html.erb
@@ -1,4 +1,5 @@
-<h3>Tag That Recipe! <a href="<%= @recipe.url %>" target="_blank" class="popup"><%= image_tag "preview.png", title:"Show the Recipe", class: "preview_button" %></a></h3>
+<h3>Tag That Recipe!<%= recipe_popup @recipe %></h3>
+
<%= form_for @recipe do |f| %>
<%= show_errors @recipe.errors %>
<div class="recipe_pic_div" >
View
2  app/views/shared/_rcplist_smallpic.html.erb
@@ -7,7 +7,7 @@
</div>
<div class="rcp_list_text">
<div class="rcp_list_element_title">
- <%= link_to recipe.trimmed_title, recipe.url %>
+ <%= link_to recipe.trimmed_title, recipe.url %><%= recipe_popup recipe %>
</div>
<div class="rcp_list_element_source">
from <%= link_to recipe.sourcename, recipe.sourcehome %>
View
5 db/migrate/20120426001425_add_cur_page_to_rcpqueries.rb
@@ -0,0 +1,5 @@
+class AddCurPageToRcpqueries < ActiveRecord::Migration
+ def change
+ add_column :rcpqueries, :cur_page, :integer, :default => 1
+ end
+end
View
19 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120423052109) do
+ActiveRecord::Schema.define(:version => 20120426001425) do
create_table "expressions", :force => true do |t|
t.integer "tag_id"
@@ -68,6 +68,7 @@
t.string "listmode"
t.integer "status"
t.text "specialtags"
+ t.integer "cur_page", :default => 1
end
create_table "rcprefs", :force => true do |t|
@@ -109,6 +110,22 @@
t.integer "user_id"
end
+ create_table "site_referents", :force => true do |t|
+ t.string "site"
+ t.string "sample"
+ t.string "home"
+ t.string "subsite"
+ t.string "scheme"
+ t.string "host"
+ t.string "port"
+ t.string "logo"
+ t.text "tags_serialized"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.string "ttlcut"
+ t.string "ttlrepl"
+ end
+
create_table "sites", :force => true do |t|
t.string "site"
t.string "sample"

0 comments on commit 60a0c0d

Please sign in to comment.
Something went wrong with that request. Please try again.