Skip to content

Instantly share code, notes, and snippets.

@rickcnagy
Forked from rickcnagy/SaveRecords.js
Last active August 29, 2015 13:57
Show Gist options
  • Save rickcnagy/9902200 to your computer and use it in GitHub Desktop.
Save rickcnagy/9902200 to your computer and use it in GitHub Desktop.
Copies values from one Zeus Report Card identifier to another. Relies on all report cards using the "For Identifier Value Copying" template.
//
// CopyZeusValues.js
// Rick Nagy
// 2014-03-31
//
// 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 (stopAsap) quit();
if (validRow(row)) {
row.children(":last").click();
afterLoad(interactWithRecord, row);
} else {
nextRecord(row);
}
}
function validRow(row) {
return true;
}
function interactWithRecord(row) {
var old = $( "div:contains('Old identifier:'):last + *" ).text()
$( "div:contains('New identifier:'):last + *" ).text(old).blur()
saveAndClose(row);
}
function saveAndClose(row) {
$( "button:contains('Save & 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) {
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