diff --git a/projects/Hood.Admin/Controllers/MediaController.cs b/projects/Hood.Admin/Controllers/MediaController.cs index d33342f6..ed8dc6a1 100644 --- a/projects/Hood.Admin/Controllers/MediaController.cs +++ b/projects/Hood.Admin/Controllers/MediaController.cs @@ -25,7 +25,7 @@ public MediaController() } [Route("admin/media/list/")] - public async Task List(MediaListModel model, string viewName = "_List_Media") + public virtual async Task List(MediaListModel model, string viewName = "_List_Media") { IQueryable media = _db.Media.AsQueryable(); @@ -95,19 +95,19 @@ public async Task List(MediaListModel model, string viewName = "_ } [Route("admin/media/")] - public async Task Index(MediaListModel model) + public virtual async Task Index(MediaListModel model) { return await List(model, "Index"); } [Route("admin/media/action/")] - public async Task Action(MediaListModel model) + public virtual async Task Action(MediaListModel model) { return await List(model, "Action"); } [Route("admin/media/blade/")] - public async Task Blade(int id) + public virtual async Task Blade(int id) { MediaObject media = await _db.Media.Include(m => m.Directory).SingleOrDefaultAsync(u => u.Id == id); return View("_Blade_Media", media); @@ -115,7 +115,7 @@ public async Task Blade(int id) [HttpPost] [Route("admin/media/delete/")] - public async Task Delete(int id) + public virtual async Task Delete(int id) { try { @@ -134,13 +134,13 @@ public async Task Delete(int id) #region Directories [Route("admin/media/directories/list/")] - public IActionResult Directories(MediaListModel model) + public virtual IActionResult Directories(MediaListModel model) { model.TopLevelDirectories = GetDirectoriesForCurrentUser(); return View("_List_Directories", model); } - private IEnumerable GetDirectoriesForCurrentUser() + protected virtual IEnumerable GetDirectoriesForCurrentUser() { if (User.IsAdminOrBetter()) { @@ -157,7 +157,7 @@ private IEnumerable GetDirectoriesForCurrentUser() } [Route("admin/media/directory/create/")] - public async Task CreateDirectoryAsync(int id) + public virtual async Task CreateDirectoryAsync(int id) { try { @@ -198,7 +198,7 @@ public async Task CreateDirectoryAsync(int id) [HttpPost] [Route("admin/media/directory/create/")] - public async Task CreateDirectory(MediaDirectory model) + public virtual async Task CreateDirectory(MediaDirectory model) { try { @@ -242,7 +242,7 @@ public async Task CreateDirectory(MediaDirectory model) [HttpPost] [Route("admin/media/directory/delete/")] - public async Task DeleteDirectory(int id) + public virtual async Task DeleteDirectory(int id) { try { @@ -315,7 +315,7 @@ public async Task DeleteDirectory(int id) /// [HttpPost] [Route("admin/media/attach/")] - public async Task Attach(MediaListModel model) + public virtual async Task Attach(MediaListModel model) { try { @@ -401,7 +401,7 @@ public async Task Attach(MediaListModel model) /// [HttpPost] [Route("admin/media/clear/")] - public async Task Clear(MediaListModel model) + public virtual async Task Clear(MediaListModel model) { try { @@ -483,7 +483,7 @@ public async Task Clear(MediaListModel model) #region Uploads [HttpPost] [Route("admin/media/upload/simple/")] - public async Task UploadToDirectory(IEnumerable files, int? directoryId) + public virtual async Task UploadToDirectory(IEnumerable files, int? directoryId) { try { diff --git a/projects/Hood.Development/src/ts/core/DataList.ts b/projects/Hood.Development/src/ts/core/DataList.ts index acafc54a..3bfc43ad 100644 --- a/projects/Hood.Development/src/ts/core/DataList.ts +++ b/projects/Hood.Development/src/ts/core/DataList.ts @@ -94,16 +94,6 @@ export class DataList { }.bind(this)); - // $('body').on('submit', '.hood-inline-list form', function (e) { - // e.preventDefault(); - // $.hood.Loader(true); - // let $form = $(this); - // let $list = $form.parents('.hood-inline-list'); - // var url = document.createElement('a'); - // url.href = $list.data('url'); - // url.search = "?" + $form.serialize(); - // $.hood.Inline.DataList.Reload($list, url); - // }); } reload(this: DataList, url: URL = null) { diff --git a/projects/Hood.Development/src/ts/core/Inline.ts b/projects/Hood.Development/src/ts/core/Inline.ts index 54226f24..d7855b3d 100644 --- a/projects/Hood.Development/src/ts/core/Inline.ts +++ b/projects/Hood.Development/src/ts/core/Inline.ts @@ -90,13 +90,13 @@ export class Inline { } - static handleError(xhr: { status: string | number; }) { + static handleError(xhr: { status: string | number; }, textStatus: any, errorThrown: any) { if (xhr.status === 500) { - Alerts.error("There was an error processing the content, please contact an administrator if this continues.", "Error " + xhr.status); + Alerts.error("There was an error processing the content, please contact an administrator if this continues.", "Error " + xhr.status, 10000); } else if (xhr.status === 404) { - Alerts.error("The content could not be found.", "Error " + xhr.status); + Alerts.error("The content could not be found.", "Error " + xhr.status, 10000); } else if (xhr.status === 401) { - Alerts.error("You are not allowed to view this resource, are you logged in correctly?", "Error " + xhr.status); + Alerts.error("You are not allowed to view this resource, are you logged in correctly?", "Error " + xhr.status, 10000); window.location = window.location; } } diff --git a/projects/Hood.Development/src/ts/core/Modal.ts b/projects/Hood.Development/src/ts/core/Modal.ts index 00d705d8..f61ffbaa 100644 --- a/projects/Hood.Development/src/ts/core/Modal.ts +++ b/projects/Hood.Development/src/ts/core/Modal.ts @@ -89,7 +89,13 @@ export class ModalController { }.bind(this)) - .fail(this.options.onError ?? Inline.handleError); + .fail(function (this: ModalController, xhr: { status: string | number; }, textStatus: any, errorThrown: any) { + this.isOpen = false; + if (this.options.onError) { + this.options.onError(xhr, textStatus, errorThrown); + } + Inline.handleError(xhr, textStatus, errorThrown); + }.bind(this)); } close() { diff --git a/projects/Hood.Development/src/ts/core/Validator.ts b/projects/Hood.Development/src/ts/core/Validator.ts index dceaca78..35b37f99 100644 --- a/projects/Hood.Development/src/ts/core/Validator.ts +++ b/projects/Hood.Development/src/ts/core/Validator.ts @@ -20,14 +20,17 @@ export interface ValidatorOptions { */ onError?: (jqXHR: any, textStatus: any, errorThrown: any) => void; - serializationFunction?: () => string; + serializationFunction?: () => string; + + useAjax?: boolean; } export class Validator { element: HTMLFormElement; options: ValidatorOptions = { - errorAlert: 'There are errors, please check the form.' + errorAlert: 'There are errors, please check the form.', + useAjax: true }; /** @@ -52,6 +55,23 @@ export class Validator { e.stopImmediatePropagation(); this.submitForm(); }.bind(this)); + var tag = '[data-submit="#' + this.element.id + '"]'; + let submitButtons = $(tag); + if (submitButtons) { + submitButtons.on('click', function (this: Validator, e: Event) { + e.preventDefault(); + e.stopImmediatePropagation(); + let exit = $(e.currentTarget).data('exit'); + if (exit) { + $(this.element).find("input#exit").remove(); + $("").attr("type", "hidden") + .attr("name", "exit") + .attr("value", "true") + .appendTo(this.element); + } + this.submitForm(); + }.bind(this)); + } } submitForm() { @@ -74,14 +94,22 @@ export class Validator { this.options.onSubmit(this); } - let formData = this.options.serializationFunction(); + if (this.options.useAjax) { - $.post(this.element.action, formData, function (this: Validator, data: any) { - if (this.options.onComplete) { - this.options.onComplete(data, this); - } - }.bind(this)) - .fail(this.options.onError ?? Inline.handleError); + let formData = this.options.serializationFunction(); + + $.post(this.element.action, formData, function (this: Validator, data: any) { + if (this.options.onComplete) { + this.options.onComplete(data, this); + } + }.bind(this)) + .fail(this.options.onError ?? Inline.handleError); + + } else { + + this.element.submit(); + + } } else { diff --git a/projects/Hood.Development/src/ts/core/alerts.ts b/projects/Hood.Development/src/ts/core/alerts.ts index 66bd2df8..8713121b 100644 --- a/projects/Hood.Development/src/ts/core/alerts.ts +++ b/projects/Hood.Development/src/ts/core/alerts.ts @@ -3,8 +3,8 @@ import 'jquery-toast-plugin'; const BootstrapSwal = Swal.mixin({ customClass: { - confirmButton: 'btn btn-success btn-lg m-1 pl-4 pr-4', - cancelButton: 'btn btn-danger btn-lg m-1' + confirmButton: 'btn btn-success m-1 px-3', + cancelButton: 'btn btn-danger m-1 px-3' }, buttonsStyling: false }); @@ -120,7 +120,7 @@ export class Alerts { let baseOptions: SweetAlertOptions = { showCancelButton: true, - footer: ' This cannot be undone.', + footer: null, title: 'Are you sure?', html: 'Are you sure you want to do this?', confirmButtonText: 'Ok',