Created
December 5, 2012 09:44
-
-
Save cKlee/4214339 to your computer and use it in GitHub Desktop.
zdb_Reziprok
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function zdb_Reziprok() { | |
/************************************************************** | |
edits Hachmann, Grund, Klee | |
letzte Änderung 2012-12-05 Klee | |
/**************************************************************/ | |
// Skript muss bei reziprokem Verknuepfungsfeld aufgerufen werden und erzeugt an der Gegenaufnahme eine Verknüpfung. | |
if (!application.activeWindow.title) | |
{ | |
application.messageBox("Reziprok", "Die Funktion kann nur aus dem Korrekturmodus aufgerufen werden.", "alert-icon"); | |
return; | |
} | |
// Quell-ID-Nummer | |
var quellID = application.activeWindow.getVariable("P3GPP"); | |
var felder = { | |
"510 vorg":"510 !" + quellID + "!$4nach", | |
"510 nach":"510 !" + quellID + "!$4vorg", | |
"511 vorg":"511 !" + quellID + "!$4nach", | |
"511 nach":"511 !" + quellID + "!$4vorg", | |
"551 vorg":"551 !" + quellID + "!$4nach", | |
"551 nach":"551 !" + quellID + "!$4vorg", | |
"4244 f#":"4244 s#!" + quellID + "!", | |
"4244 s#":"4244 f#!" + quellID + "!", | |
"4244 z#":"4244 z#!" + quellID + "!", | |
"4241":"4242 !" + quellID + "!", | |
"4242":"4241 !" + quellID + "!", | |
"4243":"4243 !" + quellID + "!"} | |
// Aktuelle Feldnummer ermitteln | |
var tag = application.activeWindow.title.tag; | |
var tagcontent = application.activeWindow.title.currentField; | |
// Prüfen, ob eine von Ausrufezeichen umschlossene IDN vorhanden ist | |
var text = tagcontent.substring(tagcontent.indexOf("!"),tagcontent.lastIndexOf("!")+1); | |
var regExpPPN = /!(\d{8,9}[\d|x|X])!/; | |
if (!regExpPPN.test(text)) { | |
application.messageBox("Reziprok linken", "Es ist keine ID-Nummer zum Verlinken gefunden worden.", "error-icon"); | |
return; | |
} | |
application.activeWindow.title.startOfField(false); | |
var reziFeld = ""; | |
//Unterschiede zw. GND- und Titelfeldern | |
if (tag.length < 4) | |
{ | |
//Relationscode ermitteln | |
var code = tagcontent.substr(tagcontent.indexOf("$4")+2,4) | |
var feldnr = tag + " " + code; | |
reziFeld = felder[feldnr]; | |
} | |
else | |
{ | |
var feldnr = tagcontent.match(/^\d{4,4}(\s[fsz]#)?/g); | |
reziFeld = felder[feldnr[0]]; | |
} | |
// Fehlermeldung bei falschem Feld | |
if (reziFeld == "" || reziFeld == null || !reziFeld) { | |
application.messageBox("Reziprok", "Die Funktion kann nicht aus dem Feld '" + tag + "' aufgerufen werden.", "alert-icon"); | |
return; | |
} | |
// Datensatz speichern, wenn Status != OK Abbruch. | |
application.activeWindow.simulateIBWKey ("FR"); | |
if (application.activeWindow.status != "OK"){ | |
application.messageBox("Reziprok linken", "Bitte Fehler korrigieren und Funktion erneut ausführen", "error-icon"); | |
return; | |
} | |
zielID = regExpPPN.exec(text); | |
// Kommando abschicken und Ergebnis in gleichen Fenster anzeigen | |
application.activeWindow.command("f idn " + zielID[1], false); // <=== Kommando in demselben Fenster | |
//Datensatz in der Vollanzeige prüfen. Wenn PPN noch nicht vorkommt, dann jetzt einfuegen: | |
if (application.activeWindow.copyTitle().indexOf(quellID) == -1 ) | |
{ | |
// F7 (Korrektur" drücken) | |
application.activeWindow.simulateIBWKey ("F7"); | |
application.activeWindow.title.endOfBuffer(false); | |
application.activeWindow.title.insertText(reziFeld + "\n"); | |
var thePrompter = utility.newPrompter(); | |
if (thePrompter.confirmEx("reziprok Linken", "Datensatz jetzt speichern?", "Ja", "Nein", "", "", "") == 0) | |
{ | |
application.activeWindow.simulateIBWKey ("FR"); | |
if (application.activeWindow.status == "OK") | |
{ | |
application.activeWindow.command("f idn " + quellID + " or " + zielID[1] + ";s k", false); | |
} | |
} | |
} | |
else { | |
application.messageBox("Reziprok", "Der Link zu " + quellID + " ist schon vorhanden!", "alert-icon"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment