Skip to content

Commit

Permalink
Added search help
Browse files Browse the repository at this point in the history
  • Loading branch information
fourlincoln10 committed Mar 18, 2012
1 parent d9f321c commit 1b9df0e
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 96 deletions.
193 changes: 99 additions & 94 deletions app/assets/javascripts/offerings.js.erb
Expand Up @@ -4,115 +4,94 @@ var OfferingEnhancements = {
// table row (tr) correctly
// ------------------------------------------------------------
forceHelper: function(e,ui) {
$(".ui-state-highlight").html("<td colspan='100%'>&nbsp;</td>");
$(".ui-state-highlight").html("<td colspan='100%'>&nbsp;</td>");
},

// ------------------------------------------------------------
// Allows persistent, user-based sorting of content and objectives
// ------------------------------------------------------------
makeContentAndObjectivesSortable: function() {
var container = $('#objectives_container, #content_container');
if(container.length < 1) {
return;
}
container.each(function(index, element){
makeContentAndObjectivesSortable: function() {
var container = $('#objectives_container, #content_container');
if(container.length < 1) {
return;
}
container.each(function(index, element){
$('tbody tr', element).addClass("draggable");
$('tbody', element).sortable({
axis: 'y',
items: 'tr',
placeholder: 'ui-state-highlight',
opacity: 0.4,
scroll: true,
change: function(e, ui) {
OfferingEnhancements.forceHelper(e,ui);
}
});
});
$('.offering-content-groups').submit(function(){
$(".offering-content-groups input.position").each(function(index) {
$(this).val(index);
});
return true;
});
},

interceptPaginationLinks: function() {
var context = this;
$(".pagination a").click(function(evt){
evt.preventDefault();
$.ajax({
type: 'GET',
url: $(this).attr("href"),
dataType: 'html',
data: {partial: 'true'},
context: context,
success: function(results, textStatus, jqXHR) {
$(this.resultsSelector).replaceWith(results);
this.interceptPaginationLinks();
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("Error. Status code: " + jqXHR.status, jqXHR.statusText);
}
});
});
axis: 'y',
items: 'tr',
placeholder: 'ui-state-highlight',
opacity: 0.4,
scroll: true,
change: function(e, ui) {
OfferingEnhancements.forceHelper(e,ui);
}
});
});

$('.offering-content-groups').submit(function(){
$(".offering-content-groups input.position").each(function(index) {
$(this).val(index);
});
return true;
});
},

interceptPaginationLinks: function() {
var context = this;
$(".pagination a").click(function(evt){
evt.preventDefault();
$.ajax({
type: 'GET',
url: $(this).attr("href"),
dataType: 'html',
data: {partial: 'true'},
context: context,
success: function(results, textStatus, jqXHR) {
$(this.resultsSelector).replaceWith(results);
this.interceptPaginationLinks();
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("Error. Status code: " + jqXHR.status, jqXHR.statusText);
}
});
});
},

// ------------------------------------------------------------
// Loads facets for Visual Search from the server.
// ------------------------------------------------------------
loadFacets: function() {
this.searchContainer = $('#offerings');
if(this.searchContainer.length < 1) {
return;
}
this.baseUrl = this.searchContainer.data('baseurl');
if(this.baseUrl.length < 1) {
return;
}
this.resultsSelector = this.searchContainer.data('results-selector');
if(this.resultsSelector.length < 1) {
return;
}
$.ajax({
type: 'GET',
url: this.baseUrl + "/facets",
dataType: 'json',
context: this,
success: function(facets, textStatus, jqXHR) {
this.initializeSearch(facets, this.baseUrl, this.searchContainer);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus);
}
});
},

// ------------------------------------------------------------
// Called by the VS search method when a user selects a facet
// and value
// ------------------------------------------------------------
runSearch: function(data, context) {
$.ajax({
type: 'GET',
url: context.baseUrl,
data: data,
dataType: "html",
context: context,
success: function(searchResults, textStatus, jqXHR) {
$(context.resultsSelector).replaceWith(searchResults);
context.interceptPaginationLinks();
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus)
}
});
this.searchContainer = $('#offerings');
if(this.searchContainer.length < 1) {
return;
}
this.baseUrl = this.searchContainer.data('baseurl');
if(this.baseUrl.length < 1) {
return;
}
this.resultsSelector = this.searchContainer.data('results-selector');
if(this.resultsSelector.length < 1) {
return;
}
var context = this;
$.when(
$.ajax({url: this.baseUrl + "/facets", dataType: 'json'}),
$.get(this.baseUrl + "/search_explanation")
)
.done(function(facetArgs, explanationArgs) {
context.initializeSearch(facetArgs[0], explanationArgs[0]);
})
.fail(function(jqXHR, statusText, errorMsg){
console.log(statusText);
});
},

// ------------------------------------------------------------
// Initialize / configure Visual Search (visualsearch.js)
// VS: http://documentcloud.github.com/visualsearch/
// ------------------------------------------------------------
initializeSearch: function(facets, baseUrl) {
initializeSearch: function(facets, search_help) {
facetCategories = [];
for (var propertyName in facets) {
if (facets.hasOwnProperty(propertyName)) {
Expand All @@ -139,10 +118,36 @@ var OfferingEnhancements = {
callback(facets[facet], {preserveOrder: true});
}
}
});
this.searchContainer.append("<div id='search_help'>Possible search terms are: " + facetCategories.join(", "));
},

});
this.searchContainer.append("<div id='search_explanation'>Possible search terms are: " + facetCategories.join(", ") + " <a href='#' id='toggle_search_help'>(more info)</a>");
$("#toggle_search_help", this.searchContainer).click(function(evt){
evt.preventDefault();
$("#search_help").toggle("fast");
});
this.searchContainer.append("<div id='search_help'>" + search_help + "</div>");
$("#search_help").css("display", "none");
},

// ------------------------------------------------------------
// Called by the VS search method when a user selects a facet
// and value
// ------------------------------------------------------------
runSearch: function(data, context) {
$.ajax({
type: 'GET',
url: context.baseUrl,
data: data,
dataType: "html",
context: context,
success: function(searchResults, textStatus, jqXHR) {
$(context.resultsSelector).replaceWith(searchResults);
context.interceptPaginationLinks();
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus)
}
});
},
// ------------------------------------------------------------
// The sum of the values in every cell in a content row
// must equal this value
Expand Down
3 changes: 1 addition & 2 deletions app/assets/stylesheets/offerings.css.scss
Expand Up @@ -44,9 +44,8 @@ form.offering-assessment {
}
}

#search_help {
#search_explanation {
font-size: 11px;
color: #aaa;
}

#offering-index {
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/offerings_controller.rb
Expand Up @@ -127,6 +127,10 @@ def facets
render :json => obj
end

def search_explanation
render :partial => 'search_explanation', :layout => false
end

def export
@offerings = Offering

Expand Down
9 changes: 9 additions & 0 deletions app/views/offerings/_search_explanation.html.erb
@@ -0,0 +1,9 @@
<p>The search bar allows you to search for offerings using predefined search terms and values.</p>
<ul>
<li>The search bar will auto-complete search terms when you start typing.</li>
<li>Select a search term and you will be provided with a list of associated values.</li>
<li>Choose a value to initiate a search.</li>
<li>Search terms/values can be chained together. For example you can search for a term and an instructor.</li>
<li>Deleting a search term will initiate a search using the remaining search terms if any are found or a search for all offerings if not.</li>
<li>An empty search (no search terms are present) will return a list of all offerings.</li>
</ul>
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -41,6 +41,7 @@
get :search
get :export
get :facets
get :search_explanation
end
member do
get :export, action: :export_member, as: "export"
Expand Down

0 comments on commit 1b9df0e

Please sign in to comment.