Langbahn Team – Weltmeisterschaft

User:DannyS712/SATG.js

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
//Date: 12 January 2019
//Copied from [[User:Abelmoschus Esculentus/SATG.js]
//<nowiki>
function screen2(number) {
  var source = ["placeholder"], ind = ["placeholder"], ind_just = ["placeholder"], rel = ["placeholder"], rel_just = ["placeholder"], sig = ["placeholder"], sig_just = ["placeholder"];
	$('.SATG-source').each(function () {
		source.push(this.value);
  });
  $('.SATG-selecti').each(function () {
		ind.push(this.value);
  });
  $('.SATG-justi').each(function () {
		ind_just.push(this.value);
  });
  $('.SATG-selectr').each(function () {
		rel.push(this.value);
  });
  $('.SATG-justr').each(function () {
		rel_just.push(this.value);
  });
  $('.SATG-selects').each(function () {
		sig.push(this.value);
  });
  $('.SATG-justs').each(function () {
		sig_just.push(this.value);
  });
  var output = "{{ source assess table |\n";
  for (var i = 1; i <= number; i++) {
    output += "{{ source assess\n";
    output += "| source   =     " + source[i] + "\n";
    output += "| ind      =     " + ind[i] + "\n";
    output += "| ind_just =     " + ind_just[i] + "\n";
    output += "| rel      =     " + rel[i] + "\n";
    output += "| rel_just =     " + rel_just[i] + "\n";
    output += "| sig      =     " + sig[i] + "\n";
    output += "| sig_just =     " + sig_just[i] + "\n";
    output += "}}\n";
  }
  output += "}}";
	$("#SATG-interface-content").css({
      "min-height": "7em",
      "width" : "875px",
      "height" : "400px",
      "overflow-y": "hidden"
    });
	$("#SATG-interface-content").empty();
	$("#SATG-interface-content").text('Generating...');
	$('.SATG-tip').remove();
	$("#SATG-interface-content").empty();
	$("#SATG-interface-content").append(
		$('<button>').attr('id','SATG-copy').text('Copy'),
		$('<label>').attr('id','SATG-copied').text(''),
		$('<textarea>').css({'resize':'none'}).attr({'id':'SATG-output','readonly':'true','rows':'20','cols':'35'}).text(output)
	);
	$('#SATG-copy').click(function() {
		var copy = document.getElementById("SATG-output");
		copy.select();
		document.execCommand("copy");
		$('#SATG-copied').text(' Copied to your clipboard!');
	});
}
function screen1(number) {
	if ($("#SATG-interface-content").text() == "Loading form...") {
        $("#SATG-interface-content").empty();
    }
    $("#SATG-interface-footer").append(
    	$('<button>').attr('id', 'SATG-back').css('margin-left','1em').text('Back')
	);
	$("#SATG-interface-footer").prepend(
		$('<small>').attr('class','SATG-tip').text('**Only available for options "Yes", "No", "Partially" and "Unknown"'),
		$('<br>').attr('class','SATG-tip')
	);
    $('#SATG-back').click(function () {
        $('#SATG-back').remove();
        $("#SATG-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-interface-content").append('<hr>');
    	}
    	$("#SATG-interface-content").append(
    		$('<div>').css('margin-bottom','0.5em').append(
    			$('<label>').text('Source '+i+': '),
    			$('<input>').attr({'type':'text','class':'SATG-source'})
        ),
          $('<div>').css('margin-bottom','0.5em').append(
             $('<label>').text('Independent? '),
             $('<select>').attr('class','SATG-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-justi'})
          ),
          $('<div>').css('margin-bottom','0.5em').append(
            $('<label>').text('Reliable? '),
            $('<select>').attr('class','SATG-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-justr'})
         ),
         $('<div>').css('margin-bottom','0.5em').append(
          $('<label>').attr('id','SATG-labels-'+i).text('Significant coverage? '),
            $('<select>').attr('class','SATG-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-justs'})
          )
        );
    }
    $("#SATG-interface-content").append(
    	$('<button>').attr('id','SATG-generate').text('Generate!')
    );
    $('#SATG-generate').click(function() {
    	screen2(number);
    });
}
function satg_init() {
  mw.util.addPortletLink('p-tb', 'javascript:void(0)', 'SA Table Generator', 'aca-satg', null, null);
  $('#aca-satg').on('click', function() {
    $('body').prepend('<div id="SATG-modal">'+
      '<div id="SATG-interface">'+
        '<h4 id="SATG-interface-header"></h4>'+
        '<hr>'+
        '<div id="SATG-interface-content"></div>'+
        '<hr>'+
        '<div id="SATG-interface-footer"></div>'+
      '</div>'+
    '</div>');
    $("#SATG-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-interface").css({
      "background-color": "#e8f0ff",
      "margin": "15% auto",
      "padding": "2px 20px",
      "border": "1px solid #888",
      "width": "80%",
      "max-width": "60em",
      "font-size": "90%"
    });
    $("#SATG-interface-content").css({
      "min-height": "7em",
      "width" : "875px",
      "height" : "400px",
      "overflow-y": "scroll"
    });
    $("#SATG-interface-footor").css("min-height", "3em");
    screen0();
  });
}
var screen0 = function() {
  $("#SATG-interface-header, #SATG-interface-content, #SATG-interface-footer").empty();
  $("#SATG-interface-header").text("Source Assess Table Generator");
  $("#SATG-interface-content").append(
    $('<div>').css('margin-bottom','0.5em').append(
      $('<label>').attr({'for':'SATG-userinput-label', 'id':'SATG-userinput-label'}).text('How many sources do you want to assess? '),
      $('<input>').attr({'type':'number', 'name':'SATG-userinput','id':'SATG-userinput','min':'1','max':'100','value':'1'}) //set limits
    ),
    $('<div>').css('margin-bottom','0.5em').append(
      $('<button>').attr({'name':'SATG-userinput-button', 'id':'SATG-userinput-button'}).text('Load')
    )
  );
  $("#SATG-interface-footer").append(
    $('<button>').attr('id', 'SATG-cancel').text('Close')
  );
  $('#SATG-cancel').click(function() {
    $('#SATG-modal').remove();
  });
  $('#SATG-userinput-button').click(function() {
  	var temp = $('#SATG-userinput').val();
  	if (temp > 100 || temp < 1) {
  		alert('Invalid value');
  	}
  	else {
  		$('#SATG-interface-content').empty();
  		$('#SATG-interface-content').text('Loading form...');
  		screen1(temp);
  	}
  });
};
mw.loader.using(['mediawiki.util'], function() {
  satg_init();
});
//</nowiki>