<commit_before>/*globals $ */

function listImages(collection, item) {
	// TODO: Check for an initialized datatable & if it exists, destroy it
	//Clear away any existing contents of the table in the DOM
	$('tbody#page-images').empty();
	// Hide the item selector div and display a modal dialogue while the appropriate page image links are retrieved
	$('#itemSelector').hide();
	$('#loading_modal').ajaxStart(function(){
		$(this).modal('show');
	});

	// Check to see if a partial manifest already exists
	var checkServer = $.ajax({
		type: "HEAD",
		url: "/metadata/manifests/" + item + ".xml"
	});
	// If a partial manifest exists, GET it and construct a table with the data returned
	checkServer.done(function() {
		var manifestPromise = $.ajax({
			type: "GET",
			url: "/metadata/manifests/" + item + ".xml",
			dataType: "xml"
		});
		// Create table rows with info retrieved from the server: filename | link to page image | label
		manifestPromise.done(function(xml) {
			// Set the name of the item as the title for the table
			$('#imageTable > h2').append(item);
			// Parse the XML returned by AJAX and build html strings with the data. Add them to the table
			$(xml).find("item").each(function(){
				var tdString = '<tr><td>'+$(this).children("filename").text()+'</td><td><a class="fancybox" href="http://sga.mith.org/images/derivatives/'+collection+'/'+$(this).children("filename").text()+'" target="_blank"><i class="icon-picture"></i></a></td><td class="editable">'+$(this).children("label").text()+'</td></tr>';
				$('#page-images').prepend(tdString);
			});
		});
		// Initialize jquery datatable from DOM table to add pagination, sorting, editing functionality
		manifestPromise.done(function() {
			// dataTable() takes an object with initialization parameters. See dataTable API
			var editableTable = $('#imageDataTable').dataTable({
				"bDestroy":true,
				"bStateSave": true,
				"sPaginationType": "full_numbers",
				"bAutoWidth": false
			});
			// Make the rows editable (this adds another dependency)
			$('td.editable', editableTable.fnGetNodes()).editable(function(value, settings) {
				var aPos = editableTable.fnGetPosition(this);
				editableTable.fnUpdate(value, aPos[0], aPos[1]);
			},
			{
				onblur : "submit"
			});
		});
		// Add an event handler to reset to item selection state
		$('#prev-to-manifest button').one('click', function() {
			// Hide the table, deactivate save, tear down data tables functionality & empty the table
			$('#imageTable').hide();
			$('#jsSave').off();
			$('#imageDataTable').dataTable().fnDestroy();
			$('tbody#page-images').empty();
			$('#imageTable > h2').empty();
			// Run getItems again to get the item list
			getItems($('#select-repo option:selected').attr('value'));
		});

		// When everything is constructed, add save handler, show the div with the table and clear the modal dialogue
		manifestPromise.done(function() {
			$('#jsSave').on("click", function(){
				saveManifest();
			});
			$('#imageTable').show();
			$('#loading_modal').ajaxStop(function(){
				$(this).modal('hide');
			});
		});
	}); // End of manifest exists block

	// If no manifest exists, GET the listing from the sga.mith.org/images directory & build the table from that
	checkServer.fail(function() {
		var remoteDirPromise = $.ajax({
			type: "GET",
			url: "/metadata/xq/image_getter.xquery?coll-id="+collection+"&item="+item,
			dataType: "xml"
		});
		remoteDirPromise.done(function(xml){
			$('#imageTable > h2').append(item);
			$(xml).find("a").each(function(){
				var tdString = '<tr><td>'+$(this).text()+'</td><td><a href="http://sga.mith.org/images/derivatives/'+collection+'/'+$(this).text()+'" target="_blank"><i class="icon-picture"></i></a></td><td class="editable">&#x20;</td></tr>';
				$('#page-images').prepend(tdString);
			});
		});
		remoteDirPromise.done(function() {
			// dataTable() takes an object with initialization parameters. See dataTable API
			var editableTable = $('#imageDataTable').dataTable({
				"bDestroy":true,
				"bStateSave": true,
				"sPaginationType": "full_numbers",
				"bAutoWidth": false
			});
			// Make the rows editable (this adds another dependency)
			$('td.editable', editableTable.fnGetNodes()).editable(function(value, settings) {
				var aPos = editableTable.fnGetPosition(this);<commit_msg>HOTFIX: restore lightbox functionality on image lists from new manifest<commit_after>/*globals $ */

function listImages(collection, item) {
	// TODO: Check for an initialized datatable & if it exists, destroy it
	//Clear away any existing contents of the table in the DOM
	$('tbody#page-images').empty();
	// Hide the item selector div and display a modal dialogue while the appropriate page image links are retrieved
	$('#itemSelector').hide();
	$('#loading_modal').ajaxStart(function(){
		$(this).modal('show');
	});

	// Check to see if a partial manifest already exists
	var checkServer = $.ajax({
		type: "HEAD",
		url: "/metadata/manifests/" + item + ".xml"
	});
	// If a partial manifest exists, GET it and construct a table with the data returned
	checkServer.done(function() {
		var manifestPromise = $.ajax({
			type: "GET",
			url: "/metadata/manifests/" + item + ".xml",
			dataType: "xml"
		});
		// Create table rows with info retrieved from the server: filename | link to page image | label
		manifestPromise.done(function(xml) {
			// Set the name of the item as the title for the table
			$('#imageTable > h2').append(item);
			// Parse the XML returned by AJAX and build html strings with the data. Add them to the table
			$(xml).find("item").each(function(){
				var tdString = '<tr><td>'+$(this).children("filename").text()+'</td><td><a class="fancybox" href="http://sga.mith.org/images/derivatives/'+collection+'/'+$(this).children("filename").text()+'" target="_blank"><i class="icon-picture"></i></a></td><td class="editable">'+$(this).children("label").text()+'</td></tr>';
				$('#page-images').prepend(tdString);
			});
		});
		// Initialize jquery datatable from DOM table to add pagination, sorting, editing functionality
		manifestPromise.done(function() {
			// dataTable() takes an object with initialization parameters. See dataTable API
			var editableTable = $('#imageDataTable').dataTable({
				"bDestroy":true,
				"bStateSave": true,
				"sPaginationType": "full_numbers",
				"bAutoWidth": false
			});
			// Make the rows editable (this adds another dependency)
			$('td.editable', editableTable.fnGetNodes()).editable(function(value, settings) {
				var aPos = editableTable.fnGetPosition(this);
				editableTable.fnUpdate(value, aPos[0], aPos[1]);
			},
			{
				onblur : "submit"
			});
		});
		// Add an event handler to reset to item selection state
		$('#prev-to-manifest button').one('click', function() {
			// Hide the table, deactivate save, tear down data tables functionality & empty the table
			$('#imageTable').hide();
			$('#jsSave').off();
			$('#imageDataTable').dataTable().fnDestroy();
			$('tbody#page-images').empty();
			$('#imageTable > h2').empty();
			// Run getItems again to get the item list
			getItems($('#select-repo option:selected').attr('value'));
		});

		// When everything is constructed, add save handler, show the div with the table and clear the modal dialogue
		manifestPromise.done(function() {
			$('#jsSave').on("click", function(){
				saveManifest();
			});
			$('#imageTable').show();
			$('#loading_modal').ajaxStop(function(){
				$(this).modal('hide');
			});
		});
	}); // End of manifest exists block

	// If no manifest exists, GET the listing from the sga.mith.org/images directory & build the table from that
	checkServer.fail(function() {
		var remoteDirPromise = $.ajax({
			type: "GET",
			url: "/metadata/xq/image_getter.xquery?coll-id="+collection+"&item="+item,
			dataType: "xml"
		});
		remoteDirPromise.done(function(xml){
			$('#imageTable > h2').append(item);
			$(xml).find("a").each(function(){
				var tdString = '<tr><td>'+$(this).text()+'</td><td><a class="fancybox" href="http://sga.mith.org/images/derivatives/'+collection+'/'+$(this).text()+'" target="_blank"><i class="icon-picture"></i></a></td><td class="editable">&#x20;</td></tr>';
				$('#page-images').prepend(tdString);
			});
		});
		remoteDirPromise.done(function() {
			// dataTable() takes an object with initialization parameters. See dataTable API
			var editableTable = $('#imageDataTable').dataTable({
				"bDestroy":true,
				"bStateSave": true,
				"sPaginationType": "full_numbers",
				"bAutoWidth": false
			});
			// Make the rows editable (this adds another dependency)
			$('td.editable', editableTable.fnGetNodes()).editable(function(value, settings) {
				var aPos = editableTable.fnGetPosition(this);
{'fraction_non_alphanumeric': 0.1813798645390885, 'fraction_numerical': 0.0016071633566754678, 'mean_word_length': 4.26404833836858, 'pattern_counts': {'":': 16, '<': 51, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3155379', 'n_tokens_mistral': 2918, 'n_tokens_neox': 2599, 'n_words': 705}