Frontend and UI – Staffing UX Utilities

This section covers the custom JavaScript utilities that power the staffing workflows in the Prep Network Events platform. These utilities provide:

  • Staff autocomplete using Select2
  • Interactive staffing grid with hover and click actions
  • Dynamic event/venue pickers to fetch and display staffing data

Select2 Staff Autocomplete 🎯

Enhances staff‐select fields with live search, custom formatting, and “create new staff” links when no results appear.

Initialization

Add the js-staff-search-ajax class to any <select> you wish to enable autocomplete on. For example, in the Add Staff modal:

<select
  name="staff_id"
  id="staff_id"
  class="js-staff-search-ajax form-control"
></select>

The Select2 plugin must be loaded before these scripts.

staffAutoComplete() Function

Configures Select2 with AJAX and templating:

function staffAutoComplete() {
  $('.js-staff-search-ajax').select2({
    ajax: {
      url: '/staff/select2',
      delay: 250,
      dataType: 'json',
      data: function(params) {
        return { term: params.term };
      },
      processResults: function(data) {
        return { results: data.map(e => ({ id: e.id, text: e.name, ...e })) };
      },
      cache: true
    },
    placeholder: "Search staff.",
    minimumInputLength: 2,
    language: {
      noResults: () => {
        setTimeout(() => { loadModal(); }, 300);
        return "No results found. <a href='/staffing/editor-create-staff/' class='load-modal'>Create New Staff →</a>";
      }
    },
    escapeMarkup: markup => markup,
    templateSelection: formatStaffSelection,
    templateResult: formatStaffResult
  });
}
staffAutoComplete();

Excerpt from the main JS bundle .

Template Helpers

Helper Purpose
formatStaffSelection Renders the selected staff with name, role, and star-rating icons.
formatStaffResult Displays each result row with name, role, state, and stars.
function formatStaffSelection(item) {
  if (!item.name) return $(`<span>${item.text}</span>`);
  let stars = (item.rating||0).toString().repeat(item.rating)
    .split('').map(() => '<i class="fa fa-star text-warning"></i>').join('');
  let role = item.role ? ` - ${item.role}` : '';
  return $(`<span>${item.name}${role}${stars}</span>`);
}

function formatStaffResult(item) {
  if (item.loading) return item.text;
  let stars = Array(item.rating).fill('<i class="fa fa-star text-warning"></i>').join('');
  let state = item.state_abbrev ? `(${item.state_abbrev})` : '';
  let role  = item.role || '';
  return $(`<div>${item.name} - ${role} ${state} ${stars}</div>`);
}

Staffing Grid Interactions ⚙️

Provides hover feedback and click handlers on the staffing grid to streamline assignment.

Court Hover Effects

When the user hovers over a cell, its column header highlights:

$('#staffing-grid').on('mouseenter', function() {
  $('#staffing-grid td')
    .on('mouseenter', function() {
      let court = $(this).data('court');
      $(`#staffing-grid th#court-${court}`).addClass('hover');
    })
    .on('mouseleave', function() {
      let court = $(this).data('court');
      $(`#staffing-grid th#court-${court}`).removeClass('hover');
    });
});

Row Actions & Modals

  • Clear Position:
    Clicking an “×” button calls deleteClockBookStaff() after confirmation.

  • Add/Update Staff:
    Clicking a not-staffed or partially-staffed cell triggers loadModal(), then shows the Add Staff modal and attaches data attributes for grid insertion.

Handlers are bound when getStaffingGrid() completes .

deleteClockBookStaff() Function

function deleteClockBookStaff(el) {
  if (!confirm("Are you sure?")) return;
  let event = $("#eventVenuePicker select[name='events']").val();
  let venue = $("#eventVenuePicker select[name='venues']").val();
  $.post('/staffing/delete-grid-staff', {
    staffCourt: $(el).attr('id'),
    venueId: venue,
    eventId: event
  }).done(() => getStaffingGrid());
  $(".popover.show").remove();
}

Event & Venue Pickers 🎛️

Dynamically loads venues and grid data based on user selection.

Picker Setup

let eventVenuePicker = $("#eventVenuePicker");
eventVenuePicker.find("select[name='events']")
  .on('change', updateVenues)
  .on('change', setStaffingExportButton)
  .on('change', setStaffingApplicationLinksButton);
eventVenuePicker.find("select[name='venues']")
  .on('change', getStaffingGrid)
  .on('change', getNonClockBookTableData);

if (eventVenuePicker.length) {
  getStaffingGrid();
  getNonClockBookTableData();
  $("#grid-table #report-loading, #non-clock-book #report-loading").addClass("d-none");
}

updateVenues() Function

Fetches venues for the selected event and populates the venue dropdown:

function updateVenues() {
  let eventId = $("#eventVenuePicker select[name='events']").val();
  $.get(`/events/${eventId}/getvenues`, data => {
    let $venues = $('#eventVenuePicker #event-venues').empty()
      .append($("<option>", { value: "", text: "Choose Venue." }));
    data.forEach(v => $venues.append(
      $("<option>", { value: v.id, text: v.name }).prop('selected', true)
    ));
  }).done(() => {
    resetJSPopovers();
    getStaffingGrid();
    getNonClockBookTableData();
  });
}

getStaffingGrid() & getNonClockBookTableData()

  1. Show loading spinner
  2. Clear existing popovers and modals
  3. AJAX GET to /staffing/event-venue-grid/{event}/{venue}
  4. Inject returned HTML into #staffing-grid
  5. Re-bind hover and click handlers
  6. Hide spinner and fetch additional data (getEventData)
function getStaffingGrid() {
  let e = $("#eventVenuePicker select[name='events']").val();
  let v = $("#eventVenuePicker select[name='venues']").val();
  $("#grid-table #report-loading").removeClass("d-none");
  $(".popover.show, .modal.grid-add-staff, .modal-backdrop").remove();
  if (e && v) {
    $.get(`/staffing/event-venue-grid/${e}/${v}`, data => {
      $("#staffing-grid").html(data);
    }).done(() => {
      resetJSPopovers();
      $("#grid-table #report-loading").addClass("d-none");
      getEventData(e);
      // rebind handlers...
    });
  }
}

Staffing Grid Data Flow

flowchart LR
  A[User selects Event] --> B[updateVenues()]
  B -->|AJAX /getvenues| C[Populate Venue Dropdown]
  C --> D[resetJSPopovers()]
  D --> E[getStaffingGrid() & getNonClockBookTableData()]
  E -->|AJAX /event-venue-grid| F[Render Grid HTML]
  F --> G[Bind Hover & Click Handlers]
  A --> H[setStaffingExportButton()]
  A --> I[setStaffingApplicationLinksButton()]

Dependencies & Integration

  • jQuery: DOM manipulation and AJAX
  • Select2: Enhanced <select> dropdowns
  • Bootstrap Modals: Display forms and dialogs
  • Custom Helpers:
    • loadModal() – loads modal content via AJAX
    • resetJSPopovers() – clears any existing Bootstrap popovers

Integration: These scripts are bundled into the main app.js and initialized on pages under dashboard.staffing.*.

{
  "title": "Best Practice",
  "content": "Ensure Select2 CSS/JS files load before invoking the staff autocomplete utility."
}