namethatanime / templates / user_settings.html

<h2>Settings</h2>

<h3 id="banhead">Banned anime (<span id="bansize">0</span>/10)</h3>
You can block anime you don't like from appearing in game.<br/><br/>


<input id="anime" style="width: 350px;"/>
<input id="anime_id" type="hidden"/>
<input type="submit" class="btn primary" value="Add" id="add" style="margin-left: 20px;">
<br/>
<br/>
<div class="row">
 <div id="banlist" class="span8">
 </div>
</div>

<script type="text/javascript" src="/static/js/animelist.js"></script>
<script>
	var banned_titles = new Array();
	$(function() {
		{% if banned %}
			var banned = {{ banned }};	
			$('#bansize').text(banned.length);
			
			$.each(banned, function(j, b) {
				$.each(animes, function(i, a) {
					if (a.id == b) {
						banned_titles[banned_titles.length] = a.value;
						var list_entry = '<div class="alert-message warning fade in" id="a' + a.id + '"><a class="close" href="#">×</a>' + a.value + '</div>';
						$('#banlist').append(list_entry);
						$("div[id^='a"+a.id + "'] > a").click( function () {
							var id = $(this).parent().attr('id').replace('a','');
							var map = { 
								anime_id: id,
							}						
							$.post("/u{{ user.id }}/settings/remban", map,
								function(data) {
									  if (data == 'ok') {
										  banned_titles.splice($("div[id='a"+id + "']").text().substr(1), 1);
										  $("div[id='a"+id + "']").remove();
										  $('#banerr').remove();
										  $('#bansize').text(banned_titles.length);
									  } else {
										  alert('Error: ' + data);
									  }
								 }
							);							
						});
						return false;
					}				
				});		
			});	
		{% end %}
		
		$( "#anime" ).focus( function () {
			$('#banerr').remove();
		});
		
		$( "#anime" ).autocomplete({		
			minLength: 3,
			source: animes,
			select: function( event, ui ) {
				$( "#anime" ).val( ui.item.value );
				$( "#anime_id" ).val( ui.item.id );
				return false;
			}
		});		
		
		$("#add").click( function () {
			// Check length
			if (banned_titles.length == 10) {
				$('#banerr').remove();
				$('#banhead').append('<p class="alert-message block-message error" id="banerr">Limit reached!</p>');
			} else {							
				var found = false;
				// Search duplicates
				$.each(banned_titles, function(i, a) {
					if (a == $( "#anime" ).val()) {
						found = true;
					}				
				});
				if (found) {
					$('#banerr').remove();
					$('#banhead').append('<p class="alert-message block-message error" id="banerr">Already on list!</p>');
				} else {
					$.each(animes, function(i, a) {
						if (a.value == $( "#anime" ).val()) {
							found = true;
							$( "#anime_id" ).val( a.id);
						}				
					});
					if (found) {
						var title = $( "#anime" ).val();
						var aid =  $('#anime_id').val();
						var map = { 
							anime_id: aid,
						}
					
						$.post("/u{{ user.id }}/settings/addban", map,
							function(data) {
								  if (data == 'ok') {
										banned_titles[banned_titles.length] = title;
										var list_entry = '<div class="alert-message warning fade in" id="a' + aid + '"><a class="close" href="#">×</a>' + title + '</div>';
										$('#banlist').append(list_entry);
										$('#bansize').text(banned_titles.length);
										$("div[id^='a"+aid + "'] > a").click( function () {
											var id = $(this).parent().attr('id').replace('a','');
											var map = { 
												anime_id: id,
											}						
											$.post("/u{{ user.id }}/settings/remban", map,
												function(data) {
													  if (data == 'ok') {
														  banned_titles.splice($("div[id='a"+id + "']").text().substr(1), 1);
														  $("div[id='a"+id + "']").remove();
														  $('#banerr').remove();
														  $('#bansize').text(banned_titles.length);
													  } else {
														  alert('Error: ' + data);
													  }
												 }
											);							
										});
								  } else {
									  alert('Error: ' + data);
								  }
							 }
						);
					} else {
						alert('Error: Anime not found');
					}
				}
			}
		});
	});
</script>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.