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
 
(Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt)
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')
  if (mw.config.get('wgCanonicalSpecialPageName') === 'FormEdit') {
    .then(response => response.json())
    .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
    if (formName === 'GutachtenAuspragungForm') {
        warning.style.display = "block";
     
       }
      const apiUrl = mw.util.wikiScript('api') + '?action=query&titles=' + encodeURIComponent(pageName) + '&format=json';
     })
 
     .catch(error => {
       $.getJSON(apiUrl, function(data) {
       console.error('Error:', error);
         const pages = data.query.pages;
      warning.innerText = "Es gab ein Problem beim Prüfen der Seite.";
        const exists = !pages.hasOwnProperty('-1');
       warning.style.display = "block";
 
     });
        if (!exists) {
   });
          // Directly redirect with a query parameter indicating the issue
          const redirectUrl = mw.util.getUrl('Spezial:Mit_Formular_bearbeiten', {
            form: 'GutachtenAuspragungForm',
            warning: 'notexist'
          });
         
          window.location.replace(redirectUrl);
        }
       });
     }
 
    // Check for warning parameter and display message if redirected here
    const urlParams = new URLSearchParams(window.location.search);
     if (urlParams.get('warning') === 'notexist') {
       mw.loader.using('mediawiki.notification', function(){
        mw.notify('Das angeforderte Gutachten existiert nicht. Bitte nutzen Sie dieses Formular, um ein neues Gutachten anzulegen.', {
          title: 'Hinweis',
          type: 'warn',
          autoHideSeconds: 7
        });
       });
     }
   }
});
});

Aktuelle Version vom 5. Mai 2025, 12:58 Uhr

$(document).ready(function() {

  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]);

    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) {
          // Directly redirect with a query parameter indicating the issue
          const redirectUrl = mw.util.getUrl('Spezial:Mit_Formular_bearbeiten', {
            form: 'GutachtenAuspragungForm',
            warning: 'notexist'
          });
          
          window.location.replace(redirectUrl);
        }
      });
    }

    // Check for warning parameter and display message if redirected here
    const urlParams = new URLSearchParams(window.location.search);
    if (urlParams.get('warning') === 'notexist') {
      mw.loader.using('mediawiki.notification', function(){
        mw.notify('Das angeforderte Gutachten existiert nicht. Bitte nutzen Sie dieses Formular, um ein neues Gutachten anzulegen.', {
          title: 'Hinweis',
          type: 'warn',
          autoHideSeconds: 7
        });
      });
    }
  }
});