Skip to content

Commit

Permalink
Merge pull request #364 from CityOfNewYork/hotfix/OP-1440
Browse files Browse the repository at this point in the history
Hotfix/OP-1440: Make Specific Agency Request Instructions Hidden By Default
  • Loading branch information
johnyu95 authored May 8, 2018
2 parents f58f8ca + d0404f3 commit faee3da
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 108 deletions.
71 changes: 64 additions & 7 deletions app/static/js/request/main.js
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -77,7 +77,64 @@ 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("<p>" + data["specific_request_instructions"]["text"] + "</p>");
requestInstructionsDiv.show();
}
else {
requestInstructionsDiv.hide();
}
},
error: function () {
requestInstructionsDiv.hide();
}
});
}
}

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 = "<button type=\"button\" id=\"request-agency-instructions-btn\" class=\"btn btn-block btn-info\"><span class=\"glyphicon glyphicon-chevron-up\"></span>&nbsp;&nbsp;Hide Agency Instructions&nbsp;&nbsp;<span class=\"glyphicon glyphicon-chevron-up\"></span></button>";
var showHtml = "<button type=\"button\" id=\"request-agency-instructions-btn\" class=\"btn btn-block btn-info\"><span class=\"glyphicon glyphicon-chevron-down\"></span>&nbsp;&nbsp;Show Agency Instructions&nbsp;&nbsp;<span class=\"glyphicon glyphicon-chevron-down\"></span></button>";

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();
}
}
}
41 changes: 9 additions & 32 deletions app/static/js/request/new-request-agency.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
"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());


// Prevent user from entering a non numeric value into phone and fax field
$("#phone").keypress(function (key) {
if (key.charCode != 0) {
Expand All @@ -25,40 +28,14 @@ $(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("<p>" + data["specific_request_instructions"]["text"] + "</p>");
requestInstructionsDiv.show();
}
else {
requestInstructionsDiv.hide();
}
},
error: function () {
requestInstructionsDiv.hide();
}

$("#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 = "<button type=\"button\" id=\"request-agency-instructions-btn\" class=\"btn btn-block btn-info\"><span class=\"glyphicon glyphicon-chevron-up\"></span>&nbsp;&nbsp;Hide Agency Instructions&nbsp;&nbsp;<span class=\"glyphicon glyphicon-chevron-up\"></span></button>";
var showHtml = "<button type=\"button\" id=\"request-agency-instructions-btn\" class=\"btn btn-block btn-info\"><span class=\"glyphicon glyphicon-chevron-down\"></span>&nbsp;&nbsp;Show Agency Instructions&nbsp;&nbsp;<span class=\"glyphicon glyphicon-chevron-down\"></span></button>";
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
Expand Down Expand Up @@ -250,7 +227,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();
Expand Down
45 changes: 12 additions & 33 deletions app/static/js/request/new-request-anon.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"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());

Expand All @@ -24,7 +28,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",
Expand All @@ -41,46 +45,21 @@ $(document).ready(function () {
opt.value = data[i][0];
sel.append(opt);
}
// Determine if the agencyRequestInstructions need to be shown on page load.
getRequestAgencyInstructions();
toggleRequestAgencyInstructions("show");
}
});
});

// 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("<p>" + data["specific_request_instructions"]["text"] + "</p>");
requestInstructionsDiv.show();
}
else {
requestInstructionsDiv.hide();
}
},
error: function () {
requestInstructionsDiv.hide();
}

});
$("#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 = "<button type=\"button\" id=\"request-agency-instructions-btn\" class=\"btn btn-block btn-info\"><span class=\"glyphicon glyphicon-chevron-up\"></span>&nbsp;&nbsp;Hide Agency Instructions&nbsp;&nbsp;<span class=\"glyphicon glyphicon-chevron-up\"></span></button>";
var showHtml = "<button type=\"button\" id=\"request-agency-instructions-btn\" class=\"btn btn-block btn-info\"><span class=\"glyphicon glyphicon-chevron-down\"></span>&nbsp;&nbsp;Show Agency Instructions&nbsp;&nbsp;<span class=\"glyphicon glyphicon-chevron-down\"></span></button>";
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
Expand Down
48 changes: 13 additions & 35 deletions app/static/js/request/new-request-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
"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());

// ajax call to get and populate list of agencies choices based on selected category

$("#request-category").change(function () {
$.ajax({
url: "/request/agencies",
Expand All @@ -25,46 +28,21 @@ $(document).ready(function () {
opt.value = data[i][0];
sel.append(opt);
}
// Determine if the agencyRequestInstructions need to be shown on page load.
getRequestAgencyInstructions();
toggleRequestAgencyInstructions("show");
}
});
});

// 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("<p>" + data["specific_request_instructions"]["text"] + "</p>");
requestInstructionsDiv.show();
}
else {
requestInstructionsDiv.hide();
}
},
error: function () {
requestInstructionsDiv.hide();
}

});
$("#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 = "<button type=\"button\" id=\"request-agency-instructions-btn\" class=\"btn btn-block btn-info\"><span class=\"glyphicon glyphicon-chevron-up\"></span>&nbsp;&nbsp;Hide Agency Instructions&nbsp;&nbsp;<span class=\"glyphicon glyphicon-chevron-up\"></span></button>";
var showHtml = "<button type=\"button\" id=\"request-agency-instructions-btn\" class=\"btn btn-block btn-info\"><span class=\"glyphicon glyphicon-chevron-down\"></span>&nbsp;&nbsp;Show Agency Instructions&nbsp;&nbsp;<span class=\"glyphicon glyphicon-chevron-down\"></span></button>";
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({
Expand Down Expand Up @@ -156,7 +134,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();
Expand Down
2 changes: 1 addition & 1 deletion app/templates/request/new_request_agency.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h1>Request a Record</h1>
{% else %}
<input type="hidden" id="request-agency" value="{{ current_user.default_agency_ein }}" />
{% endif %}
<div class="alert alert-info" id="request-agency-instructions">
<div class="alert alert-info" id="request-agency-instructions" hidden>
<div id="request-agency-instructions-content" style="display: none;"></div>
<span id="request-agency-instructions-toggle"><button type="button" id="request-agency-instructions-btn" class="btn btn-block btn-info"><span class="glyphicon glyphicon-chevron-down"></span>&nbsp;&nbsp;Show Agency Instructions&nbsp;&nbsp;<span class="glyphicon glyphicon-chevron-down"></span></button></span>
</div>
Expand Down

0 comments on commit faee3da

Please sign in to comment.