MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus smw-dev03
Wechseln zu:Navigation, Suche
(Die Seite wurde neu angelegt: „→‎Das folgende JavaScript wird für alle Benutzer geladen.: document.addEventListener("DOMContentLoaded", function() { const form = document.querySelector("form[action*='Special:FormEdit']"); const input = form.querySelector("input[type='text']"); const warning = document.getElementById("gutachten-warning"); form.addEventListener("submit", function(e) { e.preventDefault(); const pageName = input.value.trim(); if (!pageName) retur…“)
 
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
/* Das folgende JavaScript wird für alle Benutzer geladen. */
$(document).ready(function() {
document.addEventListener("DOMContentLoaded", function() {
  const form = document.querySelector("form[action*='Special:FormEdit']");
  const input = form.querySelector("input[type='text']");
  const warning = document.getElementById("gutachten-warning");
 
  form.addEventListener("submit", function(e) {
    e.preventDefault();
    const pageName = input.value.trim();
    if (!pageName) return;


    fetch(mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&titles=' + encodeURIComponent(pageName) + '&format=json')
  // Only run on Special:Mit_Formular_bearbeiten
    .then(response => response.json())
  if (mw.config.get('wgCanonicalSpecialPageName') === 'FormEdit') {
    .then(data => {
      const pages = data.query.pages;
      const pageExists = !pages["-1"];


      if (pageExists) {
    const urlParts = window.location.pathname.split('/');
        // redirect to edit existing page
    const formName = urlParts[urlParts.length - 2];
        window.location.href = form.action + '/' + encodeURIComponent(pageName);
    const pageName = decodeURIComponent(urlParts[urlParts.length - 1]);
       } else {
 
         // show warning message
    // Only run for the GutachtenAuspragungForm
        warning.style.display = "block";
    if (formName === 'GutachtenAuspragungForm') {
      }
     
    })
      const apiUrl = mw.util.wikiScript('api') + '?action=query&titles=' + encodeURIComponent(pageName) + '&format=json';
    .catch(error => {
 
      console.error('Error:', error);
       $.getJSON(apiUrl, function(data) {
      warning.innerText = "Es gab ein Problem beim Prüfen der Seite.";
         const pages = data.query.pages;
       warning.style.display = "block";
        const exists = !pages.hasOwnProperty('-1');
     });
 
   });
        if (!exists) {
          // If page doesn't exist, show warning and redirect user to creation link instead
          alert('Dieses Gutachten existiert nicht. Bitte verwenden Sie den Button „Neues Gutachten erstellen“, um ein Gutachten anzulegen.');
          window.location.href = mw.util.getUrl('Spezial:Mit_Formular_bearbeiten', {form: 'GutachtenAuspragungForm'});
        }
        // else: existing page, no action needed
       });
     }
   }
});
});

Version vom 5. Mai 2025, 12:52 Uhr

$(document).ready(function() {

  // Only run on Special:Mit_Formular_bearbeiten
  if (mw.config.get('wgCanonicalSpecialPageName') === 'FormEdit') {

    const urlParts = window.location.pathname.split('/');
    const formName = urlParts[urlParts.length - 2];
    const pageName = decodeURIComponent(urlParts[urlParts.length - 1]);

    // Only run for the GutachtenAuspragungForm
    if (formName === 'GutachtenAuspragungForm') {
      
      const apiUrl = mw.util.wikiScript('api') + '?action=query&titles=' + encodeURIComponent(pageName) + '&format=json';

      $.getJSON(apiUrl, function(data) {
        const pages = data.query.pages;
        const exists = !pages.hasOwnProperty('-1');

        if (!exists) {
          // If page doesn't exist, show warning and redirect user to creation link instead
          alert('Dieses Gutachten existiert nicht. Bitte verwenden Sie den Button „Neues Gutachten erstellen“, um ein Gutachten anzulegen.');
          window.location.href = mw.util.getUrl('Spezial:Mit_Formular_bearbeiten', {form: 'GutachtenAuspragungForm'});
        }
        // else: existing page, no action needed
      });
    }
  }
});