add news support, work out some form handling details
This commit is contained in:
parent
54819ec21d
commit
043b74e25a
@ -1,4 +1,8 @@
|
||||
<h1>Config</h1>
|
||||
{{ if has_flash_success() then }}
|
||||
<div class="ui alert">
|
||||
{{ get_flash_success() }}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
<form action="/admin/config" method="post">
|
||||
<div>
|
||||
|
27
fs/templates/admin/news.html
Normal file
27
fs/templates/admin/news.html
Normal file
@ -0,0 +1,27 @@
|
||||
<p>Here you can write a new news article. This will replace the current one on town pages.</p>
|
||||
|
||||
<form action="/admin/news" method="post" id="news_form">
|
||||
<textarea name="content" style="display: block; width: 100%; min-height: 240px;"></textarea>
|
||||
<div>
|
||||
<label for="author">Author</label>
|
||||
<input type="text" name="author" id="author" value="{{ username }}">
|
||||
</div>
|
||||
<button type="submit" class="ui button primary">Submit</button>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
$('#news_form').on('submit', function(e) {
|
||||
e.preventDefault()
|
||||
|
||||
$('#main .ui.alert').remove()
|
||||
|
||||
$.post('/admin/news', $(this).serialize())
|
||||
.done(function(data) {
|
||||
const alertClass = data.success ? 'success' : 'failure'
|
||||
$('#main').prepend(`<div class="ui alert ${alertClass}">${data.message}</div>`)
|
||||
})
|
||||
.fail(function() {
|
||||
$('#main').prepend('<div class="ui alert failure">Request failed</div>')
|
||||
})
|
||||
})
|
||||
</script>
|
@ -2,7 +2,6 @@
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
border: none;
|
||||
font-size: 1rem;
|
||||
background: #f7f8fa linear-gradient(rgba(255, 255, 255, 0), rgba(0, 0, 0, 0.1));
|
||||
box-shadow: 0 1px 0 1px rgba(255, 255, 255, 0.3) inset, 0 0 0 1px #adb2bb inset;
|
||||
color: #111111;
|
||||
|
@ -4,4 +4,5 @@ else
|
||||
env_set("game_open", false)
|
||||
end
|
||||
|
||||
http_redirect("/admin/config")
|
||||
redirect_with_success("/admin/config", "Config saved successfully")
|
||||
--http_redirect("/admin/config")
|
||||
|
5
routes/admin/news/get.lua
Normal file
5
routes/admin/news/get.lua
Normal file
@ -0,0 +1,5 @@
|
||||
local a = require("admin")
|
||||
|
||||
local d = sqlite("dk"):get_one("SELECT username FROM users WHERE id = :i", {i = session_get("user_id")})
|
||||
|
||||
return a.page("news.html", "News", {username = d.username})
|
12
routes/admin/news/post.lua
Normal file
12
routes/admin/news/post.lua
Normal file
@ -0,0 +1,12 @@
|
||||
local content = string.trim(ctx.form.content)
|
||||
if content == "" then return { success = 0, message = "Content is required" } end
|
||||
|
||||
local author = string.trim(ctx.form.author)
|
||||
if author == "" then return { success = 0, message = "Author is required" } end
|
||||
|
||||
sqlite("dk"):insert("news", {
|
||||
content = content,
|
||||
author = author
|
||||
})
|
||||
|
||||
return { success = 1, message = "News posted successfully" }
|
@ -140,6 +140,7 @@ db:create_table("monsters",
|
||||
db:create_table("news",
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT",
|
||||
"posted INTEGER NOT NULL DEFAULT (unixepoch())",
|
||||
"type INTEGER NOT NULL DEFAULT 0",
|
||||
"author TEXT NOT NULL DEFAULT 'Guild Master'",
|
||||
"content TEXT NOT NULL"
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user