1 dojo.require('dijit.Dialog');
2 dojo.require('dijit.form.Button');
3 dojo.require('dijit.form.DropDownButton');
4 dojo.require('dijit.form.FilteringSelect');
5 dojo.require('dijit.form.Form');
6 dojo.require('dijit.form.NumberSpinner');
7 dojo.require('dijit.form.TextBox');
8 dojo.require("dijit.Menu");
9 dojo.require("dijit.MenuItem");
10 dojo.require('dojox.xml.parser');
11 dojo.require('DojoSRF');
12 dojo.require("fieldmapper.Fieldmapper");
13 dojo.require('openils.CGI');
14 dojo.require('openils.PermaCrud');
15 dojo.require('openils.XUL');
16 dojo.require('openils.widget.OrgUnitFilteringSelect');
18 var cgi = new openils.CGI();
21 // OrgUnits do not currently affect the retrieval of authority records,
22 // but this is how to display them if they become OrgUnit-aware
23 function authOUListInit() {
24 new openils.User().buildPermOrgSelector(
25 "STAFF_LOGIN", // anywhere you can log in
27 null, // pre-selected org
31 dojo.addOnLoad(authOUListInit);
33 function displayAuthorities(data) {
36 // Grab each record from the returned authority records
37 dojo.query("record", data).forEach(function(node) {
42 // Grab each authority record field from the authority record
43 dojo.query("datafield[tag^='1']", node).forEach(function(dfNode) {
44 auth.text += dojox.xml.parser.textContent(dfNode);
45 auth.name = dojo.attr(dfNode, 'tag');
46 auth.ind1 = dojo.attr(dfNode, 'ind1');
47 auth.ind2 = dojo.attr(dfNode, 'ind2');
51 // Grab the ID of the authority record
52 dojo.query("datafield[tag='901'] subfield[code='c']", node).forEach(function(dfNode) {
53 auth.id = dojox.xml.parser.textContent(dfNode);
56 idArr.push(parseInt(auth.id));
58 // Create the authority record listing entry
59 dojo.place('<div class="authEntry" id="auth' + auth.id + '"><span class="text" id="authLabel' + auth.id + '">' + auth.text + '</span></div>', "authlist-div", "last");
61 // Add the menu of new/edit/delete/mark-for-merge options
62 var auth_menu = new dijit.Menu({});
65 new dijit.MenuItem({"id": "edit_" + auth.id, "onClick": function(){
66 var pcrud = new openils.PermaCrud();
67 var auth_rec = pcrud.retrieve("are", auth.id);
69 loadMarcEditor(pcrud, auth_rec);
71 }, "label":"Edit"}).placeAt(auth_menu, "first");
74 new dijit.MenuItem({"id": "merge_" + auth.id, "onClick":function(){
76 dojo.query('#auth' + auth.id + ' span.text').forEach(function(node) {
77 auth.text += dojox.xml.parser.textContent(node);
80 // If there is a toMerge item already, this is a target record
81 var mergeRole = '<td style="border: 1px solid black; padding-left: 0.5em; padding-right: 1em;">';
82 var isTarget = dojo.query('.toMerge').length;
84 mergeRole += 'Target</td>';
86 mergeRole += 'Master</td>';
89 dojo.place('<tr class="toMerge" id="toMerge_' + auth.id + '"><td>' + mergeRole + '</td><td style="border: 1px solid black;" id="mergeMeta_' + auth.id + '"></td><td style="border: 1px solid black; padding-left: 1em; padding-right: 1em;" >' + auth.text + '</td></tr>', 'mergebox-tbody', 'last');
90 dojo.place('<span class="authmeta" style="font-family: monospace;">' + auth.name + ' ' + auth.ind1 + auth.ind2 + '</span>', 'mergeMeta_' + auth.id, 'last');
91 dojo.removeClass('mergebox-div', 'hidden');
92 }, "label":"Mark for Merge"}).placeAt(auth_menu, "last");
96 "id": "delete_" + auth.id,
100 var pcrud = new openils.PermaCrud();
101 var auth_rec = pcrud.retrieve("are", auth.id);
103 // Bit of a hack to get the linked bib count until an explicit ID
104 var linkedBibs = dojox.xml.parser.textContent(
105 dojo.query("#authLabel" + auth.id)[0].previousSibling
108 var delDlg = dijit.byId("delDialog_" + auth.id);
110 dojo.query('#auth' + auth.id + ' span.text').forEach(function(node) {
111 auth.text += dojo.trim(dojox.xml.parser.textContent(node));
115 var content = '<div>Delete the authority record: "' + auth.text + '"?</div>';
116 if (parseInt(linkedBibs) > 0) {
117 content = "<div id='delAuthSum_" + auth.id + "'>Number of linked bibliographic records: " + linkedBibs + "</div>";
119 content += "<div id='authMARC" + auth.id + "' style='width: 100%; display:none;'>";
120 content += "<hr style='width: 100%;' />";
121 content += marcToHTML(auth_rec.marc());
122 content += "</div><hr style='width: 100%;' /><div>";
123 content += "<input type='button' dojoType='dijit.form.Button' label='Cancel' onClick='cancelDelete(" + auth.id + ")'/>";
124 content += "<input type='button' dojoType='dijit.form.Button' label='Delete' onClick='confirmDelete(" + auth.id + ")'/>";
125 content += "<input id='viewMARC" + auth.id + "' type='button' "
126 + "style='float:right;' dojoType='dijit.form.Button' "
127 + "label='View MARC' onClick='viewMARC(" + auth.id + ")'/>";
128 content += "<input id='hideMARC" + auth.id + "' type='button' "
129 + "style='display: none; float:right;' dojoType='dijit.form.Button' "
130 + "label='Hide MARC' onClick='hideMARC(" + auth.id + ")'/>";
132 delDlg = new dijit.Dialog({
133 "id":"delDialog_" + auth.id,
134 "title":"Confirm deletion of record # " + auth.id,
140 }, "label":"Delete"}).placeAt(auth_menu, "last");
142 auth_mb = new dijit.form.DropDownButton({dropDown: auth_menu, label:"Actions", id:"menu" + auth.id});
143 auth_mb.placeAt("auth" + auth.id, "first");
150 function viewMARC(recId) {
151 dojo.style(dojo.byId("authMARC" + recId), 'display', 'block');
152 dojo.style(dijit.byId("viewMARC" + recId).domNode, 'display', 'none');
153 dojo.style(dijit.byId("hideMARC" + recId).domNode, 'display', 'block');
156 function hideMARC(recId) {
157 dojo.style(dojo.byId("authMARC" + recId), 'display', 'none');
158 dojo.style(dijit.byId("hideMARC" + recId).domNode, 'display', 'none');
159 dojo.style(dijit.byId("viewMARC" + recId).domNode, 'display', 'block');
162 function marcToHTML(marc) {
163 var html = '<table><tbody>';
164 marc = dojox.xml.parser.parse(marc);
165 dojo.query('leader', marc).forEach(function(node) {
166 html += '<tr><td>LDR</td><td> </td><td> </td><td>' + dojox.xml.parser.textContent(node) + '</td></tr>';
168 dojo.query('controlfield', marc).forEach(function(node) {
169 html += '<tr><td>' + dojo.attr(node, "tag") + '</td><td> </td><td> </td><td>' + dojox.xml.parser.textContent(node) + '</td></tr>';
171 dojo.query('datafield', marc).forEach(function(node) {
173 html += '<tr><td>' + dojo.attr(node, "tag") + '</td><td>' + dojo.attr(node, "ind1") + '</td><td>' + dojo.attr(node, "ind2") + '</td>';
174 dojo.query('subfield', node).forEach(function(sf) {
176 html += '<td>$' + dojo.attr(sf, "code") + ' ' + dojox.xml.parser.textContent(sf) + '</td></tr>';
179 html += '<tr><td colspan="3"></td><td>$' + dojo.attr(sf, "code") + ' ' + dojox.xml.parser.textContent(sf) + '</td></tr>';
183 html += '</tbody></table>';
187 function cancelDelete(recId) {
188 dijit.byId("delDialog_" + recId).hide();
191 function confirmDelete(recId) {
192 var pcrud = new openils.PermaCrud();
193 var auth_rec = pcrud.retrieve("are", recId);
195 pcrud.eliminate(auth_rec);
196 dijit.byId("delDialog_" + recId).attr("content", "Deleted authority record # " + recId);
197 setTimeout(function() {
198 dijit.byId("delDialog_" + recId).hide();
203 function showBibCount(authIds) {
204 /* Decorate the list with # of bibs linked to each authority record */
205 var ses = new OpenSRF.ClientSession('open-ils.cat');
206 var req = ses.request('open-ils.cat.authority.records.count_linked_bibs', authIds);
208 req.oncomplete = function(r) {
209 var msg = r.recv().content();
210 dojo.forEach(msg, function(auth) {
211 linkedIds.push(auth.authority);
212 dojo.place('<span class="bibcount">' + auth.bibs + '</span>', 'authLabel' + auth.authority, 'before');
216 /* Assign counts of 0 for every non-linked authority */
217 dojo.forEach(authIds, function (id) {
219 dojo.forEach(linkedIds, function (lid) {
225 dojo.place('<span class="bibcount">0</span>', 'authLabel' + id, 'before');
232 function loadMarcEditor(pcrud, rec) {
234 To run in Firefox directly, must set signed.applets.codebase_principal_support
235 to true in about:config
237 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
238 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
241 "record": {"marc": rec.marc(), "rtype": "are"},
244 "func": function(xmlString) {
246 rec.edit_date('now');
249 alert("Record was saved");
253 'lock_tab' : typeof xulG != 'undefined' ? (typeof xulG['lock_tab'] != 'undefined' ? xulG.lock_tab : undefined) : undefined,
254 'unlock_tab' : typeof xulG != 'undefined' ? (typeof xulG['unlock_tab'] != 'undefined' ? xulG.unlock_tab : undefined) : undefined
258 function authListInit() {
259 var term = cgi.param('authTerm') || '';
260 var page = cgi.param('authPage') || 0;
261 var axis = cgi.param('authAxis') || 'authority.author';
263 dijit.byId('authAxis').attr('value', axis);
266 dijit.byId('authPage').attr('value', page);
269 dijit.byId('authTerm').attr('value', term);
273 dojo.connect(dijit.byId('authAxis'), 'onKeyPress', function(evt) {
274 if (evt.keyCode == dojo.keys.ENTER) {
275 dijit.byId('authPage').attr('value', 0);
280 dojo.connect(dijit.byId('authPage'), 'onKeyPress', function(evt) {
281 if (evt.keyCode == dojo.keys.ENTER) {
282 dijit.byId('authPage').attr('value', 0);
287 dojo.connect(dijit.byId('authTerm'), 'onKeyPress', function(evt) {
288 if (evt.keyCode == dojo.keys.ENTER) {
289 dijit.byId('authPage').attr('value', 0);
294 dijit.byId('authTerm').focus();
297 dojo.addOnLoad(authListInit);
299 function displayRecords(parms) {
301 if (parms && parms.page) {
302 if (parms.page == 'next') {
303 page = dijit.byId('authPage').attr('value');
304 dijit.byId('authPage').attr('value', page + 1);
305 } else if (parms.page == 'prev') {
306 page = dijit.byId('authPage').attr('value');
307 dijit.byId('authPage').attr('value', page - 1);
309 dijit.byId('authPage').attr('value', parms.page);
313 /* Protect against null input */
314 if (!dijit.byId('authTerm').attr('value')) {
318 /* Clear out the current contents of the page */
319 var widgets = dijit.findWidgets(dojo.byId('authlist-div'));
320 dojo.forEach(widgets, function(w) { w.destroyRecursive(true); });
322 dojo.query("#authlist-div div").orphan();
324 var url = '/opac/extras/startwith/marcxml/'
325 + dijit.byId('authAxis').attr('value')
326 // + '/' + dijit.byId('authOU').attr('value')
327 + '/1' // replace with preceding line if OUs gain some meaning
328 + '/' + dijit.byId('authTerm').attr('value')
329 + '/' + dijit.byId('authPage').attr('value')
330 + '/' + '20' // 20 results per page
332 dojo.xhrGet({"url":url, "handleAs":"xml", "content":{"format":"marcxml"}, "preventCache": true, "load":displayAuthorities });
335 function clearMergeRecords() {
336 var records = dojo.query('.toMerge').orphan();
337 dojo.addClass('mergebox-div', 'hidden');
340 function mergeRecords() {
341 var records = dojo.query('.toMerge').attr('id');
342 dojo.forEach(records, function(item, idx) {
343 records[idx] = parseInt(item.slice(item.lastIndexOf('_') + 1));
346 /* Take the first record in the list and use that as the master */
347 fieldmapper.standardRequest(
348 ['open-ils.cat', 'open-ils.cat.authority.records.merge'],
350 params: [openils.User.authtoken, records.shift(), records],
351 oncomplete : function(r) {
352 alert("Record merge is complete.");