forked from openwebwork/webwork2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove action scope and add action form validation.
On the UserList, ProblemSetList, and AchievementList managers, remove the scope option that helps determine which items to act on, instead users will always select which items to act on and can use filters to change the list of items to select from. This address openwebwork#1991. In addition add javascript form validation that will inform the user if the form is missing information, such as no items are selected, a text string is not provided, a valid file is not selected, and so on. Last, disable the import tab if no valid files are found to import from.
- Loading branch information
Showing
35 changed files
with
357 additions
and
361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
(() => { | ||
// Action form validation. | ||
const is_achievement_selected = () => { | ||
for (const achievement of document.getElementsByName('selected_achievements')) { | ||
if (achievement.checked) return true; | ||
} | ||
document.getElementById('select_achievement_err_msg')?.classList.remove('d-none'); | ||
document.getElementById('achievement-table')?.addEventListener('change', e => { | ||
document.getElementById('select_achievement_err_msg')?.classList.add('d-none'); | ||
}, { once : true }); | ||
return false; | ||
}; | ||
|
||
document.getElementById('achievement-list')?.addEventListener('submit', e => { | ||
const action = document.getElementById('current_action')?.value || ''; | ||
if (['edit', 'assign', 'export', 'score'].includes(action)) { | ||
if (!is_achievement_selected()) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
} | ||
} else if (action === 'create') { | ||
const create_text = document.getElementById('create_text'); | ||
if (create_text.value === '') { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
document.getElementById('create_file_err_msg')?.classList.remove('d-none'); | ||
create_text.classList.add('is-invalid'); | ||
create_text.addEventListener('change', e => { | ||
document.getElementById('create_file_err_msg')?.classList.add('d-none'); | ||
document.getElementById('create_text')?.classList.remove('is-invalid'); | ||
}, { once : true }); | ||
} else if (document.getElementById('create_select')?.selectedIndex == 1 && !is_achievement_selected()) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
} | ||
} else if (action === 'delete') { | ||
const delete_confirm = document.getElementById('delete_select'); | ||
if (!is_achievement_selected()) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
} else if (delete_confirm.value != 'yes') { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
document.getElementById('delete_confirm_err_msg')?.classList.remove('d-none'); | ||
delete_confirm.classList.add('is-invalid'); | ||
delete_confirm.addEventListener('change', e => { | ||
document.getElementById('delete_select')?.classList.remove('is-invalid'); | ||
document.getElementById('delete_confirm_err_msg')?.classList.add('d-none'); | ||
}, { once : true }); | ||
} | ||
} | ||
}); | ||
|
||
// Remove select error message when changing tabs. | ||
for (const tab of document.querySelectorAll('a[data-bs-toggle="tab"]')) { | ||
tab.addEventListener('shown.bs.tab', e => { | ||
document.getElementById('select_achievement_err_msg')?.classList.add('d-none'); | ||
}, { once : true }); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.