From b0d97a30441d4f4da8ea93725f96440c4c081cf1 Mon Sep 17 00:00:00 2001 From: Joel Castillo Date: Mon, 7 May 2018 17:33:20 -0400 Subject: [PATCH 1/4] Fixing issues with agency request info --- app/static/js/request/new-request-agency.js | 56 ++++++++++++------- app/static/js/request/new-request-anon.js | 59 ++++++++++++-------- app/static/js/request/new-request-user.js | 62 +++++++++++++-------- 3 files changed, 110 insertions(+), 67 deletions(-) diff --git a/app/static/js/request/new-request-agency.js b/app/static/js/request/new-request-agency.js index 8c9cc4317..fe02829cc 100755 --- a/app/static/js/request/new-request-agency.js +++ b/app/static/js/request/new-request-agency.js @@ -5,9 +5,40 @@ "use strict"; $(document).ready(function () { + $(window).load(function () { + // Determine if the agencyRequestInstructions need to be shown on page load. + getRequestAgencyInstructions(); + }); - $("input[name='tz-name']").val(jstz.determine().name()); + function getRequestAgencyInstructions() { + /* + * ajax call to get additional information for the specified agency + */ + + var agencyEin = $("#request-agency").val(); + var requestInstructionsDiv = $("#request-agency-instructions"); + var requestInstructionsContentDiv = $("#request-agency-instructions-content"); + $.ajax({ + url: "/agency/feature/" + agencyEin + "/" + "specific_request_instructions", + type: "GET", + success: function (data) { + if (data["specific_request_instructions"]["text"] !== "") { + requestInstructionsContentDiv.html("

" + data["specific_request_instructions"]["text"] + "

"); + requestInstructionsDiv.show(); + } + else { + requestInstructionsDiv.hide(); + } + }, + error: function () { + requestInstructionsDiv.hide(); + } + + }); + } + + $("input[name='tz-name']").val(jstz.determine().name()); // Prevent user from entering a non numeric value into phone and fax field $("#phone").keypress(function (key) { @@ -25,26 +56,9 @@ $(document).ready(function () { } }); - // ajax call to get additional information for the specified agency - var selectedAgency = $("#request-agency").val(); - var requestInstructionsDiv = $("#request-agency-instructions"); - var requestInstructionsContentDiv = $("#request-agency-instructions-content"); - $.ajax({ - url: "/agency/feature/" + selectedAgency + "/" + "specific_request_instructions", - type: "GET", - success: function (data) { - if (data["specific_request_instructions"]["text"] !== "") { - requestInstructionsContentDiv.html("

" + data["specific_request_instructions"]["text"] + "

"); - requestInstructionsDiv.show(); - } - else { - requestInstructionsDiv.hide(); - } - }, - error: function () { - requestInstructionsDiv.hide(); - } + $("#request-agency").change(function () { + getRequestAgencyInstructions(); }); $("#request-agency-instructions-toggle").click(function () { @@ -250,7 +264,7 @@ $(document).ready(function () { // Disable submit button on form submission $("#request-form").submit(function () { // Prevent multiple submissions - $(this).submit(function() { + $(this).submit(function () { return false; }); $("#submit").hide(); diff --git a/app/static/js/request/new-request-anon.js b/app/static/js/request/new-request-anon.js index acd144e60..fc5798c5e 100755 --- a/app/static/js/request/new-request-anon.js +++ b/app/static/js/request/new-request-anon.js @@ -5,6 +5,38 @@ "use strict"; $(document).ready(function () { + $(window).load(function () { + // Determine if the agencyRequestInstructions need to be shown on page load. + getRequestAgencyInstructions(); + }); + + function getRequestAgencyInstructions() { + /* + * ajax call to get additional information for the specified agency + */ + + var agencyEin = $("#request-agency").val(); + var requestInstructionsDiv = $("#request-agency-instructions"); + var requestInstructionsContentDiv = $("#request-agency-instructions-content"); + + $.ajax({ + url: "/agency/feature/" + agencyEin + "/" + "specific_request_instructions", + type: "GET", + success: function (data) { + if (data["specific_request_instructions"]["text"] !== "") { + requestInstructionsContentDiv.html("

" + data["specific_request_instructions"]["text"] + "

"); + requestInstructionsDiv.show(); + } + else { + requestInstructionsDiv.hide(); + } + }, + error: function () { + requestInstructionsDiv.hide(); + } + + }); + } $("input[name='tz-name']").val(jstz.determine().name()); @@ -24,7 +56,7 @@ $(document).ready(function () { } }); - // ajax call to get and populate list of agencies choices based on selected category + $("#request-category").change(function () { $.ajax({ url: "/request/agencies", @@ -41,32 +73,15 @@ $(document).ready(function () { opt.value = data[i][0]; sel.append(opt); } + // Determine if the agencyRequestInstructions need to be shown on page load. + getRequestAgencyInstructions(); } }); }); - // ajax call to get additional information for the specified agency - $("#request-agency").change(function () { - var selectedAgency = $("#request-agency").val(); - var requestInstructionsDiv = $("#request-agency-instructions"); - var requestInstructionsContentDiv = $("#request-agency-instructions-content"); - $.ajax({ - url: "/agency/feature/" + selectedAgency + "/" + "specific_request_instructions", - type: "GET", - success: function (data) { - if (data["specific_request_instructions"]["text"] !== "") { - requestInstructionsContentDiv.html("

" + data["specific_request_instructions"]["text"] + "

"); - requestInstructionsDiv.show(); - } - else { - requestInstructionsDiv.hide(); - } - }, - error: function () { - requestInstructionsDiv.hide(); - } - }); + $("#request-agency").change(function () { + getRequestAgencyInstructions(); }); $("#request-agency-instructions-toggle").click(function () { diff --git a/app/static/js/request/new-request-user.js b/app/static/js/request/new-request-user.js index 2c3fbaf94..b20dd414d 100755 --- a/app/static/js/request/new-request-user.js +++ b/app/static/js/request/new-request-user.js @@ -5,10 +5,41 @@ "use strict"; $(document).ready(function () { + $(window).load(function () { + // Determine if the agencyRequestInstructions need to be shown on page load. + getRequestAgencyInstructions(); + }); - $("input[name='tz-name']").val(jstz.determine().name()); + function getRequestAgencyInstructions() { + /* + * ajax call to get additional information for the specified agency + */ + + var agencyEin = $("#request-agency").val(); + var requestInstructionsDiv = $("#request-agency-instructions"); + var requestInstructionsContentDiv = $("#request-agency-instructions-content"); + + $.ajax({ + url: "/agency/feature/" + agencyEin + "/" + "specific_request_instructions", + type: "GET", + success: function (data) { + if (data["specific_request_instructions"]["text"] !== "") { + requestInstructionsContentDiv.html("

" + data["specific_request_instructions"]["text"] + "

"); + requestInstructionsDiv.show(); + } + else { + requestInstructionsDiv.hide(); + } + }, + error: function () { + requestInstructionsDiv.hide(); + } + + }); + } - // ajax call to get and populate list of agencies choices based on selected category + $("input[name='tz-name']").val(jstz.determine().name()); + $("#request-category").change(function () { $.ajax({ url: "/request/agencies", @@ -25,32 +56,15 @@ $(document).ready(function () { opt.value = data[i][0]; sel.append(opt); } + // Determine if the agencyRequestInstructions need to be shown on page load. + getRequestAgencyInstructions(); } }); }); - // ajax call to get additional information for the specified agency - $("#request-agency").change(function () { - var selectedAgency = $("#request-agency").val(); - var requestInstructionsDiv = $("#request-agency-instructions"); - var requestInstructionsContentDiv = $("#request-agency-instructions-content"); - $.ajax({ - url: "/agency/feature/" + selectedAgency + "/" + "specific_request_instructions", - type: "GET", - success: function (data) { - if (data["specific_request_instructions"]["text"] !== "") { - requestInstructionsContentDiv.html("

" + data["specific_request_instructions"]["text"] + "

"); - requestInstructionsDiv.show(); - } - else { - requestInstructionsDiv.hide(); - } - }, - error: function () { - requestInstructionsDiv.hide(); - } - }); + $("#request-agency").change(function () { + getRequestAgencyInstructions(); }); $("#request-agency-instructions-toggle").click(function () { @@ -156,7 +170,7 @@ $(document).ready(function () { // Disable submit button on form submission $("#request-form").submit(function () { // Prevent multiple submissions - $(this).submit(function() { + $(this).submit(function () { return false; }); $("#submit").hide(); From 2bc753f427ba07affc0c7c26f517e03ec055586f Mon Sep 17 00:00:00 2001 From: Joel Castillo Date: Tue, 8 May 2018 11:03:03 -0400 Subject: [PATCH 2/4] Streamline app; Fix JS error --- app/static/js/request/main.js | 43 +++++++++++++++++---- app/static/js/request/new-request-agency.js | 28 -------------- app/static/js/request/new-request-anon.js | 28 -------------- app/static/js/request/new-request-user.js | 28 -------------- 4 files changed, 36 insertions(+), 91 deletions(-) diff --git a/app/static/js/request/main.js b/app/static/js/request/main.js index 22b329c24..f94a4132b 100644 --- a/app/static/js/request/main.js +++ b/app/static/js/request/main.js @@ -1,21 +1,21 @@ "use strict"; // Don't cache ajax requests -$.ajaxSetup({ cache: false }); +$.ajaxSetup({cache: false}); $(function () { $("[data-toggle='popover']").popover(); }); -$(function() { - $(".disable-enter-submit").keypress(function(e){ +$(function () { + $(".disable-enter-submit").keypress(function (e) { if (e.keyCode == '13') { - e.preventDefault(); + e.preventDefault(); } }); }); -function characterCounter (target, limit, currentLength, minLength) { +function characterCounter(target, limit, currentLength, minLength) { /* Global character counter * * Parameters: @@ -47,7 +47,7 @@ function characterCounter (target, limit, currentLength, minLength) { } } -function regexUrlChecker (value) { +function regexUrlChecker(value) { /* Checks the value of a url link using regex with one of the following allowed protocols: http, https, ftp, git * * Parameters: @@ -77,7 +77,36 @@ function notHolidayOrWeekend(date, forPicker) { } var formattedDate = $.datepicker.formatDate('yy-mm-dd', date); var holiday_or_weekend = $.inArray(formattedDate, holiday_dates) !== -1 || - date.getDay() === 0 || date.getDay() === 6; + date.getDay() === 0 || date.getDay() === 6; // TODO: would be nice to display the name of the holiday (tooltip) return forPicker ? [!holiday_or_weekend] : !holiday_or_weekend; } + + +function getRequestAgencyInstructions() { + /* + * ajax call to get additional information for the specified agency + */ + + var agencyEin = $("#request-agency").val(); + var requestInstructionsDiv = $("#request-agency-instructions"); + var requestInstructionsContentDiv = $("#request-agency-instructions-content"); + if (agencyEin !== "") { + $.ajax({ + url: "/agency/feature/" + agencyEin + "/" + "specific_request_instructions", + type: "GET", + success: function (data) { + if (data["specific_request_instructions"]["text"] !== "") { + requestInstructionsContentDiv.html("

" + data["specific_request_instructions"]["text"] + "

"); + requestInstructionsDiv.show(); + } + else { + requestInstructionsDiv.hide(); + } + }, + error: function () { + requestInstructionsDiv.hide(); + } + }); + } +} \ No newline at end of file diff --git a/app/static/js/request/new-request-agency.js b/app/static/js/request/new-request-agency.js index fe02829cc..98ee105fc 100755 --- a/app/static/js/request/new-request-agency.js +++ b/app/static/js/request/new-request-agency.js @@ -10,34 +10,6 @@ $(document).ready(function () { getRequestAgencyInstructions(); }); - function getRequestAgencyInstructions() { - /* - * ajax call to get additional information for the specified agency - */ - - var agencyEin = $("#request-agency").val(); - var requestInstructionsDiv = $("#request-agency-instructions"); - var requestInstructionsContentDiv = $("#request-agency-instructions-content"); - - $.ajax({ - url: "/agency/feature/" + agencyEin + "/" + "specific_request_instructions", - type: "GET", - success: function (data) { - if (data["specific_request_instructions"]["text"] !== "") { - requestInstructionsContentDiv.html("

" + data["specific_request_instructions"]["text"] + "

"); - requestInstructionsDiv.show(); - } - else { - requestInstructionsDiv.hide(); - } - }, - error: function () { - requestInstructionsDiv.hide(); - } - - }); - } - $("input[name='tz-name']").val(jstz.determine().name()); // Prevent user from entering a non numeric value into phone and fax field diff --git a/app/static/js/request/new-request-anon.js b/app/static/js/request/new-request-anon.js index fc5798c5e..4bfa19cd6 100755 --- a/app/static/js/request/new-request-anon.js +++ b/app/static/js/request/new-request-anon.js @@ -10,34 +10,6 @@ $(document).ready(function () { getRequestAgencyInstructions(); }); - function getRequestAgencyInstructions() { - /* - * ajax call to get additional information for the specified agency - */ - - var agencyEin = $("#request-agency").val(); - var requestInstructionsDiv = $("#request-agency-instructions"); - var requestInstructionsContentDiv = $("#request-agency-instructions-content"); - - $.ajax({ - url: "/agency/feature/" + agencyEin + "/" + "specific_request_instructions", - type: "GET", - success: function (data) { - if (data["specific_request_instructions"]["text"] !== "") { - requestInstructionsContentDiv.html("

" + data["specific_request_instructions"]["text"] + "

"); - requestInstructionsDiv.show(); - } - else { - requestInstructionsDiv.hide(); - } - }, - error: function () { - requestInstructionsDiv.hide(); - } - - }); - } - $("input[name='tz-name']").val(jstz.determine().name()); // Prevent user from entering a non numeric value into phone and fax field diff --git a/app/static/js/request/new-request-user.js b/app/static/js/request/new-request-user.js index b20dd414d..7b996df29 100755 --- a/app/static/js/request/new-request-user.js +++ b/app/static/js/request/new-request-user.js @@ -10,34 +10,6 @@ $(document).ready(function () { getRequestAgencyInstructions(); }); - function getRequestAgencyInstructions() { - /* - * ajax call to get additional information for the specified agency - */ - - var agencyEin = $("#request-agency").val(); - var requestInstructionsDiv = $("#request-agency-instructions"); - var requestInstructionsContentDiv = $("#request-agency-instructions-content"); - - $.ajax({ - url: "/agency/feature/" + agencyEin + "/" + "specific_request_instructions", - type: "GET", - success: function (data) { - if (data["specific_request_instructions"]["text"] !== "") { - requestInstructionsContentDiv.html("

" + data["specific_request_instructions"]["text"] + "

"); - requestInstructionsDiv.show(); - } - else { - requestInstructionsDiv.hide(); - } - }, - error: function () { - requestInstructionsDiv.hide(); - } - - }); - } - $("input[name='tz-name']").val(jstz.determine().name()); $("#request-category").change(function () { From e622f610b4a36b6daadde96e6f5c8dbae38ffc99 Mon Sep 17 00:00:00 2001 From: Jonathan Yu Date: Tue, 8 May 2018 12:46:09 -0400 Subject: [PATCH 3/4] Added function to toggle agency instructions content --- app/static/js/request/main.js | 28 +++++++++++++++++++++ app/static/js/request/new-request-agency.js | 13 ++-------- app/static/js/request/new-request-anon.js | 14 +++-------- app/static/js/request/new-request-user.js | 14 +++-------- 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/app/static/js/request/main.js b/app/static/js/request/main.js index f94a4132b..423ca078d 100644 --- a/app/static/js/request/main.js +++ b/app/static/js/request/main.js @@ -109,4 +109,32 @@ function getRequestAgencyInstructions() { } }); } +} + +function toggleRequestAgencyInstructions(action) { + /* + * determine whether or not to show agency instruction content + */ + var el = $("#request-agency-instructions-toggle"); + var requestInstructionsContentDiv = $("#request-agency-instructions-content"); + var hideHtml = ""; + var showHtml = ""; + + if (action === "show") { + el.html(hideHtml); + requestInstructionsContentDiv.show(); + } + else if (action === "hide") { + el.html(showHtml); + requestInstructionsContentDiv.hide(); + } + else if (action === "default") { + if (el.html() === showHtml) { + el.html(hideHtml); + requestInstructionsContentDiv.show(); + } else { + el.html(showHtml); + requestInstructionsContentDiv.hide(); + } + } } \ No newline at end of file diff --git a/app/static/js/request/new-request-agency.js b/app/static/js/request/new-request-agency.js index 98ee105fc..1e3a3d1e5 100755 --- a/app/static/js/request/new-request-agency.js +++ b/app/static/js/request/new-request-agency.js @@ -31,20 +31,11 @@ $(document).ready(function () { $("#request-agency").change(function () { getRequestAgencyInstructions(); + toggleRequestAgencyInstructions("hide"); }); $("#request-agency-instructions-toggle").click(function () { - var el = $("#request-agency-instructions-toggle"); - var requestInstructionsContentDiv = $("#request-agency-instructions-content"); - var hideHtml = ""; - var showHtml = ""; - if (el.html() === showHtml) { - el.html(hideHtml); - requestInstructionsContentDiv.show(); - } else { - el.html(showHtml); - requestInstructionsContentDiv.hide(); - } + toggleRequestAgencyInstructions("default"); }); // javascript to add tooltip popovers when selecting the title and description diff --git a/app/static/js/request/new-request-anon.js b/app/static/js/request/new-request-anon.js index 4bfa19cd6..3ff91213e 100755 --- a/app/static/js/request/new-request-anon.js +++ b/app/static/js/request/new-request-anon.js @@ -47,6 +47,7 @@ $(document).ready(function () { } // Determine if the agencyRequestInstructions need to be shown on page load. getRequestAgencyInstructions(); + toggleRequestAgencyInstructions("show"); } }); }); @@ -54,20 +55,11 @@ $(document).ready(function () { $("#request-agency").change(function () { getRequestAgencyInstructions(); + toggleRequestAgencyInstructions("show"); }); $("#request-agency-instructions-toggle").click(function () { - var el = $("#request-agency-instructions-toggle"); - var requestInstructionsContentDiv = $("#request-agency-instructions-content"); - var hideHtml = ""; - var showHtml = ""; - if (el.html() === showHtml) { - el.html(hideHtml); - requestInstructionsContentDiv.show(); - } else { - el.html(showHtml); - requestInstructionsContentDiv.hide(); - } + toggleRequestAgencyInstructions("default"); }); // javascript to add tooltip popovers when selecting the title and description diff --git a/app/static/js/request/new-request-user.js b/app/static/js/request/new-request-user.js index 7b996df29..47958b09d 100755 --- a/app/static/js/request/new-request-user.js +++ b/app/static/js/request/new-request-user.js @@ -30,6 +30,7 @@ $(document).ready(function () { } // Determine if the agencyRequestInstructions need to be shown on page load. getRequestAgencyInstructions(); + toggleRequestAgencyInstructions("show"); } }); }); @@ -37,20 +38,11 @@ $(document).ready(function () { $("#request-agency").change(function () { getRequestAgencyInstructions(); + toggleRequestAgencyInstructions("show"); }); $("#request-agency-instructions-toggle").click(function () { - var el = $("#request-agency-instructions-toggle"); - var requestInstructionsContentDiv = $("#request-agency-instructions-content"); - var hideHtml = ""; - var showHtml = ""; - if (el.html() === showHtml) { - el.html(hideHtml); - requestInstructionsContentDiv.show(); - } else { - el.html(showHtml); - requestInstructionsContentDiv.hide(); - } + toggleRequestAgencyInstructions("default"); }); // javascript to add tooltip popovers when selecting the title and description $("#request-title").attr({ From d0404f3801b6908aed1f5fa0380316100d74806c Mon Sep 17 00:00:00 2001 From: Jonathan Yu Date: Tue, 8 May 2018 12:50:50 -0400 Subject: [PATCH 4/4] Added hidden to instructions in new_request_agency.html --- app/templates/request/new_request_agency.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/request/new_request_agency.html b/app/templates/request/new_request_agency.html index 87553ef4d..c1a61ca01 100644 --- a/app/templates/request/new_request_agency.html +++ b/app/templates/request/new_request_agency.html @@ -32,7 +32,7 @@

Request a Record

{% else %} {% endif %} -
+