This commit is contained in:
David Štaleker
2023-06-23 14:17:57 +02:00
parent d0fa4db3d8
commit 25e98d63ec
5 changed files with 61 additions and 32 deletions

View File

@@ -51,22 +51,37 @@
</div>
<div class="col-6">
<h4>Vezave</h4>
<table class="table card-table">
<thead>
<tr>
<th style="width: 30px;"></th>
<th>Veza</th>
</tr>
</thead>
<tbody id="tableBodyLinks">
<div class="row">
<div class="col-6">
<h5>Uvodno</h5>
<table class="table card-table">
<tbody id="tableBodyLinksPreText">
</tbody>
</table>
</div>
<div class="col-6">
<h5>Zaključno</h5>
<table class="table card-table">
<tbody id="tableBodyLinksPostText">
</tbody>
</table>
</div>
</div>
</tbody>
</table>
</div>
</div>
</div>
<div class="card-footer py-3 text-right">
<button id="savePrePostText" type="submit" class="btn btn-primary">Shrani nalog</button>
@if (Model.PrePostText.IdPrePostText > 0)
{
<button id="savePrePostText" type="submit" class="btn btn-primary">Shrani</button>
}
else
{
<button id="savePrePostText" type="submit" class="btn btn-primary">Dodaj</button>
}
<a asp-page="Index" class="btn btn-default">Prekliči</a>
</div>
</form>
@@ -124,7 +139,8 @@
success: function (data) {
$.unblockUI();
if (data.successful) {
$('#tableBodyLinks').html(data.tableLinks);
$('#tableBodyLinksPreText').html(data.tableLinksPreText);
$('#tableBodyLinksPostText').html(data.tableLinksPostText);
$('.chb-link').on('change',
function() {
toggleLink(this);
@@ -152,6 +168,7 @@
}
let row = $(checkbox).parent().parent();
let link = $(row).attr('data-link');
let type = $(row).attr('data-type');
let idPrePostTextLink = $(row).attr('data-idlink');
let idPrePostText = parseInt($('#inputIdPrePostText').val());
@@ -163,7 +180,7 @@
$('input:hidden[name="__RequestVerificationToken"]').val());
},
url: "AddEdit/?handler=LinkToggle",
data: { idPrePostText, link, idPrePostTextLink },
data: { idPrePostText, link, type, idPrePostTextLink },
success: function(data) {
$.unblockUI();
if (data.successful) {

View File

@@ -123,21 +123,32 @@ namespace EveryThing.Pages.CodeTablePrePostText
var insertedLinks = _context.CodeTablePrePostTextLink
.Where(x => x.IdPrePostTextFk == idPrePostText);
var tableLinks = new StringBuilder();
var tableLinksPreText = new StringBuilder();
typeof(CodeTablePrePostTextLink.LinkEnum).GetEnumListClass<DisplayAttribute>().ForEach(link =>
{
var insertedLink = insertedLinks.FirstOrDefault(x => (int)x.Link == link.EnumValue);
tableLinks.Append($"<tr data-link='{link.EnumValue}' data-idlink='{insertedLink?.IdPrePostTextLink ?? 0}'>");
tableLinks.Append($"<td><input type='checkbox' class='chb-link' {((insertedLink?.IdPrePostTextLink ?? 0) > 0 ? "checked='checked'" : "")}/></td>");
tableLinks.Append($"<td>{link.EnumAttribute.Name}</td>");
tableLinks.Append("</tr>");
var insertedLink = insertedLinks.FirstOrDefault(x => (int)x.Link == link.EnumValue && x.Type == CodeTablePrePostTextLink.TypeEnum.PreText);
tableLinksPreText.Append($"<tr data-link='{link.EnumValue}' data-type='{(int)CodeTablePrePostTextLink.TypeEnum.PreText}' data-idlink='{insertedLink?.IdPrePostTextLink ?? 0}'>");
tableLinksPreText.Append($"<td><input type='checkbox' class='chb-link' {((insertedLink?.IdPrePostTextLink ?? 0) > 0 ? "checked='checked'" : "")}/></td>");
tableLinksPreText.Append($"<td>{link.EnumAttribute.Name}</td>");
tableLinksPreText.Append("</tr>");
});
return new JsonResult(new { tableLinks = tableLinks.ToString(), successful = true });
var tableLinksPostText = new StringBuilder();
typeof(CodeTablePrePostTextLink.LinkEnum).GetEnumListClass<DisplayAttribute>().ForEach(link =>
{
var insertedLink = insertedLinks.FirstOrDefault(x => (int)x.Link == link.EnumValue && x.Type == CodeTablePrePostTextLink.TypeEnum.PostText);
tableLinksPostText.Append($"<tr data-link='{link.EnumValue}' data-type='{(int)CodeTablePrePostTextLink.TypeEnum.PostText}' data-idlink='{insertedLink?.IdPrePostTextLink ?? 0}'>");
tableLinksPostText.Append($"<td><input type='checkbox' class='chb-link' {((insertedLink?.IdPrePostTextLink ?? 0) > 0 ? "checked='checked'" : "")}/></td>");
tableLinksPostText.Append($"<td>{link.EnumAttribute.Name}</td>");
tableLinksPostText.Append("</tr>");
});
return new JsonResult(new { tableLinksPreText = tableLinksPreText.ToString(), tableLinksPostText = tableLinksPostText.ToString(), successful = true });
}
public IActionResult OnPostLinkToggle(int idPrePostText, int link, int idPrePostTextLink)
public IActionResult OnPostLinkToggle(int idPrePostText, int link, int type, int idPrePostTextLink)
{
var user = _userManager.GetUserAsync(User).Result;
var idLink = 0;
@@ -155,7 +166,8 @@ namespace EveryThing.Pages.CodeTablePrePostText
var newLink = new CodeTablePrePostTextLink
{
IdPrePostTextFk = idPrePostText,
Link = (CodeTablePrePostTextLink.LinkEnum)link
Link = (CodeTablePrePostTextLink.LinkEnum)link,
Type = (CodeTablePrePostTextLink.TypeEnum)type
};
_context.CodeTablePrePostTextLink.Add(newLink);