Favorites list
Create new favorite groups and add products to your favorites list.
Error executing template "Designs/Swift/eCom/CustomerExperienceCenter/Favorites/FavoriteLists_Custom.cshtml" System.ArgumentNullException: Value cannot be null. Parameter name: source at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable`1 source, Func`2 selector) at CompiledRazorTemplates.Dynamic.RazorEngine_a3b73b064c0548bcaed1273935bf8a66.Execute() in D:\dynamicweb.net\Solutions\twodayco3\simas.cloud.dynamicweb-cms.com\Files\Templates\Designs\Swift\eCom\CustomerExperienceCenter\Favorites\FavoriteLists_Custom.cshtml:line 16 at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader) at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag) at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer) at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter) at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template) at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template) at Dynamicweb.Rendering.Template.RenderRazorTemplate()
1 @inherits ViewModelTemplate<FavoriteListListViewModel> 2 @using Dynamicweb.Rendering 3 @using Dynamicweb.Ecommerce.Frontend 4 @using System.Linq 5 @using Co3.Simas.Custom.Constants 6 @using Co3.Simas.Custom.Extensions 7 @using Co3.Simas.Custom.Models 8 @using Co3.Simas.Custom.Services 9 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 10 @using Dynamicweb.Security.UserManagement 11 @using ProductViewModel = Dynamicweb.Ecommerce.ProductCatalog.ProductViewModel 12 @{ 13 string themeRaw = Pageview.CurrentParagraph.Item["Theme"]?.ToString(); 14 string theme = !string.IsNullOrEmpty(themeRaw) ? " h-100 theme " + themeRaw.Replace(" ", "").Trim().ToLower() : ""; 15 bool sharedList = (Dynamicweb.Frontend.PageView.Current().CurrentParagraph.ModuleProperties.GetValue("RetrieveListBasedOn") == "UseCustomerNumber"); 16 List<int> allFavoriteListIds = Model.FavoriteLists.Select(fl => fl.Id).ToList(); 17 } 18 @if (sharedList) 19 { 20 @SnippetStart("FavoriteListsShared") 21 if (theme != "") 22 { 23 <div class="@(theme)"> 24 @RenderContent() 25 </div> 26 } 27 else 28 { 29 @RenderContent() 30 } 31 32 @SnippetEnd("FavoriteListsShared") 33 } 34 else 35 { 36 if (theme != "") 37 { 38 <div class="@(theme)"> 39 @RenderContent() 40 </div> 41 } 42 else 43 { 44 @RenderContent() 45 } 46 47 <div class="mt-6"> 48 @RenderSnippet("FavoriteListsShared") 49 </div> 50 51 if (allFavoriteListIds.Any() == true) 52 { 53 <div class="mt-6 pt-2 border-top"> 54 <p class="text-end"> 55 <button type="button" class="btn btn-link btn-sm p-0" data-bs-toggle="modal" data-bs-target="#ownershipFavoriteListModal">@Translate("Manage ownership")</button> 56 </p> 57 </div> 58 } 59 } 60 61 62 @helper RenderContent() 63 { 64 bool sharedList = (Dynamicweb.Frontend.PageView.Current().CurrentParagraph.ModuleProperties.GetValue("RetrieveListBasedOn") == "UseCustomerNumber"); 65 string title = Pageview.CurrentParagraph.Item["Title"]?.ToString(); 66 string listPageLink = Pageview.CurrentParagraph.Item["ProductListPage"] != null ? Pageview.CurrentParagraph.Item["ProductListPage"].ToString() : ""; 67 string currentPageUrl = "/Default.aspx?ID=" + Pageview.Page.ID; 68 string url = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService")); 69 70 IEnumerable<IGrouping<string, FavoriteListViewModel>> listGroups = Model.FavoriteLists.Where(fl => fl.ShowInList(sharedList)).OrderBy(fl => string.IsNullOrEmpty(fl.Category()) == false ? fl.Category() : "zz").ThenBy(fl => fl.Name).GroupBy(fl => fl.Category()); 71 72 int listsCount = listGroups.Count(); 73 int pageSize = Model.PageSize; 74 75 76 <header class="d-flex flex-wrap align-items-center"> 77 <h4 class="m-0 flex-fill mb-2"> 78 <small>@title (@listsCount)</small> 79 </h4> 80 @if (listsCount > 0) 81 { 82 <button type="button" class="btn btn-link p-0 border-0" data-bs-toggle="modal" data-list-isshared="@sharedList" data-bs-target="#createFavoriteListModal"> 83 + @Translate("Add new favorite list")</button> 84 } 85 </header> 86 87 if (listsCount < 1) 88 { 89 <div class="grid"> 90 <div class="g-col-12 g-start-lg-3 g-col-lg-8 d-flex flex-column gap-3 text-center py-3"> 91 <h2 class="h5 m-0">@Translate("It looks like you do not have any favorites yet")</h2> 92 <p class="m-0">@Translate("Save and arrange the best things here until you are ready for them")</p> 93 94 <div class="d-flex flex-column flex-sm-row gap-3 justify-content-center"> 95 <button type="button" class="btn btn-link p-0 border-0" data-bs-toggle="modal" data-list-isshared="@sharedList" data-bs-target="#createFavoriteListModal"> 96 + @Translate("Add new favorite list")</button> 97 </div> 98 </div> 99 </div> 100 } 101 else 102 { 103 <div class="mb-4"> 104 @{ 105 int accordionItemLoopCounter = 0; 106 } 107 @foreach (IGrouping<string, FavoriteListViewModel> categoryGroup in listGroups) 108 { 109 bool isFirstItemInLoop = accordionItemLoopCounter == 0; 110 bool expandFirstAccordionItem = false; //isFirstItemInLoop == true; 111 string accordionItemId = Guid.NewGuid().ToHtmlId(); 112 string groupName = string.IsNullOrEmpty(categoryGroup.Key) == false ? categoryGroup.Key : Translate("Ingen kategori"); 113 string buttonAriaExpanded = expandFirstAccordionItem == true ? "true" : "false"; 114 string buttonClassState = expandFirstAccordionItem == true ? "" : "collapsed"; 115 string collapseClassState = expandFirstAccordionItem == true ? "show" : "collapse"; 116 117 <div class="accordion mb-2"> 118 <div class="accordion-item"> 119 <h5 class="accordion-header"> 120 <button class="fw-bold fs-5 accordion-button @buttonClassState" type="button" data-bs-toggle="collapse" data-bs-target="#@accordionItemId" aria-expanded="@buttonAriaExpanded" aria-controls="@accordionItemId">@groupName</button> 121 </h5> 122 <div id="@accordionItemId" class="accordion-collapse @collapseClassState"> 123 <div class="accordion-body"> 124 <ul class="list-unstyled m-0"> 125 @foreach (FavoriteListViewModel theList in categoryGroup) 126 { 127 string favoriteListLink = listPageLink + "&FavoriteListId=" + theList.Id; 128 string listName = !string.IsNullOrEmpty(theList.Name) ? theList.Name : Translate("Favorites"); 129 string location = theList.Location(); 130 string isShared = theList.IsShared().ToString().ToLowerInvariant(); 131 string description = theList.Description(); 132 string category = theList.Category(); 133 string machine = theList.Machine(); 134 <li class="mb-4"> 135 <p class="d-flex align-items-center m-0"> 136 <a href="@favoriteListLink" class="text-decoration-none"> 137 <strong>@listName</strong> 138 </a> 139 @if (theList.IsShared() == true) 140 { 141 string isSharedByUserName = theList.GetFavoriteList().IsShareByUserName(); 142 143 if (isSharedByUserName == "YOU" || isSharedByUserName == "UNKNOWN") 144 { 145 isSharedByUserName = Translate("SharedBy:" + isSharedByUserName, isSharedByUserName); 146 } 147 148 <small class="badge bg-info ms-3">@Translate("Shared by") @isSharedByUserName</small> 149 } 150 @if (theList.IsEditableForCurrentUser()) 151 { 152 <span class="mx-3"> · </span> 153 154 <button type="button" 155 class="btn btn-link btn-sm p-0 me-2 renameFavoriteListModal" 156 data-bs-toggle="modal" 157 data-bs-target="#renameFavoriteListModal" 158 data-list-id="@theList.Id" 159 data-list-isshared="@isShared" 160 data-list-location="@location" 161 data-list-description="@description" 162 data-list-category="@category" 163 data-list-machine="@machine" 164 data-list-isshared="@sharedList" 165 data-list-name="@listName"> 166 @Translate("Rename") 167 </button> 168 <button type="button" 169 class="btn btn-link btn-sm p-0 mx-1 px-1 deleteFavoriteNameButton" 170 data-bs-toggle="modal" 171 data-bs-target="#deleteFavoriteListModal" 172 data-list-id="@theList.Id" 173 data-list-name="@listName"> 174 @Translate("Delete") 175 </button> 176 } 177 </p> 178 <p class="opacity-75 mb-1">@description</p> 179 <form method="post" action="@url" class="d-flex align-items-center"> 180 <input type="hidden" name="CartCmd" id="CartCmd" value="addMulti"> 181 @{ 182 int listProductLoopCounter = 1; 183 } 184 @foreach (FavoriteProduct favoriteProduct in theList.GetFavoriteList().Products()) 185 { 186 string quantityName = $"Quantity{listProductLoopCounter}"; 187 string productIdName = $"ProductID{listProductLoopCounter}"; 188 string locationName = $"EcomOrderLineFieldInput_{OrderLineFieldIds.Location}{listProductLoopCounter}"; 189 string machineName = $"EcomOrderLineFieldInput_{OrderLineFieldIds.Machine}{listProductLoopCounter}"; 190 string categoryName = $"EcomOrderLineFieldInput_{OrderLineFieldIds.Category}{listProductLoopCounter}"; 191 string listProductLoopCounterName = $"ProductLoopCounter{listProductLoopCounter}"; 192 193 <input type="hidden" name="@quantityName" value="@Math.Max(1, (int)favoriteProduct.Quantity)"> 194 <input type="hidden" name="@productIdName" value="@favoriteProduct.ProductId"> 195 <input type="hidden" name="@locationName" value="@location"> 196 <input type="hidden" name="@machineName" value="@machine"> 197 <input type="hidden" name="@categoryName" value="@category"> 198 <input type="hidden" name="@listProductLoopCounterName" value="@listProductLoopCounter"> 199 listProductLoopCounter += 1; 200 } 201 <button type="submit" class="btn btn-link btn-sm me-2 p-0">@Translate("Add all products in this list to your cart")</button> 202 </form> 203 </li> 204 } 205 </ul> 206 </div> 207 @{ int categoryProductLoopCounter = 1; } 208 <form method="post" action="@url" class="d-flex align-items-center text-center border-top"> 209 <input type="hidden" name="CartCmd" id="CartCmd" value="addMulti"> 210 @foreach (FavoriteListViewModel theList in categoryGroup) 211 { 212 string location = theList.Location(); 213 string machine = theList.Machine(); 214 string category = theList.Category(); 215 foreach (FavoriteProduct favoriteProduct in theList.GetFavoriteList().Products()) 216 { 217 string quantityName = $"Quantity{categoryProductLoopCounter}"; 218 string productIdName = $"ProductID{categoryProductLoopCounter}"; 219 string locationName = $"EcomOrderLineFieldInput_{OrderLineFieldIds.Location}{categoryProductLoopCounter}"; 220 string machineName = $"EcomOrderLineFieldInput_{OrderLineFieldIds.Machine}{categoryProductLoopCounter}"; 221 string categoryName = $"EcomOrderLineFieldInput_{OrderLineFieldIds.Category}{categoryProductLoopCounter}"; 222 string categoryProductLoopCounterName = $"ProductLoopCounter{categoryProductLoopCounter}"; 223 <input type="hidden" name="@quantityName" value="@Math.Max(1, (int)favoriteProduct.Quantity)"> 224 <input type="hidden" name="@productIdName" value="@favoriteProduct.ProductId"> 225 <input type="hidden" name="@locationName" value="@location"> 226 <input type="hidden" name="@machineName" value="@machine"> 227 <input type="hidden" name="@categoryName" value="@category"> 228 <input type="hidden" name="@categoryProductLoopCounterName" value="@categoryProductLoopCounter"> 229 categoryProductLoopCounter += 1; 230 } 231 } 232 <button type="submit" class="btn btn-link btn-sm mx-auto">@Translate("Add all products in this category to your cart")</button> 233 </form> 234 </div> 235 </div> 236 </div> 237 accordionItemLoopCounter++; 238 } 239 </div> 240 } 241 242 if (listsCount > pageSize) 243 { 244 <div class="p-3"> 245 @RenderPagination(currentPageUrl, Model.PageCount, Model.CurrentPage, Model.PageSize) 246 </div> 247 } 248 } 249 250 251 @if (!sharedList) 252 { 253 <div class="modal fade" tabindex="-1" id="createFavoriteListModal"> 254 <div class="modal-dialog modal-dialog-centered"> 255 <div class="modal-content"> 256 <div class="modal-header"> 257 <h5 class="modal-title">@Translate("Create favorite list")</h5> 258 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 259 </div> 260 <div class="modal-body d-flex flex-column gap-3"> 261 <p>@Translate("Create favorite list help text", "OBS: Du kan må bruge specialtegn i felterne.")</p> 262 <div hidden> 263 <label for="createFavoriteListInputName" class="form-label">@Translate("Name the favorite list")</label> 264 <input type="text" readonly="readonly" class="form-control" id="createFavoriteListInputName" placeholder="@Translate("Name")"> 265 </div> 266 <div> 267 <label for="createFavoriteListInputCategory" class="form-label">@Translate("Category")</label> 268 <input type="text" class="form-control" id="createFavoriteListInputCategory" placeholder="@Translate("Category - placeholder")"/> 269 </div> 270 <div> 271 <label for="createFavoriteListInputLocation" class="form-label">@Translate("Location")</label> 272 <input type="text" class="form-control" id="createFavoriteListInputLocation" placeholder="@Translate("Location - placeholder")"> 273 </div> 274 <div> 275 <label for="createFavoriteListInputMachine" class="form-label">@Translate("Machine")</label> 276 <input type="text" class="form-control" id="createFavoriteListInputMachine" placeholder="@Translate("Machine - placeholder")"> 277 </div> 278 279 <div> 280 <label for="createFavoriteListInputDescription" class="form-label">@Translate("Description")</label> 281 <textarea class="form-control" id="createFavoriteListInputDescription" placeholder="@Translate("Description - placeholder")"></textarea> 282 </div> 283 284 <div class="alert alert-danger m-0 d-none" role="alert" id="createFavoriteListError">@Translate("A Favorite List must have a name")</div> 285 </div> 286 <div class="modal-footer"> 287 <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">@Translate("Cancel")</button> 288 <button type="button" class="btn btn-primary" id="createFavoriteListButton">@Translate("Create list")</button> 289 </div> 290 </div> 291 </div> 292 </div> 293 294 <div class="modal fade" tabindex="-1" id="renameFavoriteListModal"> 295 <div class="modal-dialog modal-dialog-centered"> 296 <div class="modal-content"> 297 <div class="modal-header"> 298 <h5 class="modal-title">@Translate("Rename favorite list")</h5> 299 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 300 </div> 301 <div class="modal-body"> 302 <p>@Translate("Rename favorite list help text", "OBS: Du kan må bruge specialtegn i felterne.")</p> 303 <div> 304 <label for="renameFavoriteListInputName" class="form-label">@Translate("Rename favorite list"):</label> 305 <input type="text" readonly="readonly" class="form-control" id="renameFavoriteListInputName" placeholder="@Translate("Name")"> 306 </div> 307 <div> 308 <label for="renameFavoriteListInputCategory" class="form-label">@Translate("Category")</label> 309 <input type="text" class="form-control" id="renameFavoriteListInputCategory" placeholder="@Translate("Category - placeholder")"/> 310 </div> 311 <div> 312 <label for="renameFavoriteListInputLocation" class="form-label">@Translate("Location")</label> 313 <input type="text" class="form-control" id="renameFavoriteListInputLocation" placeholder="@Translate("Location - placeholder")"/> 314 </div> 315 <div> 316 <label for="renameFavoriteListInputMachine" class="form-label">@Translate("Machine")</label> 317 <input type="text" class="form-control" id="renameFavoriteListInputMachine" placeholder="@Translate("Machine - placeholder")"/> 318 </div> 319 <div> 320 <label for="renameFavoriteListInputDescription" class="form-label">@Translate("Description")</label> 321 <textarea class="form-control" id="renameFavoriteListInputDescription" placeholder="@Translate("Description - placeholder")"></textarea> 322 </div> 323 <div class="form-check"> 324 <input class="form-check-input" type="checkbox" value="true" id="renameFavoriteListInputIsShared"> 325 <label class="form-check-label" for="renameFavoriteListInputIsShared"> 326 @Translate("IsShared - placeholder") 327 </label> 328 </div> 329 <div class="alert alert-danger m-0 d-none" role="alert" id="renameFavoriteListError">@Translate("A Favorite List must have a name")</div> 330 </div> 331 <div class="modal-footer"> 332 <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">@Translate("Cancel")</button> 333 <button type="button" class="btn btn-primary" id="renameFavoriteListButton">@Translate("Update list")</button> 334 </div> 335 </div> 336 </div> 337 </div> 338 339 <div class="modal fade" tabindex="-1" id="deleteFavoriteListModal"> 340 <div class="modal-dialog modal-dialog-centered"> 341 <div class="modal-content"> 342 <div class="modal-header"> 343 <h5 class="modal-title">@Translate("Delete favorite list")</h5> 344 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 345 </div> 346 <div class="modal-body"> 347 <p>@Translate("You are about to delete"): <strong id="deleteFavoriteName"></strong>.</p> 348 <p>@Translate("Are you sure you want to delete it?")</p> 349 </div> 350 <div class="modal-footer"> 351 <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">@Translate("Cancel")</button> 352 <button type="button" class="btn btn-primary" id="deleteFavoriteListButton">@Translate("Delete list")</button> 353 </div> 354 </div> 355 </div> 356 </div> 357 358 <div class="modal fade" tabindex="-1" id="ownershipFavoriteListModal"> 359 <div class="modal-dialog modal-dialog-centered"> 360 <form class="modal-content"> 361 <div class="modal-header"> 362 <h5 class="modal-title">@Translate("Favorite list ownership")</h5> 363 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 364 </div> 365 <div class="modal-body"> 366 <p>@Translate("Transfer ownership of all lists to this user:")</p> 367 <p> 368 <input type="hidden" name="custfavoritecmd" value="transferfavoritelists"> 369 <input type="hidden" name="favoritlistids" value="@string.Join(",", allFavoriteListIds)"> 370 <select class="form-select" name="touserid"> 371 @foreach (User user in UserService.Instance.GetUsersFromSameCompany()) 372 { 373 bool isCurrentUser = user.ID == UserContext.Current.Customer?.ID; 374 <option value="@user.ID" @(isCurrentUser ? "selected" : string.Empty)>@user.Name @(isCurrentUser ? Translate("(Me)") : string.Empty)</option> 375 } 376 </select> 377 </p> 378 </div> 379 <div class="modal-footer"> 380 <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">@Translate("Cancel")</button> 381 <button type="submit" class="btn btn-primary" id="ownershipFavoriteListButton">@Translate("Transfer ownership")</button> 382 </div> 383 </form> 384 </div> 385 </div> 386 387 <script> 388 let userId = @Pageview.User.ID; 389 let renameFavoriteListModal = document.querySelector("#renameFavoriteListModal") 390 let deleteFavoriteListModal = document.querySelector("#deleteFavoriteListModal") 391 let createFavoriteListModal = document.querySelector("#createFavoriteListModal") 392 393 renameFavoriteListModal.addEventListener('show.bs.modal', function (event) { 394 let button = event.relatedTarget 395 let renameIsShared = button.getAttribute('data-list-isshared') === 'true' ? true : false; 396 let renameFavoriteListId = button.getAttribute('data-list-id'); 397 let renameFromName = button.getAttribute('data-list-name') 398 let renameFromLocation = button.getAttribute('data-list-location') 399 let renameFromDescription = button.getAttribute('data-list-description') 400 let renameFromCategory = button.getAttribute('data-list-category') 401 let renameFromMachine = button.getAttribute('data-list-machine') 402 let renameFavoriteListInputName = document.getElementById('renameFavoriteListInputName'); 403 let renameFavoriteListInputLocation = document.getElementById('renameFavoriteListInputLocation'); 404 let renameFavoriteListInputDescription = document.getElementById('renameFavoriteListInputDescription'); 405 let renameFavoriteListInputCategory = document.getElementById('renameFavoriteListInputCategory'); 406 let renameFavoriteListInputMachine = document.getElementById('renameFavoriteListInputMachine'); 407 let renameFavoriteListInputIsShared = document.getElementById('renameFavoriteListInputIsShared'); 408 409 renameFavoriteListInputName.value = renameFromName; 410 renameFavoriteListInputLocation.value = renameFromLocation; 411 renameFavoriteListInputDescription.value = renameFromDescription; 412 renameFavoriteListInputCategory.value = renameFromCategory; 413 renameFavoriteListInputMachine.value = renameFromMachine; 414 renameFavoriteListInputIsShared.checked = renameIsShared; 415 416 document.querySelector("#renameFavoriteListButton").addEventListener("click", function () { 417 if (renameFavoriteListInputLocation.value !== "") { 418 // Rename Favorite List 419 document.location.href = "/?custfavoritecmd=renamefavoritelist&userId=" + userId + "&favoriteListId=" + renameFavoriteListId + "&name=" + renameFavoriteListInputName.value + "&location=" + renameFavoriteListInputLocation.value + "&description=" + renameFavoriteListInputDescription.value + "&category=" + renameFavoriteListInputCategory.value + "&machine=" + renameFavoriteListInputMachine.value + "&isshared=" + (renameFavoriteListInputIsShared.checked === true ? "true" : "false"); 420 } else if (document.querySelector("#renameFavoriteListError")) { 421 document.querySelector("#renameFavoriteListError").classList.remove("d-none"); 422 } 423 }); 424 }) 425 426 deleteFavoriteListModal.addEventListener('show.bs.modal', function (event) { 427 let button = event.relatedTarget; 428 let deleteFavoriteListId = button.getAttribute('data-list-id'); 429 let deleteFavoriteListName = button.getAttribute('data-list-name'); 430 let deleteFavoriteName = document.querySelector("#deleteFavoriteName"); 431 432 // Update label to confirm before deletion 433 deleteFavoriteName.innerHTML = deleteFavoriteListName; 434 435 // Delete Favorite List 436 document.querySelector("#deleteFavoriteListButton").addEventListener("click", function () { 437 DeleteFavoriteList(userId, deleteFavoriteListId); 438 }); 439 }) 440 441 async function DeleteFavoriteList(userId, favoriteListId) { 442 var url = "/?favoritecmd=removefavoritelist&userId=" + userId + "&favoriteListId=" + favoriteListId; 443 444 let response = await fetch(url); 445 if (response.ok) { 446 document.location.href = "/Default.aspx?ID=@(Pageview.Page.ID)"; 447 } 448 } 449 450 createFavoriteListModal.addEventListener('show.bs.modal', function (event) { 451 let button = event.relatedTarget; 452 let createIsShared = button.getAttribute('data-list-isshared'); 453 454 // Create new Favorite List 455 document.querySelector("#createFavoriteListButton").addEventListener("click", function () { 456 let createFavoriteListName = document.querySelector("#createFavoriteListInputName").value; 457 let createFavoriteListLocation = document.querySelector("#createFavoriteListInputLocation").value; 458 let createFavoriteListInputDescription = document.getElementById('createFavoriteListInputDescription'); 459 let createFavoriteListMachine = document.querySelector("#createFavoriteListInputMachine").value; 460 let createFavoriteListCategory = document.querySelector("#createFavoriteListInputCategory").value; 461 462 if (createFavoriteListLocation !== "") { 463 464 document.location.href = "/?custfavoritecmd=createfavoritelist&userId=" + userId + "&name=" + createFavoriteListName + "&location=" + createFavoriteListLocation + "&category=" + createFavoriteListCategory + "&machine=" + createFavoriteListMachine + "&description=" + createFavoriteListInputDescription.value + "&isshared=" + createIsShared; 465 } else if (document.querySelector("#createFavoriteListError")) { 466 document.querySelector("#createFavoriteListError").classList.remove("d-none"); 467 } 468 }); 469 }) 470 </script> 471 } 472 473 @helper RenderPagination(string currentPageLink, int pageCount, int currentPage, int pageSize) 474 { 475 <ul class="pagination m-0"> 476 @{ string pageHrefTemplate = string.Format("<a class=\"page-link\" href=\"{0}&PageNum={{0}}&PageSize={{1}}\">{{0}}</a>", currentPageLink); } 477 @for (int i = 1; i <= pageCount; i++) 478 { 479 var css = i == currentPage 480 ? "page-item active" 481 : "page-item"; 482 <li class="@css"> 483 @string.Format(pageHrefTemplate, i, pageSize) 484 </li> 485 } 486 </ul> 487 } 488
Error executing template "Designs/Swift/eCom/CustomerExperienceCenter/Favorites/FavoriteLists_Custom.cshtml" System.ArgumentNullException: Value cannot be null. Parameter name: source at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable`1 source, Func`2 selector) at CompiledRazorTemplates.Dynamic.RazorEngine_a3b73b064c0548bcaed1273935bf8a66.Execute() in D:\dynamicweb.net\Solutions\twodayco3\simas.cloud.dynamicweb-cms.com\Files\Templates\Designs\Swift\eCom\CustomerExperienceCenter\Favorites\FavoriteLists_Custom.cshtml:line 16 at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader) at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag) at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer) at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter) at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template) at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template) at Dynamicweb.Rendering.Template.RenderRazorTemplate()
1 @inherits ViewModelTemplate<FavoriteListListViewModel> 2 @using Dynamicweb.Rendering 3 @using Dynamicweb.Ecommerce.Frontend 4 @using System.Linq 5 @using Co3.Simas.Custom.Constants 6 @using Co3.Simas.Custom.Extensions 7 @using Co3.Simas.Custom.Models 8 @using Co3.Simas.Custom.Services 9 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 10 @using Dynamicweb.Security.UserManagement 11 @using ProductViewModel = Dynamicweb.Ecommerce.ProductCatalog.ProductViewModel 12 @{ 13 string themeRaw = Pageview.CurrentParagraph.Item["Theme"]?.ToString(); 14 string theme = !string.IsNullOrEmpty(themeRaw) ? " h-100 theme " + themeRaw.Replace(" ", "").Trim().ToLower() : ""; 15 bool sharedList = (Dynamicweb.Frontend.PageView.Current().CurrentParagraph.ModuleProperties.GetValue("RetrieveListBasedOn") == "UseCustomerNumber"); 16 List<int> allFavoriteListIds = Model.FavoriteLists.Select(fl => fl.Id).ToList(); 17 } 18 @if (sharedList) 19 { 20 @SnippetStart("FavoriteListsShared") 21 if (theme != "") 22 { 23 <div class="@(theme)"> 24 @RenderContent() 25 </div> 26 } 27 else 28 { 29 @RenderContent() 30 } 31 32 @SnippetEnd("FavoriteListsShared") 33 } 34 else 35 { 36 if (theme != "") 37 { 38 <div class="@(theme)"> 39 @RenderContent() 40 </div> 41 } 42 else 43 { 44 @RenderContent() 45 } 46 47 <div class="mt-6"> 48 @RenderSnippet("FavoriteListsShared") 49 </div> 50 51 if (allFavoriteListIds.Any() == true) 52 { 53 <div class="mt-6 pt-2 border-top"> 54 <p class="text-end"> 55 <button type="button" class="btn btn-link btn-sm p-0" data-bs-toggle="modal" data-bs-target="#ownershipFavoriteListModal">@Translate("Manage ownership")</button> 56 </p> 57 </div> 58 } 59 } 60 61 62 @helper RenderContent() 63 { 64 bool sharedList = (Dynamicweb.Frontend.PageView.Current().CurrentParagraph.ModuleProperties.GetValue("RetrieveListBasedOn") == "UseCustomerNumber"); 65 string title = Pageview.CurrentParagraph.Item["Title"]?.ToString(); 66 string listPageLink = Pageview.CurrentParagraph.Item["ProductListPage"] != null ? Pageview.CurrentParagraph.Item["ProductListPage"].ToString() : ""; 67 string currentPageUrl = "/Default.aspx?ID=" + Pageview.Page.ID; 68 string url = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService")); 69 70 IEnumerable<IGrouping<string, FavoriteListViewModel>> listGroups = Model.FavoriteLists.Where(fl => fl.ShowInList(sharedList)).OrderBy(fl => string.IsNullOrEmpty(fl.Category()) == false ? fl.Category() : "zz").ThenBy(fl => fl.Name).GroupBy(fl => fl.Category()); 71 72 int listsCount = listGroups.Count(); 73 int pageSize = Model.PageSize; 74 75 76 <header class="d-flex flex-wrap align-items-center"> 77 <h4 class="m-0 flex-fill mb-2"> 78 <small>@title (@listsCount)</small> 79 </h4> 80 @if (listsCount > 0) 81 { 82 <button type="button" class="btn btn-link p-0 border-0" data-bs-toggle="modal" data-list-isshared="@sharedList" data-bs-target="#createFavoriteListModal"> 83 + @Translate("Add new favorite list")</button> 84 } 85 </header> 86 87 if (listsCount < 1) 88 { 89 <div class="grid"> 90 <div class="g-col-12 g-start-lg-3 g-col-lg-8 d-flex flex-column gap-3 text-center py-3"> 91 <h2 class="h5 m-0">@Translate("It looks like you do not have any favorites yet")</h2> 92 <p class="m-0">@Translate("Save and arrange the best things here until you are ready for them")</p> 93 94 <div class="d-flex flex-column flex-sm-row gap-3 justify-content-center"> 95 <button type="button" class="btn btn-link p-0 border-0" data-bs-toggle="modal" data-list-isshared="@sharedList" data-bs-target="#createFavoriteListModal"> 96 + @Translate("Add new favorite list")</button> 97 </div> 98 </div> 99 </div> 100 } 101 else 102 { 103 <div class="mb-4"> 104 @{ 105 int accordionItemLoopCounter = 0; 106 } 107 @foreach (IGrouping<string, FavoriteListViewModel> categoryGroup in listGroups) 108 { 109 bool isFirstItemInLoop = accordionItemLoopCounter == 0; 110 bool expandFirstAccordionItem = false; //isFirstItemInLoop == true; 111 string accordionItemId = Guid.NewGuid().ToHtmlId(); 112 string groupName = string.IsNullOrEmpty(categoryGroup.Key) == false ? categoryGroup.Key : Translate("Ingen kategori"); 113 string buttonAriaExpanded = expandFirstAccordionItem == true ? "true" : "false"; 114 string buttonClassState = expandFirstAccordionItem == true ? "" : "collapsed"; 115 string collapseClassState = expandFirstAccordionItem == true ? "show" : "collapse"; 116 117 <div class="accordion mb-2"> 118 <div class="accordion-item"> 119 <h5 class="accordion-header"> 120 <button class="fw-bold fs-5 accordion-button @buttonClassState" type="button" data-bs-toggle="collapse" data-bs-target="#@accordionItemId" aria-expanded="@buttonAriaExpanded" aria-controls="@accordionItemId">@groupName</button> 121 </h5> 122 <div id="@accordionItemId" class="accordion-collapse @collapseClassState"> 123 <div class="accordion-body"> 124 <ul class="list-unstyled m-0"> 125 @foreach (FavoriteListViewModel theList in categoryGroup) 126 { 127 string favoriteListLink = listPageLink + "&FavoriteListId=" + theList.Id; 128 string listName = !string.IsNullOrEmpty(theList.Name) ? theList.Name : Translate("Favorites"); 129 string location = theList.Location(); 130 string isShared = theList.IsShared().ToString().ToLowerInvariant(); 131 string description = theList.Description(); 132 string category = theList.Category(); 133 string machine = theList.Machine(); 134 <li class="mb-4"> 135 <p class="d-flex align-items-center m-0"> 136 <a href="@favoriteListLink" class="text-decoration-none"> 137 <strong>@listName</strong> 138 </a> 139 @if (theList.IsShared() == true) 140 { 141 string isSharedByUserName = theList.GetFavoriteList().IsShareByUserName(); 142 143 if (isSharedByUserName == "YOU" || isSharedByUserName == "UNKNOWN") 144 { 145 isSharedByUserName = Translate("SharedBy:" + isSharedByUserName, isSharedByUserName); 146 } 147 148 <small class="badge bg-info ms-3">@Translate("Shared by") @isSharedByUserName</small> 149 } 150 @if (theList.IsEditableForCurrentUser()) 151 { 152 <span class="mx-3"> · </span> 153 154 <button type="button" 155 class="btn btn-link btn-sm p-0 me-2 renameFavoriteListModal" 156 data-bs-toggle="modal" 157 data-bs-target="#renameFavoriteListModal" 158 data-list-id="@theList.Id" 159 data-list-isshared="@isShared" 160 data-list-location="@location" 161 data-list-description="@description" 162 data-list-category="@category" 163 data-list-machine="@machine" 164 data-list-isshared="@sharedList" 165 data-list-name="@listName"> 166 @Translate("Rename") 167 </button> 168 <button type="button" 169 class="btn btn-link btn-sm p-0 mx-1 px-1 deleteFavoriteNameButton" 170 data-bs-toggle="modal" 171 data-bs-target="#deleteFavoriteListModal" 172 data-list-id="@theList.Id" 173 data-list-name="@listName"> 174 @Translate("Delete") 175 </button> 176 } 177 </p> 178 <p class="opacity-75 mb-1">@description</p> 179 <form method="post" action="@url" class="d-flex align-items-center"> 180 <input type="hidden" name="CartCmd" id="CartCmd" value="addMulti"> 181 @{ 182 int listProductLoopCounter = 1; 183 } 184 @foreach (FavoriteProduct favoriteProduct in theList.GetFavoriteList().Products()) 185 { 186 string quantityName = $"Quantity{listProductLoopCounter}"; 187 string productIdName = $"ProductID{listProductLoopCounter}"; 188 string locationName = $"EcomOrderLineFieldInput_{OrderLineFieldIds.Location}{listProductLoopCounter}"; 189 string machineName = $"EcomOrderLineFieldInput_{OrderLineFieldIds.Machine}{listProductLoopCounter}"; 190 string categoryName = $"EcomOrderLineFieldInput_{OrderLineFieldIds.Category}{listProductLoopCounter}"; 191 string listProductLoopCounterName = $"ProductLoopCounter{listProductLoopCounter}"; 192 193 <input type="hidden" name="@quantityName" value="@Math.Max(1, (int)favoriteProduct.Quantity)"> 194 <input type="hidden" name="@productIdName" value="@favoriteProduct.ProductId"> 195 <input type="hidden" name="@locationName" value="@location"> 196 <input type="hidden" name="@machineName" value="@machine"> 197 <input type="hidden" name="@categoryName" value="@category"> 198 <input type="hidden" name="@listProductLoopCounterName" value="@listProductLoopCounter"> 199 listProductLoopCounter += 1; 200 } 201 <button type="submit" class="btn btn-link btn-sm me-2 p-0">@Translate("Add all products in this list to your cart")</button> 202 </form> 203 </li> 204 } 205 </ul> 206 </div> 207 @{ int categoryProductLoopCounter = 1; } 208 <form method="post" action="@url" class="d-flex align-items-center text-center border-top"> 209 <input type="hidden" name="CartCmd" id="CartCmd" value="addMulti"> 210 @foreach (FavoriteListViewModel theList in categoryGroup) 211 { 212 string location = theList.Location(); 213 string machine = theList.Machine(); 214 string category = theList.Category(); 215 foreach (FavoriteProduct favoriteProduct in theList.GetFavoriteList().Products()) 216 { 217 string quantityName = $"Quantity{categoryProductLoopCounter}"; 218 string productIdName = $"ProductID{categoryProductLoopCounter}"; 219 string locationName = $"EcomOrderLineFieldInput_{OrderLineFieldIds.Location}{categoryProductLoopCounter}"; 220 string machineName = $"EcomOrderLineFieldInput_{OrderLineFieldIds.Machine}{categoryProductLoopCounter}"; 221 string categoryName = $"EcomOrderLineFieldInput_{OrderLineFieldIds.Category}{categoryProductLoopCounter}"; 222 string categoryProductLoopCounterName = $"ProductLoopCounter{categoryProductLoopCounter}"; 223 <input type="hidden" name="@quantityName" value="@Math.Max(1, (int)favoriteProduct.Quantity)"> 224 <input type="hidden" name="@productIdName" value="@favoriteProduct.ProductId"> 225 <input type="hidden" name="@locationName" value="@location"> 226 <input type="hidden" name="@machineName" value="@machine"> 227 <input type="hidden" name="@categoryName" value="@category"> 228 <input type="hidden" name="@categoryProductLoopCounterName" value="@categoryProductLoopCounter"> 229 categoryProductLoopCounter += 1; 230 } 231 } 232 <button type="submit" class="btn btn-link btn-sm mx-auto">@Translate("Add all products in this category to your cart")</button> 233 </form> 234 </div> 235 </div> 236 </div> 237 accordionItemLoopCounter++; 238 } 239 </div> 240 } 241 242 if (listsCount > pageSize) 243 { 244 <div class="p-3"> 245 @RenderPagination(currentPageUrl, Model.PageCount, Model.CurrentPage, Model.PageSize) 246 </div> 247 } 248 } 249 250 251 @if (!sharedList) 252 { 253 <div class="modal fade" tabindex="-1" id="createFavoriteListModal"> 254 <div class="modal-dialog modal-dialog-centered"> 255 <div class="modal-content"> 256 <div class="modal-header"> 257 <h5 class="modal-title">@Translate("Create favorite list")</h5> 258 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 259 </div> 260 <div class="modal-body d-flex flex-column gap-3"> 261 <p>@Translate("Create favorite list help text", "OBS: Du kan må bruge specialtegn i felterne.")</p> 262 <div hidden> 263 <label for="createFavoriteListInputName" class="form-label">@Translate("Name the favorite list")</label> 264 <input type="text" readonly="readonly" class="form-control" id="createFavoriteListInputName" placeholder="@Translate("Name")"> 265 </div> 266 <div> 267 <label for="createFavoriteListInputCategory" class="form-label">@Translate("Category")</label> 268 <input type="text" class="form-control" id="createFavoriteListInputCategory" placeholder="@Translate("Category - placeholder")"/> 269 </div> 270 <div> 271 <label for="createFavoriteListInputLocation" class="form-label">@Translate("Location")</label> 272 <input type="text" class="form-control" id="createFavoriteListInputLocation" placeholder="@Translate("Location - placeholder")"> 273 </div> 274 <div> 275 <label for="createFavoriteListInputMachine" class="form-label">@Translate("Machine")</label> 276 <input type="text" class="form-control" id="createFavoriteListInputMachine" placeholder="@Translate("Machine - placeholder")"> 277 </div> 278 279 <div> 280 <label for="createFavoriteListInputDescription" class="form-label">@Translate("Description")</label> 281 <textarea class="form-control" id="createFavoriteListInputDescription" placeholder="@Translate("Description - placeholder")"></textarea> 282 </div> 283 284 <div class="alert alert-danger m-0 d-none" role="alert" id="createFavoriteListError">@Translate("A Favorite List must have a name")</div> 285 </div> 286 <div class="modal-footer"> 287 <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">@Translate("Cancel")</button> 288 <button type="button" class="btn btn-primary" id="createFavoriteListButton">@Translate("Create list")</button> 289 </div> 290 </div> 291 </div> 292 </div> 293 294 <div class="modal fade" tabindex="-1" id="renameFavoriteListModal"> 295 <div class="modal-dialog modal-dialog-centered"> 296 <div class="modal-content"> 297 <div class="modal-header"> 298 <h5 class="modal-title">@Translate("Rename favorite list")</h5> 299 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 300 </div> 301 <div class="modal-body"> 302 <p>@Translate("Rename favorite list help text", "OBS: Du kan må bruge specialtegn i felterne.")</p> 303 <div> 304 <label for="renameFavoriteListInputName" class="form-label">@Translate("Rename favorite list"):</label> 305 <input type="text" readonly="readonly" class="form-control" id="renameFavoriteListInputName" placeholder="@Translate("Name")"> 306 </div> 307 <div> 308 <label for="renameFavoriteListInputCategory" class="form-label">@Translate("Category")</label> 309 <input type="text" class="form-control" id="renameFavoriteListInputCategory" placeholder="@Translate("Category - placeholder")"/> 310 </div> 311 <div> 312 <label for="renameFavoriteListInputLocation" class="form-label">@Translate("Location")</label> 313 <input type="text" class="form-control" id="renameFavoriteListInputLocation" placeholder="@Translate("Location - placeholder")"/> 314 </div> 315 <div> 316 <label for="renameFavoriteListInputMachine" class="form-label">@Translate("Machine")</label> 317 <input type="text" class="form-control" id="renameFavoriteListInputMachine" placeholder="@Translate("Machine - placeholder")"/> 318 </div> 319 <div> 320 <label for="renameFavoriteListInputDescription" class="form-label">@Translate("Description")</label> 321 <textarea class="form-control" id="renameFavoriteListInputDescription" placeholder="@Translate("Description - placeholder")"></textarea> 322 </div> 323 <div class="form-check"> 324 <input class="form-check-input" type="checkbox" value="true" id="renameFavoriteListInputIsShared"> 325 <label class="form-check-label" for="renameFavoriteListInputIsShared"> 326 @Translate("IsShared - placeholder") 327 </label> 328 </div> 329 <div class="alert alert-danger m-0 d-none" role="alert" id="renameFavoriteListError">@Translate("A Favorite List must have a name")</div> 330 </div> 331 <div class="modal-footer"> 332 <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">@Translate("Cancel")</button> 333 <button type="button" class="btn btn-primary" id="renameFavoriteListButton">@Translate("Update list")</button> 334 </div> 335 </div> 336 </div> 337 </div> 338 339 <div class="modal fade" tabindex="-1" id="deleteFavoriteListModal"> 340 <div class="modal-dialog modal-dialog-centered"> 341 <div class="modal-content"> 342 <div class="modal-header"> 343 <h5 class="modal-title">@Translate("Delete favorite list")</h5> 344 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 345 </div> 346 <div class="modal-body"> 347 <p>@Translate("You are about to delete"): <strong id="deleteFavoriteName"></strong>.</p> 348 <p>@Translate("Are you sure you want to delete it?")</p> 349 </div> 350 <div class="modal-footer"> 351 <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">@Translate("Cancel")</button> 352 <button type="button" class="btn btn-primary" id="deleteFavoriteListButton">@Translate("Delete list")</button> 353 </div> 354 </div> 355 </div> 356 </div> 357 358 <div class="modal fade" tabindex="-1" id="ownershipFavoriteListModal"> 359 <div class="modal-dialog modal-dialog-centered"> 360 <form class="modal-content"> 361 <div class="modal-header"> 362 <h5 class="modal-title">@Translate("Favorite list ownership")</h5> 363 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 364 </div> 365 <div class="modal-body"> 366 <p>@Translate("Transfer ownership of all lists to this user:")</p> 367 <p> 368 <input type="hidden" name="custfavoritecmd" value="transferfavoritelists"> 369 <input type="hidden" name="favoritlistids" value="@string.Join(",", allFavoriteListIds)"> 370 <select class="form-select" name="touserid"> 371 @foreach (User user in UserService.Instance.GetUsersFromSameCompany()) 372 { 373 bool isCurrentUser = user.ID == UserContext.Current.Customer?.ID; 374 <option value="@user.ID" @(isCurrentUser ? "selected" : string.Empty)>@user.Name @(isCurrentUser ? Translate("(Me)") : string.Empty)</option> 375 } 376 </select> 377 </p> 378 </div> 379 <div class="modal-footer"> 380 <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">@Translate("Cancel")</button> 381 <button type="submit" class="btn btn-primary" id="ownershipFavoriteListButton">@Translate("Transfer ownership")</button> 382 </div> 383 </form> 384 </div> 385 </div> 386 387 <script> 388 let userId = @Pageview.User.ID; 389 let renameFavoriteListModal = document.querySelector("#renameFavoriteListModal") 390 let deleteFavoriteListModal = document.querySelector("#deleteFavoriteListModal") 391 let createFavoriteListModal = document.querySelector("#createFavoriteListModal") 392 393 renameFavoriteListModal.addEventListener('show.bs.modal', function (event) { 394 let button = event.relatedTarget 395 let renameIsShared = button.getAttribute('data-list-isshared') === 'true' ? true : false; 396 let renameFavoriteListId = button.getAttribute('data-list-id'); 397 let renameFromName = button.getAttribute('data-list-name') 398 let renameFromLocation = button.getAttribute('data-list-location') 399 let renameFromDescription = button.getAttribute('data-list-description') 400 let renameFromCategory = button.getAttribute('data-list-category') 401 let renameFromMachine = button.getAttribute('data-list-machine') 402 let renameFavoriteListInputName = document.getElementById('renameFavoriteListInputName'); 403 let renameFavoriteListInputLocation = document.getElementById('renameFavoriteListInputLocation'); 404 let renameFavoriteListInputDescription = document.getElementById('renameFavoriteListInputDescription'); 405 let renameFavoriteListInputCategory = document.getElementById('renameFavoriteListInputCategory'); 406 let renameFavoriteListInputMachine = document.getElementById('renameFavoriteListInputMachine'); 407 let renameFavoriteListInputIsShared = document.getElementById('renameFavoriteListInputIsShared'); 408 409 renameFavoriteListInputName.value = renameFromName; 410 renameFavoriteListInputLocation.value = renameFromLocation; 411 renameFavoriteListInputDescription.value = renameFromDescription; 412 renameFavoriteListInputCategory.value = renameFromCategory; 413 renameFavoriteListInputMachine.value = renameFromMachine; 414 renameFavoriteListInputIsShared.checked = renameIsShared; 415 416 document.querySelector("#renameFavoriteListButton").addEventListener("click", function () { 417 if (renameFavoriteListInputLocation.value !== "") { 418 // Rename Favorite List 419 document.location.href = "/?custfavoritecmd=renamefavoritelist&userId=" + userId + "&favoriteListId=" + renameFavoriteListId + "&name=" + renameFavoriteListInputName.value + "&location=" + renameFavoriteListInputLocation.value + "&description=" + renameFavoriteListInputDescription.value + "&category=" + renameFavoriteListInputCategory.value + "&machine=" + renameFavoriteListInputMachine.value + "&isshared=" + (renameFavoriteListInputIsShared.checked === true ? "true" : "false"); 420 } else if (document.querySelector("#renameFavoriteListError")) { 421 document.querySelector("#renameFavoriteListError").classList.remove("d-none"); 422 } 423 }); 424 }) 425 426 deleteFavoriteListModal.addEventListener('show.bs.modal', function (event) { 427 let button = event.relatedTarget; 428 let deleteFavoriteListId = button.getAttribute('data-list-id'); 429 let deleteFavoriteListName = button.getAttribute('data-list-name'); 430 let deleteFavoriteName = document.querySelector("#deleteFavoriteName"); 431 432 // Update label to confirm before deletion 433 deleteFavoriteName.innerHTML = deleteFavoriteListName; 434 435 // Delete Favorite List 436 document.querySelector("#deleteFavoriteListButton").addEventListener("click", function () { 437 DeleteFavoriteList(userId, deleteFavoriteListId); 438 }); 439 }) 440 441 async function DeleteFavoriteList(userId, favoriteListId) { 442 var url = "/?favoritecmd=removefavoritelist&userId=" + userId + "&favoriteListId=" + favoriteListId; 443 444 let response = await fetch(url); 445 if (response.ok) { 446 document.location.href = "/Default.aspx?ID=@(Pageview.Page.ID)"; 447 } 448 } 449 450 createFavoriteListModal.addEventListener('show.bs.modal', function (event) { 451 let button = event.relatedTarget; 452 let createIsShared = button.getAttribute('data-list-isshared'); 453 454 // Create new Favorite List 455 document.querySelector("#createFavoriteListButton").addEventListener("click", function () { 456 let createFavoriteListName = document.querySelector("#createFavoriteListInputName").value; 457 let createFavoriteListLocation = document.querySelector("#createFavoriteListInputLocation").value; 458 let createFavoriteListInputDescription = document.getElementById('createFavoriteListInputDescription'); 459 let createFavoriteListMachine = document.querySelector("#createFavoriteListInputMachine").value; 460 let createFavoriteListCategory = document.querySelector("#createFavoriteListInputCategory").value; 461 462 if (createFavoriteListLocation !== "") { 463 464 document.location.href = "/?custfavoritecmd=createfavoritelist&userId=" + userId + "&name=" + createFavoriteListName + "&location=" + createFavoriteListLocation + "&category=" + createFavoriteListCategory + "&machine=" + createFavoriteListMachine + "&description=" + createFavoriteListInputDescription.value + "&isshared=" + createIsShared; 465 } else if (document.querySelector("#createFavoriteListError")) { 466 document.querySelector("#createFavoriteListError").classList.remove("d-none"); 467 } 468 }); 469 }) 470 </script> 471 } 472 473 @helper RenderPagination(string currentPageLink, int pageCount, int currentPage, int pageSize) 474 { 475 <ul class="pagination m-0"> 476 @{ string pageHrefTemplate = string.Format("<a class=\"page-link\" href=\"{0}&PageNum={{0}}&PageSize={{1}}\">{{0}}</a>", currentPageLink); } 477 @for (int i = 1; i <= pageCount; i++) 478 { 479 var css = i == currentPage 480 ? "page-item active" 481 : "page-item"; 482 <li class="@css"> 483 @string.Format(pageHrefTemplate, i, pageSize) 484 </li> 485 } 486 </ul> 487 } 488