
search.js
About this file
The dateInvalid function handles and adds attributes in the case that the date element is invalid.
The dataValid function removes attributes in the case that the date element is valid.
The valiDate function checks whether the checkDateElem item is a valid date (look in the extracted documentation for what is valid).
The valiDates function checks whether the range of dates given (fromDateElem - toDateElem) are valid. If not valid, then the search button is disabled; otherwise, the user can click on the search button.
Several fields allow for users to input dates, such as selecting range of closed or due dates. On the changes in input, the valiDates function is called on.
The enter button can be used to click on the search button, but does not submit the search form.
Upon searching, if results are found, they are rendered onto the html page and the generate document button can be clicked. Otherwise it is reported on the html page that no results were found and the generate document button is disabled
Filtering is handled through a function. If filtering by FOIL ID, filtering by title, descripting, agency request summary, and requester names are disabled.
The cycleSort function handles sorting data in ascending, descending, or no orderr and with the corresponding glyphicon.
Code Issues
-
For setting the table head values, the
if
andelse
conditions, shown below, result in two different column arrays, but the arrays share common elements. Recommend setting the column array with the same elements prior to coding the conditions.if (isAgencyUser) { resultcol = [ ["Status",""], ["ID",""], ["Date Submitted", "sort_date_submitted","desc"], ["Title", "sort_title","none"], ["Assigned Agency", ""], ["Date Due","sort_date_due","none"], ["Date Closed", ""], ["Requester Name", ""] ];
if (isAgencyUser) { resultcol = [ ["Status", ""], ["ID", ""], ["Date Submitted", "sort_date_submitted", "desc"], ["Title", "sort_title", "none"], ["Assigned Agency", ""], ["Date Due", "sort_date_due", "none"] ];
-
For the code snippet shown below, there are repeated function elements. Recommend creating functions with function names so the
event handler can call on the function name.
dateRecFromElem.on("input change", function () { valiDates(dateRecFromElem, dateRecToElem, dateSubmittedReq); }); dateRecToElem.on("input change", function () { valiDates(dateRecFromElem, dateRecToElem, dateSubmittedReq); }); dateDueFromElem.on("input change", function () { valiDates(dateDueFromElem, dateDueToElem, dateDueReq); }); dateDueToElem.on("input change", function () { valiDates(dateDueFromElem, dateDueToElem, dateDueReq); }); dateClosedFromElem.on("input change", function () { valiDates(dateClosedFromElem, dateClosedToElem, dateClosedReq); }); dateClosedToElem.on("input change", function () { valiDates(dateClosedFromElem, dateClosedToElem, dateClosedReq); });
- Recommend adding comments for what happens when the next and previous buttons are clicked.
Code Check Report
77:5 warning Function 'valiDate' has a complexity of 10 complexity 145:43 error Unexpected trailing comma comma-dangle 243:41 error Empty block statement no-empty 450:13 error Expected an assignment or function call and instead saw an expression no-unused-expressions 462:30 error Missing radix parameter radix 472:30 error Missing radix parameter radix ✖ 6 problems (5 errors, 1 warning) 1 error and 0 warnings potentially fixable with the `--fix` option.
Documentation drawn from source code
$(function () {
$("#user-agencies option").each(function () {
function dateInvalid(dateElem, msg, highlightDateRequirement, dateError) {
function dateValid(dateElem) {
function valiDate(checkDateElem, compDateElem, isLessThan, dateError) {
/*
* Check that 'checkDateElem' holds an empty value or
* that it is not a holiday or weekend and
* that it 'isLessThan' (or greater than if 'isLessThan' == false)
* compDateElem and style accordingly.
* */
function valiDates(fromDateElem, toDateElem, dateError) {
/*
* Check that 'fromDateElem' is less than 'toDateElem'
* and that both dates are not holidays or weekends.
* */
dateRecFromElem.on("input change", function () {
dateRecToElem.on("input change", function () {
dateDueFromElem.on("input change", function () {
dateDueToElem.on("input change", function () {
dateClosedFromElem.on("input change", function () {
dateClosedToElem.on("input change", function () {
$("#search-section").keyup(function (e) {
$("#search-form").on("keyup, keypress", function (e) {
$(clearSearchBtn).on('click', function (event) {
function buildResultsTableHead(col, sort) {
function buildResultsTable(theResults, count, total) {
function search() {
success: function (data) {
error: function (e) {
$(document).ready(function () {
$("input[name='foil_id']").click(function () {
function setStart(val) {
function updateSorting(theHeadingId, sequence) {
function cycleSort(elem) {
/*
* Cycle through sortSequence and 'style' elem with arrows
* glyphicons representing sort direction.
* */
function resetAndSearch() {
generateDocBtn.click(function () {
$(".status").click(function () {
searchBtn.click(function () {
searchBtnAdv.click(function () {
$("#size").change(function () {
agencySelect.change(function () {
404: function () {
success: function (data) {
$.each(data.active_users, function () {
complete: function () {
agencyUserSelect.change(function () {
next.click(function (event) {
prev.click(function (event) {
$('body').on('click', '.sort-field', function () {
function scrollToElement(theId) {
agencySelect.change(function () {