Skip to content

Commit

Permalink
Update sync page to use JSON instead of Form
Browse files Browse the repository at this point in the history
Submit new syncs with application/json instead of form encoding. #311
  • Loading branch information
CollinHeist committed Mar 22, 2023
1 parent 13c0a58 commit 58a9b02
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 35 deletions.
41 changes: 11 additions & 30 deletions app/templates/series.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,6 @@
overflow-wrap: break-word;
}

/* Set width of text input fields to 300px */
/* .inline.field >* input[type="text"] {
width: 300px !important;
} */

/* .config-label {
flex: 0 0 150px;
display: flex;
margin-right: 10px;
justify-content: flex-end;
text-align: right;
font-weight: bold;
color: var(--font-color);
} */

/* Add top padding above the delete button for each episode */
.tab[data-tab="episode-data"] .negative.button {
margin-top: 5px;
Expand All @@ -60,23 +45,14 @@
#new-episode-modal {
width: 500px !important;
}

/* Use right-aligned inline labels */
#new-episode-form label {
flex: 0 0 125px;
display: flex;
margin-right: 10px;
justify-content: flex-end;
text-align: right;
}

/* .disabled.config-label {
color: var(--font-color-disabled);
font-weight: lighter;
}

div.dropdown {
min-width: 500px;
} */
</style>

<!-- Templates -->
Expand Down Expand Up @@ -257,7 +233,6 @@

async function initAll() {
getEpisodeDataSources();
// getImageSources();
getLibraries();
getEpisodeData();
}
Expand All @@ -274,6 +249,7 @@
class: 'error',
title: 'Error Refreshing Data',
message: response.responseJSON.detail,
displayTime: 0,
});
}
});
Expand All @@ -283,11 +259,16 @@
$.ajax({
type: 'POST',
url: '/api/series/{{series.id}}/create-cards',
success: function(response) {
$.toast({class: 'blue info', title: `Created Missing Cards`});
success: (response) => {
$.toast({class: 'blue info', title: `Created title cards`});
getEpisodeData();
}, error: function(response) {
$.toast({class: 'error', title: 'Error Creating Cards'});
}, error: (response) => {
$.toast({
class: 'error',
title: 'Error creating title cards',
message: response.responseJSON.detail,
displayTime: 0,
});
}
});
}
Expand Down
15 changes: 10 additions & 5 deletions app/templates/sync.html
Original file line number Diff line number Diff line change
Expand Up @@ -672,17 +672,22 @@ <h4 class="ui horizontal divider header" title="Elements to Exclude from this sy
syncData.forEach(({interface, formID, modalID}) => {
$(`#${formID}`).on('submit', (event) => {
event.preventDefault();
// Turn form into object, turning multi selects into arrays
let form = new FormData(event.target);
let dataObj = {};
for (let [name, value] of [...form.entries()]) {
if (value === '') { form.delete(name); }
if (name.includes('_tags') || name.includes('_libraries')) {
dataObj[name] = value.split(',');
} else if (value !== '') {
dataObj[name] = value;
}
}
// Submit API request to add this sync
$.ajax({
type: 'POST',
url: `/api/sync/${interface}/new`,
data: form,
processData: false,
contentType: false,
data: JSON.stringify(dataObj),
contentType: "application/json",
success: (response) => {
$.toast({
class: 'blue info',
Expand All @@ -694,7 +699,7 @@ <h4 class="ui horizontal divider header" title="Elements to Exclude from this sy
$.toast({
class: 'error',
title: 'Error Creating Sync',
message: 'Ensure the sync name is valid',
message: response.responseJSON.detail,
});
}, complete: () => {}
});
Expand Down

0 comments on commit 58a9b02

Please sign in to comment.