User:Writ Keeper/Scripts/afcDialog.js
$(document).ready(function(){
afcDialogButtonText = "Make a selection";
if($("#afcSubmissionButton").length > 0)
{
$("#afcSubmissionButton").first().append('
');$("#afcOptionA").click(function(){$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first().text("Never mind");afcDialogButtonText ="Never mind";});
$("#afcOptionB").click(function(){$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first().text("Get help");afcDialogButtonText ="Get help";});
$("#afcOptionC").click(function(){$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first().text("Get help");afcDialogButtonText ="Get help";});
$("#afcOptionD").click(function(){$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first().text("Get help");afcDialogButtonText ="Get help";});
$("#afcOptionE").click(function(){$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first().text("Submit");afcDialogButtonText ="Submit";});
$("#afcOptionF").click(function(){$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first().text("Submit");afcDialogButtonText ="Submit";});
$("#afcSubmissionButton, #afcSubmissionButton > a").click(function(){
$( "#afcDialog" ).dialog(
{ buttons: [
{ text: afcDialogButtonText , click: function() {
var checkedInput = $('input[name=afcOptions]:checked');
var apiPath = mw.config.get('wgScriptPath') + "/api.php";
if(checkedInput.length > 0)
{
switch(checkedInput.attr("id"))
{
case "afcOptionB":
var catData={action:"query", prop:"categories", clcategories: "Category:Articles not submitted at AfC", pageids: mw.config.get( 'wgArticleId' ), format: "json"};
$.post(apiPath, catData, function(response)
{
if(typeof response.query.pages[wgArticleId].categories == "undefined")
{
var data = {action: "edit", title: mw.config.get( 'wgPageName' ), summary: "Article not submitted, automatically adding category", minor: "true", appendtext: "\n\n:Category:Articles not submitted at AfC", token: mw.user.tokens.get( 'csrfToken' )};
$.post(apiPath, data, function(){window.open(mw.util.getUrl("WP:Referencing for beginners"), "_self");});
}
else
{
window.open(mw.util.getUrl("WP:Referencing for beginners"), "_self");
}
});
break;
case "afcOptionC":
var catData={action:"query", prop:"categories", clcategories: "Category:Articles not submitted at AfC", pageids: mw.config.get( 'wgArticleId' ), format: "json"};
$.post(apiPath, catData, function(response)
{
if(typeof response.query.pages[wgArticleId].categories == "undefined")
{
var data = {action: "edit", title: mw.config.get( 'wgPageName' ), summary: "\nArticle not submitted, automatically adding category", minor: "true", appendtext: "\n\n:Category:Articles not submitted at AfC", token: mw.user.tokens.get( 'csrfToken' )};
$.post(apiPath, data, function(){window.open(mw.util.getUrl("WP:42"), "_self");});
}
else
{
window.open(mw.util.getUrl("WP:42"), "_self");
}
});
break;
case "afcOptionD":
var catData={action:"query", prop:"categories", clcategories: "Category:Articles not submitted at AfC", pageids: mw.config.get( 'wgArticleId' ), format: "json"};
$.post(apiPath, catData, function(response)
{
if(typeof response.query.pages[wgArticleId].categories == "undefined")
{
var data = {action: "edit", title: mw.config.get( 'wgPageName' ), summary: "\nArticle not submitted, automatically adding category", minor: "true", appendtext: "\n\n:Category:Articles not submitted at AfC", token: mw.user.tokens.get( 'csrfToken' )};
$.post(apiPath, data, function(){window.open(mw.util.getUrl("WP:Teahouse/Questions"), "_self");});
}
else
{
window.open(mw.util.getUrl("WP:Teahouse/Questions"), "_self");
}
});
break;
case "afcOptionE":
case "afcOptionF":
window.open(mw.config.get("wgScript") + "?title="+ mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ) +"&action=edit§ion=new&preload=Template:AFC_submission/Subst&editintro=Template:AFC_submission/Subst/Editintro", "_self");
break;
case "afcOptionA":
default:
alert("Your article has not been submitted.");
$( this ).dialog( "close" );
break;
}
}
return false;
} },
{ text: "Cancel", click: function() {
$( this ).dialog( "close" );
return false;
} }
],
minWidth:500
}
);
return false;
});
}
});