@@ -1073,23 +1073,18 @@ function createPdfSelectionWithTooltip(selectionName, page, firstX, firstY, seco
10731073function createSourceReference ( source ) {
10741074 let sourceName = source . getAttribute ( "name" ) ;
10751075 let plainTextPath = source . getAttribute ( "plainTextPath" ) ;
1076-
1076+ let path = plainTextPath . replace ( "internal://" , "sources/" )
10771077 if ( isZipMode ( ) ) {
10781078 // In zip mode, create a link that uses the zip entry
1079- if ( typeof entryMap !== 'undefined' && plainTextPath && entryMap [ plainTextPath ] !== undefined ) {
1080- let entryIndex = entryMap [ plainTextPath ] ;
1081- return ' <a href="#" data-entry-index="' + entryIndex + '"> ' + sourceName + '</a>' ;
1079+ if ( typeof entryMap !== 'undefined' && path && entryMap [ path ] !== undefined ) {
1080+ let entryIndex = entryMap [ path ] ;
1081+ return sourceName + ' <a href="#" data-entry-index="' + entryIndex + '" data-entry-name=" ' + sourceName + '" title="Download Source: ' + sourceName + '"><span class="glyphicon glyphicon-download-alt"></span> </a>';
10821082 } else {
10831083 // No link if file not found in zip
10841084 return sourceName ;
10851085 }
10861086 } else {
1087- // In non-zip mode, create a direct link to the file if it exists
1088- if ( plainTextPath ) {
1089- return '<a href="' + plainTextPath + '" target="_blank">' + sourceName + '</a>' ;
1090- } else {
1091- return sourceName ;
1092- }
1087+ return sourceName ;
10931088 }
10941089}
10951090
@@ -1237,10 +1232,25 @@ async function loadTextExcerpt(plainTextPath, startPos, endPos, sourceGuid) {
12371232}
12381233
12391234function redactSources ( guidsToRedact ) {
1240- console . log ( "Redacting sources with GUIDs:" , guidsToRedact ) ;
1241- alert ( "Redaction functionality is not yet implemented.\nSelected source GUIDs: " + guidsToRedact . join ( ', ' ) ) ;
1235+ console . log ( "Redacting sources with GUIDs:" , guidsToRedact ) ;
1236+
1237+ let redactedXmlDoc = xmlDoc . cloneNode ( true ) ;
1238+
1239+ for ( const guid of guidsToRedact ) {
1240+ // Find any source element by its GUID and remove it.
1241+ // This will also remove all its children, including annotations.
1242+ let sourceElement = redactedXmlDoc . querySelector ( '[guid="' + guid + '"]' ) ;
1243+ if ( sourceElement && sourceElement . parentNode ) {
1244+ sourceElement . parentNode . removeChild ( sourceElement ) ;
1245+ console . log ( "Removed source element and its annotations with GUID:" , guid ) ;
1246+ }
1247+ }
1248+
1249+ // For now, let's just log the redacted XML to the console to verify
1250+ console . log ( "Redacted XML:" , new XMLSerializer ( ) . serializeToString ( redactedXmlDoc ) ) ;
1251+ alert ( "Redaction of XML complete. See console for redacted XML. Next steps will handle file saving." ) ;
1252+
12421253 // In the next steps, we will implement the logic here to:
1243- // 1. Modify the XML codebook to remove selected sources and their annotations.
1244- // 2. If it's a zip file, remove the source files from the archive.
1245- // 3. POST the new redacted file to Dataverse.
1254+ // 1. If it's a zip file, remove the source files from the archive.
1255+ // 2. POST the new redacted file to Dataverse.
12461256}
0 commit comments