Widget:CJP3: Difference between revisions
Jump to navigation
Jump to search
Created page with "<includeonly> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script type"text/javascript"> $(document).ready(ensureLoggedI..." |
No edit summary |
||
Line 3: | Line 3: | ||
<script type"text/javascript"> | <script type"text/javascript"> | ||
$(document).ready(ensureLoggedIn); | $(document).ready(ensureLoggedIn); | ||
function ensureLoggedIn() { | |||
mw.loader.load('mediaWiki.user'); | |||
if ($.isEmptyObject(wgUserName)) { | |||
alert("Please Log In To Continue."); | |||
window.location.replace("http://www.wikidoc.org/index.php?title=Special:UserLogin&returnto=WikidocBoardReview"); | |||
} else { | |||
alert("You are logged in"); | |||
runQuery(); | |||
} | |||
}; | |||
function runQuery() { | |||
$('#button').click(function() { | |||
var jsonURL = "http://www.wikidoc.org/api.php?action=ask&query=[[Pill%20Shape::Oval]]|?Pill%20Imprint|?Pill%20Dosage|?Pill%20Ingred|?Pill%20Color|?Pill%20Shape|?Pill%20Size%20(mm)|?Pill%20Scoring|?NDC|?Pill%20Name&format=json" | |||
$.getJSON(jsonURL) | |||
.always(function (data) { | |||
$.each(data.query.results, function (index, value) { | |||
//Assign variables the values returned from the function// | |||
var drugNameFull = value.fulltext; | |||
var drugNameShort = drugNameLong.split("#")[0]; | |||
var pillImprint = value.printouts["Pill Imprint"]; | |||
var pillDosage = value.printouts["Pill Dosage"]; | |||
var pillIngred = value.printouts["Pill Ingred"]; | |||
var pillColor = value.printouts["Pill Color"]; | |||
var pillShape = value.printouts["Pill Shape"]; | |||
var pillSize = value.printouts["Pill Size (mm)"]; | |||
var pillScoring = value.printouts["Pill Scoring"]; | |||
var ndc = value.printouts["NDC"]; | |||
var pillName = value.printouts["Pill Name"]; | |||
//Find a <table> element with id="resultsTable-body": | |||
var table = document.getElementById("resultsTable-body"); | |||
//Create an empty <tr> element and add it to the 1st position of the table: | |||
var row = table.insertRow(index); | |||
//Insert new cells(<td> elements) into the "new" <tr> element: | |||
var cellDrugName = row.insertCell(0); | |||
var cellPillImprint = row.insertCell(1); | |||
var cellPillDosage = row.insertCell(2); | |||
var cellPillIngred = row.insertCell(3); | |||
var cellPillColor = row.insertCell(4); | |||
var cellPillShape = row.insertCell(5); | |||
var cellPillSize = row.insertCell(6); | |||
var cellPillSocring = row.insertCell(7); | |||
var cellNDC = row.insertCell(8); | |||
var cellPillName = row.insertCell(9); | |||
//Add Values to the cells: | |||
cellDrugName.innerHTML = drugNameShort ; | |||
cellPillImprint.innerHTML = pillImprint; | |||
cellPillDosage.innerHTML = pillDosage; | |||
cellPillIngred.innerHTML = pillIngred; | |||
cellPillColor.innerHTML = pillColor; | |||
cellPillShape.innerHTML = pillShape; | |||
cellPillSize.innerHTML = pillSize; | |||
cellPillSocring.innerHTML = pillScoring; | |||
cellNDC.innerHTML = ndc; | |||
cellPillName.innerHTML = pillName; | |||
}); | }); | ||
}); | |||
}; | |||
</script> | </script> | ||
<button id="button">Click Me</button> | <button id="button">Click Me</button> | ||
<div id="hideMe" style="width:200px; height:200px; background-color:red;"></div> | <div id="hideMe" style="width:200px; height:200px; background-color:red;"></div> | ||
<div id="resultsTable-container"> | |||
<table id="resultsTable"> | |||
<thead> | |||
<th> | |||
Drug Name | |||
</th> | |||
<th> | |||
Pill Imprint | |||
</th> | |||
<th> | |||
Dosage | |||
</th> | |||
<th> | |||
Ingredients | |||
</th> | |||
<th> | |||
Pill Color | |||
</th> | |||
<th> | |||
Pill Shape | |||
</th> | |||
<th> | |||
Pill Size (mm) | |||
</th> | |||
<th> | |||
Score | |||
</th> | |||
<th> | |||
NDC | |||
</th> | |||
<th> | |||
Pill Image | |||
</th> | |||
</thead> | |||
<tbody id="resultsTable-body"> | |||
</tbody> | |||
</table> | |||
</div> | |||
</includeonly> | </includeonly> |