| {% extends 'layout.html' %}
| {% from '_macros/_navigation.html' import navigation_tabs %}

| {% set title = 'dashboard' %}

| {% block og %}
meta(property="og:title", content="Dashboard")
meta(name="twitter:title", content="Blender Cloud")

meta(property="og:url", content="https://cloud.blender.org/{{ request.path }}")
meta(property="og:type", content="website")

meta(property="og:image", content="{{ url_for('static', filename='assets/img/backgrounds/cloud_services_oti.jpg')}}")
meta(name="twitter:image", content="{{ url_for('static', filename='assets/img/backgrounds/cloud_services_oti.jpg')}}")
| {% endblock %}

| {% block page_title %}
| {{current_user.full_name}}
| {% endblock %}

| {% block body %}
.dashboard-container
	section#main
		| {{ navigation_tabs(title) }}

		section#projects

			section#sub-nav-tabs.projects
				ul#sub-nav-tabs__list
					li.nav-tabs__list-tab.active(data-tab-toggle='own_projects')
						| Own Projects
						| {% if projects_user|length != 0 %}
						span ({{ projects_user|length }})
						| {% endif %}

					li.nav-tabs__list-tab(data-tab-toggle='shared')
						| Shared with me
						| {% if projects_shared|length != 0 %}
						span ({{ projects_shared|length }})
						| {% endif %}

					| {% if current_user.has_cap('subscriber') %}
					li.create(
						data-url="{{ url_for('projects.create') }}")
						a.btn.btn-success#project-create(
							href="{{ url_for('projects.create') }}")
							i.pi-plus
							| Create Project
					| {% endif %}

			section.nav-tabs__tab.active#own_projects
				ul.projects__list
					| {% if projects_user %}
					| {% for project in projects_user %}
					li.projects__list-item(
						data-url="{{ url_for('projects.view', project_url=project.url) }}")
						a.projects__list-thumbnail(
							href="{{ url_for('projects.view', project_url=project.url) }}")
							| {% if project.picture_square %}
							img(src="{{ project.picture_square.thumbnail('s', api=api) }}")
							| {% else %}
							i.pi-blender-cloud
							| {% endif %}
						.projects__list-details
							a.title(href="{{ url_for('projects.view', project_url=project.url) }}")
								| {{ project.name }}

							ul.meta
								li.status(
									class="{{ project.is_private | yesno('private,public,') }}",
									title="{{ project.is_private | yesno('Private Project,Public Project,') }}")
										| {{ project.is_private | yesno('Private,Public,') }}
								li.when(title="{{ project._created }}") {{ project._created | pretty_date }}
								li.edit
									a(href="{{ url_for('projects.edit', project_url=project.url) }}") Edit
								| {% if project.status == 'pending' and current_user.has_cap('view-pending-nodes') %}
								li.pending Not Published
								| {% endif %}

					| {% endfor %}
					| {% else %}
					li.projects__list-item
						a.projects__list-thumbnail
							i.pi-plus
						.projects__list-details
							a.title(href="{{ url_for('projects.create') }}")
								| Create a project to get started!
					| {% endif %}

			section.nav-tabs__tab#shared
				ul.projects__list
					| {% if projects_shared %}
					| {% for project in projects_shared %}
					li.projects__list-item(
						data-url="{{ url_for('projects.view', project_url=project.url) }}")
						a.projects__list-thumbnail(
							href="{{ url_for('projects.view', project_url=project.url) }}")
							| {% if project.picture_square %}
							img(src="{{ project.picture_square.thumbnail('s', api=api) }}")
							| {% else %}
							i.pi-blender-cloud
							| {% endif %}
						.projects__list-details
							a.title(href="{{ url_for('projects.view', project_url=project.url) }}")
								| {{ project.name }}

							ul.meta
								li.status(
									class="{{ project.is_private | yesno('private,public,') }}",
									title="{{ project.is_private | yesno('Private Project,Public Project,') }}")
										| {{ project.is_private | yesno('Private,Public,') }}
								li.when {{ project._created | pretty_date }}
								li.who by {{ project.user.full_name }}
								li.edit
									a(href="{{ url_for('projects.edit', project_url=project.url) }}") Edit
								| {% if project.status == 'pending' and current_user.has_cap('view-pending-nodes') %}
								li.pending Not Published
								| {% endif %}

								li.leave
									span.user-remove-prompt
										| Leave Project

									span.user-remove
										| Are you sure?
										span.user-remove-confirm(
											user-id="{{ current_user.objectid }}",
											project-url="{{url_for('projects.sharing', project_url=project.url)}}")
											i.pi-check
											| Yes, leave
										span.user-remove-cancel
											i.pi-cancel
											| No, cancel

					| {% endfor %}
					| {% else %}
					li.projects__list-item
						a.projects__list-thumbnail
							i.pi-heart-broken
						.projects__list-details
							.title
								| No projects shared with you... yet!
					| {% endif %}

	section#side
		section.announcement
			img.header(
				src="{{ url_for('static', filename='assets/img/backgrounds/services_projects.jpg')}}")
			.text
				.title Projects
				.lead
					span.
						Create and manage your own personal projects.
						Upload assets and collaborate with other Blender Cloud members.
				.buttons
					a.btn.btn-default.btn-outline.blue(
						href="https://cloud.blender.org/blog/introducing-private-projects")
						| Learn More

		section.announcement
			a(href="https://cloud.blender.org/blog/introducing-blender-sync")
			img.header(
				src="{{ url_for('static', filename='assets/img/blender_sync_header.jpg') }}")
			.text
				.title
					a(href="https://cloud.blender.org/blog/introducing-blender-sync") Textures Browser & Settings Sync

				.lead
					span.
						Get the official Blender Cloud add-on:
					ul
						li Save your Blender settings online, use them anywhere
						li Browse over 800 textures & HDRIs within Blender
						li Share Screenshots & Renders directly to Blender Cloud

				.buttons
					a.btn.btn-default.btn-outline.orange(
						href="https://cloud.blender.org/r/downloads/blender_cloud-latest-bundle.zip")
						i.pi-download
						| Download Add-on <small>v</small> {{ config.BLENDER_CLOUD_ADDON_VERSION }}
					a.btn.btn-default.btn-outline.blue(
						href="https://cloud.blender.org/blog/introducing-blender-sync")
						| Learn More

