The attachment managers for replies are now rendered with client templates
Avoid loading the topic phrases when the user isn't logged in. Don't load the topic_c_edit_post and topic_c_attach_item client templates when the user isn't logged in. Fixed a bug where multiple attachment managers wouldn't load. Added the topic_c_attach_item template.
This commit is contained in:
parent
99d6581bbb
commit
546aa5f845
|
@ -107,14 +107,21 @@ func (store *DefaultAttachmentStore) BulkMiniGetList(originTable string, ids []i
|
|||
}
|
||||
attach.Ext = extarr[len(extarr)-1]
|
||||
attach.Image = ImageFileExts.Contains(attach.Ext)
|
||||
if attach.ID != currentID {
|
||||
if currentID == 0 {
|
||||
currentID = attach.OriginID
|
||||
}
|
||||
if attach.OriginID != currentID {
|
||||
if len(buffer) > 0 {
|
||||
amap[currentID] = buffer
|
||||
currentID = attach.OriginID
|
||||
buffer = nil
|
||||
}
|
||||
}
|
||||
buffer = append(buffer, attach)
|
||||
}
|
||||
if len(buffer) > 0 {
|
||||
amap[currentID] = buffer
|
||||
}
|
||||
return amap, rows.Err()
|
||||
}
|
||||
|
||||
|
|
|
@ -169,6 +169,12 @@ type TopicCEditPost struct {
|
|||
Source string
|
||||
Ref string
|
||||
}
|
||||
type TopicCAttachItem struct {
|
||||
ID int
|
||||
ImgSrc string
|
||||
Path string
|
||||
FullPath string
|
||||
}
|
||||
|
||||
type TopicPage struct {
|
||||
*Header
|
||||
|
|
|
@ -265,7 +265,10 @@ func userCheck(w http.ResponseWriter, r *http.Request, user *User) (header *Head
|
|||
addPreScript("topics_topic")
|
||||
addPreScript("paginator")
|
||||
addPreScript("alert")
|
||||
addPreScript("topic_c_edit_post")
|
||||
if user.Loggedin {
|
||||
addPreScript("topic_c_edit_post")
|
||||
addPreScript("topic_c_attach_item")
|
||||
}
|
||||
|
||||
return header, nil
|
||||
}
|
||||
|
|
|
@ -479,6 +479,8 @@ func compileJSTemplates(wg *sync.WaitGroup, c *tmpl.CTemplateSet, themeName stri
|
|||
|
||||
tmpls.AddStd("topic_c_edit_post", "common.TopicCEditPost", TopicCEditPost{Source: "", Ref: ""})
|
||||
|
||||
tmpls.AddStd("topic_c_attach_item", "common.TopicCAttachItem", TopicCAttachItem{ID: 1, ImgSrc: "", Path: "", FullPath: ""})
|
||||
|
||||
var dirPrefix = "./tmpl_client/"
|
||||
var writeTemplate = func(name string, content string) {
|
||||
log.Print("Writing template '" + name + "'")
|
||||
|
|
|
@ -909,9 +909,13 @@ function mainInit(){
|
|||
let fileItem = document.createElement("div");
|
||||
let ext = getExt(filename);
|
||||
// TODO: Check if this is actually an image, maybe push ImageFileExts to the client from the server in some sort of gen.js?
|
||||
// TODO: Use client templates here
|
||||
fileItem.className = "attach_item attach_image_holder";
|
||||
fileItem.innerHTML = "<img src='"+e.target.result+"' height=24 width=24 /><span class='attach_item_path' aid='"+data[hash+"."+ext]+"' fullpath='//" + window.location.host + "/attachs/" + hash + "." + ext+"'>"+hash+"."+ext+"</span><button class='attach_item_select'>Select</button><button class='attach_item_copy'>Copy</button>";
|
||||
fileItem.innerHTML = Template_topic_c_attach_item({
|
||||
ID: data[hash+"."+ext],
|
||||
ImgSrc: e.target.result,
|
||||
Path: hash+"."+ext,
|
||||
FullPath: "//" + window.location.host + "/attachs/" + hash + "." + ext,
|
||||
});
|
||||
fileDock.insertBefore(fileItem,fileDock.querySelector(".attach_item_buttons"));
|
||||
|
||||
$(".attach_item_select").unbind("click");
|
||||
|
|
|
@ -173,10 +173,14 @@ function RelativeTime(date) {
|
|||
return date;
|
||||
}
|
||||
|
||||
function initPhrases() {
|
||||
function initPhrases(loggedIn) {
|
||||
console.log("in initPhrases")
|
||||
console.log("tmlInits:",tmplInits)
|
||||
fetchPhrases("status,topic_list,topic,alerts,paginator,analytics") // TODO: Break this up?
|
||||
let e = "";
|
||||
if(loggedIn) {
|
||||
e = ",topic"
|
||||
}
|
||||
fetchPhrases("status,topic_list,alerts,paginator,analytics"+e) // TODO: Break this up?
|
||||
}
|
||||
|
||||
function fetchPhrases(plist) {
|
||||
|
@ -212,26 +216,24 @@ function fetchPhrases(plist) {
|
|||
|
||||
(() => {
|
||||
runInitHook("pre_iife");
|
||||
let loggedIn = document.head.querySelector("[property='x-loggedin']").content == "true";
|
||||
|
||||
let toLoad = 2;
|
||||
// TODO: Shunt this into loggedIn if there aren't any search and filter widgets?
|
||||
notifyOnScriptW("template_topics_topic", () => {
|
||||
let q = (f) => {
|
||||
toLoad--;
|
||||
if(toLoad===0) initPhrases();
|
||||
if(!Template_topics_topic) throw("template function not found");
|
||||
});
|
||||
notifyOnScriptW("template_paginator", () => {
|
||||
toLoad--;
|
||||
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");
|
||||
});
|
||||
if(toLoad===0) initPhrases(loggedIn);
|
||||
if(f) throw("template function not found");
|
||||
};
|
||||
if(loggedIn) {
|
||||
toLoad += 2;
|
||||
notifyOnScriptW("template_topic_c_edit_post", () => q(!Template_topic_c_edit_post));
|
||||
notifyOnScriptW("template_topic_c_attach_item", () => q(!Template_topic_c_attach_item));
|
||||
}
|
||||
notifyOnScriptW("template_topics_topic", () => q(!Template_topics_topic));
|
||||
notifyOnScriptW("template_paginator", () => q(!Template_paginator));
|
||||
|
||||
let loggedIn = document.head.querySelector("[property='x-loggedin']").content;
|
||||
if(loggedIn=="true") {
|
||||
if(loggedIn) {
|
||||
fetch("/api/me/")
|
||||
.then((resp) => resp.json())
|
||||
.then((data) => {
|
||||
|
|
|
@ -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?i=0"></script>
|
||||
<script type="text/javascript" src="/static/init.js?i=1"></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>
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
<img src='{{.ImgSrc}}' height=24 width=24 />
|
||||
<span class='attach_item_path' aid='{{.ID}}' fullpath='{{.FullPath}}'>{{.Path}}</span>
|
||||
<button class='attach_item_select'>{{lang "topic.select_button_text"}}</button>
|
||||
<button class='attach_item_copy'>{{lang "topic.copy_button_text"}}</button>
|
Loading…
Reference in New Issue