diff --git a/app/controllers/admin/minor.py b/app/controllers/admin/minor.py index 8582ae27c..4a8ebadfd 100644 --- a/app/controllers/admin/minor.py +++ b/app/controllers/admin/minor.py @@ -1,17 +1,30 @@ -from flask import render_template, g, abort +from flask import render_template, g, abort, request, redirect, url_for + +from app.models.user import User from app.controllers.admin import admin_bp -from app.logic.minor import getMinorInterest, getMinorProgress +from app.logic.minor import getMinorInterest, getMinorProgress, toggleMinorInterest -@admin_bp.route('/admin/cceMinor', methods=['GET']) +@admin_bp.route('/admin/cceMinor', methods=['POST','GET']) def manageMinor(): + if not g.current_user.isAdmin: abort(403) + + if request.method == 'POST': + interested_students = request.form.getlist('interestedStudents[]') + + for i in interested_students: + user = User.get(username=i) + if not user.minorInterest: + toggleMinorInterest(i) + interestedStudentsList = getMinorInterest() interestedStudentEmailString = ';'.join([student['email'] for student in interestedStudentsList]) sustainedEngagement = getMinorProgress() + return render_template('/admin/cceMinor.html', interestedStudentsList = interestedStudentsList, diff --git a/app/static/js/manageVolunteers.js b/app/static/js/manageVolunteers.js index 5446f085e..693aa7968 100644 --- a/app/static/js/manageVolunteers.js +++ b/app/static/js/manageVolunteers.js @@ -91,7 +91,8 @@ $(document).ready(function() { url: `/addVolunteersToEvent/${eventId}`, type: "POST", data: {"selectedVolunteers": selectedVolunteers, "ajax": true}, - success: function(s){ + success: + function(s){ location.reload() }, error: function(request, status, error){ diff --git a/app/static/js/minorAdminPage.js b/app/static/js/minorAdminPage.js index 5080bdbe9..f145bd1af 100644 --- a/app/static/js/minorAdminPage.js +++ b/app/static/js/minorAdminPage.js @@ -1,3 +1,4 @@ +import searchUser from './searchUser.js' function emailAllInterested(){ // Read all student emails from the input as a string and put them in mailto format let interestedStudentEmails = $("#interestedStudentEmails").val(); @@ -37,6 +38,65 @@ $(document).ready(function() { + +function getInterestedStudents() { + // get all the checkboxes and return a list of users who's + // checkboxes are selected + let checkboxesDisplayedInModal = $("#addInterestedStudentsModal input[type=checkbox]:checked") + let interestedStudentsList = [] + checkboxesDisplayedInModal.each(function(index, checkbox){ + interestedStudentsList.push(checkbox["value"]) + }) + return interestedStudentsList +} + +function updateInterestedStudents(){ + let interestedStudentList = getInterestedStudents() + let buttonContent = $("#addInterestedStudentsbtn").html() + if (interestedStudentList.length > 1) { + if (buttonContent.charAt(buttonContent.length-1) != "s") { + // make the button text plural if there are multiple users selected + $("#addInterestedStudentsbtn").html(buttonContent + "s") + } + } else if (buttonContent.charAt(buttonContent.length-1) == "s") { + // remove the s if it is plural and we have less than 2 volunteers + $("#addInterestedStudentsbtn").html(buttonContent.slice(0, -1)) + } + // disable the submit button if there are no selectedCheckboxes + if (interestedStudentList.length == 0) { + + $("#addInterestedStudentsbtn").prop("disabled", true) + } else { + $("#addInterestedStudentsbtn").prop("disabled", false) + } +} + +var userlist = [] +function callback(selected) { + let user = $("#addStudentInput").val() + if (userlist.includes(selected["username"]) == false){ + userlist.push(user) + let i = userlist.length; + $("#interestedStudentList").prepend("