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) {
158 alert("Record was saved");
165 function authListInit() {
166 term = cgi.param('authTerm') || '';
167 page = cgi.param('authPage') || 0;
168 axis = cgi.param('authAxis') || 'authority.author';
170 dijit.byId('authAxis').attr('value', axis);
173 dijit.byId('authPage').attr('value', page);
176 dijit.byId('authTerm').attr('value', term);
179 dojo.connect(dijit.byId('authTerm'), 'onBlur', function() {
180 dijit.byId('authPage').attr('value', 0);
183 dojo.connect(dijit.byId('authTerm'), 'onKeyPress', function(evt) {
184 if (evt.keyCode == dojo.keys.ENTER) {
185 dijit.byId('authPage').attr('value', 0);
191 dojo.addOnLoad(authListInit);
193 function displayRecords(parms) {
195 if (parms && parms.page) {
196 if (parms.page == 'next') {
197 page = dijit.byId('authPage').attr('value');
198 dijit.byId('authPage').attr('value', page + 1);
199 } else if (parms.page == 'prev') {
200 page = dijit.byId('authPage').attr('value');
201 dijit.byId('authPage').attr('value', page - 1);
203 dijit.byId('authPage').attr('value', parms.page);
207 /* Protect against null input */
208 if (!dijit.byId('authTerm').attr('value')) {
212 /* Clear out the current contents of the page */
213 widgets = dijit.findWidgets(dojo.byId('authlist-div'));
214 dojo.forEach(widgets, function(w) { w.destroyRecursive(true); });
216 dojo.query("#authlist-div div").orphan();
218 url = '/opac/extras/startwith/marcxml/'
219 + dijit.byId('authAxis').attr('value')
220 // + '/' + dijit.byId('authOU').attr('value')
221 + '/1' // replace with preceding line if OUs gain some meaning
222 + '/' + dijit.byId('authTerm').attr('value')
223 + '/' + dijit.byId('authPage').attr('value')
225 dojo.xhrGet({"url":url, "handleAs":"xml", "content":{"format":"marcxml"}, "preventCache": true, "load":displayAuthorities });
228 function clearMergeRecords() {
229 records = dojo.query('.toMerge').orphan();
230 dojo.addClass('mergebox-div', 'hidden');
233 function mergeRecords() {
234 records = dojo.query('.toMerge').attr('id');
235 dojo.forEach(records, function(item, idx) {
236 records[idx] = parseInt(item.slice(item.lastIndexOf('_') + 1));
239 /* Take the first record in the list and use that as the master */
240 fieldmapper.standardRequest(
241 ['open-ils.cat', 'open-ils.cat.authority.records.merge'],
243 params: [openils.User.authtoken, records.shift(), records],
244 oncomplete : function(r) {
245 alert("Record merge is complete.");