add absolute counter in js
This commit is contained in:
parent
de446227c0
commit
27d1ed767b
@ -42,6 +42,8 @@ def upload_files(files):
|
||||
for filename, storage in files:
|
||||
filename = secure_filename(filename)
|
||||
filepath = os.path.join(current_app.static_folder, filename)
|
||||
if os.path.exists(filepath):
|
||||
os.remove(filepath)
|
||||
storage.save(filepath)
|
||||
file_url = request.url_root.rstrip('/') + url_for('static', filename=filename)
|
||||
attachment = {'url': file_url, 'filename': filename}
|
||||
@ -52,6 +54,10 @@ def upload_files(files):
|
||||
def update_airtable_attachment_field(request, record, field_name, airtable_column_name=None):
|
||||
airtable_column_name = airtable_column_name or field_name
|
||||
uploaded_files = list(request.files.items()) or []
|
||||
print("==================================")
|
||||
print("uploaded_files: " + str(uploaded_files))
|
||||
print("==================================")
|
||||
|
||||
|
||||
# set of files sent via input fields
|
||||
set_input = set(file_id[len(field_name) + 1:] for file_id, file_storage in uploaded_files if file_id.startswith(field_name))
|
||||
@ -72,11 +78,11 @@ def update_airtable_attachment_field(request, record, field_name, airtable_colum
|
||||
print("Éléments dans le formulaire mais pas dans airtable:", to_add, "(len: ", len(to_add), " )")
|
||||
|
||||
base_data = [ attachment for attachment in record['fields'].get(airtable_column_name, [])]
|
||||
print("base_data: " + str(base_data))
|
||||
print("base_data in " + field_name + " : " + str(base_data))
|
||||
data = [ attachment for attachment in record['fields'].get(airtable_column_name, []) if attachment['id'] not in to_remove]
|
||||
print(" ")
|
||||
print("======================================")
|
||||
print("base_data after filter: " + str(base_data))
|
||||
print("base_data after filter in " + field_name + " : " + str(base_data))
|
||||
if len(to_add) > 0:
|
||||
files = [file for file in uploaded_files if file[0][len(field_name) + 1:] in to_add]
|
||||
new_attachments = upload_files(files)
|
||||
|
||||
@ -22,11 +22,17 @@ function removeNewThumbnail(inputId, fieldName) {
|
||||
columnElement.remove();
|
||||
};
|
||||
|
||||
const imagesCounters = {};
|
||||
function addImage(fieldName, columnsId) {
|
||||
if (!imagesCounters.hasOwnProperty(fieldName)) {
|
||||
imagesCounters[fieldName] = 0;
|
||||
}
|
||||
imagesCounters[fieldName]++;
|
||||
|
||||
const columns = document.getElementById(columnsId);
|
||||
const inputId = `${fieldName}_${columns.childElementCount + 1}`;
|
||||
const thumbnailId = `new_${fieldName}_thumbnail_${columns.childElementCount + 1}`;
|
||||
const removeLabelId = `remove_label_${fieldName}_${columns.childElementCount + 1}`;
|
||||
const inputId = `${fieldName}_${imagesCounters[fieldName]}`;
|
||||
const thumbnailId = `new_${fieldName}_thumbnail_${imagesCounters[fieldName]}`;
|
||||
const removeLabelId = `remove_label_${fieldName}_${imagesCounters[fieldName]}`;
|
||||
|
||||
// Create a new column element
|
||||
const newColumn = document.createElement('div');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user