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) {
40 // Grab each authority record field from the authority record
41 dojo.query("datafield[tag^='1']", node).forEach(function(dfNode) {
42 authText += dojox.xml.parser.textContent(dfNode);
44 // Grab the ID of the authority record
45 dojo.query("datafield[tag='901'] subfield[code='c']", node).forEach(function(dfNode) {
46 authId = dojox.xml.parser.textContent(dfNode);
49 idArr.push(parseInt(authId));
51 // Create the authority record listing entry
52 dojo.place('<div class="authEntry" id="auth' + authId + '"><span class="text" id="authLabel' + authId + '">' + authText + '</span></div>', "authlist-div", "last");
54 // Add the menu of new/edit/delete/mark-for-merge options
55 var auth_menu = new dijit.Menu({});
58 new dijit.MenuItem({"id": "edit_" + authId, "onClick": function(){
59 recId = this.id.slice(this.id.lastIndexOf('_') + 1);
60 pcrud = new openils.PermaCrud();
61 auth_rec = pcrud.retrieve("are", recId);
63 loadMarcEditor(pcrud, auth_rec);
65 }, "label":"Edit"}).placeAt(auth_menu, "first");
68 new dijit.MenuItem({"id": "merge_" + authId, "onClick":function(){
70 recId = this.id.slice(this.id.lastIndexOf('_') + 1);
71 dojo.query('#auth' + recId + ' span.text').forEach(function(node) {
72 authText += dojox.xml.parser.textContent(node);
75 // If there is a toMerge item already, this is a target record
76 var mergeRole = '<td style="border: 1px solid black; padding-left: 0.5em; padding-right: 1em;">';
77 var isTarget = dojo.query('.toMerge').length;
79 mergeRole += 'Target</td>';
81 mergeRole += 'Master</td>';
83 dojo.place('<tr class="toMerge" id="toMerge_' + recId + '">' + mergeRole + '<td style="border: 1px solid black; padding-left: 1em;">' + authText + '</td></tr>', 'mergebox-tbody', 'last');
84 dojo.removeClass('mergebox-div', 'hidden');
85 }, "label":"Mark for Merge"}).placeAt(auth_menu, "last");
88 new dijit.MenuItem({"id": "delete_" + authId, "onClick":function(){
89 recId = this.id.slice(this.id.lastIndexOf('_') + 1);
91 // Deleting an authority record is unusual; let's be 100% sure
92 if (!confirm("Are you sure you want to delete record " + recId + "?")) {
96 pcrud = new openils.PermaCrud();
97 auth_rec = pcrud.retrieve("are", recId);
99 pcrud.eliminate(auth_rec);
100 alert("Deleted authority record # " + recId);
102 }, "label":"Delete"}).placeAt(auth_menu, "last");
104 auth_mb = new dijit.form.DropDownButton({dropDown: auth_menu, label:"Actions", id:"menu" + authId});
105 auth_mb.placeAt("auth" + authId, "first");
113 function showBibCount(authIds) {
114 /* Decorate the list with # of bibs linked to each authority record */
115 var ses = new OpenSRF.ClientSession('open-ils.cat');
116 var req = ses.request('open-ils.cat.authority.records.count_linked_bibs', authIds);
118 req.oncomplete = function(r) {
119 var msg = r.recv().content();
120 dojo.forEach(msg, function(auth) {
121 linkedIds.push(auth.authority);
122 dojo.place('<span class="bibcount">' + auth.bibs + '</span>', 'authLabel' + auth.authority, 'before');
126 /* Assign counts of 0 for every non-linked authority */
127 dojo.forEach(authIds, function (id) {
129 dojo.forEach(linkedIds, function (lid) {
135 dojo.place('<span class="bibcount">0</span>', 'authLabel' + id, 'before');
142 function loadMarcEditor(pcrud, rec) {
144 To run in Firefox directly, must set signed.applets.codebase_principal_support
145 to true in about:config
147 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
148 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
151 "record": {"marc": rec.marc(), "rtype": "are"},
154 "func": function(xmlString) {
156 rec.edit_date('now');
159 alert("Record was saved");
166 function authListInit() {
167 term = cgi.param('authTerm') || '';
168 page = cgi.param('authPage') || 0;
169 axis = cgi.param('authAxis') || 'authority.author';
171 dijit.byId('authAxis').attr('value', axis);
174 dijit.byId('authPage').attr('value', page);
177 dijit.byId('authTerm').attr('value', term);
181 dojo.connect(dijit.byId('authAxis'), 'onKeyPress', function(evt) {
182 if (evt.keyCode == dojo.keys.ENTER) {
183 dijit.byId('authPage').attr('value', 0);
188 dojo.connect(dijit.byId('authPage'), 'onKeyPress', function(evt) {
189 if (evt.keyCode == dojo.keys.ENTER) {
190 dijit.byId('authPage').attr('value', 0);
195 dojo.connect(dijit.byId('authTerm'), 'onKeyPress', function(evt) {
196 if (evt.keyCode == dojo.keys.ENTER) {
197 dijit.byId('authPage').attr('value', 0);
202 dijit.byId('authTerm').focus();
205 dojo.addOnLoad(authListInit);
207 function displayRecords(parms) {
209 if (parms && parms.page) {
210 if (parms.page == 'next') {
211 page = dijit.byId('authPage').attr('value');
212 dijit.byId('authPage').attr('value', page + 1);
213 } else if (parms.page == 'prev') {
214 page = dijit.byId('authPage').attr('value');
215 dijit.byId('authPage').attr('value', page - 1);
217 dijit.byId('authPage').attr('value', parms.page);
221 /* Protect against null input */
222 if (!dijit.byId('authTerm').attr('value')) {
226 /* Clear out the current contents of the page */
227 widgets = dijit.findWidgets(dojo.byId('authlist-div'));
228 dojo.forEach(widgets, function(w) { w.destroyRecursive(true); });
230 dojo.query("#authlist-div div").orphan();
232 url = '/opac/extras/startwith/marcxml/'
233 + dijit.byId('authAxis').attr('value')
234 // + '/' + dijit.byId('authOU').attr('value')
235 + '/1' // replace with preceding line if OUs gain some meaning
236 + '/' + dijit.byId('authTerm').attr('value')
237 + '/' + dijit.byId('authPage').attr('value')
238 + '/' + '20' // 20 results per page
240 dojo.xhrGet({"url":url, "handleAs":"xml", "content":{"format":"marcxml"}, "preventCache": true, "load":displayAuthorities });
243 function clearMergeRecords() {
244 records = dojo.query('.toMerge').orphan();
245 dojo.addClass('mergebox-div', 'hidden');
248 function mergeRecords() {
249 records = dojo.query('.toMerge').attr('id');
250 dojo.forEach(records, function(item, idx) {
251 records[idx] = parseInt(item.slice(item.lastIndexOf('_') + 1));
254 /* Take the first record in the list and use that as the master */
255 fieldmapper.standardRequest(
256 ['open-ils.cat', 'open-ils.cat.authority.records.merge'],
258 params: [openils.User.authtoken, records.shift(), records],
259 oncomplete : function(r) {
260 alert("Record merge is complete.");