{% extends "ldt/ldt_base.html" %}
{% load i18n %}
{% load static %}
{% block js_import %}
{{block.super}}
    <script type="text/javascript" src="{% url 'ldt.jsi18n' packages='ldt' %}" ></script>
	<script type="text/javascript" src='{% static "ldt/js/projectscontents.js" %}' ></script>
{% endblock %}


{% block js_declaration %}
{{block.super}}
<script type="text/javascript">

searchprojectfilterurl = "{% url 'ldt.ldt_utils.views.project.projects_filter' filter='__FILTER__' is_owner='true' status='0' %}";
publishprojecturl = "{% url 'ldt.ldt_utils.views.project.publish' '__PROJECT_ID__' 'false' %}";
unpublishprojecturl = "{% url 'ldt.ldt_utils.views.project.unpublish' '__PROJECT_ID__' 'false' %}";

function init_events(base_node) {

	init_events_base(base_node, "{% url 'embed_config_v4' %}");

	$('.publishedproject', base_node).click(function(e) {
		e.preventDefault();
		var target = $(e.target);
		var project_id = target.attr('id').replace('project_','');
		var url = unpublishprojecturl.replace('__PROJECT_ID__', project_id);

		$.getJSON(url, function(json){
			if(json.res) {
				searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0);
			}
		});

	});

	$('.unpublishedproject', base_node).click(function(e) {
		e.preventDefault();
		var target = $(e.target);
		var project_id = target.attr('id').replace('project_','');
		var url = publishprojecturl.replace('__PROJECT_ID__', project_id);

		$.getJSON(url, {}, function(json){
			if(json.res) {
				searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0);
			}
		});

	});


}

$(document).ready(function(){

	input_list_init = [
		{'input_selector':"#searchprojectsinput", 'container_selector':"#projectslistcontainer", 'url':searchprojectfilterurl}
	];

	searchFieldInit(input_list_init);

	init_events(document);

});
</script>

{% endblock %}

{% block css_import %}
{{block.super}}
    <link rel="stylesheet" href='{% static "ldt/css/workspace.css" %}' type="text/css"/>
{% endblock %}

{% block content %}
<div class="span-24" id="allcontentsdiv">
	<div class="span-12 last" id="projectsdiv">
		<div class="span-12 last titlediv" >
			<div class="span-8 projectscontentstitle" >{% trans "project list" %}</div>
			<div class="span-4 last searchfielddiv" >
			    <div class="searchfield rounded"><input id="searchprojectsinput" class="searchfieldinput searchfieldinputbase" value="{% trans 'search' %}" type="text" /><img id="projectsajaxloader" class="searchajaxloader" src='{% static "ldt/img/ajax-loader-16x16.gif" %}'/><img id="projectsclear" class="searchclear" src='{% static "ldt/img/clear-left.png" %}'/></div>
			</div>
		</div>
		<div class="span-12 last projectscontentsdiv" id="projectslistcontainer">
		{% include "ldt/ldt_utils/projectslist.html" %}
		</div>
	</div>
	<div class="span-12 last" id="createprojectdiv">
	</div>
</div>
{% endblock %}
