Widget:CJP: Difference between revisions

Jump to navigation Jump to search
Christopher Popma (talk | contribs)
No edit summary
Christopher Popma (talk | contribs)
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');
    mw.loader.load('mediaWiki.user');
if ($.isEmptyObject(wgUserName)) {
    if ($.isEmptyObject(wgUserName)) {
alert("Please Log In To Continue.");
        alert("Please Log In To Continue.");
window.location.replace("http://wikidoc.org/index.php?title=Special:UserLogin&returnto=LabelEditor");
        window.location.replace("http://wikidoc.org/index.php?title=Special:UserLogin&returnto=LabelEditor");
} else {
    } else {
createMicrochapter();
        createMicrochapter();
}
    }
}
}


function createMicrochapter() {
function createMicrochapter() {
$("#executeGo").click(function () {
    $("#executeGo").click(function () {
microChapterData();
        microChapterData();
});
    });
function createPage() {
    function createPage() {
var chapterText = $("#chapterContent").val();
        var chapterText = $("#chapterContent").val();
var api = new mw.Api();
        var api = new mw.Api();
api.post({
        api.post({
action : 'edit',
            action : 'edit',
token : mw.user.tokens.get('editToken'),
            token : mw.user.tokens.get('editToken'),
text : chapterText,
            text : chapterText,
title : $("#drugName").val() + "/" + $("#microChapter").val(),
            title : $("#drugName").val() + "/" + $("#microChapter").val(),
format : 'json'
            format : 'json'
})
        })
.always(function (data) {
        .always(function (data) {
alert("Great success?");
            alert("Great success?");
$('option:selected', 'select').removeAttr('selected').next('option').attr('selected', 'selected');
            $('option:selected', 'select').removeAttr('selected').next('option').attr('selected', 'selected');
microChapterData();
            microChapterData();
});
        });
}
    }
function createSection() {
    function createSection() {
var chapterText = $("#chapterContent").val();
        var chapterText = $("#chapterContent").val();
var api = new mw.Api();
        var api = new mw.Api();
api.post({
        api.post({
action : 'edit',
            action : 'edit',
token : mw.user.tokens.get('editToken'),
            token : mw.user.tokens.get('editToken'),
text : chapterText,
            text : chapterText,
title : $("#drugName").val() + "/" + $("#microChapter").val(),
            title : $("#drugName").val() + "/" + $("#microChapter").val(),
format : 'json'
            format : 'json'
})
        })
.always(function (data) {
        .always(function (data) {
alert("Great success?");
            alert("Great success?");
$('#microChapter option:selected').removeAttr('selected').next('option').attr('selected', 'selected');
            $('#microChapter option:selected').removeAttr('selected').next('option').attr('selected', 'selected');
microChapterData();
            microChapterData();
});
        });
}
    }
function microChapterData(){
    function microChapterData() {


if ($('#microChapter option:selected').text() === "Black Box Warning") {
        if ($('#microChapter option:selected').text() === "Black Box Warning") {
resetForm();
            resetForm();
$("#chapterContent2").css("visibility", "visible");
            $("#chapterContent2").css("visibility", "visible");
} else if ($('#microChapter option:selected').text() === "Adult Indications and Dosage") {
            $("#prepend").val("{{TopOfDrugPage}} \n \n {{BlackBoxTemplate|blackBoxWarningTitle=");
resetForm();
            $("pend").val("|blackBoxWarningBody=");
if ($('#headings option').length == 0) {
            $("#append").val("}}");
addHeading(["FDA-Labeled Indications and Dosage Information (Adults)", "Off-Label Use and Dosage (Adults)"]);
            $("#instructions").html("These are some instructions");
                                microChapterData();
        } else if ($('#microChapter option:selected').text() === "Adult Indications and Dosage") {
$("#instructions").html("These are some instructions");
            resetForm();
} else if ($('#headings option:selected').text() === "FDA-Labeled Indications and Dosage Information (Adults)") {
            if ($('#headings option').length == 0) {
alert("Hi");
                addHeading(["FDA-Labeled Indications and Dosage Information (Adults)", "Off-Label Use and Dosage (Adults)"]);
                        $('#headings option:selected').removeAttr('selected').next('option').attr('selected', 'selected');
                microChapterData();
} else if ($('#headings option:selected').text() === "Off-Label Use and Dosage (Adults)") {
                $("#instructions").html("These are some instructions");
alert("Clear!");
            } else if ($('#headings option:selected').text() === "FDA-Labeled Indications and Dosage Information (Adults)") {
resetForm();
                alert("Hi");
}
                $('#headings option:selected').removeAttr('selected').next('option').attr('selected', 'selected');
} else if ($('#microChapter option:selected').text() === "Contraindications") {
            } else if ($('#headings option:selected').text() === "Off-Label Use and Dosage (Adults)") {
alert("Passed.");
                alert("Clear!");
}
                resetForm();
}
            }
function clearHeading() {
        } else if ($('#microChapter option:selected').text() === "Contraindications") {
$('#headings option').each(function () {
            alert("Passed.");
$(this).remove();
        }
});
    }
$("#headingDiv").css("visibility", "hidden");
    function clearHeading() {
}
        $('#headings option').each(function () {
function addHeading(headings) {
            $(this).remove();
$("#headingDiv").css("visibility", "visible");
        });
$.each(headings, function (key, value) {
        $("#headingDiv").css("visibility", "hidden");
$('#headings').append("<option>" + value + "</option>");
    }
});
    function addHeading(headings) {
}
        $("#headingDiv").css("visibility", "visible");
function resetForm() {
        $.each(headings, function (key, value) {
$("#instructions").html(" ");
            $('#headings').append("<option>" + value + "</option>");
$("#chapterContent").val(" ");
        });
$("#chapterContent2").val(" ");
    }
$("#prepend").val(" ");
    function resetForm() {
$("#pend").val(" ");
        $("#instructions").html(" ");
$("#append").val(" ");
        $("#chapterContent").val(" ");
$("#chapterContent2").css("visibility", "hidden");
        $("#chapterContent2").val(" ");
$("#headingDiv").css("visibility", "hidden");
        $("#prepend").val(" ");
}
        $("#pend").val(" ");
        $("#append").val(" ");
        $("#chapterContent2").css("visibility", "hidden");
        $("#headingDiv").css("visibility", "hidden");
    }
    function contentView() {
        alert($("#prepend").val() + " " + $("#chapterContent").val());
    }
}
}
$(document).ready(ensureLoggedIn);
$(document).ready(ensureLoggedIn);
</script>
< / script >
Page Title: <input type="text" id="drugName" /><br />
Page Title: <input type="text" id="drugName" /><br />
<div id="instructions">
<div id="instructions">

Revision as of 19:30, 20 March 2014