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();
|
||||
});
|
||||
|
||||
function uploadFileHandler(fileList,maxFiles = 5, step1 = () => {}, step2 = () => {}) {
|
||||
function uploadFileHandler(fileList, maxFiles = 5, step1 = () => {}, step2 = () => {}) {
|
||||
let files = [];
|
||||
for(var i = 0; i < fileList.length && i < 5; i++) {
|
||||
files[i] = fileList[i];
|
||||
}
|
||||
for(var i = 0; i < fileList.length && i < 5; i++) files[i] = fileList[i];
|
||||
|
||||
let totalSize = 0;
|
||||
for(let i = 0; i < files.length; i++) {
|
||||
|
@ -883,14 +881,13 @@ function mainInit(){
|
|||
|
||||
// TODO: Surely, there's a prettier and more elegant way of doing this?
|
||||
function getExt(filename) {
|
||||
if(!filename.indexOf('.' > -1)) {
|
||||
throw("This file doesn't have an extension");
|
||||
}
|
||||
if(!filename.indexOf('.' > -1)) throw("This file doesn't have an extension");
|
||||
return filename.split('.').pop();
|
||||
}
|
||||
|
||||
// Attachment Manager
|
||||
function uploadAttachHandler2() {
|
||||
let post = this.closest(".post_item");
|
||||
let fileDock = this.closest(".attach_edit_bay");
|
||||
try {
|
||||
uploadFileHandler(this.files, 5, () => {},
|
||||
|
@ -899,28 +896,29 @@ function mainInit(){
|
|||
|
||||
let formData = new FormData();
|
||||
formData.append("session",me.User.Session);
|
||||
for(let i = 0; i < this.files.length; i++) {
|
||||
formData.append("upload_files",this.files[i]);
|
||||
}
|
||||
for(let i = 0; i < this.files.length; i++) formData.append("upload_files",this.files[i]);
|
||||
bindAttachManager();
|
||||
|
||||
let req = new XMLHttpRequest();
|
||||
req.addEventListener("load", () => {
|
||||
let data = JSON.parse(req.responseText);
|
||||
//console.log("hash:",hash);
|
||||
//console.log("rdata:",data);
|
||||
let fileItem = document.createElement("div");
|
||||
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?
|
||||
fileItem.className = "attach_item attach_image_holder";
|
||||
fileItem.className = "attach_item attach_item_item attach_image_holder";
|
||||
fileItem.innerHTML = Template_topic_c_attach_item({
|
||||
ID: data[hash+"."+ext],
|
||||
ID: data.elems[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");
|
||||
$(".attach_item_copy").unbind("click");
|
||||
bindAttachItems()
|
||||
post.classList.add("has_attachs");
|
||||
bindAttachItems();
|
||||
});
|
||||
req.open("POST","//"+window.location.host+"/"+fileDock.getAttribute("type")+"/attach/add/submit/"+fileDock.getAttribute("id"));
|
||||
req.send(formData);
|
||||
|
@ -976,12 +974,18 @@ function mainInit(){
|
|||
if(uploadFilesOp != null) {
|
||||
uploadFilesOp.addEventListener("change", uploadAttachHandler2, false);
|
||||
}
|
||||
let uploadFilesPost = document.getElementsByClassName("upload_files_post");
|
||||
if(uploadFilesPost != null) {
|
||||
for(let i = 0; i < uploadFilesPost.length; i++) {
|
||||
uploadFilesPost[i].addEventListener("change", uploadAttachHandler2, false);
|
||||
|
||||
function bindAttachManager() {
|
||||
let uploadFiles = document.getElementsByClassName("upload_files_post");
|
||||
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) {
|
||||
const el = document.createElement('textarea');
|
||||
|
@ -996,13 +1000,12 @@ function mainInit(){
|
|||
}
|
||||
|
||||
function bindAttachItems() {
|
||||
$(".attach_item_select").unbind("click");
|
||||
$(".attach_item_copy").unbind("click");
|
||||
$(".attach_item_select").click(function(){
|
||||
let hold = $(this).closest(".attach_item");
|
||||
if(hold.hasClass("attach_item_selected")) {
|
||||
hold.removeClass("attach_item_selected");
|
||||
} else {
|
||||
hold.addClass("attach_item_selected");
|
||||
}
|
||||
if(hold.hasClass("attach_item_selected")) hold.removeClass("attach_item_selected");
|
||||
else hold.addClass("attach_item_selected");
|
||||
});
|
||||
$(".attach_item_copy").click(function(){
|
||||
let hold = $(this).closest(".attach_item");
|
||||
|
@ -1016,8 +1019,9 @@ function mainInit(){
|
|||
let formData = new URLSearchParams();
|
||||
formData.append("session",me.User.Session);
|
||||
|
||||
let post = this.closest(".post_item");
|
||||
let aidList = "";
|
||||
let elems = document.getElementsByClassName("attach_item_selected");
|
||||
let elems = post.getElementsByClassName("attach_item_selected");
|
||||
if(elems == null) return;
|
||||
|
||||
for(let i = 0; i < elems.length; i++) {
|
||||
|
@ -1030,10 +1034,18 @@ function mainInit(){
|
|||
console.log("aidList",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 fileDock = this.closest(".attach_edit_bay");
|
||||
req.open("POST","//"+window.location.host+"/"+fileDock.getAttribute("type")+"/attach/remove/submit/"+fileDock.getAttribute("id"),true);
|
||||
req.send(formData);
|
||||
|
||||
bindAttachItems();
|
||||
bindAttachManager();
|
||||
});
|
||||
|
||||
$(".moderate_link").click((event) => {
|
||||
|
|
|
@ -402,7 +402,7 @@ func AddAttachToReplySubmit(w http.ResponseWriter, r *http.Request, user common.
|
|||
elemStr = elemStr[:len(elemStr)-1]
|
||||
}
|
||||
|
||||
w.Write([]byte(`{"success":"1","elems":[{` + elemStr + `}]}`))
|
||||
w.Write([]byte(`{"success":"1","elems":{` + elemStr + `}}`))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -436,7 +436,11 @@ func RemoveAttachFromReplySubmit(w http.ResponseWriter, r *http.Request, user co
|
|||
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)
|
||||
if err != nil {
|
||||
return common.LocalErrorJS(phrases.GetErrorPhrase("id_must_be_integer"), w, r)
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
</div>
|
||||
</article>
|
||||
{{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 }}
|
||||
<div class="content_container">
|
||||
<div class="hide_on_edit topic_content user_content" itemprop="text">{{.Topic.ContentHTML}}</div>
|
||||
|
@ -70,7 +70,7 @@
|
|||
{{if .CurrentUser.Perms.EditTopic}}
|
||||
<div class="show_on_edit attach_edit_bay" type="topic" id="{{.Topic.ID}}">
|
||||
{{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}}
|
||||
<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>
|
||||
|
|
|
@ -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" . }}
|
||||
<div class="content_container"{{if .ActionType}} style="margin-left: 0px;"{{end}}>
|
||||
{{if .ActionType}}
|
||||
|
@ -12,7 +12,7 @@
|
|||
{{if $.CurrentUser.Perms.EditReply}}
|
||||
<div class="show_on_edit show_on_block_edit attach_edit_bay" type="reply" id="{{.ID}}">
|
||||
{{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}}
|
||||
<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>
|
||||
|
|
|
@ -1016,6 +1016,9 @@ input[type=checkbox]:checked + label .sel {
|
|||
.attach_item button {
|
||||
margin-top: -1px;
|
||||
}
|
||||
.post_item:not(.has_attachs) .attach_item_delete {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.zone_view_topic .pageset {
|
||||
margin-bottom: 14px;
|
||||
|
|
Loading…
Reference in New Issue