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);
76 pcrud = new openils.PermaCrud();
77 auth_rec = pcrud.retrieve("are", recId);
79 pcrud.eliminate(auth_rec);
80 alert("Deleted authority record # " + recId);
82 }, "label":"Delete"}).placeAt(auth_menu, "last");
84 auth_mb = new dijit.form.DropDownButton({dropDown: auth_menu, label:"Actions"});
85 auth_mb.placeAt("auth" + authId, "first");
90 function loadMarcEditor(pcrud, rec) {
92 To run in Firefox directly, must set signed.applets.codebase_principal_support
93 to true in about:config
95 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
96 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
99 "record": {"marc": rec.marc()},
102 "func": function(xmlString) {
106 alert("Record was saved");
113 function authListInit() {
114 term = cgi.param('authTerm') || '';
115 page = cgi.param('authPage') || 0;
116 axis = cgi.param('authAxis') || 'authority.author';
118 dijit.byId('authAxis').attr('value', axis);
121 dijit.byId('authPage').attr('value', page);
124 dijit.byId('authTerm').attr('value', term);
127 dojo.connect(dijit.byId('authTerm'), 'onBlur', 'displayRecords');
129 dojo.addOnLoad(authListInit);
131 function displayRecords(parms) {
133 if (parms && parms.page) {
134 if (parms.page == 'next') {
135 page = dijit.byId('authPage').attr('value');
136 dijit.byId('authPage').attr('value', page + 1);
137 } else if (parms.page == 'prev') {
138 page = dijit.byId('authPage').attr('value');
139 dijit.byId('authPage').attr('value', page - 1);
141 dijit.byId('authPage').attr('value', parms.page);
145 /* Protect against null input */
146 if (!dijit.byId('authTerm').attr('value')) {
150 /* Clear out the current contents of the page */
151 widgets = dijit.findWidgets(dojo.byId('authlist-div'));
152 dojo.forEach(widgets, function(w) { w.destroyRecursive(true); });
154 dojo.query("#authlist-div div").orphan();
156 url = '/opac/extras/startwith/marcxml/'
157 + dijit.byId('authAxis').attr('value')
158 // + '/' + dijit.byId('authOU').attr('value')
159 + '/1' // replace with preceding line if OUs gain some meaning
160 + '/' + dijit.byId('authTerm').attr('value')
161 + '/' + dijit.byId('authPage').attr('value')
163 dojo.xhrGet({"url":url, "handleAs":"xml", "content":{"format":"marcxml"}, "preventCache": true, "load":displayAuthorities });
166 function clearMergeRecords() {
167 records = dojo.query('.toMerge').orphan();
168 dojo.addClass('mergebox-div', 'hidden');
171 function mergeRecords() {
172 records = dojo.query('.toMerge').attr('id');
173 dojo.forEach(records, function(item, idx) {
174 records[idx] = parseInt(item.slice(item.lastIndexOf('_') + 1));
176 alert('TODO: actually merge the gathered records: ' + dojo.toJson(records));