Widget:UserExamQuery: Difference between revisions
Jump to navigation
Jump to search
Matt Pijoan (talk | contribs) No edit summary |
Matt Pijoan (talk | contribs) No edit summary |
||
Line 3: | Line 3: | ||
#metrics{ | #metrics{ | ||
width:80%; | width:80%; | ||
text-align: center; | |||
} | } | ||
.cell{ | .cell{ | ||
width:20%; | width:20%; | ||
text-align: center; | |||
display: inline-block; | display: inline-block; | ||
} | } | ||
Line 14: | Line 16: | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
function ensureLoggedIn() { | function ensureLoggedIn() { | ||
mw.loader.using('mediawiki.user', function () { ; | mw.loader.using('mediawiki.user', function() {; | ||
if ($.isEmptyObject(wgUserName)) { | |||
alert("Please Log In To Continue."); | |||
window.location.replace("http://wikidoc.org/index.php?title=Special:UserLogin&returnto=UserExamQuery"); | |||
} else { | |||
runQuery(); | |||
} | |||
}); | }); | ||
} | } | ||
Line 31: | Line 33: | ||
}) | }) | ||
.always(function (data) { | .always(function (data) { | ||
$.each(data.userExamQuery[0], function(index, value){ | |||
var outstring = ""; | |||
var timeBegin = ""; | |||
var timeEnd = ""; | |||
var scoreString = ""; | |||
if(value.begin != null){ | |||
timeBegin = new Date(value.begin * 1000).toDateString(); | |||
} | |||
if(value.end != null){ | |||
timeEnd = new Date (value.end * 1000).toDateString(); | |||
scoreString = value.score + "%"; | |||
} else { | |||
timeEnd = "Unfinished"; | |||
scoreString = "N/A"; | |||
} | |||
outstring += "<ul><li><span class='cell'>"+value.id+"</span><span class='cell'>"+timeBegin+"</span><span class='cell'>"+scoreString+"</span><span class='cell'>"+timeEnd+"</span><span class='cell'>"+value.type+"</span></li>"; | |||
if($(value.questions).length > 0){ | |||
outstring += "<ul>"; | |||
$.each(value.questions, function(ind, val){ | |||
outstring += "<li>"+val.title+"</li>"; | |||
}); | |||
outstring += "</ul>"; | |||
} | |||
outstring += "</ul>"; | |||
$("#metrics").append(outstring); | |||
}); | |||
}); | }); | ||
} | } |