treconomics_project/static/javascripts/ajax_search.js
/*
Function which processes the AJAX request. Sends the request and displays the results on the page.
*/
Function which processes the AJAX request. Sends the request and displays the results on the page.
Function which processes the AJAX request . Sends the request and displays the results on the page .
function processRequest(serializedFormData, noDelay) {
    if (INTERFACE_ENABLED) {
        changeInteractionStatus(false);
    }
    if (noDelay) {
        serializedFormData += '&noDelay=true';
    }
    if (getHashValue('noperf') == 'true') {
        serializedFormData += '&noperf=true';
    }
    var posting = $.post("", serializedFormData);
    posting.done(function(data) {
        var results = $('div.results');
        results.empty(); 
        var results_nav = $('div.results_nav');
        results_nav.empty(); 
        if ('no_results' in data) {
            alert('No search term(s) were provided.');
            $('#query').focus();
        }
        else {
            if (data['trec_search']) {
                results.append('<div class="results_squash"><div class="query"><strong>Search Terms: <em>' + data['display_query'] + '</em></strong> <span>Showing page <em>' + data['curr_page'] + '</em> out of <em>' + data['num_pages'] + '</em> page(s).</span></div></div>');
                for (var result_no in data['trec_results']) {
                    var result = data['trec_results'][result_no];
                    results.append('<div class="search_result" id="' + result['docid'] + '" rank="' + result['rank'] + '" page="' + data['curr_page'] + '" whooshid="' + result['whooshid'] + '"><div class="results_squash"><div class="entry"><p class="result_title"><strong><a class="doc-link" href="' + result['url'] + '">' + result['title'] + '</a></strong></p><p class="summary">' + result['summary'] + '</p></div><div class="byline">' + result['source'] + '</div></div></div>');
                }
                var nextButton = "";
                var prevButton = "";
                if (data['curr_page'] < data['num_pages']) {
                    nextButton = '<input class="navButton largebutton" type="button" onclick="switchToPage(\'' + data['next_page_link'] + '\');" value="Next Page" />';
                }
                if (data['curr_page'] > 1) {
                    if ((data['curr_page'] - 1) == 1) {
                        prevButton = '<input class="navButton largebutton" type="button" onclick="switchToPage(\'' + data['prev_page_link'] + '\', true);" value="Prev Page" />';
                    }
                    else {
                        prevButton = '<input class="navButton largebutton" type="button" onclick="switchToPage(\'' + data['prev_page_link'] + '\');" value="Prev Page" />';
                    }
                }
                results_nav.append('<div class="result_nav"><center><form>' + prevButton + nextButton + '</form></center></div>');
                $('.searchbox, .smallsearchbox').blur();
            }
            else {
                results.append('<div class="query"><div class="results_squash"><strong>Search Terms: <em>' + data['query'] + '</em></strong> <span>No results found.</span></div></div>');
                $('#query').focus();
            }
            stopHashChange = true;
            if ('curr_page' in data) {
                window.location.hash = 'query=' + data['query'] + '&page=' + data['curr_page'];
            }
            else {
                window.location.hash = 'query=' + data['query'];
            }
        }
        changeInteractionStatus(true);
        $('body').scrollTop(0);
    });
        if ('
 ' in responseData) {
            alert("Your time for this exercise has expired. We will now redirect you to the next step.");
            window.location = APP_ROOT + 'next/';
        }
        else {
            alert("Something went wrong with your request!");
            console.log("Server error on AJAX request: " + data.responseText);
        }
    });
}
function processRequest ( serializedFormData , noDelay ) { if ( INTERFACE_ENABLED ) { changeInteractionStatus ( false ) ; } if ( noDelay ) { serializedFormData += '&noDelay=true' ; } if ( getHashValue ( 'noperf' ) == 'true' ) { serializedFormData += '&noperf=true' ; } var posting = $ . post ( "" , serializedFormData ) ; posting . done ( function ( data ) { var results = $ ( 'div.results' ) ; results . empty ( ) ; var results_nav = $ ( 'div.results_nav' ) ; results_nav . empty ( ) ; if ( 'no_results' in data ) { alert ( 'No search term(s) were provided.' ) ; $ ( '#query' ) . focus ( ) ; } else { if ( data [ 'trec_search' ] ) { results . append ( '<div class="results_squash"><div class="query"><strong>Search Terms: <em>' + data [ 'display_query' ] + '</em></strong> <span>Showing page <em>' + data [ 'curr_page' ] + '</em> out of <em>' + data [ 'num_pages' ] + '</em> page(s).</span></div></div>' ) ; for ( var result_no in data [ 'trec_results' ] ) { var result = data [ 'trec_results' ] [ result_no ] ; results . append ( '<div class="search_result" id="' + result [ 'docid' ] + '" rank="' + result [ 'rank' ] + '" page="' + data [ 'curr_page' ] + '" whooshid="' + result [ 'whooshid' ] + '"><div class="results_squash"><div class="entry"><p class="result_title"><strong><a class="doc-link" href="' + result [ 'url' ] + '">' + result [ 'title' ] + '</a></strong></p><p class="summary">' + result [ 'summary' ] + '</p></div><div class="byline">' + result [ 'source' ] + '</div></div></div>' ) ; } var nextButton = "" ; var prevButton = "" ; if ( data [ 'curr_page' ] < data [ 'num_pages' ] ) { nextButton = '<input class="navButton largebutton" type="button" onclick="switchToPage(\'' + data [ 'next_page_link' ] + '\');" value="Next Page" />' ; } if ( data [ 'curr_page' ] > 1 ) { if ( ( data [ 'curr_page' ] - 1 ) == 1 ) { prevButton = '<input class="navButton largebutton" type="button" onclick="switchToPage(\'' + data [ 'prev_page_link' ] + '\', true);" value="Prev Page" />' ; } else { prevButton = '<input class="navButton largebutton" type="button" onclick="switchToPage(\'' + data [ 'prev_page_link' ] + '\');" value="Prev Page" />' ; } } results_nav . append ( '<div class="result_nav"><center><form>' + prevButton + nextButton + '</form></center></div>' ) ; $ ( '.searchbox, .smallsearchbox' ) . blur ( ) ; } else { results . append ( '<div class="query"><div class="results_squash"><strong>Search Terms: <em>' + data [ 'query' ] + '</em></strong> <span>No results found.</span></div></div>' ) ; $ ( '#query' ) . focus ( ) ; } stopHashChange = true ; if ( 'curr_page' in data ) { window . location . hash = 'query=' + data [ 'query' ] + '&page=' + data [ 'curr_page' ] ; } else { window . location . hash = 'query=' + data [ 'query' ] ; } } changeInteractionStatus ( true ) ; $ ( 'body' ) . scrollTop ( 0 ) ; } ) ; }
Function which processes the AJAX request.
Function which processes the AJAX request .
// Remove all children for the new results set // Remove all children from the navigation button container // Add the top part // Add each of the results // Add navigation buttons at bottom of page (if applicable) //bindDocumentClicks(); //bindResultHovering(); // Bind hovering actions to the new document elements. //    posting.fail(function(data) { //        var responseData = $.parseJSON(data.responseText); // //        if (' // ' in responseData) { //            alert("Your time for this exercise has expired. We will now redirect you to the next step."); //            window.location = APP_ROOT + 'next/'; //        } //        else { //            alert("Something went wrong with your request!"); //            console.log("Server error on AJAX request: " + data.responseText); //        } //    });