Skip to content

Commit

Permalink
v2-Beta12 release
Browse files Browse the repository at this point in the history
  • Loading branch information
kid1194 committed May 3, 2023
1 parent 0c2460a commit 944f96b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 18 deletions.
29 changes: 23 additions & 6 deletions frappe_better_attach_control/public/js/better_attach_webform.js
Original file line number Diff line number Diff line change
Expand Up @@ -1958,6 +1958,9 @@
this._allow_remove = true;
this._display_ready = false;
this._unprocessed_files = [];
frappe.realtime.on("better_attach_console", function(ret) {
console.log(ret);
});
}
_update_options() {
if (isEmpty(this._options) && isEmpty(this.df.better_attach_options) || !isEmpty(this._options) && this._latest_options === this.df.better_attach_options)
Expand Down Expand Up @@ -2290,15 +2293,17 @@
_add_list_file(file, idx) {
if (!this._allow_multiple || !this._$list)
return;
let meta = "";
let meta = "", rem = !this._allow_remove ? " ba-hidden" : "";
if (file.size && file.size_str) {
meta = '<div class="ba-meta">' + file.size_str + "</div>";
}
this._$list_group.append($(
'<li class="list-group-item ba-attachment" data-file-idx="' + idx + '"><div class="row align-items-center"><div class="col ba-hidden-overflow"><div class="flex align-center"><div class="ba-file ba-' + file.class + '"></div><a href="' + file.file_url + '" class="ba-link" target="__blank">' + file.file_name + "</a>" + meta + '</div></div><div class="col-auto ba-actions"><button type="button" class="ba-remove btn btn-danger btn-xs mx-0"><span class="fa fa-times fa-fw"></span></button></div></div></li>'
'<li class="list-group-item ba-attachment" data-file-idx="' + idx + '"><div class="row align-items-center"><div class="col ba-hidden-overflow"><div class="flex align-center"><div class="ba-file ba-' + file.class + '"></div><a href="' + file.file_url + '" class="ba-link" target="__blank">' + file.file_name + "</a>" + meta + '</div></div><div class="col-auto ba-actions"><button type="button" class="ba-remove btn btn-danger btn-xs mx-0' + rem + '"><span class="fa fa-times fa-fw"></span></button></div></div></li>'
));
}
_remove_files(data, callback, error2) {
if (!isArray(data))
data = [data];
request("remove_files", { files: data }, callback, error2);
}
_remove_file_by_idx(idx) {
Expand All @@ -2319,15 +2324,13 @@
this._remove_file_by_url(url);
}
_remove_file_by_url(url) {
if (!this.frm) {
this._remove_files([url], function(ret) {
if (!this.frm || !this.frm.attachments) {
this._remove_files(url, function(ret) {
if (!cint(ret))
error("Unable to remove the uploaded attachment ({0}).", [url]);
});
return;
}
if (!this.frm.attachments)
return;
var me = this;
this.frm.attachments.remove_attachment_by_filename(
url,
Expand All @@ -2349,6 +2352,20 @@
'<div class="attached-file row align-center mt-4 ba-hidden"><div class="col-12"><ul class="list-group"></ul></div></div>'
).appendTo(this.input_area);
this._$list_group = this._$list.find("ul.list-group");
this._$list_group.click(".ba-remove", function() {
let $el = $(this);
if (!$el.hasClass("ba-remove"))
return;
let $parent = $el.parents(".ba-attachment");
if (!$parent.length)
return;
let idx = $parent.attr("data-file-idx");
if (!idx || !/[0-9]+/.test("" + idx))
return;
idx = cint(idx);
if (idx >= 0)
_remove_file_by_idx(idx);
});
}
_destroy_list() {
if (this._$list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,9 @@
this._allow_remove = true;
this._display_ready = false;
this._unprocessed_files = [];
frappe.realtime.on("better_attach_console", function(ret) {
console.log(ret);
});
},
_update_options: function() {
if (isEmpty(this._options) && isEmpty(this.df.better_attach_options) || !isEmpty(this._options) && this._latest_options === this.df.better_attach_options)
Expand Down Expand Up @@ -2207,15 +2210,17 @@
_add_list_file: function(file, idx) {
if (!this._allow_multiple || !this._$list)
return;
var meta = "";
var meta = "", rem = !this._allow_remove ? " ba-hidden" : "";
if (file.size && file.size_str) {
meta = '<div class="ba-meta">' + file.size_str + "</div>";
}
this._$list_group.append($(
'<li class="list-group-item ba-attachment" data-file-idx="' + idx + '"><div class="row align-items-center"><div class="col ba-hidden-overflow"><div class="flex align-center"><div class="ba-file ba-' + file.class + '"></div><a href="' + file.file_url + '" class="ba-link" target="__blank">' + file.file_name + "</a>" + meta + '</div></div><div class="col-auto ba-actions"><button type="button" class="ba-remove btn btn-danger btn-xs mx-0"><span class="fa fa-times fa-fw"></span></button></div></div></li>'
'<li class="list-group-item ba-attachment" data-file-idx="' + idx + '"><div class="row align-items-center"><div class="col ba-hidden-overflow"><div class="flex align-center"><div class="ba-file ba-' + file.class + '"></div><a href="' + file.file_url + '" class="ba-link" target="__blank">' + file.file_name + "</a>" + meta + '</div></div><div class="col-auto ba-actions"><button type="button" class="ba-remove btn btn-danger btn-xs mx-0' + rem + '"><span class="fa fa-times fa-fw"></span></button></div></div></li>'
));
},
_remove_files: function(data, callback, error2) {
if (!isArray(data))
data = [data];
request("remove_files", { files: data }, callback, error2);
},
_remove_file_by_idx: function(idx) {
Expand All @@ -2236,15 +2241,13 @@
this._remove_file_by_url(url);
},
_remove_file_by_url: function(url) {
if (!this.frm) {
this._remove_files([url], function(ret) {
if (!this.frm || !this.frm.attachments) {
this._remove_files(url, function(ret) {
if (!cint(ret))
error("Unable to remove the uploaded attachment ({0}).", [url]);
});
return;
}
if (!this.frm.attachments)
return;
var me = this;
this.frm.attachments.remove_attachment_by_filename(
url,
Expand All @@ -2265,6 +2268,20 @@
'<div class="attached-file row align-center mt-4 ba-hidden"><div class="col-12"><ul class="list-group"></ul></div></div>'
).appendTo(this.input_area);
this._$list_group = this._$list.find("ul.list-group");
this._$list_group.click(".ba-remove", function() {
var $el = $(this);
if (!$el.hasClass("ba-remove"))
return;
var $parent = $el.parents(".ba-attachment");
if (!$parent.length)
return;
var idx = $parent.attr("data-file-idx");
if (!idx || !/[0-9]+/.test("" + idx))
return;
idx = cint(idx);
if (idx >= 0)
_remove_file_by_idx(idx);
});
},
_destroy_list: function() {
if (this._$list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,9 @@
this._allow_remove = true;
this._display_ready = false;
this._unprocessed_files = [];
frappe.realtime.on("better_attach_console", function(ret) {
console.log(ret);
});
},
_update_options: function() {
if (isEmpty(this._options) && isEmpty(this.df.better_attach_options) || !isEmpty(this._options) && this._latest_options === this.df.better_attach_options)
Expand Down Expand Up @@ -2265,15 +2268,17 @@
_add_list_file: function(file, idx) {
if (!this._allow_multiple || !this._$list)
return;
var meta = "";
var meta = "", rem = !this._allow_remove ? " ba-hidden" : "";
if (file.size && file.size_str) {
meta = '<div class="ba-meta">' + file.size_str + "</div>";
}
this._$list_group.append($(
'<li class="list-group-item ba-attachment" data-file-idx="' + idx + '"><div class="row align-items-center"><div class="col ba-hidden-overflow"><div class="flex align-center"><div class="ba-file ba-' + file.class + '"></div><a href="' + file.file_url + '" class="ba-link" target="__blank">' + file.file_name + "</a>" + meta + '</div></div><div class="col-auto ba-actions"><button type="button" class="ba-remove btn btn-danger btn-xs mx-0"><span class="fa fa-times fa-fw"></span></button></div></div></li>'
'<li class="list-group-item ba-attachment" data-file-idx="' + idx + '"><div class="row align-items-center"><div class="col ba-hidden-overflow"><div class="flex align-center"><div class="ba-file ba-' + file.class + '"></div><a href="' + file.file_url + '" class="ba-link" target="__blank">' + file.file_name + "</a>" + meta + '</div></div><div class="col-auto ba-actions"><button type="button" class="ba-remove btn btn-danger btn-xs mx-0' + rem + '"><span class="fa fa-times fa-fw"></span></button></div></div></li>'
));
},
_remove_files: function(data, callback, error2) {
if (!isArray(data))
data = [data];
request("remove_files", { files: data }, callback, error2);
},
_remove_file_by_idx: function(idx) {
Expand All @@ -2294,15 +2299,13 @@
this._remove_file_by_url(url);
},
_remove_file_by_url: function(url) {
if (!this.frm) {
this._remove_files([url], function(ret) {
if (!this.frm || !this.frm.attachments) {
this._remove_files(url, function(ret) {
if (!cint(ret))
error("Unable to remove the uploaded attachment ({0}).", [url]);
});
return;
}
if (!this.frm.attachments)
return;
var me = this;
this.frm.attachments.remove_attachment_by_filename(
url,
Expand All @@ -2323,6 +2326,20 @@
'<div class="attached-file row align-center mt-4 ba-hidden"><div class="col-12"><ul class="list-group"></ul></div></div>'
).appendTo(this.input_area);
this._$list_group = this._$list.find("ul.list-group");
this._$list_group.click(".ba-remove", function() {
var $el = $(this);
if (!$el.hasClass("ba-remove"))
return;
var $parent = $el.parents(".ba-attachment");
if (!$parent.length)
return;
var idx = $parent.attr("data-file-idx");
if (!idx || !/[0-9]+/.test("" + idx))
return;
idx = cint(idx);
if (idx >= 0)
_remove_file_by_idx(idx);
});
},
_destroy_list: function() {
if (this._$list) {
Expand Down

0 comments on commit 944f96b

Please sign in to comment.