{% extends "base.html" %}
{# TODO: Rewrite repo browser templates as one single template. #}
{% block pagetitle %}Repository Browser{% endblock pagetitle %}
{% block body_attribs %} class="animated"{% endblock body_attribs %}
{% block stats %}{% endblock stats %}
{% block styles %}
	{{ super() }}
	<style type="text/css">
		.cl-mcont {
			margin-left: 0px;
		}
	</style>
{% endblock styles %}
{% block maincontainer %}
	<div class="cl-mcont aside">
		<div class="page-aside tree">
			<div class="nano nscroller">
				<div class="nano-content">
					<div class="title">
						<h2 style="font-family: Raleway;font-size: 24px;font-weight: 400;">Repository Browser</h2>
						<h3 style="font-family: Raleway;font-size: 18px;font-weight: 400;">Staging</h3>
					</div>
					<ul class="nav nav-list treeview">
						<li class="open">
							<label id="repo" class="tree-toggler nav-header"><i class="fa fa-folder-open-o"></i> repo</label>
							<ul class="nav nav-list tree">
								<li class="open">
									<label id="antergos" class="tree-toggler nav-header"><i class="fa fa-folder-open-o"></i>
										antergos</label>
									<ul class="nav nav-list tree">
										<li class="file-li">
											<a id="i686" href="#" onclick="//goToi686()"><i class="fa fa-folder-o"></i> i686</a>
										</li>
										<li class="file-li">
											<a id="x86_64" href="#" onclick="//goTox86_64()"><i class="fa fa-folder-open-o"></i> x86_64
											</a></li>
									</ul>
								</li>
							</ul>
						</li>

					</ul>
				</div>
			</div>
		</div>

		<div class="content">
			<iframe id="filesFrame" style="border:none; background: #F0F0F0;" src="https:{% if release %}//repo.antergos.info/iso/release{% elif testing %}//repo.antergos.info/iso/testing{% else %}//repo.antergos.info/iso/testing/uefi/antergos-staging/x86_64{% endif %}" width="100%" height="100%"
					seamless="seamless" sandbox="allow-scripts allow-same-origin allow-forms" referrerpolicy="origin-when-cross-origin"></iframe>
		</div>
	</div>
{% endblock maincontainer %}

{% block scripts %}
	{{ super() }}
	<script type="text/javascript">

		jQuery(window).load(function () {

			jQuery('label.tree-toggler').click(function () {
				console.log('clicked');
				var icon = jQuery(this).children(".fa");
				if (icon.hasClass("fa-folder-o")) {
					icon.removeClass("fa-folder-o").addClass("fa-folder-open-o");
				} else {
					icon.removeClass("fa-folder-open-o").addClass("fa-folder-o");
				}

				jQuery(this).parent().children('ul.tree').toggle(300, function () {
					jQuery(this).parent().toggleClass("open");
					//jQuery(".tree .nscroller").nanoScroller({preventPageScrolling: true});
				});

				if (jQuery(this).attr('id') == 'antergos') {
					jQuery('#filesFrame').attr('src', 'https://repo.antergos.info/iso/testing/uefi/antergos-staging');
				}
				else if (jQuery(this).attr('id') == 'repo') {
					jQuery('#filesFrame').attr('src', 'https://repo.antergos.info/iso/testing/uefi/antergos-staging');
				}

			});


		});
		jQuery('.file-li').on('click', function (e) {

			var icon = jQuery(this).find("a .fa");
			var sibicon = jQuery(this).siblings('li').find("a .fa");
			if (jQuery(icon).hasClass("fa-folder-o")) {
				jQuery(icon).removeClass("fa-folder-o").addClass("fa-folder-open-o");
				jQuery(sibicon).removeClass("fa-folder-open-o").addClass("fa-folder-o");
			} else {
				jQuery(icon).removeClass("fa-folder-open-o").addClass("fa-folder-o");

			}

			jQuery(this).toggleClass("open");
			if (jQuery(this).siblings('.open').length) {
				console.log('matched');
				jQuery(this).siblings('li').toggleClass("open");
			}
			//jQuery(".tree .nscroller").nanoScroller({preventPageScrolling: true})

			if (jQuery(this).children('#i686').length) {

				jQuery('#filesFrame').attr('src', 'https://repo.antergos.info/iso/testing/uefi/antergos-staging/i686');
			} else if (jQuery(this).children('#x86_64').length) {
				jQuery('#filesFrame').attr('src', 'https://repo.antergos.info/iso/testing/uefi/antergos-staging/x86_64');
			}
		});


		function goToi686() {
			jQuery('#filesFrame').attr('src', 'https://repo.antergos.info/iso/testing/uefi/antergos-staging/i686');
		}
		function goTox86_64() {
			jQuery('#filesFrame').attr('src', 'https://repo.antergos.info/iso/testing/uefi/antergos-staging/x86_64');
		}

	</script>
{% endblock scripts %}
