Widget:CJP: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
<includeonly> | <includeonly> | ||
< script type = "text/javascript" > | <script type="text/javascript"> | ||
function ensureLoggedIn() { | function ensureLoggedIn() { | ||
mw.loader.load('mediaWiki.user'); | |||
if ($.isEmptyObject(wgUserName)) { | |||
alert("Please Log In To Continue."); | |||
window.location.replace("http://wikidoc.org/index.php?title=Special:UserLogin&returnto=LabelEditor"); | |||
} else { | |||
createMicrochapter(); | |||
} | |||
} | } | ||
function createMicrochapter() { | function createMicrochapter() { | ||
$("#executeGo").click(function () { | |||
microChapterData(); | |||
}); | |||
function createPage() { | |||
var chapterText = $("#chapterContent").val(); | |||
var api = new mw.Api(); | |||
api.post({ | |||
action : 'edit', | |||
token : mw.user.tokens.get('editToken'), | |||
text : chapterText, | |||
title : $("#drugName").val() + "/" + $("#microChapter").val(), | |||
format : 'json' | |||
}) | |||
.always(function (data) { | |||
alert("Great success?"); | |||
$('option:selected', 'select').removeAttr('selected').next('option').attr('selected', 'selected'); | |||
microChapterData(); | |||
}); | |||
} | |||
function createSection() { | |||
var chapterText = $("#chapterContent").val(); | |||
var api = new mw.Api(); | |||
api.post({ | |||
action : 'edit', | |||
token : mw.user.tokens.get('editToken'), | |||
text : chapterText, | |||
title : $("#drugName").val() + "/" + $("#microChapter").val(), | |||
format : 'json' | |||
}) | |||
.always(function (data) { | |||
alert("Great success?"); | |||
$('#microChapter option:selected').removeAttr('selected').next('option').attr('selected', 'selected'); | |||
microChapterData(); | |||
}); | |||
} | |||
function microChapterData(){ | |||
if ($('#microChapter option:selected').text() === "Black Box Warning") { | |||
resetForm(); | |||
$("#chapterContent2").css("visibility", "visible"); | |||
} else if ($('#microChapter option:selected').text() === "Adult Indications and Dosage") { | |||
resetForm(); | |||
if ($('#headings option').length == 0) { | |||
addHeading(["FDA-Labeled Indications and Dosage Information (Adults)", "Off-Label Use and Dosage (Adults)"]); | |||
microChapterData(); | |||
$("#instructions").html("These are some instructions"); | |||
} else if ($('#headings option:selected').text() === "FDA-Labeled Indications and Dosage Information (Adults)") { | |||
alert("Hi"); | |||
$('#headings option:selected').removeAttr('selected').next('option').attr('selected', 'selected'); | |||
} else if ($('#headings option:selected').text() === "Off-Label Use and Dosage (Adults)") { | |||
alert("Clear!"); | |||
resetForm(); | |||
} | |||
} else if ($('#microChapter option:selected').text() === "Contraindications") { | |||
alert("Passed."); | |||
} | |||
} | |||
function clearHeading() { | |||
$('#headings option').each(function () { | |||
$(this).remove(); | |||
}); | |||
$("#headingDiv").css("visibility", "hidden"); | |||
} | |||
function addHeading(headings) { | |||
$("#headingDiv").css("visibility", "visible"); | |||
$.each(headings, function (key, value) { | |||
$('#headings').append("<option>" + value + "</option>"); | |||
}); | |||
} | |||
function resetForm() { | |||
$("#instructions").html(" "); | |||
$("#chapterContent").val(" "); | |||
$("#chapterContent2").val(" "); | |||
$("#prepend").val(" "); | |||
$("#pend").val(" "); | |||
$("#append").val(" "); | |||
$("#chapterContent2").css("visibility", "hidden"); | |||
$("#headingDiv").css("visibility", "hidden"); | |||
} | |||
} | } | ||
$(document).ready(ensureLoggedIn); | $(document).ready(ensureLoggedIn); | ||
< | </script> | ||
Page Title: <input type="text" id="drugName" /><br /> | Page Title: <input type="text" id="drugName" /><br /> | ||
<div id="instructions"> | <div id="instructions"> |