From cae2d6b639d15c777b68b7c8e8bd07885a267006 Mon Sep 17 00:00:00 2001 From: Uncled1023 Date: Wed, 15 Feb 2017 12:21:49 -0800 Subject: [PATCH] Fixed the ability to edit/create vaults from the main site. --- Teknik/Areas/Paste/Views/Paste/Full.cshtml | 2 +- Teknik/Areas/Upload/Views/Upload/Index.cshtml | 2 +- .../Vault/Controllers/VaultController.cs | 4 ++++ Teknik/Areas/Vault/Scripts/Vault.js | 20 +++++++++++++++++-- .../Vault/ViewModels/ModifyVaultViewModel.cs | 2 ++ .../Areas/Vault/ViewModels/VaultViewModel.cs | 2 ++ .../Vault/Views/Vault/ModifyVault.cshtml | 4 ++-- .../Areas/Vault/Views/Vault/ViewVault.cshtml | 2 +- 8 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Teknik/Areas/Paste/Views/Paste/Full.cshtml b/Teknik/Areas/Paste/Views/Paste/Full.cshtml index df6bca3..e71eb91 100644 --- a/Teknik/Areas/Paste/Views/Paste/Full.cshtml +++ b/Teknik/Areas/Paste/Views/Paste/Full.cshtml @@ -29,7 +29,7 @@ } diff --git a/Teknik/Areas/Upload/Views/Upload/Index.cshtml b/Teknik/Areas/Upload/Views/Upload/Index.cshtml index e51522c..632b260 100644 --- a/Teknik/Areas/Upload/Views/Upload/Index.cshtml +++ b/Teknik/Areas/Upload/Views/Upload/Index.cshtml @@ -60,7 +60,7 @@ } diff --git a/Teknik/Areas/Vault/Controllers/VaultController.cs b/Teknik/Areas/Vault/Controllers/VaultController.cs index a64486f..1dbee70 100644 --- a/Teknik/Areas/Vault/Controllers/VaultController.cs +++ b/Teknik/Areas/Vault/Controllers/VaultController.cs @@ -36,6 +36,7 @@ namespace Teknik.Areas.Vault.Controllers ViewBag.Title = foundVault.Title + " - Teknik Vault"; VaultViewModel model = new VaultViewModel(); + model.CurrentSub = Subdomain; model.Url = foundVault.Url; model.UserId = foundVault.UserId; @@ -103,6 +104,7 @@ namespace Teknik.Areas.Vault.Controllers { ViewBag.Title = "Create Vault"; ModifyVaultViewModel model = new ModifyVaultViewModel(); + model.CurrentSub = Subdomain; return View("~/Areas/Vault/Views/Vault/ModifyVault.cshtml", model); } @@ -112,6 +114,7 @@ namespace Teknik.Areas.Vault.Controllers { ViewBag.Title = "Create Vault"; ModifyVaultViewModel model = new ModifyVaultViewModel(); + model.CurrentSub = Subdomain; string decodedItems = HttpUtility.UrlDecode(items); string[] allURLs = decodedItems.Split(','); @@ -154,6 +157,7 @@ namespace Teknik.Areas.Vault.Controllers ViewBag.Title = "Edit Vault - " + foundVault.Title; ModifyVaultViewModel model = new ModifyVaultViewModel(); + model.CurrentSub = Subdomain; model.isEdit = true; model.vaultId = foundVault.VaultId; model.title = foundVault.Title; diff --git a/Teknik/Areas/Vault/Scripts/Vault.js b/Teknik/Areas/Vault/Scripts/Vault.js index 84f7b59..d79c3a4 100644 --- a/Teknik/Areas/Vault/Scripts/Vault.js +++ b/Teknik/Areas/Vault/Scripts/Vault.js @@ -56,6 +56,10 @@ type: "POST", url: validateItemURL, data: AddAntiForgeryToken({ type: type, url: url }), + headers: { 'X-Requested-With': 'XMLHttpRequest' }, + xhrFields: { + withCredentials: true + }, success: function (response) { if (response.result) { itemCount++; @@ -153,13 +157,21 @@ type: "POST", url: modifyVaultURL, data: AddAntiForgeryToken({ vaultId: vaultId, title: title, description: description, items: items }), + headers: { 'X-Requested-With': 'XMLHttpRequest' }, + xhrFields: { + withCredentials: true + }, success: function (response) { if (response.result) { window.location = response.result.url; } else { + var err = response; + if (response.error) { + err = response.error.message; + } $("#top_msg").css('display', 'inline', 'important'); - $("#top_msg").html('
' + response.error.message + '
'); + $("#top_msg").html('
' + err + '
'); } } }); @@ -183,8 +195,12 @@ window.location = html.result.url; } else { + var err = html; + if (html.error) { + err = html.error.message; + } $("#top_msg").css('display', 'inline', 'important'); - $("#top_msg").html('
' + html.error.message + '
'); + $("#top_msg").html('
' + err + '
'); } } }); diff --git a/Teknik/Areas/Vault/ViewModels/ModifyVaultViewModel.cs b/Teknik/Areas/Vault/ViewModels/ModifyVaultViewModel.cs index 3a46b99..6dedcd3 100644 --- a/Teknik/Areas/Vault/ViewModels/ModifyVaultViewModel.cs +++ b/Teknik/Areas/Vault/ViewModels/ModifyVaultViewModel.cs @@ -11,6 +11,7 @@ namespace Teknik.Areas.Vault.ViewModels { public bool isEdit { get; set; } public int vaultId { get; set; } + public string CurrentSub { get; set; } public string title { get; set; } public string description { get; set; } public List items { get; set; } @@ -19,6 +20,7 @@ namespace Teknik.Areas.Vault.ViewModels { isEdit = false; vaultId = -1; + CurrentSub = "vault"; title = string.Empty; description = string.Empty; items = new List(); diff --git a/Teknik/Areas/Vault/ViewModels/VaultViewModel.cs b/Teknik/Areas/Vault/ViewModels/VaultViewModel.cs index 5267146..27a0395 100644 --- a/Teknik/Areas/Vault/ViewModels/VaultViewModel.cs +++ b/Teknik/Areas/Vault/ViewModels/VaultViewModel.cs @@ -12,6 +12,7 @@ namespace Teknik.Areas.Vault.ViewModels public string Url { get; set; } public int? UserId { get; set; } public Users.Models.User User { get; set; } + public string CurrentSub { get; set; } public string Title { get; set; } public string Description { get; set; } public DateTime DateCreated { get; set; } @@ -20,6 +21,7 @@ namespace Teknik.Areas.Vault.ViewModels public VaultViewModel() { + CurrentSub = "vault"; Title = string.Empty; Description = string.Empty; DateCreated = DateTime.Now; diff --git a/Teknik/Areas/Vault/Views/Vault/ModifyVault.cshtml b/Teknik/Areas/Vault/Views/Vault/ModifyVault.cshtml index 1a48720..82bd142 100644 --- a/Teknik/Areas/Vault/Views/Vault/ModifyVault.cshtml +++ b/Teknik/Areas/Vault/Views/Vault/ModifyVault.cshtml @@ -12,8 +12,8 @@