summaryrefslogtreecommitdiff
path: root/Library Catalog (Koha).js
blob: 1789388ddde01efc8a177c1f6e2507f548cde098 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
{
	"translatorID": "8e66aa6d-5b2a-4b44-b384-a838e23b8538",
	"label": "Library Catalog (Koha)",
	"creator": "Sebastian Karcher",
	"target": "cgi-bin/koha/opac-(detail|search)",
	"minVersion": "2.1.9",
	"maxVersion": "",
	"priority": 260,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsibv",
	"lastUpdated": "2014-09-25 15:46:46"
}

/*
	***** BEGIN LICENSE BLOCK *****
	
	KOHA Translator, Copyright © 2012 Sebastian Karcher 
	This file is part of Zotero.
	
	Zotero is free software: you can redistribute it and/or modify
	it under the terms of the GNU Affero General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	Zotero is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Affero General Public License for more details.
	
	You should have received a copy of the GNU Affero General Public License
	along with Zotero.  If not, see <http://www.gnu.org/licenses/>.
	
	***** END LICENSE BLOCK *****
*/

function detectWeb(doc, url) {
	if (url.match(/\/opac-search\.pl\?/) && getSearchResults(doc, true)) return "multiple";
	if (url.match(/\/opac-detail\.pl\?/)) return "book";
}

function getSearchResults(doc, checkOnly) {
	var items = {}, found = false;
	var resultContainer = doc.getElementsByClassName('searchresults')[0];
	if (!resultContainer) return false;
	
	resultContainer = doc.getElementsByTagName('tr');
	for (var i=0; i<resultContainer.length; i++) {
		var item = ZU.xpath(resultContainer[i], '(.//a[contains(@href, "opac-detail.pl")])[1]')[0];
		if (!item) continue;
		
		if(checkOnly) return true;
		found = true;
		items[item.href] = ZU.trimInternal(item.textContent);
	}
	
	return found ? items : false;
}

function doWeb(doc, url) {
	if (detectWeb(doc, url) == "multiple") {
		Zotero.selectItems(getSearchResults(doc), function (items) {
			if (!items) return true;
			
			var articles = [];
			for (var i in items) {
				articles.push(marcURL(i));
			}
			scrape(articles);
		});
	} else {
		scrape(marcURL(url));
	}
}

function scrape(marcurl) {
	Zotero.Utilities.HTTP.doGet(marcurl, function (text) {
		var translator = Zotero.loadTranslator("import");
		// Use MARC translator
		translator.setTranslator("a6ee60df-1ddc-4aae-bb25-45e0537be973");
		translator.setString(text);
		translator.setHandler("itemDone", function (obj, item) {
			//editors get mapped as contributors - but so do many others who should be
			// --> for books that don't have an author, turn contributors into editors.
			if (item.itemType=="book"){
				var hasAuthor = false;
				for (var i in item.creators) {
					if (item.creators[i].creatorType=="author") {
						hasAuthor = true;
						break;
					}
				}
				if (!hasAuthor) {
					for (var i in item.creators) {
						if (item.creators[i].creatorType=="contributor") {
							item.creators[i].creatorType="editor";
						}
					}
				}
			}
			item.complete();
		});
		translator.translate();
	}) //doGet end
} 

