Browse Source

[search] Remember the previously selected collection

The selected collection is stored on the hueSearchLastCore cookie
Added spinner for page load/unload
Enrico Berti 12 years ago
parent
commit
a804769
2 changed files with 16 additions and 4 deletions
  1. 13 2
      apps/search/src/search/templates/search.mako
  2. 3 2
      apps/search/src/search/views.py

+ 13 - 2
apps/search/src/search/templates/search.mako

@@ -57,7 +57,10 @@ ${ commonheader(_('Search'), "search", user, "40px") | n,unicode }
 </div>
 </div>
 
 
 <div class="container-fluid">
 <div class="container-fluid">
-  <div class="row-fluid">
+  <div id="loader" class="row-fluid">
+    <img src="/static/art/spinner.gif" />
+  </div>
+  <div id="mainContent" class="row-fluid hide">
     % if error:
     % if error:
     <div class="span12">
     <div class="span12">
       <div class="alert">
       <div class="alert">
@@ -276,6 +279,13 @@ ${ hue_core.result.get_extracode() | n,unicode }
 
 
 <script>
 <script>
   $(document).ready(function () {
   $(document).ready(function () {
+    $("#loader").hide();
+    $("#mainContent").removeClass("hide");
+    window.onbeforeunload = function (e) {
+      $("#loader").show();
+      $("#mainContent").addClass("hide");
+    };
+
     $(".dateFacet").each(function () {
     $(".dateFacet").each(function () {
       var _m = moment($(this).text());
       var _m = moment($(this).text());
       $(this).text(_m.fromNow());
       $(this).text(_m.fromNow());
@@ -296,7 +306,7 @@ ${ hue_core.result.get_extracode() | n,unicode }
     });
     });
     $(".dateFacetHeader").after(orderedDateFacets);
     $(".dateFacetHeader").after(orderedDateFacets);
 
 
-    $(".current-core").text($("select[name='collection'] option:selected").text());
+    $(".current-core").text("${ current_core }");
     % if user.is_superuser:
     % if user.is_superuser:
         $(".dropdown-core").each(function () {
         $(".dropdown-core").each(function () {
           if ($(this).data("value") == $("select[name='collection']").val()) {
           if ($(this).data("value") == $("select[name='collection']").val()) {
@@ -312,6 +322,7 @@ ${ hue_core.result.get_extracode() | n,unicode }
       % if user.is_superuser:
       % if user.is_superuser:
           $(".change-settings").attr("href", $(this).data("settings-url"));
           $(".change-settings").attr("href", $(this).data("settings-url"));
       % endif
       % endif
+      $.cookie("hueSearchLastCore", $(this).text(), {expires: 90});
       $("form").submit();
       $("form").submit();
     });
     });
 
 

+ 3 - 2
apps/search/src/search/views.py

@@ -53,6 +53,8 @@ def index(request):
 
 
   if search_form.is_valid():
   if search_form.is_valid():
     core = search_form.cleaned_data['collection']
     core = search_form.cleaned_data['collection']
+    if request.GET.get('collection') is None:
+      core = request.COOKIES.get('hueSearchLastCore', cores['status'].keys()[0])
     solr_query['core'] = core
     solr_query['core'] = core
     solr_query['q'] = search_form.cleaned_data['query']
     solr_query['q'] = search_form.cleaned_data['query']
     solr_query['fq'] = search_form.cleaned_data['fq']
     solr_query['fq'] = search_form.cleaned_data['fq']
@@ -68,7 +70,7 @@ def index(request):
     except Exception, e:
     except Exception, e:
       error['message'] = unicode(str(e), "utf8")
       error['message'] = unicode(str(e), "utf8")
   else:
   else:
-    core = cores['status'].keys()[0]
+    core = request.COOKIES.get('hueSearchLastCore', cores['status'].keys()[0])
     hue_core = Core.objects.get_or_create(name=core)
     hue_core = Core.objects.get_or_create(name=core)
 
 
   return render('search.mako', request, {
   return render('search.mako', request, {
@@ -155,7 +157,6 @@ def admin_core_facets(request, core):
   hue_cores = Core.objects.all()
   hue_cores = Core.objects.all()
 
 
   if request.method == 'POST':
   if request.method == 'POST':
-    print request.POST
     hue_core.facets.update_from_post(request.POST)
     hue_core.facets.update_from_post(request.POST)
     hue_core.facets.save()
     hue_core.facets.save()
     return HttpResponse(json.dumps({}), mimetype="application/json")
     return HttpResponse(json.dumps({}), mimetype="application/json")