From 032b2747b69c8157e0a1744ac0abf0ea3a959a58 Mon Sep 17 00:00:00 2001 From: Maier Stephan SI Date: Fri, 29 Sep 2023 15:00:54 +0200 Subject: [PATCH] Sicherung vor Urlaub --- .../Controllers/OrganizationController.cs | 193 +++++++++++++++--- .../Controllers/ProjectController.cs | 27 ++- ...ner.cs => 20230929113426_Init.Designer.cs} | 11 +- ...0340_Initial.cs => 20230929113426_Init.cs} | 7 +- .../ApplicationDbContextModelSnapshot.cs | 7 +- .../FSI.Prj.Mgt/Models/Organization.cs | 26 ++- FSI.Prj.Mgt/FSI.Prj.Mgt/Models/Project.cs | 1 - .../Views/Organization/AddOrEdit.cshtml | 21 +- .../Views/Organization/Index.cshtml | 5 +- .../Views/Organization/_ViewAll.cshtml | 36 ++-- .../FSI.Prj.Mgt/Views/Plant/_ViewAll.cshtml | 3 +- .../Views/Project/AddOrEdit.cshtml | 2 - .../FSI.Prj.Mgt/Views/Project/_ViewAll.cshtml | 2 +- FSI.Prj.Mgt/FSI.Prj.Mgt/wwwroot/js/site.js | 28 ++- 14 files changed, 264 insertions(+), 105 deletions(-) rename FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/{20230928130340_Initial.Designer.cs => 20230929113426_Init.Designer.cs} (98%) rename FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/{20230928130340_Initial.cs => 20230929113426_Init.cs} (96%) diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Controllers/OrganizationController.cs b/FSI.Prj.Mgt/FSI.Prj.Mgt/Controllers/OrganizationController.cs index 4db5861..bf81a49 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Controllers/OrganizationController.cs +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Controllers/OrganizationController.cs @@ -1,5 +1,6 @@ using FSI.Prj.Mgt.Data; using FSI.Prj.Mgt.Models; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage; @@ -10,6 +11,7 @@ namespace FSI.Prj.Mgt.Controllers { public class OrganizationController : Controller { + private readonly ApplicationDbContext _context; public OrganizationController(ApplicationDbContext context) @@ -19,10 +21,8 @@ namespace FSI.Prj.Mgt.Controllers public async Task Index(string searchString, int? page) { - IQueryable items = _context.Organizations.Include(x => x.Parent); - if (!string.IsNullOrEmpty(searchString)) { items = items.Where(x => x.Name!.Contains(searchString) || x.Description!.Contains(searchString)); @@ -33,46 +33,179 @@ namespace FSI.Prj.Mgt.Controllers - List nodes = new(); + //////List nodes = new(); - // Loop and add the Parent Nodes - foreach (Organization organization in _context.Organizations) + //////// Loop and add the Parent Nodes + //////foreach (Organization organization in _context.Organizations) + //////{ + ////// if (organization.ParentId == null) + ////// { + ////// nodes.Add(new TreeViewNode + ////// { + ////// id = organization.Id.ToString(), + ////// parent = "#", + ////// text = organization.Name, + ////// }); + ////// } + ////// else + ////// { + ////// nodes.Add(new TreeViewNode + ////// { + ////// id = organization.Id.ToString(), + ////// parent = organization.ParentId.ToString(), + ////// text = organization.Name, + ////// }); + ////// } + //////} + //////ViewBag.Json = JsonConvert.SerializeObject(nodes); + } + + public async Task AddOrEdit(int id = 0) + { + + if (id == 0) { - if (organization.ParentId == null) + var item = new Organization(); + item.Parents = _context.Organizations.OrderBy(x => x.Name).ToList(); + item.Parents.Add(new Organization()); + + if (item.ParentId == null) { - nodes.Add(new TreeViewNode - { - id = organization.Id.ToString(), - parent = "#", - text = organization.Name, - }); - } - else - { - nodes.Add(new TreeViewNode - { - id = organization.Id.ToString(), - parent = organization.ParentId.ToString(), - text = organization.Name, - }); + item.ParentId = 0; } + + return View(item); + } + else + { + var item = await _context.Organizations.FindAsync(id); + + if (item == null) + { + return NotFound(); + } + + item.Parents = _context.Organizations.ToList(); + item.Parents.Add(new Organization()); // neue & leere Organisation einfügen + item.Parents.Remove(item); // eingene Organisation entfernen + item.Parents.OrderBy(x => x.Name); // sortieren + + if (item.ParentId == null) + { + item.ParentId = 0; + } + + return View(item); } - ViewBag.Json = JsonConvert.SerializeObject(nodes); - } [HttpPost] - public IActionResult Index (string selectedItems) + public async Task AddOrEdit(int id, Organization item) { - if (selectedItems != null) - { - List items = JsonConvert.DeserializeObject>(selectedItems); - } + ModelState.Remove("Parent"); + ModelState.Remove("Parents"); + ModelState.Remove("FullShortName"); - return RedirectToAction("Index", "Organization"); + if (ModelState.IsValid) + { + + if (item.ParentId == 0) + { + item.ParentId = null; + } + + if (id == 0) // Insert + { + _context.Add(item); + await _context.SaveChangesAsync(); + + + } + else // Update + { + try + { + _context.Update(item); + + _context.Update(item); + await _context.SaveChangesAsync(); + } + catch (Exception ex) + { + + } + } + + return Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAll", await ((IQueryable)_context.Organizations).ToPagedListAsync(1, 10)) }); + } + else + { + var errors = ModelState.SelectMany(x => x.Value.Errors.Select(z => z.Exception)); + } + item.Parents.Add(new Organization()); + return Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", item) }); } - + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + await _context.Organizations + .Where(x => x.ParentId == id) + .ForEachAsync(x => x.ParentId = null); // Parent Ids auf null sezten + + var item = await _context.Organizations.FindAsync(id); + _context.Organizations.Remove(item); + + await _context.SaveChangesAsync(); + + return Json(new { html = Helper.RenderRazorViewToString(this, "_ViewAll", await ((IQueryable)_context.Organizations).ToPagedListAsync(1, 10)) }); + } + + + //[HttpPost] + //public IActionResult Index(string selectedItems) + //{ + // if (selectedItems != null) + // { + // List items = JsonConvert.DeserializeObject>(selectedItems); + // } + + // return RedirectToAction("Index", "Organization"); + //} + + public async void UpdateFullShortName() + { + foreach (var organization in _context.Organizations) + { + foreach (var item in _context.Organizations) + { + item.FullShortName = GetFullShortName(_context.Organizations.ToList(), item.ParentId, item.ShortName); + _context.Update(item); + await _context.SaveChangesAsync(); + } + } + } + + private string GetFullShortName(List items, int? parentId, string? name) + { + foreach (var item in items) + { + if (item.Id == parentId) + { + if (item.ParentId.HasValue) + { + return GetFullShortName(items, item.ParentId.Value, item.ShortName + " " + name); + } + else + { + return item.ShortName + name + " "; + } + } + } + + return string.Empty; + } } diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Controllers/ProjectController.cs b/FSI.Prj.Mgt/FSI.Prj.Mgt/Controllers/ProjectController.cs index 769cac7..725127f 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Controllers/ProjectController.cs +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Controllers/ProjectController.cs @@ -1,5 +1,6 @@ using FSI.Prj.Mgt.Data; using FSI.Prj.Mgt.Models; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Migrations; @@ -21,7 +22,6 @@ namespace FSI.Prj.Mgt.Controllers { IQueryable items = _context.Projects.Include(x => x.Plant); - if (!string.IsNullOrEmpty(searchString)) { items = items.Where(x => x.No!.ToString().Contains(searchString) || x.Name!.Contains(searchString) || x.Description!.Contains(searchString)); @@ -33,8 +33,6 @@ namespace FSI.Prj.Mgt.Controllers public async Task AddOrEdit(int id = 0) { - // ViewBag.Plants = _context.Plants; - if (id == 0) { var item = new Project(); @@ -45,7 +43,6 @@ namespace FSI.Prj.Mgt.Controllers else { var item = await _context.Projects.FindAsync(id); - if (item == null) { @@ -58,17 +55,18 @@ namespace FSI.Prj.Mgt.Controllers } [HttpPost] - //[ValidateAntiForgeryToken] + [ValidateAntiForgeryToken] public async Task AddOrEdit(int id, Project item) { - ModelState.Remove("Plants"); ModelState.Remove("Plant"); + ModelState.Remove("Plants"); + + if (ModelState.IsValid) + { - if (ModelState.IsValid) - { - if (id == 0) // Insert { + _context.Add(item); await _context.SaveChangesAsync(); } @@ -79,17 +77,18 @@ namespace FSI.Prj.Mgt.Controllers _context.Update(item); await _context.SaveChangesAsync(); } - catch(DbUpdateConcurrencyException) + catch (DbUpdateConcurrencyException) { - + } } - return Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAll", _context.Projects.ToList()) }); + return Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAll", await ((IQueryable)_context.Projects).ToPagedListAsync(1, 10)) }); } else { var errors = ModelState.SelectMany(x => x.Value.Errors.Select(z => z.Exception)); - } + } + item.Plants = (_context.Plants.ToList()); return Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", item) }); } @@ -138,7 +137,7 @@ namespace FSI.Prj.Mgt.Controllers //return RedirectToAction("Index"); - + public async Task DeleteProject(int? id) { diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230928130340_Initial.Designer.cs b/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230929113426_Init.Designer.cs similarity index 98% rename from FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230928130340_Initial.Designer.cs rename to FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230929113426_Init.Designer.cs index 00d7be8..b1d3ef9 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230928130340_Initial.Designer.cs +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230929113426_Init.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace FSI.Prj.Mgt.Data.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20230928130340_Initial")] - partial class Initial + [Migration("20230929113426_Init")] + partial class Init { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -34,6 +34,9 @@ namespace FSI.Prj.Mgt.Data.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("FullShortName") .IsRequired() .HasColumnType("nvarchar(max)"); @@ -329,7 +332,7 @@ namespace FSI.Prj.Mgt.Data.Migrations modelBuilder.Entity("FSI.Prj.Mgt.Models.Organization", b => { b.HasOne("FSI.Prj.Mgt.Models.Organization", "Parent") - .WithMany("Organizations") + .WithMany("Parents") .HasForeignKey("ParentId"); b.Navigation("Parent"); @@ -404,7 +407,7 @@ namespace FSI.Prj.Mgt.Data.Migrations modelBuilder.Entity("FSI.Prj.Mgt.Models.Organization", b => { - b.Navigation("Organizations"); + b.Navigation("Parents"); }); modelBuilder.Entity("FSI.Prj.Mgt.Models.Project", b => diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230928130340_Initial.cs b/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230929113426_Init.cs similarity index 96% rename from FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230928130340_Initial.cs rename to FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230929113426_Init.cs index 800cddf..5eab674 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230928130340_Initial.cs +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230929113426_Init.cs @@ -5,7 +5,7 @@ namespace FSI.Prj.Mgt.Data.Migrations { /// - public partial class Initial : Migration + public partial class Init : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -18,9 +18,10 @@ namespace FSI.Prj.Mgt.Data.Migrations .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(type: "nvarchar(max)", nullable: false), ShortName = table.Column(type: "nvarchar(max)", nullable: false), - Description = table.Column(type: "nvarchar(max)", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: true), ParentId = table.Column(type: "int", nullable: true), - Type = table.Column(type: "int", nullable: false) + Type = table.Column(type: "int", nullable: false), + FullShortName = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/ApplicationDbContextModelSnapshot.cs b/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/ApplicationDbContextModelSnapshot.cs index 8e1cffb..35e43e5 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -31,6 +31,9 @@ namespace FSI.Prj.Mgt.Data.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("FullShortName") .IsRequired() .HasColumnType("nvarchar(max)"); @@ -326,7 +329,7 @@ namespace FSI.Prj.Mgt.Data.Migrations modelBuilder.Entity("FSI.Prj.Mgt.Models.Organization", b => { b.HasOne("FSI.Prj.Mgt.Models.Organization", "Parent") - .WithMany("Organizations") + .WithMany("Parents") .HasForeignKey("ParentId"); b.Navigation("Parent"); @@ -401,7 +404,7 @@ namespace FSI.Prj.Mgt.Data.Migrations modelBuilder.Entity("FSI.Prj.Mgt.Models.Organization", b => { - b.Navigation("Organizations"); + b.Navigation("Parents"); }); modelBuilder.Entity("FSI.Prj.Mgt.Models.Project", b => diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Models/Organization.cs b/FSI.Prj.Mgt/FSI.Prj.Mgt/Models/Organization.cs index 3eb75b6..80c83b9 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Models/Organization.cs +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Models/Organization.cs @@ -1,4 +1,6 @@ -using System.ComponentModel; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.EntityFrameworkCore.Storage; +using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -6,30 +8,38 @@ namespace FSI.Prj.Mgt.Models { public class Organization { + public Organization() + { + Parents = new HashSet(); + } + [Key] public int Id { get; set; } [DisplayName("Name")] - [Required(ErrorMessage = "Dieses Feld wird benötigt.")] + [Required(ErrorMessage = "Namen eingeben.")] public string Name { get; set; } [DisplayName("Kurzname")] - [Required(ErrorMessage = "Dieses Feld wird benötigt.")] + [Required(ErrorMessage = "Kurznamen eingeben.")] public string ShortName { get; set; } - [DisplayName("Beschreibung")] - public string Description { get; set; } + [DisplayName("Beschreibung")] + public string? Description { get; set; } [ForeignKey("Id")] [DisplayName("übergeordnetes Element")] public int? ParentId { get; set; } - public virtual Organization Parent { get; set; } - public virtual List Parents{ get; set; } + public virtual Organization? Parent { get; set; } + public virtual ICollection Parents { get; set; } [DisplayName("Type")] [Required(ErrorMessage = "Dieses Feld wird benötigt.")] public OrganizationType Type { get; set; } + + [DisplayName("vollständiger Kurzname")] + public virtual string FullShortName { get; set; } } public enum OrganizationType @@ -43,7 +53,7 @@ namespace FSI.Prj.Mgt.Models [Display(Name = "Anlage")] plant, [Display(Name = "Teilanlage")] - subPlant, + subPlant, } } diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Models/Project.cs b/FSI.Prj.Mgt/FSI.Prj.Mgt/Models/Project.cs index 7bca69d..acc44ca 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Models/Project.cs +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Models/Project.cs @@ -34,7 +34,6 @@ namespace FSI.Prj.Mgt.Models [ForeignKey("Id")] [DisplayName("Anlage, Teilanlage, ...")] public int? PlantId { get; set; } - public virtual Plant Plant { get; set; } public virtual ICollection Plants { get; set; } diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Organization/AddOrEdit.cshtml b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Organization/AddOrEdit.cshtml index 5e06f76..41dc2c5 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Organization/AddOrEdit.cshtml +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Organization/AddOrEdit.cshtml @@ -5,31 +5,28 @@ @model FSI.Prj.Mgt.Models.Organization -
-
-
- + + -
- +
- - - + + +
- +
@@ -41,9 +38,9 @@
- +
- +
diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Organization/Index.cshtml b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Organization/Index.cshtml index 616f7cb..faf00b5 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Organization/Index.cshtml +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Organization/Index.cshtml @@ -8,7 +8,7 @@ ViewData["Title"] = "Organisationen"; } -

Projekt-Übersicht

+

Organisationen


@@ -41,7 +41,7 @@ - +@* @@ -105,3 +105,4 @@ } + *@ \ No newline at end of file diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Organization/_ViewAll.cshtml b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Organization/_ViewAll.cshtml index 6331f92..e3e5a2d 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Organization/_ViewAll.cshtml +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Organization/_ViewAll.cshtml @@ -22,12 +22,15 @@ @Html.DisplayNameFor(x => x.GetEnumerator().Current.Type) - @Html.DisplayNameFor(x => x.GetEnumerator().Current.Parent) + @Html.DisplayNameFor(x => x.GetEnumerator().Current.ParentId) - + @Html.DisplayNameFor(x => x.GetEnumerator().Current.FullShortName) + + + - neues Organisation + neue @@ -54,16 +57,19 @@ @Html.DisplayFor(modelItem => @item.Type) - @Html.DisplayFor(modelItem => @item.Parent.Name) @Html.DisplayFor(modelItem => @item.Parent.ShortName) + @Html.DisplayFor(modelItem => @item.Parent.Name) @(item.Parent == null ? "" : "(")@Html.DisplayFor(modelItem => @item.Parent.ShortName)@(item.Parent == null ? "" : ")") + + + @Html.DisplayFor(modelItem => @item.FullShortName)
- + - - @* - *@ + + +
@@ -73,17 +79,3 @@ - - diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Plant/_ViewAll.cshtml b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Plant/_ViewAll.cshtml index d3ea75b..1608264 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Plant/_ViewAll.cshtml +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Plant/_ViewAll.cshtml @@ -4,7 +4,6 @@ @model IPagedList - @@ -80,4 +79,4 @@ DisplayLinkToPreviousPage = PagedListDisplayMode.Always, DisplayLinkToNextPage = PagedListDisplayMode.Always }) - * \ No newline at end of file + \ No newline at end of file diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/AddOrEdit.cshtml b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/AddOrEdit.cshtml index 7f9648c..ec4eab8 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/AddOrEdit.cshtml +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/AddOrEdit.cshtml @@ -5,7 +5,6 @@ @model FSI.Prj.Mgt.Models.Project -
@@ -14,7 +13,6 @@ -
diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/_ViewAll.cshtml b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/_ViewAll.cshtml index 95bc92a..7b02155 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/_ViewAll.cshtml +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/_ViewAll.cshtml @@ -25,7 +25,7 @@ @Html.DisplayNameFor(x => x.GetEnumerator().Current.Status)
- + neues Projekt erstellen diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/wwwroot/js/site.js b/FSI.Prj.Mgt/FSI.Prj.Mgt/wwwroot/js/site.js index fd1759d..844424f 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/wwwroot/js/site.js +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/wwwroot/js/site.js @@ -31,8 +31,7 @@ jQueryAjaxPost = form => { $('#form-modal').modal('hide'); } else - $("#form-modal .modal-body").html(res.html); - + $("#form-modal .modal-body").html(res.html); }, error: function (err) { console.log(err) @@ -43,4 +42,29 @@ jQueryAjaxPost = form => { } catch (ex) { console.log(ex) } +} + +jQueryAjaxDelete = form => { + if (confirm('Soll der Datensatz gelöscht werden?')) { + try { + $.ajax({ + type: 'POST', + url: form.action, + data: new FormData(form), + contentType: false, + processData: false, + success: function (res) { + $('#view-all').html(res.html); + }, + error: function (err) { + console.log(err) + } + }) + } catch (ex) { + console.log(ex) + } + } + + //prevent default form submit event + return false; } \ No newline at end of file