From 16d2d0d60ae75a5c7c4842781875a70092d85521 Mon Sep 17 00:00:00 2001
From: Sylvain Chevillard <sylvain.chevillard@ens-lyon.org>
Date: Thu, 19 Oct 2023 15:26:38 +0200
Subject: [PATCH] =?UTF-8?q?Premi=C3=A8re=20tentative=20pour=20le=20remplis?=
 =?UTF-8?q?sage=20automatique=20de=20l'ajout=20d'exemplaires.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 koha_bibagos.user.js | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/koha_bibagos.user.js b/koha_bibagos.user.js
index bcc46a4..536aef8 100644
--- a/koha_bibagos.user.js
+++ b/koha_bibagos.user.js
@@ -34,7 +34,7 @@
 // ==UserScript==
 // @name         koha_bibagos
 // @namespace    http://gitlab.inria.fr/
-// @version      4.0
+// @version      5.0
 // @description  Personnaliser l'interface de Koha pour la BibAGOS
 // @author       Sylvain Chevillard
 // @match      https://emprunts-agos-admin.inria.fr/*
@@ -49,7 +49,7 @@
 	var test = 0;
 	var i = 0;
 	var logmsg="";
-	
+
 	while(!test) {
 	    test = (L[i].innerText.search('Code à barres non trouvé')) >= 0;
 	    i = i+1;
@@ -76,9 +76,33 @@
 	}
     }
 
+    function ajouteNouvelExemplaire() {
+	var nouveaute, localisation, code_barre, typepret, msg;
+	nouveaute = document.querySelector("#subfield995B").querySelector("select");
+	nouveaute.value = "1";
+	nouveaute.querySelector("option[value='1']").selected=1;
+	nouveaute.dispatchEvent(new Event('change'))
+	localisation = document.querySelector("#subfield995e").querySelector("select");
+	localisation.value = "SOP_MED";
+	localisation.querySelector("option[value='SOP_MED']").selected=1;
+	localisation.dispatchEvent(new Event('change'))
+	code_barre = document.querySelector("#subfield995f").querySelector("input");
+	set_barcode(code_barre.id, false);
+	typepret = document.querySelector("#subfield995r").querySelector("select");
+	typepret.value = "PS";
+	typepret.querySelector("option[value='PS']").selected=1;
+	typepret.dispatchEvent(new Event('change'));
+	msg = "Valider l'auto-complétion suivante ?\n\n  Nouveauté : oui\n  Localisation : Médiathèque Sophia\n  code barre : "+code_barre.value+"\n  Type de prêt : prêt sans caution réservable.";
+	if(confirm(msg)) {
+	    document.querySelector("input[name='add_submit']").click();
+	}
+    }
+
     /* Déclenchement des actions au chargement de la page */
     if (/circulation.pl/.test(window.location.href)) {
 	masqueExemplairesExternes();
     }
-
+    if (/additem.pl/.test(window.location.href)) {
+	ajoutNouvelExemplaire();
+    }
 })();
-- 
GitLab