<!DOCTYPE html>
<html class="" lang="en">
<head>

    {% include 'twig/common/header/include.twig' %}
    <script src="/dev/js/project/project.js?v=<?=_version?>" type="text/javascript"   charset="utf-8"></script>
    <script src="/dev/lib/handlebars-v4.0.10.js" type="text/javascript" charset="utf-8"></script>
    <script src="/dev/js/handlebars.helper.js?v=<?=_version?>" type="text/javascript" charset="utf-8"></script>

    <link rel="stylesheet" href="/dev/css/project/main.css?v=<?=_version?>">
</head>
<body class="" data-group="" data-page="projects:issues:index" data-project="xphp">
{% include 'twig/common/body/script.twig' %}

<section class="has-sidebar page-layout max-sidebar">
    {% include 'twig/common/body/page-left.twig' %}

    <div class="page-layout page-content-body">
        {% include 'twig/common/body/header-content.twig' %}

        <script>
            var findFileURL = "";
        </script>
        <div class="page-with-sidebar">


            <div class="content-wrapper page-with-layout-nav page-with-sub-nav">
                <div class="alert-wrapper">
                    <div class="flash-container flash-container-page">
                    </div>
                </div>
                <div class="container-fluid container-limited">
                    <div class="content" id="content-body">
                        <div class="container-fluid">
                            <div class="top-area">
                                <ul class="nav-links issues-state-filters">
                                    <li class=""  id="js-masterlab-project-type-tab-main" >
                                        <a title="全部"
                                           href="javascript:void(0);"
                                           onclick="selectByType(0, this)"><span> 全部 </span>
                                        </a>
                                    </li>
                                    {% for key,item in type_list %}
                                        <!--<li class="" {% if (key == 0)  %} id="js-masterlab-project-type-tab-main" {% endif %}>
                                            <a title="<?=item['display_name']?>"
                                               href="javascript:void(0);"
                                               onclick="selectByType(<?=key?>, this)"><span> <?=item['display_name']?> </span>
                                                 <span class="badge"><?=item['count']?></span>
                                            </a>
                                        </li>-->
                                    {% endfor %}
                                </ul>

                                <div class="nav-controls row-fixed-content">

                                    <input type="search" name="name" id="project-filter-form-field" placeholder="通过项目名搜索" class="form-control input-short" spellcheck="false" tabindex="2">
                                    <input type="hidden" name="sort" id="project-filter-sort" value="{% if (projects_sort) %}<?= projects_sort ?>{% else %}created_desc{% endif %}">

                                    <select  name="project_tpl_id" id="project_tpl_id" title="所属模板" class="selectpicker hide">
                                        {% for row in project_tpl_arr %}
                                            {% set  display_name = row['display_name'] %}
                                            <option value="<?=row.id?>" ><?=row.name?></option>
                                        {% endfor %}
                                    </select>
                                    <div class="dropdown js-project-filter-dropdown-wrap">
                                        <button class="dropdown-menu-toggle " id="filter-project_tpl_id" type="button"
                                                data-toggle="dropdown" data-display="static" aria-expanded="true">
                                            <span class="dropdown-toggle-text" id="js-masterlab-selected-tpl">所属模板</span>
                                            <i class="fa fa-chevron-down"></i>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right dropdown-menu-selectable">
                                            {% for key,item in project_tpl_arr %}
                                                <li>
                                                    <a class="filter_by_tpl " style="cursor:pointer;"  data-project_tpl_id="<?=item['id']?>" ><?=item['name']?>
                                                    </a>
                                                </li>
                                            {% endfor %}
                                        </ul>
                                    </div>
                                    <div class="dropdown js-project-filter-dropdown-wrap">
                                        <button class="dropdown-menu-toggle " id="sort-projects-dropdown" type="button" data-toggle="dropdown" data-display="static" aria-expanded="false">
                                            <span class="dropdown-toggle-text" id="js-masterlab-selected-sort">最后创建</span>
                                            <i aria-hidden="true" data-hidden="true" class="fa fa-chevron-down"></i>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right dropdown-menu-selectable">
                                            <li class="dropdown-header">
                                                排序
                                            </li>
                                            <!--li>
                                                <a class="js-masterlab-filter-selector-sort" style="cursor:pointer;" data-filter_sort="latest_activity_desc">最后更新
                                                </a>
                                            </li-->
                                            <li>
                                                <a class="js-masterlab-filter-selector-sort is-active" style="cursor:pointer;" data-filter_sort="created_desc">最后创建
                                                </a>
                                            </li>
                                            <li>
                                                <a class="js-masterlab-filter-selector-sort" style="cursor:pointer;" data-filter_sort="name_asc">项目名
                                                </a>
                                            </li>
                                            <li>
                                                <a class="js-masterlab-filter-selector-sort" style="cursor:pointer;" data-filter_sort="lead_asc">按负责人
                                                </a>
                                            </li>
                                        </ul>
                                    </div>



                                    {% if (is_admin) %}
                                        &nbsp;<a class="btn btn-create new-tag-btn js-key-create" data-key-mode="new-page"
                                           href="/project/main/new">
                                            创建项目
                                        </a>
                                    {% endif %}


                                </div>

                            </div>

                            <div class="js-projects-list-holder">
                                <ul class="projects-list" id="list_render_id">

                                </ul>
                                <div class="gl-pagination">

                                </div>

                            </div>

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

        </div>
    </div>
