Klavzule
This commit is contained in:
187
EveryThing/Pages/CodeTablePrePostText/AddEdit.cshtml
Normal file
187
EveryThing/Pages/CodeTablePrePostText/AddEdit.cshtml
Normal file
@@ -0,0 +1,187 @@
|
||||
@page "{handler?}"
|
||||
@model EveryThing.Pages.CodeTablePrePostText.AddEditModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Urejanje klavzule";
|
||||
Layout = "~/Pages/Layouts/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<!-- Editor -->
|
||||
<link rel="stylesheet" href="~/vendor/libs/quill/typography.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/vendor/libs/quill/editor.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/vendor/libs/select2/select2.css" asp-append-version="true" />
|
||||
|
||||
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
|
||||
<span>
|
||||
<span class="text-muted font-weight-light">Nalog /</span>
|
||||
@if (Model.PrePostText.IdPrePostText > 0)
|
||||
{
|
||||
<span>Urejanje</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Vnos</span>
|
||||
}
|
||||
</span>
|
||||
</h4>
|
||||
|
||||
<div class="nav-tabs-top nav-responsive-sm">
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" data-toggle="tab" href="#item-basic">Osnovni podatki</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane fade show active" id="item-basic">
|
||||
<form method="post" data-ajax="true" data-ajax-method="post" asp-page-handler="order" data-ajax-complete="orderPostCompleted" onsubmit="handleEditors()">
|
||||
<div class="card-body">
|
||||
<input id="inputIdPrePostText" type="hidden" asp-for="PrePostText.IdPrePostText" />
|
||||
<input type="hidden" asp-for="PrePostText.IdCompanyFk" />
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<h4>Vsebina</h4>
|
||||
<div class="form-group mb-0">
|
||||
<input type="hidden" id="value-content" asp-for="@Model.PrePostText.Content"/>
|
||||
<div id="editor-content" style="height: 250px">
|
||||
@Html.Raw(Model.PrePostText.Content)
|
||||
</div>
|
||||
<span asp-validation-for="PrePostText.Content" class="text-danger"></span>
|
||||
</div>
|
||||
</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">
|
||||
|
||||
</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>
|
||||
<a asp-page="Index" class="btn btn-default">Prekliči</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
@section Scripts {
|
||||
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
|
||||
|
||||
<!-- Editor -->
|
||||
<script src="~/vendor/libs/quill/quill.js" asp-append-version="true"></script>
|
||||
<script src="~/vendor/libs/select2/select2.js" asp-append-version="true"></script>
|
||||
|
||||
<script>
|
||||
var Block = Quill.import('blots/block');
|
||||
Block.tagName = 'DIV';
|
||||
Quill.register(Block, true);
|
||||
|
||||
var laddaSaveOrder = Ladda.create(document.querySelector('#savePrePostText'));
|
||||
|
||||
let editorContent;
|
||||
|
||||
function handleEditors() {
|
||||
document.getElementById('value-content').value = editorContent.root.innerHTML;
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$('.select2').select2();
|
||||
editorContent = new Quill('#editor-content', { modules: { toolbar: [['bold', 'italic', 'underline'], ['color'], [{ 'list': 'ordered' }, { 'list': 'bullet' }], ['align'], ['clean']] }, theme: 'snow' });
|
||||
loadLinks();
|
||||
});
|
||||
|
||||
orderPostCompleted = function (xhr) {
|
||||
laddaSaveOrder.stop();
|
||||
location.replace('AddEdit?Id=' + xhr.responseJSON.id);
|
||||
};
|
||||
|
||||
function loadLinks() {
|
||||
let idPrePostText = parseInt($('#inputIdPrePostText').val());
|
||||
if (idPrePostText <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.blockUI();
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "AddEdit/?handler=LinksTable",
|
||||
data: {
|
||||
idPrePostText
|
||||
},
|
||||
success: function (data) {
|
||||
$.unblockUI();
|
||||
if (data.successful) {
|
||||
$('#tableBodyLinks').html(data.tableLinks);
|
||||
$('.chb-link').on('change',
|
||||
function() {
|
||||
toggleLink(this);
|
||||
});
|
||||
} else {
|
||||
console.log(data);
|
||||
Swal.fire('Napaka pri branju povezav',
|
||||
data.error,
|
||||
'error');
|
||||
}
|
||||
},
|
||||
error: function (xhr, ajaxOptions, thrownError) {
|
||||
console.log(xhr);
|
||||
alert(xhr.responseText);
|
||||
$.unblockUI();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let disableToggleLink = false;
|
||||
|
||||
function toggleLink(checkbox) {
|
||||
if (disableToggleLink) {
|
||||
return;
|
||||
}
|
||||
let row = $(checkbox).parent().parent();
|
||||
let link = $(row).attr('data-link');
|
||||
let idPrePostTextLink = $(row).attr('data-idlink');
|
||||
let idPrePostText = parseInt($('#inputIdPrePostText').val());
|
||||
|
||||
$.blockUI();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
beforeSend: function(xhr) {
|
||||
xhr.setRequestHeader("XSRF-TOKEN",
|
||||
$('input:hidden[name="__RequestVerificationToken"]').val());
|
||||
},
|
||||
url: "AddEdit/?handler=LinkToggle",
|
||||
data: { idPrePostText, link, idPrePostTextLink },
|
||||
success: function(data) {
|
||||
$.unblockUI();
|
||||
if (data.successful) {
|
||||
disableToggleLink = true;
|
||||
$(checkbox).prop("checked", data.idLink > 0);
|
||||
disableToggleLink = false;
|
||||
} else {
|
||||
console.log(data);
|
||||
Swal.fire('Napaka pri vnosu povezave',
|
||||
data.error,
|
||||
'error');
|
||||
}
|
||||
},
|
||||
error: function (xhr, ajaxOptions, thrownError) {
|
||||
alert(xhr.responseText);
|
||||
$.unblockUI();
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
}
|
||||
169
EveryThing/Pages/CodeTablePrePostText/AddEdit.cshtml.cs
Normal file
169
EveryThing/Pages/CodeTablePrePostText/AddEdit.cshtml.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using EveryThing.Models.CodeTable;
|
||||
using EveryThing.Classess;
|
||||
|
||||
namespace EveryThing.Pages.CodeTablePrePostText
|
||||
|
||||
{
|
||||
[Authorize(Roles = "Administrator,TransportThingUser,InvoicingUser")]
|
||||
public class AddEditModel : PageModel
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly UserManager<IdentityApplicationUser> _userManager;
|
||||
|
||||
public AddEditModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager)
|
||||
{
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public Models.CodeTable.CodeTablePrePostText PrePostText { get; set; }
|
||||
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(int? id)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
|
||||
if (id == null)
|
||||
{
|
||||
PrePostText = new Models.CodeTable.CodeTablePrePostText
|
||||
{
|
||||
Content = "",
|
||||
IdCompanyFk = user.IdCompanyFk
|
||||
};
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
PrePostText = await _context.CodeTablePrePostText
|
||||
.FirstOrDefaultAsync(m => m.IdPrePostText == id && m.IdCompanyFk == user.IdCompanyFk);
|
||||
|
||||
|
||||
if (PrePostText == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostOrderAsync()
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("OnPostOrderAsync");
|
||||
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
ViewData["IdPartnerFk"] = new SelectList(_context.CodeTablePartners.Where(x => x.IdCompanyFk == user.IdCompanyFk), "IdPartner", "Title");
|
||||
ViewData["IdVehicleFk"] = new SelectList(_context.Vehicles.Where(x => x.IdCompanyFk == user.IdCompanyFk), "IdVehicle", "RegistrationNumber");
|
||||
return Page();
|
||||
}
|
||||
|
||||
PrePostText.Content = PrePostText.Content.Replace("<div><br></div>", "");
|
||||
|
||||
if (PrePostText.IdPrePostText > 0)
|
||||
{
|
||||
_context.Attach(PrePostText).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!PrePostTextExists(PrePostText.IdPrePostText))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
// OrderNumber and OrderYear
|
||||
|
||||
_context.CodeTablePrePostText.Add(PrePostText);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
|
||||
return new JsonResult(new { id = PrePostText.IdPrePostText});
|
||||
}
|
||||
|
||||
|
||||
private bool PrePostTextExists(int id)
|
||||
{
|
||||
return _context.CodeTablePrePostText.Any(e => e.IdPrePostText == id);
|
||||
}
|
||||
|
||||
public IActionResult OnGetLinksTable(int idPrePostText)
|
||||
{
|
||||
var insertedLinks = _context.CodeTablePrePostTextLink
|
||||
.Where(x => x.IdPrePostTextFk == idPrePostText);
|
||||
|
||||
var tableLinks = 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>");
|
||||
});
|
||||
|
||||
return new JsonResult(new { tableLinks = tableLinks.ToString(), successful = true });
|
||||
}
|
||||
|
||||
public IActionResult OnPostLinkToggle(int idPrePostText, int link, int idPrePostTextLink)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
var idLink = 0;
|
||||
|
||||
var exitingLink =
|
||||
_context.CodeTablePrePostTextLink.FirstOrDefault(x => x.IdPrePostTextLink == idPrePostTextLink && x.IdPrePostTextFk == idPrePostText);
|
||||
|
||||
if (exitingLink != null)
|
||||
{
|
||||
_context.CodeTablePrePostTextLink.Remove(exitingLink);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
var newLink = new CodeTablePrePostTextLink
|
||||
{
|
||||
IdPrePostTextFk = idPrePostText,
|
||||
Link = (CodeTablePrePostTextLink.LinkEnum)link
|
||||
};
|
||||
|
||||
_context.CodeTablePrePostTextLink.Add(newLink);
|
||||
_context.SaveChanges();
|
||||
idLink = newLink.IdPrePostTextLink;
|
||||
}
|
||||
|
||||
return new JsonResult(new { error = "", successful = true, idLink });
|
||||
}
|
||||
}
|
||||
}
|
||||
67
EveryThing/Pages/CodeTablePrePostText/Index.cshtml
Normal file
67
EveryThing/Pages/CodeTablePrePostText/Index.cshtml
Normal file
@@ -0,0 +1,67 @@
|
||||
@page
|
||||
@model EveryThing.Pages.CodeTablePrePostText.IndexModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Klavzule";
|
||||
Layout = "~/Pages/Layouts/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
|
||||
<span>
|
||||
<span class="text-muted font-weight-light">Klavzule /</span> Pregled
|
||||
</span>
|
||||
</h4>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 mb-2 text-right">
|
||||
<form method="get">
|
||||
<div class="btn-group">
|
||||
<input class="form-control" type="text" name="searchString" value="@ViewData["SearchString"]" placeholder="Iskanje..." autocomplete="off">
|
||||
<button type="submit" class="btn btn-secondary" aria-label="Osveži" title="Osveži">
|
||||
<i class="opacity-75 ion ion-md-refresh"></i>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
|
||||
<h6 class="card-header">
|
||||
Seznam klavzul
|
||||
</h6>
|
||||
|
||||
<table class="table card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Klavzula
|
||||
</th>
|
||||
<th style="width: 80px;"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model.PrePostTexts)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.ContentDisplay)
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" asp-page="AddEdit" asp-route-id="@item.IdPrePostText" data-toggle="tooltip" data-placement="top" title="Urejanje" data-state="secondary"><i class="fas fa-pencil-alt"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="card-footer py-3 text-right">
|
||||
<a asp-page="AddEdit" class="btn btn-primary">Vnos nove</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
$('[data-toggle="tooltip"]').tooltip({container: 'table'});
|
||||
</script>
|
||||
}
|
||||
49
EveryThing/Pages/CodeTablePrePostText/Index.cshtml.cs
Normal file
49
EveryThing/Pages/CodeTablePrePostText/Index.cshtml.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models;
|
||||
using EveryThing.Models.Transport;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace EveryThing.Pages.CodeTablePrePostText
|
||||
{
|
||||
[Authorize(Roles = "Administrator,TransportThingUser,InvoicingUser")]
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
private readonly EveryThing.Data.ApplicationDbContext _context;
|
||||
private readonly UserManager<IdentityApplicationUser> _userManager;
|
||||
|
||||
public IndexModel(EveryThing.Data.ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager)
|
||||
{
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
public IList<Models.CodeTable.CodeTablePrePostText> PrePostTexts { get;set; }
|
||||
|
||||
public async Task OnGetAsync(string searchString)
|
||||
{
|
||||
ViewData["SearchString"] = searchString;
|
||||
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
PrePostTexts = await _context.CodeTablePrePostText
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk)
|
||||
.OrderByDescending(x => x.Content)
|
||||
.ToListAsync();
|
||||
|
||||
if (!string.IsNullOrEmpty(searchString))
|
||||
{
|
||||
PrePostTexts = PrePostTexts.Where(x => x.Content == searchString).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user