From 977eb2bb465b59c383ad686c934df3fba895493d Mon Sep 17 00:00:00 2001 From: Lawrence Hoerst Date: Tue, 14 Jan 2025 12:23:01 -0500 Subject: [PATCH 1/2] I added an empty table message. Somehow lost the ability to remove instructors sometimes --- app/static/js/instructorTable.js | 11 +++++++++++ app/static/js/slcNewProposal.js | 7 ++++--- app/templates/serviceLearning/slcProposal.html | 11 ++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/static/js/instructorTable.js b/app/static/js/instructorTable.js index ae7a78f28..acceee605 100644 --- a/app/static/js/instructorTable.js +++ b/app/static/js/instructorTable.js @@ -31,6 +31,8 @@ export function createNewRow(selectedInstructor) { let editLink = newRow.find("td:eq(0) a") editLink.attr("id", `editButton-${username}`); + console.log("Added Row:") + console.log(username) editLink.attr("data-username", username) newRow.prop("hidden", false); lastRow.after(newRow); @@ -43,9 +45,18 @@ export function createNewRow(selectedInstructor) { } $("#instructorTableNames").append(``) + updateEmptyTableMessage() } export function getCourseInstructors() { // get usernames out of the table rows return $("#instructorTableNames input").map((i,el) => $(el).val()) +} + +export function updateEmptyTableMessage(){ + if ($("#instructorTable tbody tr").length > 2){ + $("#instructorTable tbody tr").first().attr("hidden", true) + } else{ + $("#instructorTable tbody tr").first().attr("hidden", false) + } } \ No newline at end of file diff --git a/app/static/js/slcNewProposal.js b/app/static/js/slcNewProposal.js index af24ef676..01d28ed0e 100644 --- a/app/static/js/slcNewProposal.js +++ b/app/static/js/slcNewProposal.js @@ -1,4 +1,4 @@ -import {getCourseInstructors, getRowUsername, createNewRow} from './instructorTable.js' +import {getCourseInstructors, getRowUsername, createNewRow, updateEmptyTableMessage} from './instructorTable.js' import searchUser from './searchUser.js' var currentTab = 0; // Current tab is set to be the first tab (0) @@ -130,13 +130,14 @@ $(document).ready(function(e) { $("#instructorTable").on("click", ".removeButton", function() { let closestRow = $(this).closest("tr"); let username = closestRow.data('username'); - + console.log(closestRow) // Check if the username is not empty or undefined if (username) { $("#instructorTableNames input[value='" + username + "']").remove(); closestRow.remove(); } -}); + updateEmptyTableMessage(); + }); $("#courseInstructor").on('input', function() { searchUser("courseInstructor", createNewRow, true, null, "instructor"); diff --git a/app/templates/serviceLearning/slcProposal.html b/app/templates/serviceLearning/slcProposal.html index 5fb99b65f..b386ecd63 100644 --- a/app/templates/serviceLearning/slcProposal.html +++ b/app/templates/serviceLearning/slcProposal.html @@ -16,16 +16,22 @@

Status: placeholder="Search instructor" value="" /> - + + + + + {% endfor %} -
InstructorInstructor(s)
+ +
{% for instructor in courseInstructor %} From 82cc7b0c09f1317a2ca3598fad3c5b0a2f649885 Mon Sep 17 00:00:00 2001 From: Lawrence Hoerst Date: Thu, 16 Jan 2025 09:35:35 -0500 Subject: [PATCH 2/2] Clarified the form validation and added autofocus improvements to the search user method --- app/static/js/instructorTable.js | 3 +-- app/static/js/searchUser.js | 3 ++- app/static/js/slcNewProposal.js | 27 ++++++++++++++----- .../serviceLearning/slcProposal.html | 9 ++----- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/app/static/js/instructorTable.js b/app/static/js/instructorTable.js index acceee605..626c63b31 100644 --- a/app/static/js/instructorTable.js +++ b/app/static/js/instructorTable.js @@ -31,8 +31,7 @@ export function createNewRow(selectedInstructor) { let editLink = newRow.find("td:eq(0) a") editLink.attr("id", `editButton-${username}`); - console.log("Added Row:") - console.log(username) + newRow.attr("data-username", username) editLink.attr("data-username", username) newRow.prop("hidden", false); lastRow.after(newRow); diff --git a/app/static/js/searchUser.js b/app/static/js/searchUser.js index 7698c342d..5ebf57c70 100644 --- a/app/static/js/searchUser.js +++ b/app/static/js/searchUser.js @@ -35,6 +35,7 @@ export default function searchUser(inputId, callback, clear=false, parentElement } return false; - } + }, + autoFocus: true }); }; diff --git a/app/static/js/slcNewProposal.js b/app/static/js/slcNewProposal.js index 01d28ed0e..e9ee642c4 100644 --- a/app/static/js/slcNewProposal.js +++ b/app/static/js/slcNewProposal.js @@ -130,7 +130,7 @@ $(document).ready(function(e) { $("#instructorTable").on("click", ".removeButton", function() { let closestRow = $(this).closest("tr"); let username = closestRow.data('username'); - console.log(closestRow) + // Check if the username is not empty or undefined if (username) { $("#instructorTableNames input[value='" + username + "']").remove(); @@ -139,9 +139,22 @@ $(document).ready(function(e) { updateEmptyTableMessage(); }); - $("#courseInstructor").on('input', function() { - searchUser("courseInstructor", createNewRow, true, null, "instructor"); - }); + $("#courseInstructor").on("focusout", function(){ + $("#courseInstructor").val("") + }) + + $("#courseInstructor").on('input', function() { + searchUser("courseInstructor", createNewRow, true, null, "instructor"); + }); + + $("#courseInstructor").popover({ + trigger: "hover", + sanitize: false, + html: true, + content: function() { + return $(this).data('tooltip'); + } + }); // for each row in instructorTable that has an instructor, pass that instructors phone data to setupPhoneNumber $('#instructorTable tr').each(function(){ @@ -307,9 +320,11 @@ function validateForm() { var instructors = getCourseInstructors() if (!instructors.length && currentTab == 1) { valid = false; - $("#courseInstructor").addClass("invalid"); + $("#instructorTable .emptyTableMessage").addClass("table-danger"); + $("#instructorTable .emptyTableMessage label").removeClass("text-secondary"); } else { - $("#courseInstructor").removeClass("invalid"); + $("#instructorTable .emptyTableMessage").removeClass("table-danger"); + $("#instructorTable .emptyTableMessage label").addClass("text-secondary"); } if (valid) { diff --git a/app/templates/serviceLearning/slcProposal.html b/app/templates/serviceLearning/slcProposal.html index b386ecd63..32be1bacf 100644 --- a/app/templates/serviceLearning/slcProposal.html +++ b/app/templates/serviceLearning/slcProposal.html @@ -14,21 +14,16 @@

Status: class="form-control" type="search" placeholder="Search instructor" + data-tooltip="Click on an instructor to add them" value="" /> - - - - - -
Instructor(s)
- +