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);
74 dojo.place('<div class="toMerge" id="toMerge_' + recId + '">' + authText + '</div>', 'mergebox-div', 'last');
75 dojo.removeClass('mergebox-div', 'hidden');
76 }, "label":"Mark for Merge"}).placeAt(auth_menu, "last");
79 new dijit.MenuItem({"id": "delete_" + authId, "onClick":function(){
80 recId = this.id.slice(this.id.lastIndexOf('_') + 1);
82 // Deleting an authority record is unusual; let's be 100% sure
83 if (!confirm("Are you sure you want to delete record " + recId + "?")) {
87 pcrud = new openils.PermaCrud();
88 auth_rec = pcrud.retrieve("are", recId);
90 pcrud.eliminate(auth_rec);
91 alert("Deleted authority record # " + recId);
93 }, "label":"Delete"}).placeAt(auth_menu, "last");
95 auth_mb = new dijit.form.DropDownButton({dropDown: auth_menu, label:"Actions", id:"menu" + authId});
96 auth_mb.placeAt("auth" + authId, "first");
104 function showBibCount(authIds) {
105 /* Decorate the list with # of bibs linked to each authority record */
106 var ses = new OpenSRF.ClientSession('open-ils.cat');
107 var req = ses.request('open-ils.cat.authority.records.count_linked_bibs', authIds);
109 req.oncomplete = function(r) {
110 var msg = r.recv().content();
111 dojo.forEach(msg, function(auth) {
112 linkedIds.push(auth.authority);
113 dojo.place('<span class="bibcount">' + auth.bibs + '</span>', 'authLabel' + auth.authority, 'before');
117 /* Assign counts of 0 for every non-linked authority */
118 dojo.forEach(authIds, function (id) {
120 dojo.forEach(linkedIds, function (lid) {
126 dojo.place('<span class="bibcount">0</span>', 'authLabel' + id, 'before');
133 function loadMarcEditor(pcrud, rec) {
135 To run in Firefox directly, must set signed.applets.codebase_principal_support
136 to true in about:config
138 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
139 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
142 "record": {"marc": rec.marc()},
145 "func": function(xmlString) {
149 alert("Record was saved");
156 function authListInit() {
157 term = cgi.param('authTerm') || '';
158 page = cgi.param('authPage') || 0;
159 axis = cgi.param('authAxis') || 'authority.author';
161 dijit.byId('authAxis').attr('value', axis);
164 dijit.byId('authPage').attr('value', page);
167 dijit.byId('authTerm').attr('value', term);
170 dojo.connect(dijit.byId('authTerm'), 'onBlur', function() {
171 dijit.byId('authPage').attr('value', 0);
174 dojo.connect(dijit.byId('authTerm'), 'onKeyPress', function(evt) {
175 if (evt.keyCode == dojo.keys.ENTER) {
176 dijit.byId('authPage').attr('value', 0);
182 dojo.addOnLoad(authListInit);
184 function displayRecords(parms) {
186 if (parms && parms.page) {
187 if (parms.page == 'next') {
188 page = dijit.byId('authPage').attr('value');
189 dijit.byId('authPage').attr('value', page + 1);
190 } else if (parms.page == 'prev') {
191 page = dijit.byId('authPage').attr('value');
192 dijit.byId('authPage').attr('value', page - 1);
194 dijit.byId('authPage').attr('value', parms.page);
198 /* Protect against null input */
199 if (!dijit.byId('authTerm').attr('value')) {
203 /* Clear out the current contents of the page */
204 widgets = dijit.findWidgets(dojo.byId('authlist-div'));
205 dojo.forEach(widgets, function(w) { w.destroyRecursive(true); });
207 dojo.query("#authlist-div div").orphan();
209 url = '/opac/extras/startwith/marcxml/'
210 + dijit.byId('authAxis').attr('value')
211 // + '/' + dijit.byId('authOU').attr('value')
212 + '/1' // replace with preceding line if OUs gain some meaning
213 + '/' + dijit.byId('authTerm').attr('value')
214 + '/' + dijit.byId('authPage').attr('value')
216 dojo.xhrGet({"url":url, "handleAs":"xml", "content":{"format":"marcxml"}, "preventCache": true, "load":displayAuthorities });
219 function clearMergeRecords() {
220 records = dojo.query('.toMerge').orphan();
221 dojo.addClass('mergebox-div', 'hidden');
224 function mergeRecords() {
225 records = dojo.query('.toMerge').attr('id');
226 dojo.forEach(records, function(item, idx) {
227 records[idx] = parseInt(item.slice(item.lastIndexOf('_') + 1));
230 /* Take the first record in the list and use that as the master */
231 fieldmapper.standardRequest(
232 ['open-ils.cat', 'open-ils.cat.authority.records.merge'],
234 params: [openils.User.authtoken, records.shift(), records],
235 oncomplete : function(r) {
236 alert("Record merge is complete.");