function marcURL(url){
	var bibnumber = url.match(/(biblionumber=)(\d+)/)[2];
	var host = url.match(/^.+cgi-bin\/koha\//)[0];
	var marcURL = host + "opac-export.pl?format=utf8&op=export&bib=" + bibnumber +"save=Go";
	return marcURL;
}
/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "https://ahuntsic.koha.ccsr.qc.ca/cgi-bin/koha/opac-detail.pl?biblionumber=145770",
		"items": [
			{
				"itemType": "book",
				"title": "Synopsis: revue de cinéma",
				"creators": [
					{
						"lastName": "Collège Ahuntsic",
						"fieldMode": true
					}
				],
				"date": "2011",
				"libraryCatalog": "Library Catalog (Koha)",
				"place": "Montréal",
				"publisher": "Collège Ahuntsic",
				"shortTitle": "Synopsis",
				"attachments": [],
				"tags": [
					"Cinéma"
				],
				"notes": [
					{
						"note": "Les finissants et finissantes du Collège Ahuntsic soulignent les connaissances acquises au sein du profil Cinéma et médias en faisant découvrir leurs coups de coeur, « des films qui, à leur façon, les ont marqués par une recherche formelle, une originalité thématique, une authenticité sociologique et/ou une valeur historique. » -- P. 5"
					}
				],
				"seeAlso": []
			}
		]
	},
	{
		"type": "web",
		"url": "https://catalogue.univ-lyon3.fr/cgi-bin/koha/opac-search.pl?q=thelen",
		"items": "multiple"
	},
	{
		"type": "web",
		"url": "http://nmwa.kohalibrary.com/cgi-bin/koha/opac-search.pl?q=image&idx=&submit=Search+Catalog",
		"items": "multiple"
	},
	{
		"type": "web",
		"url": "https://ahuntsic.koha.ccsr.qc.ca/cgi-bin/koha/opac-detail.pl?biblionumber=71166",
		"items": [
			{
				"itemType": "book",
				"title": "Les jeunes et la sexualité: initiations, interdits, identités (XIXe-XXIe siècle)",
				"creators": [
					{
						"firstName": "Véronique",
						"lastName": "Blanchard",
						"creatorType": "editor"
					},
					{
						"firstName": "Régis",
						"lastName": "Revenin",
						"creatorType": "editor"
					},
					{
						"firstName": "Jean-Jacques",
						"lastName": "Yvorel",
						"creatorType": "editor"
					}
				],
				"date": "2010",
				"ISBN": "9782746713666",
				"callNumber": "HQ 27 J485",
				"libraryCatalog": "Library Catalog (Koha)",
				"numPages": "407",
				"place": "Paris",
				"publisher": "Éditions Autrement",
				"series": "Mutations",
				"seriesNumber": "262",
				"shortTitle": "Les jeunes et la sexualité",
				"attachments": [],
				"tags": [
					"Abus sexuels à l'égard des enfants",
					"Adolescents",
					"Éducation sexuelle des jeunes",
					"Prostitution juvénile",
					"Sexualité",
					"Tourisme sexuel"
				],
				"notes": [
					{
						"note": "« Le sujet préoccupe les jeunes eux-mêmes, bien entendu, mais aussi les adultes qui les entourent, parents, enseignants, travailleurs sociaux, médecins, juges, responsables politiques... Il inquiète, il paraît sulfureux, ou tabou. L'émotion suscitée dans les médias en témoigne : tournantes, tourisme sexuel, \"dédipix\" échangés, pilule du lendemain, difficulté d'assumer son homosexualité, etc. Sur les plateaux de télévision, à la radio ou dans les magazines, la parole est donnée aux \"psy\" ou aux \"témoins\", qui renforcent bien souvent les normes et les idées reçues. En contrepoint, ici sont réunis des historiens, des sociologues, des philosophes : trente-cinq chercheurs qui ont dépouillé les archives et mené l'enquête sur le terrain, en France, en Espagne, aux États-Unis, mais aussi en Argentine, au Cameroun, à Madagascar, en Iran, en Thaïlande, en Nouvelle-Zélande... Ce vaste panorama en trois volets, initiations, interdits, identités, permet de s'interroger sur notre actualité sexuelle : peu réprimée jusqu'à une époque récente, pourquoi la pédophilie est-elle aujourd'hui considérée comme le crime le plus abominable? Quel rôle joue la pornographie dans l'éducation sexuelle? La violence sexuelle des jeunes est-elle plus marquée aujourd'hui? Comment se construisent les identités de genre et les orientations sexuelles chez les jeunes? Faut-il avoir peur des jeunes et de la sexualité? Voilà de quoi alimenter la réflexion individuelle et les débats publics tout à la fois... » -- P. 4 de la couv"
					}
				],
				"seeAlso": []
			}
		]
	},
	{
		"type": "web",
		"url": "http://biblio.esd.ipl.pt/cgi-bin/koha/opac-detail.pl?biblionumber=2367",
		"items": [
			{
				"itemType": "book",
				"title": "Dia Mundial da Dança: Dança Caldas 21h30",
				"creators": [
					{
						"firstName": "Úxia",
						"lastName": "Vaello",
						"creatorType": "author"
					},
					{
						"firstName": "Inês",
						"lastName": "Oliveira",
						"creatorType": "author"
					},
					{
						"firstName": "Catarina",
						"lastName": "Câmara",
						"creatorType": "author"
					},
					{
						"firstName": "Bruno",
						"lastName": "Alexandre",
						"creatorType": "author"
					},
					{
						"firstName": "Maria",
						"lastName": "Cerveira",
						"creatorType": "author"
					},
					{
						"firstName": "Célia",
						"lastName": "Cardoso",
						"creatorType": "author"
					},
					{
						"firstName": "Ricardo",
						"lastName": "Carmona",
						"creatorType": "author"
					},
					{
						"firstName": "Catarina",
						"lastName": "Ascensão",
						"creatorType": "author"
					},
					{
						"firstName": "Ana Sofia",
						"lastName": "Leite",
						"creatorType": "author"
					},
					{
						"firstName": "Claúdia",
						"lastName": "Silva",
						"creatorType": "author"
					},
					{
						"firstName": "Diana",
						"lastName": "Alves",
						"creatorType": "author"
					},
					{
						"firstName": "Eliana",
						"lastName": "Campos",
						"creatorType": "author"
					},
					{
						"firstName": "Guida",
						"lastName": "Maurício",
						"creatorType": "author"
					},
					{
						"firstName": "Lib",
						"lastName": "Pitalúa",
						"creatorType": "author"
					},
					{
						"firstName": "Mariana",
						"lastName": "Saraiva",
						"creatorType": "author"
					},
					{
						"firstName": "Francisco",
						"lastName": "Pedro",
						"creatorType": "author"
					},
					{
						"firstName": "João Carlos",
						"lastName": "Andrade",
						"creatorType": "author"
					},
					{
						"firstName": "Miguel",
						"lastName": "Oliveira",
						"creatorType": "author"
					},
					{
						"firstName": "Luísa",
						"lastName": "Taveira",
						"creatorType": "author"
					},
					{
						"lastName": "Escola Superior de Dança",
						"creatorType": "contributor",
						"fieldMode": true
					},
					{
						"lastName": "Escola Vocacional de Dança",
						"creatorType": "contributor",
						"fieldMode": true
					}
				],
				"date": "2005",
				"language": "por",
				"libraryCatalog": "Library Catalog (Koha)",
				"place": "Lisboa",
				"publisher": "ESD",
				"shortTitle": "Dia Mundial da Dança",
				"attachments": [],
				"tags": [],
				"notes": [],
				"seeAlso": []
			}
		]
	},
	{
		"type": "web",
		"url": "https://rdl.koha.ccsr.qc.ca/cgi-bin/koha/opac-search.pl?q=test",
		"items": "multiple"
	}
]
/** END TEST CASES **/