From 1f0033aba4164cadeee8d7e481ac657b5f5f186c Mon Sep 17 00:00:00 2001 From: dbs Date: Fri, 20 Aug 2010 03:27:04 +0000 Subject: [PATCH] Give the Authority List interface the ability to merge records... almost Separate the interface into separate JavaScript vs markup files To-do: * Provide a middle layer method that accepts the array of records to merge and merges them * Teach the mergeRecords() to call that method when it exists * Provide a way of reordering the records or otherwise flagging which record should be the lead * Prevent the same record from being added to the merge slushbox twice git-svn-id: svn://svn.open-ils.org/ILS/trunk@17275 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/ui/default/cat/authority/list.js | 177 +++++++++++++++++++++ .../web/templates/default/cat/authority/list.tt2 | 177 +++------------------ 2 files changed, 195 insertions(+), 159 deletions(-) create mode 100644 Open-ILS/web/js/ui/default/cat/authority/list.js diff --git a/Open-ILS/web/js/ui/default/cat/authority/list.js b/Open-ILS/web/js/ui/default/cat/authority/list.js new file mode 100644 index 0000000000..5cffc9eabe --- /dev/null +++ b/Open-ILS/web/js/ui/default/cat/authority/list.js @@ -0,0 +1,177 @@ +dojo.require('dijit.form.Button'); +dojo.require('dijit.form.DropDownButton'); +dojo.require('dijit.form.FilteringSelect'); +dojo.require('dijit.form.Form'); +dojo.require('dijit.form.NumberSpinner'); +dojo.require('dijit.form.TextBox'); +dojo.require("dijit.Menu"); +dojo.require("dijit.MenuItem"); +dojo.require('dojox.xml.parser'); +dojo.require('openils.CGI'); +dojo.require('dojo.dnd.Source'); +dojo.require('openils.PermaCrud'); +dojo.require('openils.XUL'); +dojo.require('openils.widget.OrgUnitFilteringSelect'); + +var cgi = new openils.CGI(); + +/* +// OrgUnits do not currently affect the retrieval of authority records, +// but this is how to display them if they become OrgUnit-aware +function authOUListInit() { + new openils.User().buildPermOrgSelector( + "STAFF_LOGIN", // anywhere you can log in + dijit.byId("authOU"), + null, // pre-selected org + null + ); +} +dojo.addOnLoad(authOUListInit); +*/ +function displayAuthorities(data) { + // Grab each record from the returned authority records + dojo.query("record", data).forEach(function(node) { + authText = ''; + authId = 0; + + // Grab each authority record field from the authority record + dojo.query("datafield[tag^='1']", node).forEach(function(dfNode) { + authText += dojox.xml.parser.textContent(dfNode); + }); + // Grab the ID of the authority record + dojo.query("datafield[tag='901'] subfield[code='c']", node).forEach(function(dfNode) { + authId = dojox.xml.parser.textContent(dfNode); + }); + + // Create the authority record listing entry + dojo.place('
' + authText + '
', "authlist-div", "last"); + + // Add the menu of new/edit/delete/mark-for-merge options + var auth_menu = new dijit.Menu({}); + + // "Edit" menu item + new dijit.MenuItem({"id": "edit_" + authId, "onClick": function(){ + recId = this.id.slice(this.id.lastIndexOf('_') + 1); + pcrud = new openils.PermaCrud(); + auth_rec = pcrud.retrieve("are", recId); + if (auth_rec) { + loadMarcEditor(pcrud, auth_rec); + } + }, "label":"Edit"}).placeAt(auth_menu, "first"); + + // "Merge" menu item + new dijit.MenuItem({"id": "merge_" + authId, "onClick":function(){ + authText = ''; + recId = this.id.slice(this.id.lastIndexOf('_') + 1); + dojo.query('#auth' + recId + ' span.text').forEach(function(node) { + authText += dojox.xml.parser.textContent(node); + }); + dojo.place('
' + authText + '
', 'mergebox-div', 'last'); + dojo.removeClass('mergebox-div', 'hidden'); + }, "label":"Mark for Merge"}).placeAt(auth_menu, "last"); + + // "Delete" menu item + new dijit.MenuItem({"id": "delete_" + authId, "onClick":function(){ + recId = this.id.slice(this.id.lastIndexOf('_') + 1); + pcrud = new openils.PermaCrud(); + auth_rec = pcrud.retrieve("are", recId); + if (auth_rec) { + pcrud.eliminate(auth_rec); + alert("Deleted authority record # " + recId); + } + }, "label":"Delete"}).placeAt(auth_menu, "last"); + + auth_mb = new dijit.form.DropDownButton({dropDown: auth_menu, label:"Actions"}); + auth_mb.placeAt("auth" + authId, "first"); + auth_menu.startup(); + }); +} + +function loadMarcEditor(pcrud, rec) { + /* + To run in Firefox directly, must set signed.applets.codebase_principal_support + to true in about:config + */ + netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); + win = window.open('/xul/server/cat/marcedit.xul'); // XXX version? + + win.xulG = { + "record": {"marc": rec.marc()}, + "save": { + "label": "Save", + "func": function(xmlString) { + rec.marc(xmlString); + rec.ischanged(true); + pcrud.update(rec); + alert("Record was saved"); + win.close(); + } + } + }; +} + +function authListInit() { + term = cgi.param('authTerm') || ''; + page = cgi.param('authPage') || 0; + axis = cgi.param('authAxis') || 'authority.author'; + if (axis) { + dijit.byId('authAxis').attr('value', axis); + } + if (page) { + dijit.byId('authPage').attr('value', page); + } + if (term) { + dijit.byId('authTerm').attr('value', term); + displayRecords(); + } + dojo.connect(dijit.byId('authTerm'), 'onBlur', 'displayRecords'); +} +dojo.addOnLoad(authListInit); + +function displayRecords(parms) { + + if (parms && parms.page) { + if (parms.page == 'next') { + page = dijit.byId('authPage').attr('value'); + dijit.byId('authPage').attr('value', page + 1); + } else if (parms.page == 'prev') { + page = dijit.byId('authPage').attr('value'); + dijit.byId('authPage').attr('value', page - 1); + } else { + dijit.byId('authPage').attr('value', parms.page); + } + } + + /* Protect against null input */ + if (!dijit.byId('authTerm').attr('value')) { + return; + } + + /* Clear out the current contents of the page */ + widgets = dijit.findWidgets(dojo.byId('authlist-div')); + dojo.forEach(widgets, function(w) { w.destroyRecursive(true); }); + + dojo.query("#authlist-div div").orphan(); + + url = '/opac/extras/startwith/marcxml/' + + dijit.byId('authAxis').attr('value') + // + '/' + dijit.byId('authOU').attr('value') + + '/1' // replace with preceding line if OUs gain some meaning + + '/' + dijit.byId('authTerm').attr('value') + + '/' + dijit.byId('authPage').attr('value') + ; + dojo.xhrGet({"url":url, "handleAs":"xml", "content":{"format":"marcxml"}, "preventCache": true, "load":displayAuthorities }); +} + +function clearMergeRecords() { + records = dojo.query('.toMerge').orphan(); + dojo.addClass('mergebox-div', 'hidden'); +} + +function mergeRecords() { + records = dojo.query('.toMerge').attr('id'); + dojo.forEach(records, function(item, idx) { + records[idx] = parseInt(item.slice(item.lastIndexOf('_') + 1)); + }); + alert('TODO: actually merge the gathered records: ' + dojo.toJson(records)); +} diff --git a/Open-ILS/web/templates/default/cat/authority/list.tt2 b/Open-ILS/web/templates/default/cat/authority/list.tt2 index a85c799aac..ecfe26003d 100644 --- a/Open-ILS/web/templates/default/cat/authority/list.tt2 +++ b/Open-ILS/web/templates/default/cat/authority/list.tt2 @@ -1,165 +1,24 @@ [% ctx.page_title = 'Authority record list' %] [% WRAPPER default/base.tt2 %] - + + +
-- 2.11.0