<%inherit file="base.html" />
<%!
	import headphones
	from headphones import db, helpers
	myDB = db.DBConnection()
%>

<%def name="headerIncludes()">
	<div id="subhead_container">
		<div id="subhead_menu">
		</div>		
	</div>	
	<a href="manageUnmatched" class="back">&laquo; Back to Unmatched Albums</a>
</%def>


<%def name="body()">
	<div class="table_wrapper">
	<div id="manageheader" class="title">
		<h1 class="clearfix"><i class="fa fa-music"></i> Manage Manually Matched Albums</h1>
	</div>

	<table class="display" id="artist_table">
		<thead>
			<tr>
				<th id="artist">Local Artist</th>
				<th id="album">Local Album</th>
				<th id="status">Previous Action</th>
			</tr>
		</thead>
		<tbody>
		<% count_albums=0 %>
		%for album in manualalbums:
			<tr class="gradeZ">
			<%
				old_artist_clean = album['ArtistName'].replace('&','%26').replace('+', '%2B').replace("'","%27")
				old_album_clean = album['AlbumTitle'].replace('&','%26').replace('+', '%2B').replace("'","%27")
			%>
			<td id="artist">${album['ArtistName']}<BR>
				<button id="reset_artist${count_albums}" onClick="reset_Artist(this.id)">(<-) Reset Artist</button>
				<div id="reset_artist_dialog${count_albums}" title="Reset Artist" style="display:none">
					<table>
					<tr><td>Are you sure you want to reset Local Artist: ${album['ArtistName']} to unmatched?</td></tr>
					<tr><td align="right"><BR>
					%if album['AlbumStatus'] == "Ignored":
						<button href="javascript:void(0)" onclick="doAjaxCall('markManual?action=unignoreArtist&existing_artist=${old_artist_clean}', $(this), 'page');" data-success="Successfully reset ${album['ArtistName']} to unmatched">Reset Artist</button>
					%elif album['AlbumStatus'] == "Matched":
						<button href="javascript:void(0)" onclick="doAjaxCall('markManual?action=unmatchArtist&existing_artist=${old_artist_clean}', $(this), 'page');" data-success="Successfully restored ${album['ArtistName']} to unmatched">Reset Artist</button>
					%endif
					</td></tr>
					</table>
				</div>
			</td>
			<td id="album">${album['AlbumTitle']}<BR>
				<button id="reset_album${count_albums}" onClick="reset_Album(this.id)">(<-) Reset Album</button>
				<div id="reset_album_dialog${count_albums}" title="Reset Album" style="display:none">
					<table>
					<tr><td>Are you sure you want to reset Local Album: ${album['AlbumTitle']} to unmatched?</td></tr>
					<tr><td align="right"><BR>
					%if album['AlbumStatus'] == "Ignored":
						<button href="javascript:void(0)" onclick="doAjaxCall('markManual?action=unignoreAlbum&existing_artist=${old_artist_clean}&existing_album=${old_album_clean}', $(this), 'page');" data-success="Successfully reset ${album['AlbumTitle']} to unmatched">Reset Album</button>
					%elif album['AlbumStatus'] == "Matched":
						<button href="javascript:void(0)" onclick="doAjaxCall('markManual?action=unmatchAlbum&existing_artist=${old_artist_clean}&existing_album=${old_album_clean}', $(this), 'page');" data-success="Successfully reset ${album['AlbumTitle']} to unmatched">Reset Album</button>
					%endif
					</td></tr>
					</table>
				</div>

			</td>
			<td id="status">${album['AlbumStatus']}

			</td>
			</tr>
		<% count_albums+=1 %>
		%endfor
		</tbody>
	</table>
	</div>
</%def>

<%def name="headIncludes()">
	<link rel="stylesheet" href="interfaces/default/css/data_table.css">
</%def>

<%def name="javascriptIncludes()">
	<script src="js/libs/jquery.dataTables.min.js"></script>
	<script>
	$(document).ready(function() {
		$('#artist_table').dataTable({
			"bStateSave": true,
			"bPaginate": true,
			"oLanguage": {
				"sSearch": "",
                "sLengthMenu":"Show _MENU_ albums per page",
					"sInfo":"Showing _START_ to _END_ of _TOTAL_ albums",
					"sInfoEmpty":"Showing 0 to 0 of 0 albums",
					"sInfoFiltered":"(filtered from _MAX_ total albums)",
					"sEmptyTable": " ",
                    },
            "sPaginationType": "full_numbers",
            "fnDrawCallback": function (o) {
                // Jump to top of page
                $('html,body').scrollTop(0);
            }
         });

		initActions();
	});

	function reset_Artist(clicked_id) {
		n=clicked_id.replace("reset_artist","");
		$("#reset_artist_dialog"+n).dialog();
		return false;
	}

	function reset_Album(clicked_id) {
		n=clicked_id.replace("reset_album","");
		$("#reset_album_dialog"+n).dialog();
		return false;
	}

	</script>
</%def>