| {% endblock %}


| {% block footer_scripts %}
script.
	$(document).ready(function() {

		$('li.projects__list-item').click(function(e){
			url = $(this).data('url');
			if (typeof url === 'undefined') return;

			window.location.href = url;
			if (console) console.log(url);

			$(this).addClass('active');
			$(this).find('.projects__list-thumbnail i')
				.removeAttr('class')
				.addClass('pi-spin spin');
		});

		// Tabs behavior
		var $nav_tabs_list = $('#sub-nav-tabs__list');
		var $nav_tabs = $nav_tabs_list.find('li.nav-tabs__list-tab');
		$nav_tabs.on('click', function(e){
			e.preventDefault();

			$nav_tabs.removeClass('active');
			$(this).addClass('active');

			$('.nav-tabs__tab').hide();
			$('#' + $(this).attr('data-tab-toggle')).show();
		});

		// Create project
		$nav_tabs_list.find('li.create').on('click', function(e){
			e.preventDefault();

			$(this).addClass('disabled');
			$('a', this).html('<i class="pi-spin spin"></i> Creating project...');

			window.location.href = $(this).data('url');
		});

		// Leave project
		var $projects_list = $('ul.projects__list');
		$projects_list.find('span.user-remove-prompt').on('click', function(e){
			e.stopPropagation();
			e.preventDefault();

			$(this).next().show();
			$(this).hide();
		});

		$projects_list.find('span.user-remove-cancel').on('click', function(e){
			e.stopPropagation();
			e.preventDefault();

			$(this).parent().prev().show();
			$(this).parent().hide();
		});

		$projects_list.find('span.user-remove-confirm').on('click', function(e){
			e.stopPropagation();
			e.preventDefault();
			var parent = $(this).closest('projects__list-item');

			function removeUser(userId, projectUrl){
				$.post(projectUrl, {user_id: userId, action: 'remove'})
					.done(function (data) {
						parent.remove();
					});
			}

			removeUser($(this).attr('user-id'), $(this).attr('project-url'));
		});

		hopToTop(); // Display jump to top button
	});
| {% endblock %}
