Editing replies now uses a client template instead of inline HTML in global.js

Added the topic_c_edit_post template.
This commit is contained in:
Azareal 2019-04-11 15:46:57 +10:00
parent 3db09c6a1f
commit d61ec9a6fe
6 changed files with 20 additions and 4 deletions

View File

@ -165,6 +165,11 @@ type CustomPagePage struct {
Page *CustomPage
}
type TopicCEditPost struct {
Source string
Ref string
}
type TopicPage struct {
*Header
ItemList []ReplyUser

View File

@ -477,6 +477,8 @@ func compileJSTemplates(wg *sync.WaitGroup, c *tmpl.CTemplateSet, themeName stri
pageList := Paginate(20, itemsPerPage, 5)
tmpls.AddStd("paginator", "common.Paginator", Paginator{pageList, page, lastPage})
tmpls.AddStd("topic_c_edit_post", "common.TopicCEditPost", TopicCEditPost{Source: "", Ref: ""})
var dirPrefix = "./tmpl_client/"
var writeTemplate = func(name string, content string) {
log.Print("Writing template '" + name + "'")

View File

@ -662,8 +662,10 @@ function mainInit(){
let source = "";
if(srcNode!=null) source = srcNode.innerText;
else source = block.innerHTML;
// TODO: Add a client template for this
block.innerHTML = "<textarea style='width: 99%;' name='edit_item'>" + source + "</textarea><br><a href='" + this.closest('a').getAttribute("href") + "'><button class='submit_edit' type='submit'>Update</button></a>";
block.innerHTML = Template_topic_c_edit_post({
Source: source,
Ref: this.closest('a').getAttribute("href")
})
runHook("edit_item_pre_bind");
$(".submit_edit").click(function(event){

View File

@ -176,7 +176,7 @@ function RelativeTime(date) {
function initPhrases() {
console.log("in initPhrases")
console.log("tmlInits:",tmplInits)
fetchPhrases("status,topic_list,alerts,paginator,analytics")
fetchPhrases("status,topic_list,topic,alerts,paginator,analytics") // TODO: Break this up?
}
function fetchPhrases(plist) {
@ -224,6 +224,11 @@ function fetchPhrases(plist) {
if(toLoad===0) initPhrases();
if(!Template_paginator) throw("template function not found");
});
notifyOnScriptW("template_topic_c_edit_post", () => {
toLoad--;
if(toLoad===0) initPhrases();
if(!Template_topic_c_edit_post) throw("template function not found");
});
let loggedIn = document.head.querySelector("[property='x-loggedin']").content;
if(loggedIn=="true") {

View File

@ -7,7 +7,7 @@
{{range .Header.PreScriptsAsync}}
<script async type="text/javascript" src="/static/{{.}}"></script>{{end}}
<meta property="x-loggedin" content="{{.CurrentUser.Loggedin}}" />
<script type="text/javascript" src="/static/init.js"></script>
<script type="text/javascript" src="/static/init.js?i=0"></script>
{{range .Header.ScriptsAsync}}
<script async type="text/javascript" src="/static/{{.}}"></script>{{end}}
<script type="text/javascript" src="/static/jquery-3.1.1.min.js"></script>

View File

@ -0,0 +1,2 @@
<textarea style='width: 99%;' name='edit_item'>{{.Source}}</textarea><br>
<a href='{{.Ref}}'><button class='submit_edit' type='submit'>{{lang "topic.update_button"}}</button></a>