Skip to content

Instantly share code, notes, and snippets.

@rickcnagy
Forked from rickcnagy/SaveRecords.js
Last active August 29, 2015 14:00
Show Gist options
  • Save rickcnagy/11099867 to your computer and use it in GitHub Desktop.
Save rickcnagy/11099867 to your computer and use it in GitHub Desktop.
Deletes a specific custom semester from all transcripts - DeleteSemesterFromTranscript.js
//
// DeleteSemesterFromTranscript.js.txt
// Rick Nagy
// 2014-04-19
//
// run via js console
function init() {
stopAsap = false;
$(window).keypress(function(e) {
if (e.which === 3) {
stopAsap = true;
}
});
openRecord($( ".dataTableContentRow" ).eq(getStart() - 1));
}
function getStart() {
var startRow = prompt('Starting row?', '1');
if (startRow === null) quit();
return parseInt(startRow);
}
function nextRecord(row) {
openRecord(row.next());
}
function openRecord(row) {
if (validRow(row)) {
row.children( ":last" ).click();
afterLoad(interactWithRecord, row);
} else {
nextRecord(row);
}
}
function validRow(row) {
return true;
}
function interactWithRecord(row) {
var target = $( "td:contains(First Semester):contains(2012):contains(2013)" );
if (target.length === 0) {
close(row);
} else {
target.eq(-2).click()
$( ".item:contains(Delete custom semester)" ).click()
afterLoad(saveAndClose, row);
}
}
function saveAndClose(row) {
$( "button:contains('Save & Close')" ).click();
afterLoad(nextRecord, row);
}
function close(row) {
$( ".demotedButtonWidget:contains(Close)" ).click();
afterLoad(nextRecord, row);
}
function quit() {
while ($( "*:contains('Close')" ).length > 0) {
$( "*:contains('Close'):last" ).click();
}
throw new Error("Aborted JS");
}
function afterLoad(callback, param) {
if (stopAsap) quit();
else {
var loading = setInterval(function() {
if ($( "*[class^='load']:not('.ribbonSelectorWidget *'):visible" ).length === 0) {
clearInterval(loading);
callback(param);
}
}, 10, param);
}
}
init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment