From 1575068f2105b141b1da3cc2ffdc371e25695dba Mon Sep 17 00:00:00 2001 From: dbs Date: Tue, 28 Dec 2010 06:16:56 +0000 Subject: [PATCH] Towards a more useful authority delete confirmation pane Rather than simply creating a raw confirm dialogue that only provides the cataloguer with the ID of the authority record that is about to be deleted (not an especially useful handle), supply a confirmation dialogue that recaps how many bibliographic records are linked to this authority record and also displays the MARC of the record about to be deleted. Most authority records appear to be short enough that the MARC display is not a concern, but if it becomes a problem we can opt not to show the MARC by default and give the cataloguer the ability to click a "View MARC" button on the confirmation dialog instead. Along the way, make some more variables local and remove some unnecessary workarounds for object IDs. git-svn-id: svn://svn.open-ils.org/ILS/trunk@19067 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/ui/default/cat/authority/list.js | 95 +++++++++++++++++++----- 1 file changed, 75 insertions(+), 20 deletions(-) diff --git a/Open-ILS/web/js/ui/default/cat/authority/list.js b/Open-ILS/web/js/ui/default/cat/authority/list.js index eab6cb097..68b75f75a 100644 --- a/Open-ILS/web/js/ui/default/cat/authority/list.js +++ b/Open-ILS/web/js/ui/default/cat/authority/list.js @@ -1,3 +1,4 @@ +dojo.require('dijit.Dialog'); dojo.require('dijit.form.Button'); dojo.require('dijit.form.DropDownButton'); dojo.require('dijit.form.FilteringSelect'); @@ -62,9 +63,8 @@ function displayAuthorities(data) { // "Edit" menu item new dijit.MenuItem({"id": "edit_" + auth.id, "onClick": function(){ - recId = this.id.slice(this.id.lastIndexOf('_') + 1); - pcrud = new openils.PermaCrud(); - auth_rec = pcrud.retrieve("are", recId); + var pcrud = new openils.PermaCrud(); + var auth_rec = pcrud.retrieve("are", auth.id); if (auth_rec) { loadMarcEditor(pcrud, auth_rec); } @@ -73,8 +73,7 @@ function displayAuthorities(data) { // "Merge" menu item new dijit.MenuItem({"id": "merge_" + auth.id, "onClick":function(){ auth.text = ''; - recId = this.id.slice(this.id.lastIndexOf('_') + 1); - dojo.query('#auth' + recId + ' span.text').forEach(function(node) { + dojo.query('#auth' + auth.id + ' span.text').forEach(function(node) { auth.text += dojox.xml.parser.textContent(node); }); @@ -87,26 +86,42 @@ function displayAuthorities(data) { mergeRole += 'Master'; } - dojo.place('' + mergeRole + '' + auth.text + '', 'mergebox-tbody', 'last'); - dojo.place('' + auth.name + ' ' + auth.ind1 + auth.ind2 + '', 'mergeMeta_' + recId, 'last'); + dojo.place('' + mergeRole + '' + auth.text + '', 'mergebox-tbody', 'last'); + dojo.place('' + auth.name + ' ' + auth.ind1 + auth.ind2 + '', 'mergeMeta_' + auth.id, 'last'); dojo.removeClass('mergebox-div', 'hidden'); }, "label":"Mark for Merge"}).placeAt(auth_menu, "last"); // "Delete" menu item - new dijit.MenuItem({"id": "delete_" + auth.id, "onClick":function(){ - recId = this.id.slice(this.id.lastIndexOf('_') + 1); - - // Deleting an authority record is unusual; let's be 100% sure - if (!confirm("Are you sure you want to delete record " + recId + "?")) { - return; - } + new dijit.MenuItem({ + "id": "delete_" + auth.id, + "onClick":function(){ + auth.text = ''; + + var pcrud = new openils.PermaCrud(); + var auth_rec = pcrud.retrieve("are", auth.id); + + // Bit of a hack to get the linked bib count until an explicit ID + var linkedBibs = dojox.xml.parser.textContent( + dojo.query("#authLabel" + auth.id)[0].previousSibling + ); + + var delDlg = dijit.byId("delDialog_" + auth.id); + + dojo.query('#auth' + auth.id + ' span.text').forEach(function(node) { + auth.text += dojox.xml.parser.textContent(node); + }); + + if (!delDlg) { + delDlg = new dijit.Dialog({ + "id":"delDialog_" + auth.id, + "title":"Confirm deletion of record # " + auth.id + " (" + auth.text + ") ", + "content":"
Number of linked bibliographic records: " + linkedBibs + "

" + + marcToHTML(auth_rec.marc()) + + "
" + }); + } + delDlg.show(); - 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", id:"menu" + auth.id}); @@ -115,7 +130,47 @@ function displayAuthorities(data) { }); showBibCount(idArr); +} +function marcToHTML(marc) { + var html = ''; + marc = dojox.xml.parser.parse(marc); + dojo.query('leader', marc).forEach(function(node) { + html += ''; + }); + dojo.query('controlfield', marc).forEach(function(node) { + html += ''; + }); + dojo.query('datafield', marc).forEach(function(node) { + var cnt = 0; + html += ''; + dojo.query('subfield', node).forEach(function(sf) { + if (cnt == 0) { + html += ''; + cnt = 1; + } else { + html += ''; + } + }); + }); + html += '
LDR  ' + dojox.xml.parser.textContent(node) + '
' + dojo.attr(node, "tag") + '  ' + dojox.xml.parser.textContent(node) + '
' + dojo.attr(node, "tag") + '' + dojo.attr(node, "ind1") + '' + dojo.attr(node, "ind2") + '$' + dojo.attr(sf, "code") + ' ' + dojox.xml.parser.textContent(sf) + '
$' + dojo.attr(sf, "code") + ' ' + dojox.xml.parser.textContent(sf) + '
'; + return html; +} + +function cancelDelete(recId) { + dijit.byId("delDialog_" + recId).hide(); +} + +function confirmDelete(recId) { + var pcrud = new openils.PermaCrud(); + var auth_rec = pcrud.retrieve("are", recId); + if (auth_rec) { + pcrud.eliminate(auth_rec); + dijit.byId("delDialog_" + recId).attr("content", "Deleted authority record # " + recId); + setTimeout(function() { + dijit.byId("delDialog_" + recId).hide(); + }, 3000); + } } function showBibCount(authIds) { -- 2.11.0