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("fieldmapper.Fieldmapper");
11 dojo.require('openils.CGI');
12 dojo.require('openils.PermaCrud');
13 dojo.require('openils.XUL');
14 dojo.require('openils.widget.OrgUnitFilteringSelect');
16 var cgi = new openils.CGI();
19 // OrgUnits do not currently affect the retrieval of authority records,
20 // but this is how to display them if they become OrgUnit-aware
21 function authOUListInit() {
22 new openils.User().buildPermOrgSelector(
23 "STAFF_LOGIN", // anywhere you can log in
25 null, // pre-selected org
29 dojo.addOnLoad(authOUListInit);
31 function displayAuthorities(data) {
32 // Grab each record from the returned authority records
33 dojo.query("record", data).forEach(function(node) {
37 // Grab each authority record field from the authority record
38 dojo.query("datafield[tag^='1']", node).forEach(function(dfNode) {
39 authText += dojox.xml.parser.textContent(dfNode);
41 // Grab the ID of the authority record
42 dojo.query("datafield[tag='901'] subfield[code='c']", node).forEach(function(dfNode) {
43 authId = dojox.xml.parser.textContent(dfNode);
46 // Create the authority record listing entry
47 dojo.place('<div class="authEntry" id="auth' + authId + '"><span class="text">' + authText + '</span></div>', "authlist-div", "last");
49 // Add the menu of new/edit/delete/mark-for-merge options
50 var auth_menu = new dijit.Menu({});
53 new dijit.MenuItem({"id": "edit_" + authId, "onClick": function(){
54 recId = this.id.slice(this.id.lastIndexOf('_') + 1);
55 pcrud = new openils.PermaCrud();
56 auth_rec = pcrud.retrieve("are", recId);
58 loadMarcEditor(pcrud, auth_rec);
60 }, "label":"Edit"}).placeAt(auth_menu, "first");
63 new dijit.MenuItem({"id": "merge_" + authId, "onClick":function(){
65 recId = this.id.slice(this.id.lastIndexOf('_') + 1);
66 dojo.query('#auth' + recId + ' span.text').forEach(function(node) {
67 authText += dojox.xml.parser.textContent(node);
69 dojo.place('<div class="toMerge" id="toMerge_' + recId + '">' + authText + '</div>', 'mergebox-div', 'last');
70 dojo.removeClass('mergebox-div', 'hidden');
71 }, "label":"Mark for Merge"}).placeAt(auth_menu, "last");
74 new dijit.MenuItem({"id": "delete_" + authId, "onClick":function(){
75 recId = this.id.slice(this.id.lastIndexOf('_') + 1);
77 // Deleting an authority record is unusual; let's be 100% sure
78 if (!confirm("Are you sure you want to delete record " + recId + "?")) {
82 pcrud = new openils.PermaCrud();
83 auth_rec = pcrud.retrieve("are", recId);
85 pcrud.eliminate(auth_rec);
86 alert("Deleted authority record # " + recId);
88 }, "label":"Delete"}).placeAt(auth_menu, "last");
90 auth_mb = new dijit.form.DropDownButton({dropDown: auth_menu, label:"Actions"});
91 auth_mb.placeAt("auth" + authId, "first");
96 function loadMarcEditor(pcrud, rec) {
98 To run in Firefox directly, must set signed.applets.codebase_principal_support
99 to true in about:config
101 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
102 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
105 "record": {"marc": rec.marc()},
108 "func": function(xmlString) {
112 alert("Record was saved");
119 function authListInit() {
120 term = cgi.param('authTerm') || '';
121 page = cgi.param('authPage') || 0;
122 axis = cgi.param('authAxis') || 'authority.author';
124 dijit.byId('authAxis').attr('value', axis);
127 dijit.byId('authPage').attr('value', page);
130 dijit.byId('authTerm').attr('value', term);
133 dojo.connect(dijit.byId('authTerm'), 'onBlur', function() {
134 dijit.byId('authPage').attr('value', 0);
137 dojo.connect(dijit.byId('authTerm'), 'onKeyPress', function(evt) {
138 if (evt.keyCode == dojo.keys.ENTER) {
139 dijit.byId('authPage').attr('value', 0);
145 dojo.addOnLoad(authListInit);
147 function displayRecords(parms) {
149 if (parms && parms.page) {
150 if (parms.page == 'next') {
151 page = dijit.byId('authPage').attr('value');
152 dijit.byId('authPage').attr('value', page + 1);
153 } else if (parms.page == 'prev') {
154 page = dijit.byId('authPage').attr('value');
155 dijit.byId('authPage').attr('value', page - 1);
157 dijit.byId('authPage').attr('value', parms.page);
161 /* Protect against null input */
162 if (!dijit.byId('authTerm').attr('value')) {
166 /* Clear out the current contents of the page */
167 widgets = dijit.findWidgets(dojo.byId('authlist-div'));
168 dojo.forEach(widgets, function(w) { w.destroyRecursive(true); });
170 dojo.query("#authlist-div div").orphan();
172 url = '/opac/extras/startwith/marcxml/'
173 + dijit.byId('authAxis').attr('value')
174 // + '/' + dijit.byId('authOU').attr('value')
175 + '/1' // replace with preceding line if OUs gain some meaning
176 + '/' + dijit.byId('authTerm').attr('value')
177 + '/' + dijit.byId('authPage').attr('value')
179 dojo.xhrGet({"url":url, "handleAs":"xml", "content":{"format":"marcxml"}, "preventCache": true, "load":displayAuthorities });
182 function clearMergeRecords() {
183 records = dojo.query('.toMerge').orphan();
184 dojo.addClass('mergebox-div', 'hidden');
187 function mergeRecords() {
188 records = dojo.query('.toMerge').attr('id');
189 dojo.forEach(records, function(item, idx) {
190 records[idx] = parseInt(item.slice(item.lastIndexOf('_') + 1));
193 /* Take the first record in the list and use that as the master */
194 fieldmapper.standardRequest(
195 ['open-ils.cat', 'open-ils.cat.authority.records.merge'],
197 params: [openils.User.authtoken, records.shift(), records],
198 oncomplete : function(r) {
199 alert("Record merge is complete.");