Jump to content

User:Theleekycauldron/Scripts/PSHAW/protocols/nomination rejecter.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*<nowiki>
Copyright (c) 2023 theleekycauldron

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
$.when(
	mw.loader.using('ext.gadget.morebits'),
	$.ready
).then(async function() {
	if (mw.config.get('wgPageName').includes("Template:Did_you_know_nominations/")) {
		$(mw.util.addPortletLink(window.DYKH_portlet || 'p-cactions', '#', 'Reject (PSHAW)', 'dyk-portlet', 'Close nomination')).click(reject);
	}
});

reject = async function (e) {
	nomination = await Nomination.create(mw.config.get('wgPageName'));
	if (nomination.isHatted){
		alert("Have some mercy, it's already closed!");
		return;
	}
	if (nomination.hasBeenEditedByUser()){
		alert("Looks like you've edited this nompage before. Make sure you're not an \"involved user\" before proceeding with a close; if you've nominated or edited the article, reviewed the nomination, or wrote the hook you're about to promote, you are most likely involved.");
	}
	e.preventDefault();
	var Window = new Morebits.simpleWindow(500, 400);
	Window.setTitle("The prep set's half-assed workbench (PSHAW)");
	Window.addFooterLink("DYK promoter's rules", "Wikipedia:Did you know/Prep builder instructions");
	var form = new Morebits.quickForm();
	
	let result;
	function show(){
		result = form.render();
		Window.setContent(result);
		Window.display();
	}
	form.append({name:'header1',type:'div',label:'<b>Mark nomination as:</b>'})
	form.append({name:'type',type:'select',list:[{type:'option',name:'rejected',label:'rejected',value:'no',selected:true},
												 {type:'option',name:'withdrawn',label:'withdrawn',value:'withdrawn'}]
			   });
	form.append({type: 'button', name: 'submit', label: "submit!", event: () => evaluate(e,result)})
	
	evaluate = async function(e,result){
		console.log(result)
		form.root.childs = [];
		
		nomination.hat(result.type.value)
		
		form.append({type: 'div', name: 'closing', label: 'Closing nomination ... '})
		console.log(nomination.content)
		nomination.save(`Closing as ${result.type.value=="no"?"rejected":result.type.value}`).done(function(data){
			console.log(data)
			form.root.childs[0].data.label += 'done! :)';
			show();
			location.reload(true);
		});
	}
	show();
}