Skip to content

Commit

Permalink
refactor: use 'url_for' in JS scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Feb 20, 2024
1 parent acd1cee commit 5262229
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
3 changes: 2 additions & 1 deletion web/b3desk/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,10 @@ def edit_meeting_files(meeting_id):
return redirect(url_for("routes.welcome"))


@bp.route("/meeting/files/<int:meeting_id>/")
@bp.route("/meeting/files/<int:meeting_id>/<int:file_id>")
@auth.oidc_auth("default")
def download_meeting_files(meeting_id, file_id):
def download_meeting_files(meeting_id, file_id=None):
user = get_current_user()
meeting = db.session.get(Meeting, meeting_id)

Expand Down
4 changes: 2 additions & 2 deletions web/b3desk/templates/meeting/externalUpload.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
const nc_locator = "{{ user.nc_locator }}";
const nc_login = "{{ user.nc_login }}";
const nc_token = "{{ user.nc_token }}";
const meeting_id = "{{ meeting.id }}";
const insert_documents_url = "{{ url_for("routes.insertDocuments", meeting_id=meeting_id) }}";

function createNCFilePicker() {
let ncPickerParams = {
Expand All @@ -32,7 +32,7 @@
var csrf_token = document.getElementsByName("csrf_token")[0].value
var post_data = e.detail.selection.map(name => name.slice(1))
JSON.stringify(post_data);
fetch('/meeting/files/'+meeting_id+'/insertDocuments', {
fetch(insert_documents_url, {
method: 'POST',
headers: {
'Accept': 'application/json',
Expand Down
2 changes: 1 addition & 1 deletion web/b3desk/templates/meeting/files.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ <h1 id="delete-file-{{ file.id }}-title" class="fr-modal__title">
<button data-fr-opened="false" aria-controls="delete-file-{{file.id}}" class="fr-btn fr-fi-delete-line" title="Supprimer"></button>
</td>
<td>
<a href="{{ config.get("SERVER_FQDN") }}/meeting/files/{{ meeting.id }}/{{ file.id }}">
<a href="{{ url_for("routes.download_meeting_files", meeting_id=meeting.id, file_id=file.id, _external=True) }}">
<button class="fr-btn fr-icon-download-fill" title="Télécharger"></button>
</a>
</td>
Expand Down
23 changes: 11 additions & 12 deletions web/b3desk/templates/meeting/js_script.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
let newValue = e.target.checked;
let csrf_token = document.getElementsByName("csrf_token")[0].value;

fetch('/meeting/files/'+meeting_id+'/toggledownload', {
fetch(toggle_download_url, {
method: 'POST',
headers: {
'Accept': 'application/json',
Expand All @@ -43,11 +43,10 @@
}

function submitDefaultFile(e){

let csrf_token = document.getElementsByName("csrf_token")[0].value;
let idFileSelected = e.target.id.split('-').slice(-1);

fetch('/meeting/files/'+meeting_id+'/default', {
fetch(set_default_file_url, {
method: 'POST',
headers: {
'Accept': 'application/json',
Expand All @@ -72,8 +71,7 @@

let csrf_token = document.getElementsByName("csrf_token")[0].value;
let idFileSelected = e.target[0].value;

fetch('/meeting/files/delete', {
fetch(delete_meeting_file, {
method: 'POST',
headers: {
'Accept': 'application/json',
Expand Down Expand Up @@ -115,7 +113,6 @@
}

function append_file_to_fileslist(title, id, date, isDefault) {

var nofileavailable = document.getElementById('nofileavailable');
if (nofileavailable) {
nofileavailable.parentNode.removeChild(nofileavailable);
Expand Down Expand Up @@ -149,7 +146,7 @@

buttonLink.classList.add('fr-btn','fr-icon-download-fill');
buttonLink.setAttribute('title', 'Télécharger');
aLink.setAttribute('href', fqdn+'/meeting/files/'+meeting_id+'/'+id);
aLink.setAttribute('href', download_meeting_file_url + id);
aLink.appendChild(buttonLink);
tdDownload.appendChild(aLink);
inputIsDl.classList.add('fr-toggle__input');
Expand Down Expand Up @@ -235,7 +232,7 @@
input.setAttribute('type', 'hidden');
input.setAttribute('name', 'id');
input.setAttribute('value', id);
form.setAttribute('action', '/meeting/files/delete');
form.setAttribute('action', delete_meeting_file);
form.setAttribute('method', 'POST');
form.setAttribute('onsubmit', 'deleteFile(event)');

Expand All @@ -261,13 +258,11 @@
}

function append_file_to_default_fileslist(title, id) {

let selectDefault = document.getElementById('defaultFileSelector');
let option = document.createElement('option');
option.setAttribute('value', id);
option.innerHTML = title;
selectDefault.appendChild(option);

}

//
Expand Down Expand Up @@ -320,7 +315,7 @@
'from': from,
};
JSON.stringify(post_data);
fetch('/meeting/files/'+meeting_id, {
fetch(edit_meeting_files_url, {
method: 'POST',
headers: {
'Accept': 'application/json',
Expand Down Expand Up @@ -389,7 +384,11 @@
const nc_login = "{{ user.nc_login }}";
const nc_token = "{{ user.nc_token }}";
const meeting_id = "{{ meeting.id }}";
const fqdn = "{{ config.get("SERVER_FQDN") }}";
const toggle_download_url = "{{ url_for("routes.toggledownload", meeting_id=meeting.id) }}";
const set_default_file_url = "{{ url_for("routes.set_meeting_default_file", meeting_id=meeting.id) }}";
const download_meeting_file_url = "{{ url_for("routes.download_meeting_files", meeting_id=meeting.id, _external=True) }}";
const edit_meeting_files_url = "{{ url_for("routes.edit_meeting_files", meeting_id=meeting.id) }}";
const delete_file_url = "{{ url_for("routes.delete_meeting_file") }}";
let ncfilepicker = null;

if (!nc_locator || !nc_login || !nc_token) {
Expand Down

0 comments on commit 5262229

Please sign in to comment.