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.
//Written by Abelmoschus Esculentus and DannyS712, modified by Red-tailed hawk
//Date: 25 September 2022
//Modified from [[User:DannyS712/SATG.js]]
//Available under CC-BY-SA 3.0 Unported license and the GFDL
//<nowiki>
function screen3(number) {
  var source = ["placeholder"], ind = ["placeholder"], ind_just = ["placeholder"], rel = ["placeholder"], rel_just = ["placeholder"], sig = ["placeholder"], sig_just = ["placeholder"], sec = ["placeholder"], sec_just = ["placeholder"];
	$('.SATG_CORP-source').each(function () {
		source.push(this.value);
  });
  $('.SATG_CORP-selecti').each(function () {
		ind.push(this.value);
  });
  $('.SATG_CORP-justi').each(function () {
		ind_just.push(this.value);
  });
  $('.SATG_CORP-selectr').each(function () {
		rel.push(this.value);
  });
  $('.SATG_CORP-justr').each(function () {
		rel_just.push(this.value);
  });
  $('.SATG_CORP-selects').each(function () {
		sig.push(this.value);
  });
  $('.SATG_CORP-justs').each(function () {
		sig_just.push(this.value);
  });
  $('.SATG_CORP-select2').each(function () {
		sec.push(this.value);
  });
  $('.SATG_CORP-just2').each(function () {
		sec_just.push(this.value);
  });
  var outstring = "{{ORGCRIT assess table |\n";
  for (var i = 1; i <= number; i++) {
    outstring += "{{ ORGCRIT assess\n";
    outstring += "| source   =     " + source[i] + "\n";
    outstring += "| ind      =     " + ind[i] + "\n";
    outstring += "| ind_just =     " + ind_just[i] + "\n";
    outstring += "| rel      =     " + rel[i] + "\n";
    outstring += "| rel_just =     " + rel_just[i] + "\n";
    outstring += "| sig      =     " + sig[i] + "\n";
    outstring += "| sig_just =     " + sig_just[i] + "\n";
    outstring += "| sec      =     " + sec[i] + "\n";
    outstring += "| sec_just =     " + sec_just[i] + "\n";
    outstring += "}}\n";
  }
  outstring += "}}";
	$("#SATG_CORP-interface-content").css({
      "min-height": "7em",
      "width" : "875px",
      "height" : "400px",
      "overflow-y": "hidden"
    });
	$("#SATG_CORP-interface-content").empty();
	$("#SATG_CORP-interface-content").text('Generating...');
	$('.SATG_CORP-tip').remove();
	$("#SATG_CORP-interface-content").empty();
	$("#SATG_CORP-interface-content").append(
		$('<button>').attr('id','SATG_CORP-copy').text('Copy'),
		$('<label>').attr('id','SATG_CORP-copied').text(''),
		$('<textarea>').css({'resize':'none'}).attr({'id':'SATG_CORP-outstring','readonly':'true','rows':'20','cols':'35'}).text(outstring)
	);
	$('#SATG_CORP-copy').click(function() {
		var copy = document.getElementById("SATG_CORP-outstring");
		copy.select();
		document.execCommand("copy");
		$('#SATG_CORP-copied').text(' Copied to your clipboard!');
	});
}
function screen4(number) {
	if ($("#SATG_CORP-interface-content").text() == "Loading form...") {
        $("#SATG_CORP-interface-content").empty();
    }
    $("#SATG_CORP-interface-footer").append(
    	$('<button>').attr('id', 'SATG_CORP-back').css('margin-left','1em').text('Back')
	);
	$("#SATG_CORP-interface-footer").prepend(
		$('<small>').attr('class','SATG_CORP-tip').text('**Only available for options "Yes", "No", "Partially" and "Unknown"'),
		$('<br>').attr('class','SATG_CORP-tip')
	);
    $('#SATG_CORP-back').click(function () {
        $('#SATG_CORP-back').remove();
        $("#SATG_CORP-interface-content").css({
    		"min-height": "7em",
		    "width" : "875px",
		    "height" : "400px",
		    "overflow-y": "scroll"
	    });
        screen0();
    });
    /*var arr = [
		{val : 1, text: 'Yes'},
		{val : 2, text: 'No'},
		{val : 3, text: 'Partially'},
		{val : 4, text: 'Unknown'},
		{val : 5, text: 'None'}
	];*/
    for (var i = 1; i <= number; i++) {
    	if (i != 1) {
    		$("#SATG_CORP-interface-content").append('<hr>');
    	}
    	$("#SATG_CORP-interface-content").append(
    		$('<div>').css('margin-bottom','0.5em').append(
    			$('<label>').text('Source '+i+': '),
    			$('<input>').attr({'type':'text','class':'SATG_CORP-source'})
        ),
          $('<div>').css('margin-bottom','0.5em').append(
             $('<label>').text('Independent? '),
             $('<select>').attr('class','SATG_CORP-selecti')
            	.append($("<option>").attr('value','y').text('Yes'))
            	.append($("<option>").attr('value','n').text('No'))
            	.append($("<option>").attr('value','-').text('Partially'))
            	.append($("<option>").attr('value','?').text('Unknown'))
            	.append($("<option>").attr({'value':'','selected':'true'}).text('None')),
             $('<label>').text(' **Justification: '),
             $('<input>').attr({'type':'text','class':'SATG_CORP-justi'})
          ),
          $('<div>').css('margin-bottom','0.5em').append(
            $('<label>').text('Reliable? '),
            $('<select>').attr('class','SATG_CORP-selectr')
             .append($("<option>").attr('value','y').text('Yes'))
             .append($("<option>").attr('value','n').text('No'))
             .append($("<option>").attr('value','-').text('Partially'))
             .append($("<option>").attr('value','?').text('Unknown'))
             .append($("<option>").attr({'value':'','selected':'true'}).text('None')),
            $('<label>').text(' **Justification: '),
            $('<input>').attr({'type':'text','class':'SATG_CORP-justr'})
         ),
         $('<div>').css('margin-bottom','0.5em').append(
          $('<label>').attr('id','SATG_CORP-labels-'+i).text('Significant coverage? '),
            $('<select>').attr('class','SATG_CORP-selects')
            .append($("<option>").attr('value','y').text('Yes'))
            .append($("<option>").attr('value','n').text('No'))
            .append($("<option>").attr('value','-').text('Partially'))
            .append($("<option>").attr('value','?').text('Unknown'))
            .append($("<option>").attr({'value':'','selected':'true'}).text('None')),
            $('<label>').text(' **Justification: '),
            $('<input>').attr({'type':'text','class':'SATG_CORP-justs'})
          ),
        $('<div>').css('margin-bottom','0.5em').append(
          $('<label>').attr('id','SATG_CORP-labels-'+i).text('Secondary coverage? '),
            $('<select>').attr('class','SATG_CORP-select2')
            .append($("<option>").attr('value','y').text('Yes'))
            .append($("<option>").attr('value','n').text('No'))
            .append($("<option>").attr('value','-').text('Partially'))
            .append($("<option>").attr('value','?').text('Unknown'))
            .append($("<option>").attr({'value':'','selected':'true'}).text('None')),
            $('<label>').text(' **Justification: '),
            $('<input>').attr({'type':'text','class':'SATG_CORP-just2'})
          )
    	);
    }
    $("#SATG_CORP-interface-content").append(
    	$('<button>').attr('id','SATG_CORP-generate').text('Generate!')
    );
    $('#SATG_CORP-generate').click(function() {
    	screen3(number);
    });
}
function SATG_CORP_init() {
  mw.util.addPortletLink('p-tb', 'javascript:void(0)', 'NCORP Table Generator', 'aca-SATG_CORP', null, null);
  $('#aca-SATG_CORP').on('click', function() {
    $('body').prepend('<div id="SATG_CORP-modal">'+
      '<div id="SATG_CORP-interface">'+
        '<h4 id="SATG_CORP-interface-header"></h4>'+
        '<hr>'+
        '<div id="SATG_CORP-interface-content"></div>'+
        '<hr>'+
        '<div id="SATG_CORP-interface-footer"></div>'+
      '</div>'+
    '</div>');
    $("#SATG_CORP-modal").css({
      "position": "fixed",
      "z-index": "1",
      "left": "0",
      "top": "0",
      "width": "100%",
      "height": "100%",
      "overflow": "hidden",
      "background-color": "rgba(0,0,0,0.4)"
    });
    $("#SATG_CORP-interface").css({
      "background-color": "#e8f0ff",
      "margin": "15% auto",
      "padding": "2px 20px",
      "border": "1px solid #888",
      "width": "80%",
      "max-width": "60em",
      "font-size": "90%"
    });
    $("#SATG_CORP-interface-content").css({
      "min-height": "7em",
      "width" : "875px",
      "height" : "400px",
      "overflow-y": "scroll"
    });
    $("#SATG_CORP-interface-footor").css("min-height", "3em");
    screen0();
  });
}
var screen0 = function() {
  $("#SATG_CORP-interface-header, #SATG_CORP-interface-content, #SATG_CORP-interface-footer").empty();
  $("#SATG_CORP-interface-header").text("Source Assess Table Generator for Corporations");
  $("#SATG_CORP-interface-content").append(
    $('<div>').css('margin-bottom','0.5em').append(
      $('<label>').attr({'for':'SATG_CORP-userinput-label', 'id':'SATG_CORP-userinput-label'}).text('How many sources do you want to assess? '),
      $('<input>').attr({'type':'number', 'name':'SATG_CORP-userinput','id':'SATG_CORP-userinput','min':'1','max':'100','value':'1'}) //set limits
    ),
    $('<div>').css('margin-bottom','0.5em').append(
      $('<button>').attr({'name':'SATG_CORP-userinput-button', 'id':'SATG_CORP-userinput-button'}).text('Load')
    )
  );
  $("#SATG_CORP-interface-footer").append(
    $('<button>').attr('id', 'SATG_CORP-cancel').text('Close')
  );
  $('#SATG_CORP-cancel').click(function() {
    $('#SATG_CORP-modal').remove();
  });
  $('#SATG_CORP-userinput-button').click(function() {
  	var temp = $('#SATG_CORP-userinput').val();
  	if (temp > 100 || temp < 1) {
  		alert('Invalid value');
  	}
  	else {
  		$('#SATG_CORP-interface-content').empty();
  		$('#SATG_CORP-interface-content').text('Loading form...');
  		screen4(temp);
  	}
  });
};
mw.loader.using(['mediawiki.util'], function() {
  SATG_CORP_init();
});
//</nowiki>