Skip to content

Commit

Permalink
Fix API output usage on ajax requests
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodiegoss committed Dec 8, 2024
1 parent 8d939e1 commit ec54aa0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/users/jinja2/users/components/elements-modal.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
$('#element-upload-info').replaceWith(
'<p id="element-upload-info">' +
{{ _("Uploaded by ")|tojson }} +
owner + ', ' +
owner.username + ', ' +
{{ _("in ")|tojson }} + new Date(date).toLocaleDateString() + '</p>'
)
}
Expand All @@ -36,11 +36,12 @@
'<img id="element-src" src="' + element_src + '"/></p>'
)
}
function usedInExhibit(marker_id, object_id, exhibits_count, marker_src, augmented_src, element_id){
function usedInExhibit(marker_id, object_id, exhibits_count, marker, augmented, element_id){
let object_tag = ''
let augmented_src = augmented.source
if(augmented_src.split('.')[1] == 'mp4' || augmented_src.split('.')[1] == 'webm'){
object_tag = '<video muted autoplay loop id="' + object_id + '" class="trigger-erase artwork-content" data-elem-type="object" src="' + augmented_src + '"/></p>'
}else{
} else {
object_tag = '<img id="' + object_id + '" class="trigger-erase artwork-content" data-elem-type="object" src="' + augmented_src + '"/></p>'
}
Expand All @@ -49,7 +50,7 @@
{{ _(" Used in ")|tojson }} + '<a href="{{ url('related-content') }}?id=' + element_id + '&type=artwork">' +
exhibits_count +
{{ _(" Exhibits")|tojson }} + '</a>' +
'<img id="' + marker_id + '" class="trigger-erase artwork-content" data-elem-type="marker" src="' + marker_src + '"/>' +
'<img id="' + marker_id + '" class="trigger-erase artwork-content" data-elem-type="marker" src="' + marker.source + '"/>' +
object_tag
)
$('.trigger-erase').click(eraseModal);
Expand All @@ -65,7 +66,7 @@
}else{
$('#element-download').replaceWith(
'<p id="element-download">' +
'<a id="gif-download" href="'+ element_src +'">Download .gif (' + file_size + ' kb)</a></p>'
'<a id="gif-download" href="'+ element_src +'" download>Download .gif (' + file_size + ' kb)</a></p>'
)
}
}
Expand Down Expand Up @@ -113,25 +114,24 @@
$('#create-artwork').text(
{{ _('Create artwork with this ')|tojson }} + elemType
);
$.ajax({
url: elemUrl,
success: function(data){
elementAuthor(data['author'], data['owner_id']);
elementAuthor(data['author']);
uploadedBy(data['owner'], data['uploaded_at']);
usedIn(data['artworks'], data['exhibits'], data['source'], element_id, elemType);
downloadElement(data['type'], data['size']/1000, data['source']);
usedIn(data['artworks_count'], data['exhibits_count'], data['source'], element_id, elemType);
downloadElement(data['type'], data["source_size"]/1000, data['source']);
}
});
}else{
$('#download').attr('hidden', true)
$.ajax({
url: elemUrl,
success: function(data){
elementAuthor(data['author'], data['owner_id']);
usedInExhibit(data['id_marker'], data['id_object'], data['exhibits'], data['marker'], data['augmented'], element_id);
elementAuthor(data['author'].username);
usedInExhibit(data['id_marker'], data['id_object'], data['exhibits_count'], data['marker'], data['augmented'], element_id);
replaceButtons(data['title'], data['description']);
downloadElement(data['type'], data['augmented_size']/1000, data['augmented']);
downloadElement(data['type'], data['augmented'].source_size/1000, data['augmented'].source);
}
});
}
Expand Down
1 change: 1 addition & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def manage(ctx, cmd):
cmd = f"python3 ./src/manage.py {cmd}"
ctx.run(cmd, pty=True, env=os.environ)


#
# Translations
#
Expand Down

0 comments on commit ec54aa0

Please sign in to comment.