You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.
During the workshop today I added the ability for the session cards on the Home and My Agenda pages to progressively enhance the buttons for adding/removing sessions from the personal agenda to post using JavaScript rather than a normal form submit. It also handles dynamically updating the UI including removing the cards on the My Agenda page.
The JavaScript and modified agenda partial follow. We should consider incorporating this into the workshop.
site.js
"use strict";// Agenda form functionalityletonMyAgendaPage=document.querySelector("h1[data-myAgenda]")!==null;letform=document.querySelector("#agendaForm");if(form){form.addEventListener("submit",asynce=>{e.preventDefault();letsessionId=document.activeElement.getAttribute("value"),card=document.querySelector("#session-"+sessionId),button=card.querySelector("button:not(.template)"),template=card.querySelector("button.template"),url=button.formAction||form.action,formData=newFormData(form);formData.append("sessionId",sessionId);letresponse=awaitfetch(url,{method: form.method,body: formData});if(response.status===200){if(url.indexOf("Remove")>0&&onMyAgendaPage){lettimeSlotDiv=card.closest("div.timeSlot"),agendaDiv=document.querySelector("div.agenda"),dayPill=agendaDiv.querySelector("a.nav-link.active");card.remove();// Check if this was the last card in this time slot and if so remove the track nodeif(timeSlotDiv.querySelectorAll(".session-card").length===0){timeSlotDiv.remove();// Check if this was the last card in the day and if so remove the day pill buttonif(agendaDiv.querySelectorAll(".session-card").length===0){dayPill.remove();// Check if there are more days and if so navigate to the next day, else show the empty messageletdayPills=agendaDiv.querySelectorAll("a.nav-link");if(dayPills.length>0){document.location.search="";}else{agendaDiv.querySelector("#agendaMessage").classList.remove("template");}}}}else{button.classList.add("template");template.classList.remove("template");}}});}
_AgendaPartial.cshtml
@model IndexModel
<divclass="agenda"><ulclass="nav nav-pills mb-3">
@foreach (var day in Model.DayOffsets)
{
<lirole="presentation" class="nav-item"><aclass="nav-link @(Model.CurrentDayOffset == day.Offset ? "active" : null)" asp-route-day="@day.Offset">@day.DayofWeek?.ToString()</a></li>
}
</ul>
@{
var messageClassName = Model.Sessions.Any() ? "template" : null;
}
<pid="agendaMessage" class="@messageClassName">There don't appear to be any sessions here.</p><formauthzmethod="post" id="agendaForm">
@foreach (var timeSlot in Model.Sessions)
{
<divclass="timeSlot"><h4>@timeSlot.Key?.ToString("HH:mm")</h4><divclass="row">
@foreach (var session in timeSlot)
{
<divclass="col-md-3 mb-4 session-card" id="[email protected]"><divclass="card shadow session h-100"><divclass="card-header">@session.Track?.Name</div><divclass="card-body"><h5class="card-title"><aasp-page="Session" asp-route-id="@session.Id">@session.Title</a></h5></div><divclass="card-footer"><ulclass="list-inline mb-0">
@foreach (var speaker in session.Speakers)
{
<liclass="list-inline-item"><aasp-page="Speaker" asp-route-id="@speaker.Id">@speaker.Name</a></li>
}
</ul><pclass="mb-0"><aauthz-policy="Admin" asp-page="/Admin/EditSession" asp-route-id="@session.Id" class="btn btn-default btn-xs">Edit</a>
@{
var isInSession = Model.UserSessions.Contains(session.Id);
var removeClassName = isInSession ? "" : "template";
var addClassName = isInSession ? "template" : "";
}
<buttontype="submit" name="sessionId" value="@session.Id" asp-page-handler="Remove" class="btn btn-default btn-sm bg-transparent @removeClassName" title="Remove from my personal agenda"><iclass="icon ion-md-star" aria-hidden="true"></i></button><buttontype="submit" name="sessionId" value="@session.Id" class="btn btn-default btn-sm bg-transparent @addClassName" title="Add to my personal agenda"><iclass="icon ion-md-star-outline" aria-hidden="true"></i></button></p></div></div></div>
}
</div></div>
}
</form></div>
The text was updated successfully, but these errors were encountered:
During the workshop today I added the ability for the session cards on the Home and My Agenda pages to progressively enhance the buttons for adding/removing sessions from the personal agenda to post using JavaScript rather than a normal form submit. It also handles dynamically updating the UI including removing the cards on the My Agenda page.
The JavaScript and modified agenda partial follow. We should consider incorporating this into the workshop.
site.js
_AgendaPartial.cshtml
The text was updated successfully, but these errors were encountered: