Last active
August 29, 2015 13:57
-
-
Save rickcnagy/9399339 to your computer and use it in GitHub Desktop.
Open and save every gradebook in the Gradebook module. Useful for recalculating formulas when the gradebook data have somehow changed.
This file contains hidden or 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
// | |
// SaveAllGradebooks.js | |
// Rick Nagy | |
// 2014-03-06 | |
// | |
// run via js console | |
currentTeacher = 0; | |
currentSection = 0; | |
function nextTeacher() { | |
findElements(); | |
if (currentTeacher >= teacherDropdown.prop("length")) { | |
throw new Error("All done!"); | |
} else { | |
teacherDropdown.prop("selectedIndex", currentTeacher); | |
teacherDropdown.change(); | |
afterLoad(function() { | |
currentSection = 0; | |
currentTeacher++; | |
nextSection(); | |
}); | |
} | |
} | |
function nextSection() { | |
editAnyways(); | |
findElements(); | |
if (currentSection >= sectionDropdown.prop("length")) { | |
nextTeacher(); | |
} else { | |
sectionDropdown.prop("selectedIndex", currentSection); | |
sectionDropdown.change(); | |
afterLoad(function() { | |
currentSection++; | |
save(nextSection); | |
}); | |
} | |
} | |
// for when editing from a nonactive semester | |
function editAnyways() { | |
if ($(".linkWidget").first().prop("innerText") === "Edit it anyways.") { | |
$(".linkWidget").first().click(); | |
} | |
} | |
function findElements() { | |
teacherDropdown = $(".dropDownWidget").first().children() | |
sectionDropdown = $(".dropDownWidget").last().children() | |
saveButton = document.getElementsByClassName("emphasizedButtonWidget allButtons")[0] | |
} | |
function save(callback) { | |
findElements(); | |
saveButton.click(); | |
if (callback !== undefined) { | |
afterLoad(function() { | |
callback(); | |
}); | |
} | |
} | |
function afterLoad(callback) { | |
var waitingForLoad = setInterval(function() { | |
if (!isLoading()) { | |
clearInterval(waitingForLoad); | |
callback(); | |
} | |
}, 100, callback); | |
} | |
function isLoading() { | |
if (document.getElementsByClassName('loadingWidget').length !== 0 | |
|| document.getElementsByClassName('loadingMessage centerText').length !== 0) { | |
return true; | |
} else return false; | |
} | |
nextTeacher(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment