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");
            $("#prepend").val("{{TopOfDrugPage}} \n \n {{BlackBoxTemplate|blackBoxWarningTitle=");
} else if ($('#microChapter option:selected').text() === "Adult Indications and Dosage") {
            $("pend").val("|blackBoxWarningBody=");
resetForm();
            $("#append").val("}}");
if ($('#headings option').length == 0) {
            $("#instructions").html("These are some instructions");
addHeading(["FDA-Labeled Indications and Dosage Information (Adults)", "Off-Label Use and Dosage (Adults)"]);
        } else if ($('#microChapter option:selected').text() === "Adult Indications and Dosage") {
                                microChapterData();
            resetForm();
$("#instructions").html("These are some instructions");
            if ($('#headings option').length == 0) {
} else if ($('#headings option:selected').text() === "FDA-Labeled Indications and Dosage Information (Adults)") {
                addHeading(["FDA-Labeled Indications and Dosage Information (Adults)", "Off-Label Use and Dosage (Adults)"]);
alert("Hi");
                microChapterData();
                        $('#headings option:selected').removeAttr('selected').next('option').attr('selected', 'selected');
                $("#instructions").html("These are some instructions");
} else if ($('#headings option:selected').text() === "Off-Label Use and Dosage (Adults)") {
            } else if ($('#headings option:selected').text() === "FDA-Labeled Indications and Dosage Information (Adults)") {
alert("Clear!");
                alert("Hi");
resetForm();
                $('#headings option:selected').removeAttr('selected').next('option').attr('selected', 'selected');
}
            } else if ($('#headings option:selected').text() === "Off-Label Use and Dosage (Adults)") {
} else if ($('#microChapter option:selected').text() === "Contraindications") {
                alert("Clear!");
alert("Passed.");
                resetForm();
}
            }
}
        } else if ($('#microChapter option:selected').text() === "Contraindications") {
function clearHeading() {
            alert("Passed.");
$('#headings option').each(function () {
        }
$(this).remove();
    }
});
    function clearHeading() {
$("#headingDiv").css("visibility", "hidden");
        $('#headings option').each(function () {
}
            $(this).remove();
function addHeading(headings) {
        });
$("#headingDiv").css("visibility", "visible");
        $("#headingDiv").css("visibility", "hidden");
$.each(headings, function (key, value) {
    }
$('#headings').append("<option>" + value + "</option>");
    function addHeading(headings) {
});
        $("#headingDiv").css("visibility", "visible");
}
        $.each(headings, function (key, value) {
function resetForm() {
            $('#headings').append("<option>" + value + "</option>");
$("#instructions").html(" ");
        });
$("#chapterContent").val(" ");
    }
$("#chapterContent2").val(" ");
    function resetForm() {
$("#prepend").val(" ");
        $("#instructions").html(" ");
$("#pend").val(" ");
        $("#chapterContent").val(" ");
$("#append").val(" ");
        $("#chapterContent2").val(" ");
$("#chapterContent2").css("visibility", "hidden");
        $("#prepend").val(" ");
$("#headingDiv").css("visibility", "hidden");
        $("#pend").val(" ");
}
        $("#append").val(" ");
        $("#chapterContent2").css("visibility", "hidden");
        $("#headingDiv").css("visibility", "hidden");
    }
}
}
$(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:28, 20 March 2014