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 create a modal popup 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, make the import tabs not create a form if no valid files are found to import from.
- Loading branch information
Showing
30 changed files
with
454 additions
and
460 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,47 @@ | ||
(() => { | ||
// Action form validation. | ||
const is_achievement_selected = () => { | ||
const users = document.getElementsByName('selected_achievements'); | ||
for (let i = 0; i < users.length; i++) { | ||
if (users[i].checked) { return true; } | ||
} | ||
return false; | ||
}; | ||
|
||
document.getElementById('achievement-list')?.addEventListener('submit', e => { | ||
const action = document.getElementById('current_action'); | ||
if (['edit', 'assign', 'export', 'score'].includes(action.value)) { | ||
if (!is_achievement_selected()) { | ||
e.preventDefault(); | ||
window.takeActionErrorModal( | ||
action.dataset.errorText, action.dataset.selectText, action.dataset.okayText); | ||
} | ||
} else if (action.value == 'import') { | ||
if (!document.getElementById('import_file_select').value.endsWith('.axp')) { | ||
e.preventDefault(); | ||
window.takeActionErrorModal( | ||
action.dataset.errorText, action.dataset.importText, action.dataset.okayText); | ||
} | ||
} else if (action.value == 'create') { | ||
if (document.getElementById('create_text')?.value == '') { | ||
e.preventDefault(); | ||
window.takeActionErrorModal( | ||
action.dataset.errorText, action.dataset.createText, action.dataset.okayText); | ||
} else if (document.getElementById('create_select')?.selectedIndex == 1 && !is_achievement_selected()) { | ||
e.preventDefault(); | ||
window.takeActionErrorModal( | ||
action.dataset.errorText, action.dataset.selectText, action.dataset.okayText); | ||
} | ||
} else if (action.value == 'delete') { | ||
if (!is_achievement_selected()) { | ||
e.preventDefault(); | ||
window.takeActionErrorModal( | ||
action.dataset.errorText, action.dataset.selectText, action.dataset.okayText); | ||
} else if (document.getElementById('delete_select').value != 'yes') { | ||
e.preventDefault(); | ||
window.takeActionErrorModal( | ||
action.dataset.errorText, action.dataset.deleteText, action.dataset.okayText); | ||
} | ||
} | ||
}); | ||
})(); |
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
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.