1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

Fixed the ability to edit/create vaults from the main site.

This commit is contained in:
Uncled1023 2017-02-15 12:21:49 -08:00
parent c17637ccad
commit cae2d6b639
8 changed files with 31 additions and 7 deletions

View File

@ -29,7 +29,7 @@
<ul class="dropdown-menu pull-right" id="add-to-vault-menu">
@foreach (Vault item in Model.Vaults)
{
<li><a href="#" class="add-to-vault" data-add-to-vault-url="@Url.SubRouteUrl("v", "Vault.EditVault", new { url = item.Url, type = "Paste" })" data-paste-url="@Model.Url" data-paste-title="@((string.IsNullOrEmpty(Model.Title)) ? "Untitled" : Model.Title)">@item.Title</a></li>
<li><a href="#" class="add-to-vault" data-add-to-vault-url="@Url.SubRouteUrl("vault", "Vault.EditVault", new { url = item.Url, type = "Paste" })" data-paste-url="@Model.Url" data-paste-title="@((string.IsNullOrEmpty(Model.Title)) ? "Untitled" : Model.Title)">@item.Title</a></li>
}
</ul>
}

View File

@ -60,7 +60,7 @@
<ul class="dropdown-menu" id="add-to-vault-menu">
@foreach (Vault item in Model.Vaults)
{
<li><a href="#" class="add-to-vault" data-add-to-vault-url="@Url.SubRouteUrl("v", "Vault.EditVault", new { url = item.Url, type = "Upload" })">@item.Title</a></li>
<li><a href="#" class="add-to-vault" data-add-to-vault-url="@Url.SubRouteUrl("vault", "Vault.EditVault", new { url = item.Url, type = "Upload" })">@item.Title</a></li>
}
</ul>
}

View File

@ -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;

View File

@ -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('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + response.error.message + '</div>');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + err + '</div>');
}
}
});
@ -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('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + html.error.message + '</div>');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + err + '</div>');
}
}
});

View File

@ -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<ModifyVaultItemViewModel> 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<ModifyVaultItemViewModel>();

View File

@ -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;

View File

@ -12,8 +12,8 @@
<script type="text/javascript">
var validateItemURL = '@Url.SubRouteUrl("vault", "Vault.Action", new { action = "ValidateItem" })';
var modifyVaultURL = '@Url.SubRouteUrl("vault", "Vault.Action", new { action = action })';
var validateItemURL = '@Url.SubRouteUrl(Model.CurrentSub, "Vault.Action", new { action = "ValidateItem" })';
var modifyVaultURL = '@Url.SubRouteUrl(Model.CurrentSub, "Vault.Action", new { action = action })';
var itemCount = @Model.items.Count();

View File

@ -7,7 +7,7 @@
@Styles.Render("~/Content/vault")
<script type="text/javascript">
var deleteVaultURL = '@Url.SubRouteUrl("v", "Vault.DeleteVault")';
var deleteVaultURL = '@Url.SubRouteUrl(Model.CurrentSub, "Vault.DeleteVault")';
</script>
<div class="container">