we have a dropdown that fires an onchange to post the new value.
although, errors ensue
This commit is contained in:
parent
4bd51721b6
commit
942b11fcce
@ -45,7 +45,7 @@ public static class Enumerations
|
|||||||
Type type = enumerationValue.GetType();
|
Type type = enumerationValue.GetType();
|
||||||
if (!type.IsEnum)
|
if (!type.IsEnum)
|
||||||
{
|
{
|
||||||
throw new ArgumentException("EnumerationValue must be of Enum type", "enumerationValue");
|
throw new ArgumentException("EnumerationValue must be of Enum type", nameof(enumerationValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Tries to find a DescriptionAttribute for a potential friendly name
|
//Tries to find a DescriptionAttribute for a potential friendly name
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
@using System.ComponentModel
|
||||||
|
@using Newtonsoft.Json
|
||||||
@model Channel
|
@model Channel
|
||||||
|
|
||||||
@Html.Raw(ViewData["breadcrumbs"])
|
@Html.Raw(ViewData["breadcrumbs"])
|
||||||
@ -10,11 +12,19 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Channel type</th>
|
<th scope="row">Channel type</th>
|
||||||
<td>@Model.ChannelType</td>
|
<td>@(Model.ChannelType != null ? Enumerations.GetDescription(Model.ChannelType) : "?")</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Lewdness Filter Level</th>
|
<th scope="row">Lewdness Filter Level</th>
|
||||||
<td>@(Model.LewdnessFilterLevel?.ToString() ?? "inherited")</td>
|
<td>
|
||||||
|
<select name="LewdnessFilterLevel" id="LewdnessFilterLevel" onchange="postmodelupdate(jsonifyChannel())">
|
||||||
|
<!option value="" @(Model.LewdnessFilterLevel == null ? "selected" : "")>inhereted</!option>
|
||||||
|
@foreach (Enumerations.LewdnessFilterLevel enumVal in Enum.GetValues(typeof(Enumerations.LewdnessFilterLevel)))
|
||||||
|
{
|
||||||
|
<!option value="@((int)enumVal)" @(Model.LewdnessFilterLevel == enumVal ? "selected" : "")>@(Enumerations.GetDescription<Enumerations.LewdnessFilterLevel>(enumVal))</!option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Links Allowed</th>
|
<th scope="row">Links Allowed</th>
|
||||||
@ -34,7 +44,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Meanness Filter Level</th>
|
<th scope="row">Meanness Filter Level</th>
|
||||||
<td>@(Model.MeannessFilterLevel?.ToString() ?? "inherited")</td>
|
<td>@(Model.MeannessFilterLevel != null ? Enumerations.GetDescription<Enumerations.MeannessFilterLevel>(Model.MeannessFilterLevel.GetValueOrDefault()) : "inherited")</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Messages (count)</th>
|
<th scope="row">Messages (count)</th>
|
||||||
@ -58,3 +68,23 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
@section Scripts{
|
||||||
|
<script type="text/javascript">
|
||||||
|
@{
|
||||||
|
var modelAsString = JsonConvert.SerializeObject(Model, new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const channelOnLoad = @Html.Raw(modelAsString);
|
||||||
|
function jsonifyChannel()
|
||||||
|
{
|
||||||
|
var channelNow = channelOnLoad;
|
||||||
|
channelNow.LewdnessFilterLevel = document.querySelector("#LewdnessFilterLevel").value;
|
||||||
|
console.log(channelNow);
|
||||||
|
return channelNow;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
}
|
@ -2,3 +2,49 @@
|
|||||||
// for details on configuring this project to bundle and minify static web assets.
|
// for details on configuring this project to bundle and minify static web assets.
|
||||||
|
|
||||||
// Write your JavaScript code.
|
// Write your JavaScript code.
|
||||||
|
|
||||||
|
function testfunct(caller){
|
||||||
|
console.log("[gibberish]");
|
||||||
|
console.log(caller);
|
||||||
|
}
|
||||||
|
function postmodelupdate(model)
|
||||||
|
{
|
||||||
|
//structure the model your (dang) self into a nice object
|
||||||
|
console.log(model);
|
||||||
|
//i know the page url.
|
||||||
|
console.log(window.location.pathname);
|
||||||
|
var components = window.location.pathname.split('/');
|
||||||
|
if(components[2] !== "Details")
|
||||||
|
{
|
||||||
|
console.log("wtf are you doing? " + components[2] + " is something other than Details")
|
||||||
|
}
|
||||||
|
var type=components[1];
|
||||||
|
var id=components[3];
|
||||||
|
|
||||||
|
//todo: figure out what the URL actually needs to be, rather than assuming you get a whole-ass server to yourself.
|
||||||
|
//you selfish fuck. What are you, fox?
|
||||||
|
var apiUrl = "/api/Channels/"
|
||||||
|
|
||||||
|
console.log("dexter impression: I am now ready to post the following content:");
|
||||||
|
console.log(JSON.stringify(model));
|
||||||
|
fetch(apiUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(model),
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Network response was not "ok". which is not ok.');
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then(returnedSuccessdata => {
|
||||||
|
// perhaps a success callback
|
||||||
|
console.log('returnedSuccessdata:', returnedSuccessdata);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
});
|
||||||
|
}
|
Reference in New Issue
Block a user