Fixed a bug where hitting delete on one post would affect selected attachments on other posts.
Fixed a bug where attachments couldn't be deleted after being added with the attachment manager without refreshing. Fixed a bug where an attachment can't be reuploaded with the attachment manager after being uploaded and deleted without refreshing. Improved the error message for RemoveAttachFromReplySubmit when there aren't any aids. The delete button is now hidden when there aren't any attachments to delete.
This commit is contained in:
parent
546aa5f845
commit
adb7babc02
|
@ -846,11 +846,9 @@ function mainInit(){
|
||||||
$(".topic_create_form").hide();
|
$(".topic_create_form").hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
function uploadFileHandler(fileList,maxFiles = 5, step1 = () => {}, step2 = () => {}) {
|
function uploadFileHandler(fileList, maxFiles = 5, step1 = () => {}, step2 = () => {}) {
|
||||||
let files = [];
|
let files = [];
|
||||||
for(var i = 0; i < fileList.length && i < 5; i++) {
|
for(var i = 0; i < fileList.length && i < 5; i++) files[i] = fileList[i];
|
||||||
files[i] = fileList[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
let totalSize = 0;
|
let totalSize = 0;
|
||||||
for(let i = 0; i < files.length; i++) {
|
for(let i = 0; i < files.length; i++) {
|
||||||
|
@ -883,44 +881,44 @@ function mainInit(){
|
||||||
|
|
||||||
// TODO: Surely, there's a prettier and more elegant way of doing this?
|
// TODO: Surely, there's a prettier and more elegant way of doing this?
|
||||||
function getExt(filename) {
|
function getExt(filename) {
|
||||||
if(!filename.indexOf('.' > -1)) {
|
if(!filename.indexOf('.' > -1)) throw("This file doesn't have an extension");
|
||||||
throw("This file doesn't have an extension");
|
|
||||||
}
|
|
||||||
return filename.split('.').pop();
|
return filename.split('.').pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attachment Manager
|
// Attachment Manager
|
||||||
function uploadAttachHandler2() {
|
function uploadAttachHandler2() {
|
||||||
|
let post = this.closest(".post_item");
|
||||||
let fileDock = this.closest(".attach_edit_bay");
|
let fileDock = this.closest(".attach_edit_bay");
|
||||||
try {
|
try {
|
||||||
uploadFileHandler(this.files, 5, () => {},
|
uploadFileHandler(this.files, 5, () => {},
|
||||||
(e, hash, filename) => {
|
(e, hash, filename) => {
|
||||||
console.log("hash",hash);
|
console.log("hash",hash);
|
||||||
|
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
formData.append("session",me.User.Session);
|
formData.append("session",me.User.Session);
|
||||||
for(let i = 0; i < this.files.length; i++) {
|
for(let i = 0; i < this.files.length; i++) formData.append("upload_files",this.files[i]);
|
||||||
formData.append("upload_files",this.files[i]);
|
bindAttachManager();
|
||||||
}
|
|
||||||
|
|
||||||
let req = new XMLHttpRequest();
|
let req = new XMLHttpRequest();
|
||||||
req.addEventListener("load", () => {
|
req.addEventListener("load", () => {
|
||||||
let data = JSON.parse(req.responseText);
|
let data = JSON.parse(req.responseText);
|
||||||
|
//console.log("hash:",hash);
|
||||||
|
//console.log("rdata:",data);
|
||||||
let fileItem = document.createElement("div");
|
let fileItem = document.createElement("div");
|
||||||
let ext = getExt(filename);
|
let ext = getExt(filename);
|
||||||
|
//console.log("ext:",ext);
|
||||||
// TODO: Check if this is actually an image, maybe push ImageFileExts to the client from the server in some sort of gen.js?
|
// TODO: Check if this is actually an image, maybe push ImageFileExts to the client from the server in some sort of gen.js?
|
||||||
fileItem.className = "attach_item attach_image_holder";
|
fileItem.className = "attach_item attach_item_item attach_image_holder";
|
||||||
fileItem.innerHTML = Template_topic_c_attach_item({
|
fileItem.innerHTML = Template_topic_c_attach_item({
|
||||||
ID: data[hash+"."+ext],
|
ID: data.elems[hash+"."+ext],
|
||||||
ImgSrc: e.target.result,
|
ImgSrc: e.target.result,
|
||||||
Path: hash+"."+ext,
|
Path: hash+"."+ext,
|
||||||
FullPath: "//" + window.location.host + "/attachs/" + hash + "." + ext,
|
FullPath: "//" + window.location.host + "/attachs/" + hash + "." + ext,
|
||||||
});
|
});
|
||||||
fileDock.insertBefore(fileItem,fileDock.querySelector(".attach_item_buttons"));
|
fileDock.insertBefore(fileItem,fileDock.querySelector(".attach_item_buttons"));
|
||||||
|
|
||||||
$(".attach_item_select").unbind("click");
|
post.classList.add("has_attachs");
|
||||||
$(".attach_item_copy").unbind("click");
|
bindAttachItems();
|
||||||
bindAttachItems()
|
|
||||||
});
|
});
|
||||||
req.open("POST","//"+window.location.host+"/"+fileDock.getAttribute("type")+"/attach/add/submit/"+fileDock.getAttribute("id"));
|
req.open("POST","//"+window.location.host+"/"+fileDock.getAttribute("type")+"/attach/add/submit/"+fileDock.getAttribute("id"));
|
||||||
req.send(formData);
|
req.send(formData);
|
||||||
|
@ -976,12 +974,18 @@ function mainInit(){
|
||||||
if(uploadFilesOp != null) {
|
if(uploadFilesOp != null) {
|
||||||
uploadFilesOp.addEventListener("change", uploadAttachHandler2, false);
|
uploadFilesOp.addEventListener("change", uploadAttachHandler2, false);
|
||||||
}
|
}
|
||||||
let uploadFilesPost = document.getElementsByClassName("upload_files_post");
|
|
||||||
if(uploadFilesPost != null) {
|
function bindAttachManager() {
|
||||||
for(let i = 0; i < uploadFilesPost.length; i++) {
|
let uploadFiles = document.getElementsByClassName("upload_files_post");
|
||||||
uploadFilesPost[i].addEventListener("change", uploadAttachHandler2, false);
|
if(uploadFiles == null) return;
|
||||||
|
for(let i = 0; i < uploadFiles.length; i++) {
|
||||||
|
let uploader = uploadFiles[i];
|
||||||
|
uploader.value = "";
|
||||||
|
uploader.removeEventListener("change", uploadAttachHandler2, false);
|
||||||
|
uploader.addEventListener("change", uploadAttachHandler2, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bindAttachManager();
|
||||||
|
|
||||||
function copyToClipboard(str) {
|
function copyToClipboard(str) {
|
||||||
const el = document.createElement('textarea');
|
const el = document.createElement('textarea');
|
||||||
|
@ -996,13 +1000,12 @@ function mainInit(){
|
||||||
}
|
}
|
||||||
|
|
||||||
function bindAttachItems() {
|
function bindAttachItems() {
|
||||||
|
$(".attach_item_select").unbind("click");
|
||||||
|
$(".attach_item_copy").unbind("click");
|
||||||
$(".attach_item_select").click(function(){
|
$(".attach_item_select").click(function(){
|
||||||
let hold = $(this).closest(".attach_item");
|
let hold = $(this).closest(".attach_item");
|
||||||
if(hold.hasClass("attach_item_selected")) {
|
if(hold.hasClass("attach_item_selected")) hold.removeClass("attach_item_selected");
|
||||||
hold.removeClass("attach_item_selected");
|
else hold.addClass("attach_item_selected");
|
||||||
} else {
|
|
||||||
hold.addClass("attach_item_selected");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
$(".attach_item_copy").click(function(){
|
$(".attach_item_copy").click(function(){
|
||||||
let hold = $(this).closest(".attach_item");
|
let hold = $(this).closest(".attach_item");
|
||||||
|
@ -1016,8 +1019,9 @@ function mainInit(){
|
||||||
let formData = new URLSearchParams();
|
let formData = new URLSearchParams();
|
||||||
formData.append("session",me.User.Session);
|
formData.append("session",me.User.Session);
|
||||||
|
|
||||||
|
let post = this.closest(".post_item");
|
||||||
let aidList = "";
|
let aidList = "";
|
||||||
let elems = document.getElementsByClassName("attach_item_selected");
|
let elems = post.getElementsByClassName("attach_item_selected");
|
||||||
if(elems == null) return;
|
if(elems == null) return;
|
||||||
|
|
||||||
for(let i = 0; i < elems.length; i++) {
|
for(let i = 0; i < elems.length; i++) {
|
||||||
|
@ -1029,11 +1033,19 @@ function mainInit(){
|
||||||
if(aidList.length > 0) aidList = aidList.slice(0, -1);
|
if(aidList.length > 0) aidList = aidList.slice(0, -1);
|
||||||
console.log("aidList",aidList)
|
console.log("aidList",aidList)
|
||||||
formData.append("aids",aidList);
|
formData.append("aids",aidList);
|
||||||
|
|
||||||
|
let ec = 0;
|
||||||
|
let e = post.getElementsByClassName("attach_item_item");
|
||||||
|
if(e!=null) ec = e.length;
|
||||||
|
if(ec==0) post.classList.remove("has_attachs");
|
||||||
|
|
||||||
let req = new XMLHttpRequest();
|
let req = new XMLHttpRequest();
|
||||||
let fileDock = this.closest(".attach_edit_bay");
|
let fileDock = this.closest(".attach_edit_bay");
|
||||||
req.open("POST","//"+window.location.host+"/"+fileDock.getAttribute("type")+"/attach/remove/submit/"+fileDock.getAttribute("id"),true);
|
req.open("POST","//"+window.location.host+"/"+fileDock.getAttribute("type")+"/attach/remove/submit/"+fileDock.getAttribute("id"),true);
|
||||||
req.send(formData);
|
req.send(formData);
|
||||||
|
|
||||||
|
bindAttachItems();
|
||||||
|
bindAttachManager();
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".moderate_link").click((event) => {
|
$(".moderate_link").click((event) => {
|
||||||
|
|
|
@ -402,7 +402,7 @@ func AddAttachToReplySubmit(w http.ResponseWriter, r *http.Request, user common.
|
||||||
elemStr = elemStr[:len(elemStr)-1]
|
elemStr = elemStr[:len(elemStr)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write([]byte(`{"success":"1","elems":[{` + elemStr + `}]}`))
|
w.Write([]byte(`{"success":"1","elems":{` + elemStr + `}}`))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,7 +436,11 @@ func RemoveAttachFromReplySubmit(w http.ResponseWriter, r *http.Request, user co
|
||||||
return common.NoPermissionsJS(w, r, user)
|
return common.NoPermissionsJS(w, r, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, said := range strings.Split(r.PostFormValue("aids"), ",") {
|
saids := strings.Split(r.PostFormValue("aids"), ",")
|
||||||
|
if len(saids) == 0 {
|
||||||
|
return common.LocalErrorJS("No aids provided", w, r)
|
||||||
|
}
|
||||||
|
for _, said := range saids {
|
||||||
aid, err := strconv.Atoi(said)
|
aid, err := strconv.Atoi(said)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.LocalErrorJS(phrases.GetErrorPhrase("id_must_be_integer"), w, r)
|
return common.LocalErrorJS(phrases.GetErrorPhrase("id_must_be_integer"), w, r)
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
{{end}}
|
{{end}}
|
||||||
<article {{scope "opening_post"}} itemscope itemtype="http://schema.org/CreativeWork" class="rowitem passive deletable_block editable_parent post_item top_post" aria-label="{{lang "topic.opening_post_aria"}}">
|
<article {{scope "opening_post"}} itemscope itemtype="http://schema.org/CreativeWork" class="rowitem passive deletable_block editable_parent post_item top_post{{if .Topic.Attachments}} has_attachs{{end}}" aria-label="{{lang "topic.opening_post_aria"}}">
|
||||||
{{template "topic_alt_userinfo.html" .Topic }}
|
{{template "topic_alt_userinfo.html" .Topic }}
|
||||||
<div class="content_container">
|
<div class="content_container">
|
||||||
<div class="hide_on_edit topic_content user_content" itemprop="text">{{.Topic.ContentHTML}}</div>
|
<div class="hide_on_edit topic_content user_content" itemprop="text">{{.Topic.ContentHTML}}</div>
|
||||||
|
@ -70,7 +70,7 @@
|
||||||
{{if .CurrentUser.Perms.EditTopic}}
|
{{if .CurrentUser.Perms.EditTopic}}
|
||||||
<div class="show_on_edit attach_edit_bay" type="topic" id="{{.Topic.ID}}">
|
<div class="show_on_edit attach_edit_bay" type="topic" id="{{.Topic.ID}}">
|
||||||
{{range .Topic.Attachments}}
|
{{range .Topic.Attachments}}
|
||||||
<div class="attach_item{{if .Image}} attach_image_holder{{end}}">
|
<div class="attach_item attach_item_item{{if .Image}} attach_image_holder{{end}}">
|
||||||
{{if .Image}}<img src="//{{$.Header.Site.URL}}/attachs/{{.Path}}?sectionID={{.SectionID}}&sectionType=forums" height=24 width=24 />{{end}}
|
{{if .Image}}<img src="//{{$.Header.Site.URL}}/attachs/{{.Path}}?sectionID={{.SectionID}}&sectionType=forums" height=24 width=24 />{{end}}
|
||||||
<span class="attach_item_path" aid="{{.ID}}" fullPath="//{{$.Header.Site.URL}}/attachs/{{.Path}}">{{.Path}}</span>
|
<span class="attach_item_path" aid="{{.ID}}" fullPath="//{{$.Header.Site.URL}}/attachs/{{.Path}}">{{.Path}}</span>
|
||||||
<button class="attach_item_select">{{lang "topic.select_button_text"}}</button>
|
<button class="attach_item_select">{{lang "topic.select_button_text"}}</button>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{{range .ItemList}}<article {{scope "post"}} id="post-{{.ID}}" itemscope itemtype="http://schema.org/CreativeWork" class="rowitem passive deletable_block editable_parent post_item{{if .ActionType}} action_item{{end}}">
|
{{range .ItemList}}<article {{scope "post"}} id="post-{{.ID}}" itemscope itemtype="http://schema.org/CreativeWork" class="rowitem passive deletable_block editable_parent post_item{{if .ActionType}} action_item{{end}}{{if .Attachments}} has_attachs{{end}}">
|
||||||
{{template "topic_alt_userinfo.html" . }}
|
{{template "topic_alt_userinfo.html" . }}
|
||||||
<div class="content_container"{{if .ActionType}} style="margin-left: 0px;"{{end}}>
|
<div class="content_container"{{if .ActionType}} style="margin-left: 0px;"{{end}}>
|
||||||
{{if .ActionType}}
|
{{if .ActionType}}
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
{{if $.CurrentUser.Perms.EditReply}}
|
{{if $.CurrentUser.Perms.EditReply}}
|
||||||
<div class="show_on_edit show_on_block_edit attach_edit_bay" type="reply" id="{{.ID}}">
|
<div class="show_on_edit show_on_block_edit attach_edit_bay" type="reply" id="{{.ID}}">
|
||||||
{{range .Attachments}}
|
{{range .Attachments}}
|
||||||
<div class="attach_item{{if .Image}} attach_image_holder{{end}}">
|
<div class="attach_item attach_item_item{{if .Image}} attach_image_holder{{end}}">
|
||||||
{{if .Image}}<img src="//{{$.Header.Site.URL}}/attachs/{{.Path}}?sectionID={{.SectionID}}&sectionType=forums" height=24 width=24 />{{end}}
|
{{if .Image}}<img src="//{{$.Header.Site.URL}}/attachs/{{.Path}}?sectionID={{.SectionID}}&sectionType=forums" height=24 width=24 />{{end}}
|
||||||
<span class="attach_item_path" aid="{{.ID}}" fullPath="//{{$.Header.Site.URL}}/attachs/{{.Path}}">{{.Path}}</span>
|
<span class="attach_item_path" aid="{{.ID}}" fullPath="//{{$.Header.Site.URL}}/attachs/{{.Path}}">{{.Path}}</span>
|
||||||
<button class="attach_item_select">{{lang "topic.select_button_text"}}</button>
|
<button class="attach_item_select">{{lang "topic.select_button_text"}}</button>
|
||||||
|
|
|
@ -1016,6 +1016,9 @@ input[type=checkbox]:checked + label .sel {
|
||||||
.attach_item button {
|
.attach_item button {
|
||||||
margin-top: -1px;
|
margin-top: -1px;
|
||||||
}
|
}
|
||||||
|
.post_item:not(.has_attachs) .attach_item_delete {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.zone_view_topic .pageset {
|
.zone_view_topic .pageset {
|
||||||
margin-bottom: 14px;
|
margin-bottom: 14px;
|
||||||
|
|
Loading…
Reference in New Issue