From a28b02a4339317900a15df88664a2771c52a57be Mon Sep 17 00:00:00 2001 From: miker Date: Wed, 29 Apr 2009 00:35:40 +0000 Subject: [PATCH] adding dojo class for parsing and rendering opac/slot-data extentions git-svn-id: svn://svn.open-ils.org/ILS/trunk@13010 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/dojo/openils/BibTemplate.js | 84 +++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 Open-ILS/web/js/dojo/openils/BibTemplate.js diff --git a/Open-ILS/web/js/dojo/openils/BibTemplate.js b/Open-ILS/web/js/dojo/openils/BibTemplate.js new file mode 100644 index 0000000000..2dad934d4c --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/BibTemplate.js @@ -0,0 +1,84 @@ +/* --------------------------------------------------------------------------- + * Copyright (C) 2009 Equinox Software, Inc. + * Mike Rylander + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * --------------------------------------------------------------------------- + */ + +if(!dojo._hasResource["openils.BibTemplate"]) { + + dojo.require('dojox.data.dom'); + dojo._hasResource["openils.BibTemplate"] = true; + dojo.provide("openils.BibTemplate"); + dojo.declare('openils.BibTemplate', null, { + + constructor : function(kwargs) { + this.root = kwargs.root; + this.record = kwargs.record; + }, + + render : function() { + var all_slots = dojo.query('*[type^=opac/slot-data]', this.root); + var rec = location.href.split('?')[1]; + + var slots = {}; + dojo.forEach(all_slots, function(s){ + var datatype = 'marcxml'; + + if (s.getAttribute('type').indexOf('+') > -1) + datatype = s.getAttribute('type').split('+').reverse()[0]; + + if (!slots[datatype]) slots[datatype] = []; + slots[datatype].push(s); + }); + + for (var datatype in slots) { + + (function (slot_list,dtype,rec) { + + dojo.xhrGet({ + url: '/opac/extras/unapi?id=tag:opac:biblio-record_entry/' + rec + '/-&format=' + datatype, + handleAs: 'xml', + load: function (bib) { + + dojo.forEach(slot_list, function (slot) { + var slot_handler = dojo.query( + 'script[type=opac/slot-format]', + slot + ).orphan().map( + function(x){return x.textContent || x.innerText || x.innerHTML} + ).join(''); + + + if (slot_handler) slot_handler = new Function('item', slot_handler); + else slot_handler = new Function('item','return dojox.data.dom.textContent(item);'); + + slot.innerHTML += dojo.query( + slot.getAttribute('query'), + bib + ).map(slot_handler).join(' '); + + delete(slot_handler); + + }); + } + }); + + })(slots[datatype],datatype,this.record); + + } + + return true; + } + }); + +} -- 2.11.0