</section>
{% verbatim %}<script type="text/html" id="list_tpl">
    {{#projects}}
    <li class="project-row">
        {{#if avatar_exist}}
        <a href="#" class="avatar-image-container s40">
            <img src="{{avatar}}" class="avatar has-tooltip s40">
        </a>
        {{^}}
        <div class="avatar-container s40" style="display: block">
            <a class="project" href="/{{path}}/{{key}}">
                <div class="avatar project-avatar s40 identicon"
                     style="background-color: #E0F2F1; color: #555">{{first_word}}
                </div>
            </a>
        </div>
        {{/if}}
        <div class="project-details">
            <h3 class="prepend-top-0 append-bottom-0">
                <a class="project" href="/{{path}}/{{key}}">
                    <span class="project-full-name" style="color:#1b69b6">
                        <span class="namespace-name">
                        {{path}}
                        /
                        </span>
                        <span class="project-name">
                        {{key}}
                        </span>
                        <span class="project-name">
                        ({{name}})
                        </span>
                    </span>
                </a>
            </h3>
            <div class="description prepend-top-5">
                <span class="label-badge label-badge-gray" style="background-color: #f2f2f2;">{{type_name}}</span>
                <p data-sourcepos="1:1-1:54" dir="auto">{{description}}</p>
            </div>


        </div>
        <div class="controls project-controls">
            <div class="users-list">
                {{#if join_user_id_arr}}
                {{#each join_user_id_arr}}
                <div class="user-item">
                    <a data-hovercard-type="user" href="/{{../path}}/{{../key}}?经办人={{this.username}}">
                        <img class="avatar avatar-small" height="28" width="28" title="{{this.display_name}}"
                             alt="{{this.username}}" src="{{this.avatar}}">
                    </a>
                    {{#if is_leader}}
                    <p class="user-name">负责人</p>
                    {{/if}}
                </div>
                {{/each}}
                <a role="button" aria-label="跳转至项目用户" href="/{{path}}/{{key}}/settings_project_member"
                   class="users-btn">
                    ...
                </a>
                {{/if}}
            </div>
            <div class="project-time">
                <!-- <i class="fa fa-calendar"></i> -->
                {{create_time_text}}
            </div>
            <!--
            <span class="prepend-left-10 visibility-icon has-tooltip" data-container="body" data-placement="left" title="Private - Project access must be granted explicitly to each user.">
                <i class="fa fa-lock fa-fw"></i>
            </span>
            -->
        </div>
    </li>
    {{/projects}}
</script>{% endverbatim %}


<script>

    var $projects = null;
    var _issueConfig = {

    };


    $(function () {
        var search_sort = $('#project-filter-sort').val();
        var options = {
            list_render_id: "list_render_id",
            list_tpl_id: "list_tpl",
            filter_url: "/projects/fetch_all?name=&sort="+search_sort
        };
        window.$projects = new Project(options);
        window.$projects.fetchAll();

        $('.js-masterlab-filter-selector-sort').removeClass('is-active');
        $('.js-masterlab-filter-selector-sort').each(function(){
            if ($(this).data('filter_sort') === search_sort) {
                $(this).addClass('is-active');
                $('#js-masterlab-selected-sort').text($(this).text());
            }
        });


        $(".issues-state-filters li").eq(0).addClass("active");

        $('#project-filter-form-field').keyup(function(event){
            if (event.keyCode === 13) {
                //$("#submit").trigger("click");
                var search_key = $(this).val();
                var search_sort = $('#project-filter-sort').val();

                $('#js-masterlab-project-type-tab-main').addClass("active").siblings("li").removeClass("active");

                var options = {
                    list_render_id: "list_render_id",
                    list_tpl_id: "list_tpl",
                    filter_url: "/projects/fetch_all?name="+search_key+"&sort="+search_sort
                };
                window.$projects = new Project(options);
                window.$projects.fetchAll();
            }
        });

        $('.filter_by_tpl').on("click", function () {
            var project_tpl_id = $(this).data('project_tpl_id');
            $('.filter_by_tpl').removeClass('is-active');
            $(this).addClass('is-active');
            $('#js-masterlab-selected-tpl').text($(this).text());
            var search_key = $('#project-filter-form-field').val();
            var search_sort = $('#project-filter-sort').val();
            var options = {
                list_render_id: "list_render_id",
                list_tpl_id: "list_tpl",
                filter_url: "/projects/fetch_all?name="+search_key+"&sort="+search_sort+"&project_tpl_id="+project_tpl_id
            };
            window.$projects = new Project(options);
            window.$projects.fetchAll();
        });

        $('.js-masterlab-filter-selector-sort').on("click", function () {
            var sort = $(this).data('filter_sort');
            $('#project-filter-sort').val(sort);
            $('.js-masterlab-filter-selector-sort').removeClass('is-active');
            $(this).addClass('is-active');
            $('#js-masterlab-selected-sort').text($(this).text());

            $('#js-masterlab-project-type-tab-main').addClass("active").siblings("li").removeClass("active");

            var search_key = $('#project-filter-form-field').val();
            var search_sort = $('#project-filter-sort').val();
            var options = {
                list_render_id: "list_render_id",
                list_tpl_id: "list_tpl",
                filter_url: "/projects/fetch_all?name="+search_key+"&sort="+search_sort
            };
            window.$projects = new Project(options);
            window.$projects.fetchAll();
        });
    });

    function selectByType(typeId, selector) {
        var options = {
            list_render_id: "list_render_id",
            list_tpl_id: "list_tpl",
            filter_url: "/projects/fetch_all?typeId=" + typeId
        };

        if (selector) {
            $(selector).parent().addClass("active").siblings("li").removeClass("active");
        }

        window.$projects = new Project(options);
        window.$projects.fetchAll();
    }

</script>
</body>
</html>
