Skip to content

Instantly share code, notes, and snippets.

@BriceShatzer
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BriceShatzer/9654902 to your computer and use it in GitHub Desktop.
Save BriceShatzer/9654902 to your computer and use it in GitHub Desktop.
START Group Instructor Portal | Snippets
/* ----- building JSON objects out of training modules ----- */
// step 1 - add jQuery
var jq = document.createElement('script');
jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
//step 2 - add some handles
$('#subrightcol>div div').eq(2).attr('id', 'left');
$('#subrightcol>div div.training_completedInfo').attr('id', 'right');
//step 3 - build an array of objects
var array = [];
$('#left table td a').each(function(){
var obj = {};
obj.link = $(this).attr('href');
obj.title= $(this).text();
array.push(obj);
});
$('#right table tr').each(function(index){
var obj = array[index];
obj.completedValue_ID = $(this).find('input[type="checkbox"]').attr('id');
//obj.completedValue = $(this).find('input[type="checkbox"]').val();
obj.completedDate_ID = $(this).find('input[type="text"]').attr('id');
//obj.completedDate = $(this).find('input[type="text"]').val();
});
//step 4 - print to console
console.log( JSON.stringify(array))
/* ----- Instructor Training Modules ----- */
var modules = [
{
"name": "The TURK",
"url": "/classes-1/the_turk",
"completedValue_id": "CAT_Custom_377179_125506",
"completedDate_id": "CAT_Custom_377368_125506"
}, {
"name": "AED Plus Trainer2",
"url": "/classes-1/AED_Plus_Trainer2",
"completedValue_id": "CAT_Custom_377180_125506",
"completedDate_id": "CAT_Custom_377369_125506"
}, {
"name": "ArcelorMittal Riverdale Safety Handbook",
"url": "/classes-1/ArcelorMittal_Riverdale_Safety_Handbook",
"completedValue_id": "CAT_Custom_377181_125506",
"completedDate_id": "CAT_Custom_377370_125506"
}, {
"name": "Galaxy Automated Test System",
"url": "/classes-1/GalaxyAutomatedTestSystem",
"completedValue_id": "CAT_Custom_377261_125506",
"completedDate_id": "CAT_Custom_377371_125506"
}, {
"name": "Altair 4",
"url": "/classes-1/altair-4",
"completedValue_id": "CAT_Custom_430725_125506",
"completedDate_id": "CAT_Custom_430726_125506"
}, {
"name": "Altair 4X",
"url": "/classes-1/altair-4x",
"completedValue_id": "CAT_Custom_430727_125506",
"completedDate_id": "CAT_Custom_430728_125506"
}, {
"name": "Altair 5X",
"url": "/classes-1/altair-5x",
"completedValue_id": "CAT_Custom_430729_125506",
"completedDate_id": "CAT_Custom_430730_125506"
}, {
"name": "ArcelorMittal Contractor Safety Orientation",
"url": "/classes-1/arcelormittal-contractor-safety-orientation",
"completedValue_id": "CAT_Custom_438665_125506",
"completedDate_id": "CAT_Custom_438666_125506"
}, {
"name": "Hazard Communication Standard Training",
"url": "/classes-1/Hazard_Communication_Standard_Training",
"completedValue_id": "CAT_Custom_445369_125506",
"completedDate_id": "CAT_Custom_445370_125506"
}, {
"name": "iNet Ventis MX4 Multi-Gas Monitor",
"url": "/classes-1/inet-ventis-mx4-multi-gas-monitor",
"completedValue_id": "CAT_Custom_460522_125506",
"completedDate_id": "CAT_Custom_460523_125506"
}, {
"name": "The Importance of Bump Testing",
"url": "/classes-1/the-importance-of-bump-testing",
"completedValue_id": "CAT_Custom_460525_125506",
"completedDate_id": "CAT_Custom_460526_125506"
}, {
"name": "Lead's Role in Creating a Safety Culture",
"url": "/classes-1/leads-role-in-creating-a-safety-culture",
"completedValue_id": "CAT_Custom_471714_125506",
"completedDate_id": "CAT_Custom_471715_125506"
}, {
"name": "Technical Rescue Hand Signals",
"url": "/classes-1/technical-rescue-hand-signals",
"completedValue_id": "CAT_Custom_471722_125506",
"completedDate_id": "CAT_Custom_471723_125506"
}, {
"name": "Hearing Protection",
"url": "/classes-1/hearing-protection",
"completedValue_id": "CAT_Custom_485025_125506",
"completedDate_id": "CAT_Custom_485026_125506"
}, {
"name": "Firefighting Precautions at Facilities with Combustible Dust",
"url": "/classes-1/firefighting-precautions-at-facilities-with-combustible",
"completedValue_id": "CAT_Custom_490867_125506",
"completedDate_id": "CAT_Custom_490868_125506"
}, {
"name": "Aux Sable Safety Manual",
"url": "/classes-1/aux-sable-sable",
"completedValue_id": "CAT_Custom_494231_125506",
"completedDate_id": "CAT_Custom_494232_125506"
}, {
"name": "HIRA - Take 5 Program",
"url": "/classes-1/hira-take-5-program",
"completedValue_id": "CAT_Custom_511886_125506",
"completedDate_id": "CAT_Custom_511888_125506"
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment