1 dojo.require('dijit.form.Button');
2 dojo.require('dijit.form.DropDownButton');
3 dojo.require('dijit.form.FilteringSelect');
4 dojo.require('dijit.form.Form');
5 dojo.require('dijit.form.NumberSpinner');
6 dojo.require('dijit.form.TextBox');
7 dojo.require("dijit.Menu");
8 dojo.require("dijit.MenuItem");
9 dojo.require('dojox.xml.parser');
10 dojo.require('DojoSRF');
11 dojo.require("fieldmapper.Fieldmapper");
12 dojo.require('openils.CGI');
13 dojo.require('openils.PermaCrud');
14 dojo.require('openils.XUL');
15 dojo.require('openils.widget.OrgUnitFilteringSelect');
17 var cgi = new openils.CGI();
20 // OrgUnits do not currently affect the retrieval of authority records,
21 // but this is how to display them if they become OrgUnit-aware
22 function authOUListInit() {
23 new openils.User().buildPermOrgSelector(
24 "STAFF_LOGIN", // anywhere you can log in
26 null, // pre-selected org
30 dojo.addOnLoad(authOUListInit);
32 function displayAuthorities(data) {
35 // Grab each record from the returned authority records
36 dojo.query("record", data).forEach(function(node) {
41 // Grab each authority record field from the authority record
42 dojo.query("datafield[tag^='1']", node).forEach(function(dfNode) {
43 auth.text += dojox.xml.parser.textContent(dfNode);
44 auth.name = dojo.attr(dfNode, 'tag');
45 auth.ind1 = dojo.attr(dfNode, 'ind1');
46 auth.ind2 = dojo.attr(dfNode, 'ind2');
50 // Grab the ID of the authority record
51 dojo.query("datafield[tag='901'] subfield[code='c']", node).forEach(function(dfNode) {
52 auth.id = dojox.xml.parser.textContent(dfNode);
55 idArr.push(parseInt(auth.id));
57 // Create the authority record listing entry
58 dojo.place('<div class="authEntry" id="auth' + auth.id + '"><span class="text" id="authLabel' + auth.id + '">' + auth.text + '</span></div>', "authlist-div", "last");
60 // Add the menu of new/edit/delete/mark-for-merge options
61 var auth_menu = new dijit.Menu({});
64 new dijit.MenuItem({"id": "edit_" + auth.id, "onClick": function(){
65 recId = this.id.slice(this.id.lastIndexOf('_') + 1);
66 pcrud = new openils.PermaCrud();
67 auth_rec = pcrud.retrieve("are", recId);
69 loadMarcEditor(pcrud, auth_rec);
71 }, "label":"Edit"}).placeAt(auth_menu, "first");
74 new dijit.MenuItem({"id": "merge_" + auth.id, "onClick":function(){
76 recId = this.id.slice(this.id.lastIndexOf('_') + 1);
77 dojo.query('#auth' + recId + ' span.text').forEach(function(node) {
78 auth.text += dojox.xml.parser.textContent(node);
81 // If there is a toMerge item already, this is a target record
82 var mergeRole = '<td style="border: 1px solid black; padding-left: 0.5em; padding-right: 1em;">';
83 var isTarget = dojo.query('.toMerge').length;
85 mergeRole += 'Target</td>';
87 mergeRole += 'Master</td>';
90 dojo.place('<tr class="toMerge" id="toMerge_' + recId + '"><td>' + mergeRole + '</td><td style="border: 1px solid black;" id="mergeMeta_' + recId + '"></td><td style="border: 1px solid black; padding-left: 1em; padding-right: 1em;" >' + auth.text + '</td></tr>', 'mergebox-tbody', 'last');
91 dojo.place('<span class="authmeta" style="font-family: monospace;">' + auth.name + ' ' + auth.ind1 + auth.ind2 + '</span>', 'mergeMeta_' + recId, 'last');
92 dojo.removeClass('mergebox-div', 'hidden');
93 }, "label":"Mark for Merge"}).placeAt(auth_menu, "last");
96 new dijit.MenuItem({"id": "delete_" + auth.id, "onClick":function(){
97 recId = this.id.slice(this.id.lastIndexOf('_') + 1);
99 // Deleting an authority record is unusual; let's be 100% sure
100 if (!confirm("Are you sure you want to delete record " + recId + "?")) {
104 pcrud = new openils.PermaCrud();
105 auth_rec = pcrud.retrieve("are", recId);
107 pcrud.eliminate(auth_rec);
108 alert("Deleted authority record # " + recId);
110 }, "label":"Delete"}).placeAt(auth_menu, "last");
112 auth_mb = new dijit.form.DropDownButton({dropDown: auth_menu, label:"Actions", id:"menu" + auth.id});
113 auth_mb.placeAt("auth" + auth.id, "first");
121 function showBibCount(authIds) {
122 /* Decorate the list with # of bibs linked to each authority record */
123 var ses = new OpenSRF.ClientSession('open-ils.cat');
124 var req = ses.request('open-ils.cat.authority.records.count_linked_bibs', authIds);
126 req.oncomplete = function(r) {
127 var msg = r.recv().content();
128 dojo.forEach(msg, function(auth) {
129 linkedIds.push(auth.authority);
130 dojo.place('<span class="bibcount">' + auth.bibs + '</span>', 'authLabel' + auth.authority, 'before');
134 /* Assign counts of 0 for every non-linked authority */
135 dojo.forEach(authIds, function (id) {
137 dojo.forEach(linkedIds, function (lid) {
143 dojo.place('<span class="bibcount">0</span>', 'authLabel' + id, 'before');
150 function loadMarcEditor(pcrud, rec) {
152 To run in Firefox directly, must set signed.applets.codebase_principal_support
153 to true in about:config
155 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
156 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
159 "record": {"marc": rec.marc(), "rtype": "are"},
162 "func": function(xmlString) {
164 rec.edit_date('now');
167 alert("Record was saved");
171 'lock_tab' : typeof xulG != 'undefined' ? (typeof xulG['lock_tab'] != 'undefined' ? xulG.lock_tab : undefined) : undefined,
172 'unlock_tab' : typeof xulG != 'undefined' ? (typeof xulG['unlock_tab'] != 'undefined' ? xulG.unlock_tab : undefined) : undefined
176 function authListInit() {
177 var term = cgi.param('authTerm') || '';
178 var page = cgi.param('authPage') || 0;
179 var axis = cgi.param('authAxis') || 'authority.author';
181 dijit.byId('authAxis').attr('value', axis);
184 dijit.byId('authPage').attr('value', page);
187 dijit.byId('authTerm').attr('value', term);
191 dojo.connect(dijit.byId('authAxis'), 'onKeyPress', function(evt) {
192 if (evt.keyCode == dojo.keys.ENTER) {
193 dijit.byId('authPage').attr('value', 0);
198 dojo.connect(dijit.byId('authPage'), 'onKeyPress', function(evt) {
199 if (evt.keyCode == dojo.keys.ENTER) {
200 dijit.byId('authPage').attr('value', 0);
205 dojo.connect(dijit.byId('authTerm'), 'onKeyPress', function(evt) {
206 if (evt.keyCode == dojo.keys.ENTER) {
207 dijit.byId('authPage').attr('value', 0);
212 dijit.byId('authTerm').focus();
215 dojo.addOnLoad(authListInit);
217 function displayRecords(parms) {
219 if (parms && parms.page) {
220 if (parms.page == 'next') {
221 page = dijit.byId('authPage').attr('value');
222 dijit.byId('authPage').attr('value', page + 1);
223 } else if (parms.page == 'prev') {
224 page = dijit.byId('authPage').attr('value');
225 dijit.byId('authPage').attr('value', page - 1);
227 dijit.byId('authPage').attr('value', parms.page);
231 /* Protect against null input */
232 if (!dijit.byId('authTerm').attr('value')) {
236 /* Clear out the current contents of the page */
237 var widgets = dijit.findWidgets(dojo.byId('authlist-div'));
238 dojo.forEach(widgets, function(w) { w.destroyRecursive(true); });
240 dojo.query("#authlist-div div").orphan();
242 var url = '/opac/extras/startwith/marcxml/'
243 + dijit.byId('authAxis').attr('value')
244 // + '/' + dijit.byId('authOU').attr('value')
245 + '/1' // replace with preceding line if OUs gain some meaning
246 + '/' + dijit.byId('authTerm').attr('value')
247 + '/' + dijit.byId('authPage').attr('value')
248 + '/' + '20' // 20 results per page
250 dojo.xhrGet({"url":url, "handleAs":"xml", "content":{"format":"marcxml"}, "preventCache": true, "load":displayAuthorities });
253 function clearMergeRecords() {
254 var records = dojo.query('.toMerge').orphan();
255 dojo.addClass('mergebox-div', 'hidden');
258 function mergeRecords() {
259 var records = dojo.query('.toMerge').attr('id');
260 dojo.forEach(records, function(item, idx) {
261 records[idx] = parseInt(item.slice(item.lastIndexOf('_') + 1));
264 /* Take the first record in the list and use that as the master */
265 fieldmapper.standardRequest(
266 ['open-ils.cat', 'open-ils.cat.authority.records.merge'],
268 params: [openils.User.authtoken, records.shift(), records],
269 oncomplete : function(r) {
270 alert("Record merge is complete.");