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('openils.CGI');
11 dojo.require('dojo.dnd.Source');
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', 'displayRecords');
135 dojo.addOnLoad(authListInit);
137 function displayRecords(parms) {
139 if (parms && parms.page) {
140 if (parms.page == 'next') {
141 page = dijit.byId('authPage').attr('value');
142 dijit.byId('authPage').attr('value', page + 1);
143 } else if (parms.page == 'prev') {
144 page = dijit.byId('authPage').attr('value');
145 dijit.byId('authPage').attr('value', page - 1);
147 dijit.byId('authPage').attr('value', parms.page);
151 /* Protect against null input */
152 if (!dijit.byId('authTerm').attr('value')) {
156 /* Clear out the current contents of the page */
157 widgets = dijit.findWidgets(dojo.byId('authlist-div'));
158 dojo.forEach(widgets, function(w) { w.destroyRecursive(true); });
160 dojo.query("#authlist-div div").orphan();
162 url = '/opac/extras/startwith/marcxml/'
163 + dijit.byId('authAxis').attr('value')
164 // + '/' + dijit.byId('authOU').attr('value')
165 + '/1' // replace with preceding line if OUs gain some meaning
166 + '/' + dijit.byId('authTerm').attr('value')
167 + '/' + dijit.byId('authPage').attr('value')
169 dojo.xhrGet({"url":url, "handleAs":"xml", "content":{"format":"marcxml"}, "preventCache": true, "load":displayAuthorities });
172 function clearMergeRecords() {
173 records = dojo.query('.toMerge').orphan();
174 dojo.addClass('mergebox-div', 'hidden');
177 function mergeRecords() {
178 records = dojo.query('.toMerge').attr('id');
179 dojo.forEach(records, function(item, idx) {
180 records[idx] = parseInt(item.slice(item.lastIndexOf('_') + 1));
182 alert('TODO: actually merge the gathered records: ' + dojo.toJson(records));