{"id":16377,"date":"2021-06-09T04:56:32","date_gmt":"2021-06-09T04:56:32","guid":{"rendered":"http:\/\/www.pidsphil.org\/home\/?page_id=16377"},"modified":"2021-06-09T04:56:32","modified_gmt":"2021-06-09T04:56:32","slug":"journal-search","status":"publish","type":"page","link":"https:\/\/www.pidsphil.org\/home\/journal-search\/","title":{"rendered":"Journal Search"},"content":{"rendered":"<style>\n    #anvj_search_content p {\n        text-align: justify;\n    }\n\n    @media(min-width: 1024px){\n        #anvj_search_box{\n            display: flex;\n            max-width: 600px;\n            align-items: center\n        }\n    }\n\n    @media(max-width: 1023px){\n        #anvj_search_box{\n            display: flex;\n            flex-direction: column;\n            max-width: 600px;\n        }\n\n        #anvj_search_box select {\n            margin-top: 10px;\n        }\n    }\n\n<\/style>\n\n<div id=\"anvj_search_box\">\n    <label for=\"anvj_search\" style=\"margin-right: 10px\">Search<\/label>\n    <input class=\"form-control\" id=\"anvj_search\" placeholder=\"Search here...\" type=\"text\" autocomplete=\"off\" name=\"anvj_search\" \/>\n\n    <select id=\"anvj_search_in\">\n        <option value=\"content\">Search In Content<\/option>\n        <option value=\"title\">Search In Title<\/option>\n        <option value=\"author\">Search In Author<\/option>\n        <option value=\"keywords\">Search In Keywords<\/option>\n    <\/select>\n    &nbsp;\n    <button onclick=\"anvj_search_clicked()\" class=\"wpcf7-form-control wpcf7-submit\" type=\"button\">Search<\/button>\n<\/div>\n\n\n<p>&nbsp;<\/p>\n<div id=\"anvj_search_results\">\n    <p>Please enter the search term, and click Search.<\/p>\n<\/div>\n\n<script type=\"text\/html\" id=\"anvj_results_template\">\n    <tr><td>\n    <table>\n        <tbody>\n            <tr><th style=\"width: 100px\">Title:<\/th><td colspan=\"3\">{title}<\/td><\/tr>\n            <tr><th>Doc No:<\/th><td style=\"padding-right: 20px;\">{doc_no}<\/td><\/tr>\n            <tr><th style=\"padding-right: 20px; width: 100px\">Author:<\/th><td colspan=\"3\" style=\"padding-right: 20px;\">{author}<\/td><\/tr>\n            <tr><th style=\"padding-right: 20px;\">Keywords:<\/th><td colspan=\"3\">{keywords}<\/td><\/tr>\n            <tr><th>Link to Article:<\/th><td colspan=\"4\"><a href=\"{link}\">{link_title}<\/a><\/td><\/tr>\n            <tr><th colspan=\"4\">&nbsp;<\/th><\/tr>\n            <tr><th id=\"anvj_search_content\" colspan=\"4\">{content}<\/th><\/tr>\n        <\/tbody>\n    <\/table><\/td><\/tr>\n<\/script>\n\n<script>\njQuery(document).ready(function($){\n\n    let current_page = 1;\n    let current_term = \"\";\n    let current_search_in = \"\";\n\n    window.anvj_search_clicked = function(){\n        const term = $('#anvj_search').val();\n        const search_in = $('#anvj_search_in').val();\n\n        current_search_in = search_in;\n        current_term = term;\n        current_page = 1;\n        anvj_search();\n    }\n\n    function anvj_search(){\n\n        const container = $('#anvj_search_results');\n        $(container).html('<p>Searching....<\/p>');\n\n        $.ajax({\n           method: 'POST',\n           url: '\/home\/wp-admin\/admin-ajax.php',\n           data: {\n               action: 'anvj_search',\n               term: current_term,\n               search_in: current_search_in,\n               page: current_page\n           },\n           success: function(data){\n               build_results_view(data.result);\n           },\n           error: function(){\n               show_error_message();\n           }\n        });\n    }\n\n    function build_results_view(data){\n\n        const container = $('#anvj_search_results');\n        $(container).html('');\n\n        if(data === undefined || data.length === 0){\n            if(current_page > 1){\n\n                let nav = '<table class=\"table table-bordered\"><tr><td style=\"text-align: center\">';\n\n                nav += '<button onclick=\"anvj_search_prev()\" type=\"button\" class=\"wpcf7-form-control wpcf7-submit\"><i class=\"fa fa-arrow-left\">&nbsp;<\/i>Previous Result<\/button>';\n\n                nav += '<\/td><\/tr><\/table>';\n\n                $(nav).appendTo(container);\n                $(container).append('<p>No more results<\/p>');\n            }\n            else{\n                $(container).html('<p>Nothing found matching your criteria.<\/p>');\n            }\n\n            return;\n        }\n\n        let nav = '<table class=\"table table-bordered\"><tr><td style=\"text-align: center\">';\n\n        if(current_page > 1){\n            nav += '<button onclick=\"anvj_search_prev()\" type=\"button\" class=\"wpcf7-form-control wpcf7-submit\"><i class=\"fa fa-arrow-left\">&nbsp;<\/i>Previous Result<\/button>&nbsp;';\n        }\n\n        nav += '<button type=\"button\" onclick=\"anvj_search_next()\" class=\"wpcf7-form-control wpcf7-submit\"><i class=\"fa fa-arrow-right\">&nbsp;<\/i>Next Result<\/button><\/td><\/tr><\/table>';\n\n        $(nav).appendTo(container);\n\n        $('<table class=\"table table-responsive\"><tbody><\/tbody><\/table>').appendTo(container);\n\n        const tbody = $('tbody:last', container);\n        const row_template = $('#anvj_results_template').html();\n\n        $(data).each(function(){\n            const row = this;\n\n            const row_data = row_template\n                .replace('{doc_no}', row[\"doc_no\"] || \"\")\n                .replace('{title}', row[\"title\"] || \"\")\n                .replace('{author}', row[\"author\"] || \"\")\n                .replace('{content}', row[\"content\"] || \"\")\n                .replace('{keywords}', row[\"keywords\"] || \"\")\n                .replace(\/\\{link\\}\/g, row['link'] || \"#\")\n                .replace(\/\\{link_title\\}\/g, row['link'] || \"NA\");\n\n            $(tbody).append(row_data);\n        });\n\n        $(nav).appendTo(container);\n    }\n\n    window.anvj_search_prev = function(){\n        if(current_page > 1) {\n            current_page--;\n            anvj_search();\n        }\n    }\n\n    window.anvj_search_next = function(){\n        current_page++;\n        anvj_search();\n    }\n\n    function show_error_message(){\n        const container = $('#anvj_search_results');\n        $(container).html('<p>An error occurred. Please try again later.<\/p>');\n    }\n\n});\n<\/script>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":3,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-16377","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.pidsphil.org\/home\/wp-json\/wp\/v2\/pages\/16377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pidsphil.org\/home\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pidsphil.org\/home\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pidsphil.org\/home\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pidsphil.org\/home\/wp-json\/wp\/v2\/comments?post=16377"}],"version-history":[{"count":1,"href":"https:\/\/www.pidsphil.org\/home\/wp-json\/wp\/v2\/pages\/16377\/revisions"}],"predecessor-version":[{"id":16378,"href":"https:\/\/www.pidsphil.org\/home\/wp-json\/wp\/v2\/pages\/16377\/revisions\/16378"}],"wp:attachment":[{"href":"https:\/\/www.pidsphil.org\/home\/wp-json\/wp\/v2\/media?parent=16377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}