<!DOCTYPE html>
<html class="" lang="en">
	<head prefix="og: http://ogp.me/ns#">
		{% include 'twig/common/header/include.twig' %}

		<script src="/dev/lib/moment.js"></script>
		<script src="/dev/lib/url_param.js?v=<?=_version?>" type="text/javascript" charset="utf-8"></script>
		<script src="/dev/js/admin/issue_ui.js?v=<?=_version?>" type="text/javascript" charset="utf-8"></script>
		<script src="/dev/js/issue/form.js?v=<?=_version?>" type="text/javascript" charset="utf-8"></script>
		<script src="/dev/js/issue/adv_query.js?v=<?=_version?>" type="text/javascript" charset="utf-8"></script>
		<script src="/dev/js/issue/detail.js?v=<?=_version?>" type="text/javascript" charset="utf-8"></script>
		<script src="/dev/js/issue/main.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>
		<link href="/dev/lib/video-js/video-js.min.css" rel="stylesheet">
		<script src="/dev/lib/video-js/video.min.js"></script>

		<script>
			window.description_templates = <?= description_templates|json_encode()|raw ?>;
		</script>

		<script src="/dev/lib/bootstrap-select/js/bootstrap-select.js" type="text/javascript" charset="utf-8"></script>
		<link href="/dev/lib/bootstrap-select/css/bootstrap-select.css" rel="stylesheet">
        <script src="/dev/lib/select2-4.0.13/dist/js/select2.js" type="text/javascript" charset="utf-8"></script>
        <script src="/dev/lib/select2-4.0.13/dist/js/i18n/zh-CN.js" type="text/javascript" charset="utf-8"></script>
        <link href="/dev/lib/select2-4.0.13/dist/css/select2.css" rel="stylesheet">

		<script src="/dev/lib/bootstrap-paginator/src/bootstrap-paginator.js?v=<?=_version?>" type="text/javascript"></script>
		<script type="text/javascript" src="/dev/lib/qtip/dist/jquery.qtip.min.js"></script>
		<link rel="stylesheet" type="text/css" href="/dev/lib/qtip/dist/jquery.qtip.min.css"/>

		<script src="/dev/lib/simplemde/dist/simplemde.min.js"></script>
		<link rel="stylesheet" href="/dev/lib/simplemde/dist/simplemde.min.css">

		<!-- Fine Uploader jQuery JS file-->
		<link href="/dev/lib/fine-uploader/fine-uploader.css" rel="stylesheet">
		<link href="/dev/lib/fine-uploader/fine-uploader-gallery.css" rel="stylesheet">
		<script src="/dev/lib/e-smart-zoom-jquery.min.js"></script>
		<script src="/dev/lib/fine-uploader/jquery.fine-uploader.js?v=<?=_version?>"></script>

		<link href="/dev/lib/laydate/theme/default/laydate.css" rel="stylesheet">
		<script src="/dev/lib/laydate/laydate.js"></script>

		<script src="/dev/lib/jquery-file-upload/js/vendor/jquery.ui.widget.js"></script>
		<!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
		<script src="/dev/lib/jquery-file-upload/js/jquery.iframe-transport.js"></script>
		<script src="/dev/lib/jquery-file-upload/js/jquery.fileupload.js"></script>

		<script src="/dev/lib/mousetrap/mousetrap.min.js"></script>
		<link rel="stylesheet" href="/dev/lib/editor.md/css/editormd.css"/>

		<script src="/dev/lib/editor.md/lib/marked.min.js"></script>
		<script src="/dev/lib/editor.md/lib/prettify.min.js"></script>
		<script src="/dev/lib/editor.md/lib/flowchart.min.js"></script>
		<script src="/dev/lib/editor.md/lib/jquery.flowchart.min.js"></script>
		<script src="/dev/lib/editor.md/editormd.js"></script>

		<script src="/dev/lib/sweetalert2/sweetalert-dev.js"></script>
		<link rel="stylesheet" href="/dev/lib/sweetalert2/sweetalert-dev.css"/>

		<link rel="stylesheet" href="/dev/css/issue/list.css?v=<?=_version?>"/>
        <style type="text/css">
            .active_underline a{
                text-decoration: underline;
                font-weight: 600;
                font-size: 14px;
                line-height: 28px;
            }
            .active_underline a span{
                color: #1f78d1;
            }
            .filter_active_underline a span{
                color: #fc9403;
            }
            .nav-links.sub-nav li a {
                margin: 0;
                padding: 4px 2px 4px;
            }
        </style>
	</head>

	<body class="" data-group="" data-page="projects:issues:index" data-project="xphp">
		<div class=""></div>
		{% 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">
					{% include 'twig/project/common-page-nav-project.twig' %}
					{% include 'twig/issue/common-filter-nav-links-sub-nav.twig' %}

					<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=" ">
							<div class="content issue-list-page" id="content-body">
								<div class="container-fluid padding-0">
                                    {% include 'twig/issue/filter.twig' %}

                                    <div class="issues-holder">

                                <div class="table-holder">
                                    <table class="table  tree-table" id="tree-slider" style="display:none;">
                                        <thead>

                                        <tr>

                                            <th class="js-pipeline-info pipeline-info">
                                                {% if ( 'issue_num' in  display_fields) %}编 号
                                                {% endif %}
                                            </th>

                                            {% if ('issue_type'in display_fields) %}
                                                <th class="js-pipeline-stages pipeline-info">
                                                    <a class="sort_link" data-field="issue_type"
                                                       data-sortby="<?= sort_by == 'desc' ? 'asc' : 'desc' ?>" href="#">
                                                        类型
                                                        {% if sort_field == 'issue_type' %}
                                                            <i class="fa fa-sort-<?= sort_by ?>"></i>
                                                        {% endif %}
                                                    </a>
                                                </th>
                                            {% endif %}

                                            {% if ('priority'in display_fields) %}
                                                <th class="js-pipeline-stages pipeline-info">
                                                    <a class="sort_link" data-field="priority"
                                                       data-sortby="<?= sort_by == 'desc' ? 'asc' : 'desc' ?>" href="#">
                                                        优先级
                                                        {% if sort_field == 'priority' %}
                                                            <i class="fa fa-sort-<?= sort_by ?>"></i>
                                                        {% endif %}
                                                    </a>
                                                </th>
                                            {% endif %}

                                            {% if (is_all_issues or 'project_id' in display_fields) %}
                                                <th class="js-pipeline-info pipeline-info">项 目</th>
                                            {% endif %}

                                            {% if ('module'in display_fields) %}
                                                <th class="js-pipeline-info pipeline-info">
                                                    <a class="sort_link" data-field="module"
                                                       data-sortby="<?= sort_by == 'desc' ? 'asc' : 'desc' ?>" href="#">
                                                        模 块
                                                        {% if sort_field == 'module' %}
                                                            <i class="fa fa-sort-<?= sort_by ?>"></i>
                                                        {% endif %}
                                                    </a>
                                                </th>
                                            {% endif %}

                                            {% if ('sprint'in display_fields) %}
                                                <th class="js-pipeline-info pipeline-info">
                                                    <a class="sort_link" data-field="sprint"
                                                       data-sortby="<?= sort_by == 'desc' ? 'asc' : 'desc' ?>" href="#">
                                                        迭
                                                        代
                                                        {% if sort_field == 'sprint' %}
                                                            <i class="fa fa-sort-<?= sort_by ?>"></i>
                                                        {% endif %}
                                                    </a>
                                                </th>
                                            {% endif %}

                                            {% if ('summary'in display_fields) %}
                                                <th class="js-pipeline-commit pipeline-commit">主 题</th>
                                            {% endif %}

                                            {% if ('weight'in display_fields) %}
                                                <th class="js-pipeline-info pipeline-info">
                                                    <a class="sort_link" data-field="weight"
                                                       data-sortby="<?= sort_by == 'desc' ? 'asc' : 'desc' ?>" href="#">
                                                        权
                                                        重
                                                        {% if sort_field == 'weight' %}
                                                            <i class="fa fa-sort-<?= sort_by ?>"></i>
                                                        {% endif %}
                                                    </a>
                                                </th>
                                            {% endif %}

                                            {% if ('assignee'in display_fields) %}
                                                <th class="js-pipeline-stages pipeline-info">
                                                    <a class="sort_link" data-field="assignee"
                                                       data-sortby="<?= sort_by == 'desc' ? 'asc' : 'desc' ?>" href="#">
                                                        经办人
                                                        {% if sort_field == 'assignee' %}
                                                            <i class="fa fa-sort-<?= sort_by ?>"></i>
                                                        {% endif %}
                                                    </a>
                                                </th>
                                            {% endif %}

                                            {% if ('reporter'in display_fields) %}
                                                <th class="jjs-pipeline-stages pipeline-info">
                                                    报告人
                                                </th>
                                            {% endif %}

                                            {% if ('assistants'in display_fields) %}
                                                <th class="jjs-pipeline-stages pipeline-info">
                                                    协助人
                                                </th>
                                            {% endif %}

                                            {% if ('status'in display_fields) %}
                                                <th class="js-pipeline-stages pipeline-info">
                                                    <a class="sort_link" data-field="status"
                                                       data-sortby="<?= sort_by == 'desc' ? 'asc' : 'desc' ?>" href="#">
                                                        状
                                                        态
                                                        {% if sort_field == 'status' %}
                                                            <i class="fa fa-sort-<?= sort_by ?>"></i>
                                                        {% endif %}
                                                    </a>
                                                </th>
                                            {% endif %}

                                            {% if ('resolve'in display_fields) %}
                                                <th class="js-pipeline-stages pipeline-info">
                                                    <a class="sort_link" data-field="resolve"
                                                       data-sortby="<?= sort_by == 'desc' ? 'asc' : 'desc' ?>" href="#">
                                                        解决结果
                                                        {% if sort_field == 'resolve' %}
                                                            <i class="fa fa-sort-<?= sort_by ?>"></i>
                                                        {% endif %}
                                                    </a>
                                                </th>
                                            {% endif %}

                                            {% if ('environment'in display_fields) %}
                                                <th class="jjs-pipeline-stages pipeline-info">
                                                    运行环境
                                                </th>
                                            {% endif %}

                                            {% if ('plan_date'in display_fields) %}
                                                <th class="js-pipeline-date pipeline-date">
                                                    <a title="排序将按 '截止日期' 排列" class="sort_link" data-field="due_date"
                                                       data-sortby="<?= sort_by == 'desc' ? 'asc' : 'desc' ?>" href="#">
                                                        计划时间
                                                        {% if sort_field == 'due_date' %}
                                                            <i class="fa fa-sort-<?= sort_by ?>"></i>
                                                        {% endif %}
                                                    </a>
                                                </th>
                                            {% endif %}

                                            {% if ('resolve_date'in display_fields) %}
                                                <th class="jjs-pipeline-stages pipeline-info">
                                                    实际解决日期
                                                </th>
                                            {% endif %}

                                            {% if ('modifier'in display_fields) %}
                                                <th class="jjs-pipeline-stages pipeline-info">
                                                    最后修改人
                                                </th>
                                            {% endif %}

                                            {% if ('master_id'in display_fields) %}
                                                <th class="jjs-pipeline-stages pipeline-info">
                                                    是否父任务
                                                </th>
                                            {% endif %}

                                            {% if ('created'in display_fields) %}
                                                <th class="jjs-pipeline-stages pipeline-info">
                                                    创建时间
                                                </th>
                                            {% endif %}

                                            {% if ('updated'in display_fields) %}
                                                <th class="jjs-pipeline-stages pipeline-info">
                                                    最后修改时间
                                                </th>
                                            {% endif %}


                                            {% for item in displayCustomFieldArr %}
                                                <th class="jjs-pipeline-stages pipeline-info">
                                                    <?=item.title?>
                                                </th>
                                            {% endfor %}

                                            <th class="js-pipeline-actions pipeline-actions">操 作

                                            </th>
                                        </tr>
                                        </thead>
                                        <tbody id="list_render_id"></tbody>
                                    </table>
                                </div>
                                <div class="table-holder">
                                    <div id="detail_render_id" style="display:none;"></div>
                                </div>

                                <ul class="issues-content-list" id="ul_issues" style="display:none;"></ul>
                                <div class="row-content-block second-block" v-pre="false">
                                    <form class="filter-form js-filter-form" action="#" accept-charset="UTF-8"
                                          method="get">
                                        <div class="issuable-actions" id="issue-actions">
                                            <input type="checkbox" name="btn-check_all_issues" id="btn-check_all_issues"
                                                   class="left">
                                            全 选
                                            <span style="margin-left: 1em">
														选中项：
													</span>
                                            <div class="btn-group" role="group" aria-label="...">
                                                {% if (projectPermArr['DELETE_ISSUES'] is defined) %}

                                                    <button id="btn-batchDelete" type="button" class="btn btn-default">
                                                        <i class="fa fa-remove"></i>
                                                        删 除
                                                    </button>
                                                {% endif %}

                                                <div class="btn-group dropup" role="group">
                                                    <button type="button" class="btn btn-default dropdown-toggle"
                                                            data-toggle="dropdown" aria-haspopup="true"
                                                            aria-expanded="false">
                                                        优先级
                                                        <i class="fa fa-caret-down"></i>
                                                    </button>
                                                    <ul class="dropdown-menu">
                                                        {% for item in priority %}
                                                            <li>
                                                                <a class="btn_batch_update" data-field="priority"
                                                                   data-id="<?= item['id'] ?>" href="#"
                                                                   style="color:<?= item['status_color'] ?>"><?= item['name'] ?></a>
                                                            </li>
                                                        {% endfor %}
                                                    </ul>
                                                </div>
                                                <div class="btn-group dropup" role="group">
                                                    <button type="button" class="btn btn-default dropdown-toggle"
                                                            data-toggle="dropdown" aria-haspopup="true"
                                                            aria-expanded="false">
                                                        状 态
                                                        <i class="fa fa-caret-down"></i>
                                                    </button>
                                                    <ul class="dropdown-menu">
                                                        {% for item in issue_status %}
                                                            <li>
                                                                <a class="btn_batch_update" data-field="status"
                                                                   data-id="<?= item['id'] ?>" href="#" >
                                                                    <span class="label current label-<?=item.color ?> prepend-left-5" style="cursor:pointer;"><?= item['name'] ?></span>
                                                                </a>
                                                            </li>
                                                        {% endfor %}
                                                    </ul>
                                                </div>
                                                <div class="btn-group dropup" role="group">
                                                    <button type="button" class="btn btn-default dropdown-toggle"
                                                            data-toggle="dropdown" aria-haspopup="true"
                                                            aria-expanded="false">
                                                        解决结果
                                                        <i class="fa fa-caret-down"></i>
                                                    </button>
                                                    <ul class="dropdown-menu">
                                                        {% for item in issue_resolve %}
                                                            <li>
                                                                <a class="btn_batch_update" data-field="resolve"
                                                                   data-id="<?= item['id'] ?>" href="#"
                                                                   style="color:<?= item['color'] ?>"><?= item['name'] ?></a>
                                                            </li>
                                                        {% endfor %}
                                                    </ul>
                                                </div>

                                                <div class="btn-group dropup" role="group">
                                                    <button type="button" class="btn btn-default dropdown-toggle"
                                                            data-toggle="dropdown" aria-haspopup="true"
                                                            aria-expanded="false">
                                                        模 块
                                                        <i class="fa fa-caret-down"></i>
                                                    </button>
                                                    <ul class="dropdown-menu">
                                                        {% for key,item in project_modules %}
                                                            <li>
                                                                <a class="btn_batch_update" data-field="module"
                                                                   data-id="<?= key ?>" href="#"><?= item['name'] ?></a>
                                                            </li>
                                                        {% endfor %}

                                                    </ul>
                                                </div>

                                                <div class="btn-group dropup" role="group">
                                                    <button type="button" class="btn btn-default dropdown-toggle"
                                                            data-toggle="dropdown" aria-haspopup="true"
                                                            aria-expanded="false">
                                                        迭 代
                                                        <i class="fa fa-caret-down"></i>
                                                    </button>
                                                    <ul class="dropdown-menu">
                                                        {% for item in sprints %}
                                                            {% if item.status!=3 %}
                                                                <li>
                                                                    <a class="btn_batch_update" data-field="sprint"
                                                                       data-id="<?= item['id'] ?>"
                                                                       href="#"><?= item['name'] ?></a>
                                                                </li>
                                                            {% endif %}
                                                        {% endfor %}
                                                    </ul>
                                                </div>
                                                <div class="btn-group dropup" role="group">
                                                    <button type="button" class="btn btn-default dropdown-toggle"
                                                            data-toggle="dropdown" aria-haspopup="true"
                                                            aria-expanded="false">
                                                        移动至项目
                                                        <i class="fa fa-caret-down"></i>
                                                    </button>
                                                    <ul class="dropdown-menu">
                                                        {% for item in projects %}
                                                            {% if (item.id!=project_id) %}
                                                            <li>
                                                                <a class="btn_batch_update" data-field="project_id"
                                                                   data-id="<?= item['id'] ?>"
                                                                   href="#"><?= item['name'] ?></a>
                                                            </li>
                                                            {% endif %}

                                                        {% endfor %}
                                                    </ul>
                                                </div>
                                            </div>

                                            <span style="margin-left: 1em">
														总数:<span id="issue_count"></span>
														每页显示:<span id="page_size"></span>
													</span>
                                        </div>
                                    </form>
                                </div>

                                <div class="gl-pagination" id="ampagination-bootstrap"></div>

                            </div>

                                    {% include 'twig/issue/detail-right-list.twig' %}

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

            <!-- <div class="maskLayer hide"></div> -->
            <!--背景遮罩-->

            <div id="tips_panel" class="modal">
                <div class="modal-dialog" style="width:100%;">
                    <div class="card" style="width: 1200px;margin:0 auto;">
                        <div class="block-bg text-center">
                            <img src="/dev/img/smile.png" alt="">
                            <h4 class="text-center">header</h4>
                            <a class="btn close-detail-tips">Thanks & Return</a>
                        </div>
                        <img class="tips_arrow_bottom" src="/dev/img/tips_bottom.png" alt="">
                        <div class="card-body text-center">
                            <p class="card-text">Some make up the bulk of the card's content.</p>
                        </div>
                    </div>
                </div>
            </div>
            <!--第二阶段实施-->

            {% include 'twig/issue/list_modal.twig' %}
            {% include 'twig/issue/form.twig' %}
            {% include 'twig/issue/list_handbars_tpl.twig' %}


            <script src="/dev/js/handlebars.helper.js?v=<?= _version ?>"></script>
            <script src="/dev/js/handlebars.responsive.helper.js?v=<?= _version ?>" type="text/javascript" charset="utf-8"></script>
            <!--script src="/dev/js/websocket.js?v=<?= _version ?>"></script-->
            <script src="/dev/lib/sortable/Sortable.js"></script>
            <script src="/dev/lib/sortable/Sortable.js"></script>
            {% include 'twig/issue/list_adv_query.twig' %}

            <script type="text/javascript">
                var _issueConfig = {
                    "priority": <?= priority|json_encode()|raw ?>,
                    "issue_types": <?= issue_types|json_encode()|raw ?>,
                    "issue_status": <?= issue_status|json_encode()|raw ?>,
                    "issue_resolve": <?= issue_resolve|json_encode()|raw ?>,
                    "issue_module": <?= project_modules|json_encode()|raw ?>,
                    "issue_version": <?= project_versions|json_encode()|raw ?>,
                    "issue_labels": <?= project_labels|json_encode()|raw ?>,
                    "users": <?= users|json_encode()|raw ?>,
                    "project_users": <?= project_users|json_encode()|raw ?>,
                    "projects": <?= projects|json_encode()|raw ?>,
                    "sprint": <?= sprints|json_encode()|raw ?>,
                    "project_root_url": "<?= project_root_url ?>"
                };

                var _project_issue_types = <?= project_issue_types|json_encode()|raw ?>;

                var _simplemde = {};

                var _fineUploaderFile = {};
                var _fineImportExcelUploader = null;
                var _issue_id = null;
                var _cur_project_id = '<?= project_id ?>';
                var _active_sprint_id = '<?= active_sprint['id'] ?>';
                var _cur_uid = null;
                var _editor_md = null;
                var _description_templates = <?= description_templates|json_encode()|raw ?>;
                var _is_create_sprint_issue = false;

                var $IssueMain = null;
                var $IssueAdvQuery = null;
                var $IssueDetail = null;
                var query_str = '<?= query_str ?>';
                var urls = parseURL(window.location.href);
                var $sort_field = '<?= sort_field ?>';
                var $sort_by = '<?= sort_by ?>';
                var is_all_issues = {% if (is_all_issues)%}true{% else %}false{% endif %};
                var _default_issue_type_id = '<?=project.default_issue_type_id?>';
                var last_create_issue_data = <?=last_create_data|json_encode()|raw ?>;

                var display_fields = <?= display_fields|json_encode()|raw ?>;
                var uiDisplayFields = <?= uiDisplayFields|json_encode()|raw ?>;
                var advFields = <?= advFields|json_encode()|raw ?>;

                var is_save_filter = '0';

                var qtipApi = null;

                var _fineUploader = null;
                var _detailFineUploader = null;

                var subtack = [];
                var isFloatPart = false;
                var advQueryType = "text";
                var advQuerySource = "";
                var advQueryTitle = "请选择";
                var adv_details = [];
                var sort_adv_temp_item = {};

                var adv_filter_json = <?= adv_filter_json|raw ?>
                var is_adv_filter = '<?= is_adv_filter ?>';

                var issue_view = '<?= issue_view ?>';
                var list_render_id = 'list_render_id';
                var list_tpl_id = 'list_tpl';
                if (issue_view === 'responsive') {
                    list_render_id = 'ul_issues';
                    list_tpl_id = 'responsive_tpl';
                    $("#ul_issues").show();
                }
                if (issue_view === 'detail') {
                    isFloatPart = true;
                    list_render_id = 'list_render_id';
                    list_tpl_id = 'list_tpl';
                    $("#list_render_id").show();
                }
                if (issue_view === 'list' || issue_view === 'detail') {
                    $("#tree-slider").show();
                }

                var timer = null;

                //window.$IssueAdvQuery = new IssueAdvQuery(_issueConfig);

                // 显示右侧浮动窗
                function showFloatDetail(dataId, dataSummary) {
                    if(timer) {
                        return
                    }else{
                        getFineUploader(dataId, dataSummary);
                        getRightPartData(dataId);
                        $('.float-right-side').show();
                        timer = setTimeout(function(){
                            timer = null
                        }, 1000)
                    }

                }
                function linkIssue(id) {
                    if(issue_view!='detail'){
                        window.location.href = '/issue/detail/index/'+id;
                        return;
                    }
                    let dataSummary = $('#tree_tr_'+id).data("summary") || "";
                    $('#tree_tr_'+id).addClass("active").siblings(".tree-item").removeClass("active");
                    showFloatDetail(id, dataSummary);
                }


                $(function () {
                    var options = {
                        query_str: window.query_str,
                        query_param_obj: urls.searchObject,
                        list_render_id: list_render_id, // list_render_id detail_render_id
                        list_tpl_id: list_tpl_id, // list_tpl list_tpl_detail
                        filter_form_id: "filter_form",
                        filter_url: "/issue/main/filter?project=<?= project_id ?>",
                        get_url: "/issue/main/get",
                        update_url: "/issue/main/update",
                        add_url: "/issue/main/add",
                        delete_url: "/issue/main/delete",
                        pagination_id: "pagination"
                    };

                    function getdata(res) {
                        for (var i in res.issues) {
                            if (res.issues[i]['master_id'] && res.issues[i]['master_id'] > 0) {
                                subtack.push(res.issues[i]);
                            }
                        }
                    }




                    window.$IssueMain = new IssueMain(options);
//                    window.$FilteredSearch = new FilteredSearch(urls.searchObject, _issueConfig, _cur_project_id);
                    if(is_adv_filter==='0' || is_empty(adv_filter_json)){
                        window.$IssueMain.fetchIssueMains(getdata);
                    }else{
                        adv_details = adv_filter_json;
                        var tempData = JSON.parse(JSON.stringify(adv_details));
                        var temp = tempData.map(function (n) {
                            return {
                                logic: n.logic,
                                start_braces: n.start_braces,
                                field: n.field,
                                opt: n.opt,
                                value: n.value,
                                end_braces: n.end_braces
                            }
                        });
                        var adv_data = tempData.map(function (n) {
                            return n
                        });

                        var queryData = JSON.stringify(temp);
                        IssueMain.prototype.fetchIssuesByAdvQueryIssue(queryData,null, adv_data);
                    }

                    $('#btn-add').bind('click', function () {
                        IssueMain.prototype.add();
                    });

                    $("#btn-create-issue").bind("click", function () {
                        $('#master_issue_id').val('');
                        $('#create_master_div').hide();
                        if (window._cur_project_id !== '') {
                            var issue_types = [];
                            _cur_form_project_id = _cur_project_id;
                            for (key in _project_issue_types) {
                                issue_types.push(_project_issue_types[key]);
                            }
                            IssueMain.prototype.initCreateIssueType(_project_issue_types, true);
                        } else {
                            _cur_form_project_id = "";
                        }
                    });


                    $('#btn-update').bind('click', function () {
                        IssueMain.prototype.update();
                    });

                    $('#btn-close').bind('click', function () {
                        IssueMain.prototype.detailClose($(this).data('issue_id'));
                    });

                    $('#btn-delete').bind('click', function () {
                        IssueMain.prototype.detailDelete($(this).data('issue_id'));
                    });

                    $('#btn-batchDelete').bind('click', function () {
                        IssueMain.prototype.batchDelete();
                    });
                    $('#btn-check_all_issues').bind('click', function () {
                        IssueMain.prototype.checkedAll();
                    });

                    $('#btn-setting_columns').bind('click', function () {
                        IssueMain.prototype.saveUserIssueDisplayFields();
                    });


                    $('.btn_batch_update').bind('click', function () {
                        var field = $(this).data('field');
                        var value = $(this).data('id');
                        var name = $(this).html();
                        if(field=='project_id'){
                            IssueMain.prototype.displayMoveProject(value, name);
                        }else{
                            IssueMain.prototype.batchUpdate(field, value);
                        }
                    });

                    $('#btn-move-project').bind('click', function () {
                        IssueMain.prototype.batchMoveProject();
                    });

                    $('.sort_select').bind('click', function () {

                        var searchObj = {};
                        for (var i in urls.searchObject) {
                            let key = decodeURIComponent(i);
                            searchObj[key] = decodeURIComponent(urls.searchObject[i]);
                        }
                        var field = $(this).data('field');
                        $('#btn-sort_field').data('sort_field', field)
                        var sortby = $('#btn_sort_by').data('sortby');
                        searchObj['sort_field'] = field;
                        searchObj['sort_by'] = sortby;
                        console.log(searchObj);

                        url = root_url + urls.pathname.substr(1) + '?' + parseParam(searchObj);
                        console.log(url);
                        window.location.href = url;
                    });

                    $('#btn_sort_by').bind('click', function () {
                        var searchObj = {};
                        for (var i in urls.searchObject) {
                            var key = decodeURIComponent(i);
                            var value = decodeURIComponent(urls.searchObject[i]);
                            searchObj[key] = value;
                        }
                        var field = $('#btn-sort_field').data('sort_field');
                        var sortby = '';
                        if ($(this).data('sortby') === 'desc' || is_empty($(this).data('sortby'))) {
                            sortby = 'asc';
                        } else {
                            sortby = 'desc';
                        }
                        $(this).data('sortby', sortby);

                        searchObj['sort_field'] = field;
                        searchObj['sort_by'] = sortby;
                        console.log(searchObj);

                        url = root_url + urls.pathname.substr(1) + '?' + parseParam(searchObj);
                        console.log(url);
                        window.location.href = url;
                    });


                    $('.sort_link').bind('click', function () {

                        var searchObj = {};
                        for (var i in urls.searchObject) {
                            var key = decodeURIComponent(i);
                            var value = decodeURIComponent(urls.searchObject[i]);
                            searchObj[key] = value;
                        }

                        var field = $(this).data('field');
                        var sortby = $(this).data('sortby');
                        searchObj['sort_field'] = field;
                        searchObj['sort_by'] = sortby;
                        console.log(searchObj);

                        url = root_url + urls.pathname.substr(1) + '?' + parseParam(searchObj);
                        console.log(url);
                        window.location.href = url;
                    });


                    $('#view_choice li').bind('click', function () {

                        $('#view_choice .active').removeClass('active');
                        $(this).addClass('active');
                        var selectIssueView = $(this).data('issue_view');
                                    // alert(selectIssueView);
                        if (selectIssueView === 'detail') {
                            IssueMain.prototype.updateUserIssueView(selectIssueView);
                            $('#change_view_span').html('左右视图');
                            $('#change_view_icon').removeClass('fa-table').addClass('fa-outdent');
                            var firstTabelTr = $('#list_render_id tr:first-child');
                            var detailRender = $('#detail_render_id');
                            var dataId = firstTabelTr.data('id') || $('#detail_render_id div:first-child').data('id');
                            var dataSummary = firstTabelTr.data('summary') || $('#detail_render_id div:first-child').data('summary') || "";
                            isFloatPart = true;

                            if (detailRender.length) {
                                showFloatDetail(dataId, dataSummary);
                            } else {
                                showFloatDetail(dataId, dataSummary);
                            }
                            firstTabelTr.addClass('active');
                            detailRender.children(":first").addClass('issue-box-active');
                        } else {
                            $('#change_view_icon').removeClass('fa-outdent').addClass('fa-table');
                            $('#change_view_span').html('表格视图')
                            isFloatPart = false;
                            IssueMain.prototype.updateUserIssueView(selectIssueView);
                        }

                    });

                    // 点击tips提示
                    $('#showMoreTips').click(function () {
                        $('#tips_panel').modal();
                        $('.camper-helper').addClass('hide');
                    });

                    // 关闭背景颜色
                    $('#tips_panel').on('shown.bs.modal', function () {
                        $('.modal-backdrop.in').css('opacity', '0.2');
                    });

                    // 关闭tips提示框
                    $('#closeTips').click(function () {
                        $('.camper-helper').addClass('hide');
                    });

                    // 关闭tips的弹出框
                    $('.close-detail-tips').click(function () {
                        $('.camper-helper').removeClass('hide');
                        $('#tips_panel').modal('hide');
                    });

                    // 点击高级查询按钮
                    $('#modal-adv_query').on('shown.bs.modal', function () {
                        IssueAdvQuery.prototype.renderAdvQuery(adv_details);
                        clearAdvSearchQuery();
                    });

                    // 添加bottom的textare的focus事件
                    $('.bottom-part textarea').on('focus', function () {
                        $('.textarea-tips').addClass('hide');
                    });

                    $('.bottom-part textarea').on('blur', function () {
                        $('.textarea-tips').addClass('hide');
                        if (this.value == '') {
                            $('.textarea-tips').removeClass('hide');
                        }
                    // $('.textarea-tips').addClass('hide');
                    });

                    let el_list_render_id = $('#list_render_id');
                    var _isTable = el_list_render_id.length;

                    $(document).on('click', '.detail-pager .previous:not(".disabled")', function () {
                        IssueMain.prototype.prevIssueItem();
                    });

                    $(document).on('click', '.detail-pager .next:not(".disabled")', function () {
                        IssueMain.prototype.nextIssueItem();
                    });

                    // 点击事件，以及左侧菜单的内容
                    el_list_render_id.on('click', function (e) {
                        $('#list_render_id tr.active').removeClass('active');
                        if ($(e.target).attr('href') && $(e.target).parent().hasClass('show-tooltip')) {
                            $(e.target).parent().parent().addClass('active');
                        } else if ($(e.target).parent().next().hasClass('pop_subtack hide')) {
                            //$(e.target).parent().next().removeClass('hide');
                            $(e.target).parent().addClass('active');
                        } else if ($(e.target).parent().next().hasClass('pop_subtack')) {
                            //$(e.target).parent().next().addClass('hide');
                            $(e.target).parent().removeClass('active');
                        }
                    });

                    el_list_render_id.on("click", ".tree-item", function(e) {
                        if(e.target.nodeName.toLowerCase() != 'td') return;
                        if (isFloatPart) {
                            var el_target = $(e.target);
                            if(el_target.hasClass('no_float_event')
                            || el_target.hasClass('commit-id')
                            || el_target.hasClass('label')
                            || el_target.hasClass('prepend-left-5')
                            || el_target.parent().hasClass('resolve-select')
                            ){
                                return;
                            }
                            var dataId = $(this).data("id");
                            var dataSummary = $(this).data("summary") || "";
                            $(this).addClass("active").siblings(".tree-item").removeClass("active");
                            showFloatDetail(dataId, dataSummary);
                            
                            return false;
                        }else{
                            let have_children = 0;
                            var issue_id = $(this).data('id');
                            $('#tr_subtask_' + issue_id).toggleClass('hide');
                            have_children = $(this).data('have_children');
                            if( have_children>0){
                                IssueMain.prototype.fetchChildren(issue_id, 'ul_subtask_' + issue_id);
                                
                            }
                        }
                    });

                    $('#detail_render_id').on('click', '.issue-box', function (e) {
                        //console.log(e);
                        var dataId = $(this).data('id');
                        var dataSummary = $(this).data("summary") || "";
                        if ( !$(e.target).attr('type') && !$(e.target).hasClass('commit-id') && !$(e.target).hasClass('label') && !$(e.target).hasClass('prepend-left-5') && !$(e.target).parent().hasClass('resolve-select')) {
                            $(this).addClass('issue-box-active').siblings('.issue-box').removeClass('issue-box-active');
                            if (isFloatPart) {
                                showFloatDetail(dataId, dataSummary);
                                return false;
                            }
                        }
                    });


                    // 双击修改
                    $(document).on("dblclick", "#adv-query-box .table-text", function () {
                        var $self = $(this);
                        var dataType = $self.data("type");
                        var dataSource = $self.data("source");
                        var dataTitle = $self.data("title");
                        var dataIndex = $self.parent().parent().data("index");
                        var data = $self.data("content");
                        var filed_name = $self.data("filed");
                        var html = IssueAdvQuery.prototype.renderTableAdvQuery(filed_name, dataType, data, dataIndex, dataTitle, dataSource);

                        $self.parent().find(".table-form").html(html).removeClass("hidden");
                        $self.addClass("hidden");
                        initAdvForm();
                    });

                    $(document).on("change", "#adv-query-box .table-form select", function () {
                        var $self = $(this);
                        var index = $self.data("index");
                        var field_name = $self.data("name");
                        var value = $self.val();
                        var $selected = $self.find('option:selected');

                        if (field_name === "field") {
                            adv_details[index].data_type = $selected.data("type");
                            adv_details[index].data_source = $selected.data("source");
                            adv_details[index].data_title = $selected.data("title");
                        }

                        adv_details[index][field_name] = value;

                        if (field_name === "value") {
                            adv_details[index].display_html = $selected.data("display_html");
                        }
                        if ($selected.data("avatar")) {
                            adv_details[index].avatar = $selected.data("avatar");
                        }

                        console.log(adv_details[index]);

                        $self.parent().html("").addClass("hidden");
                        $self.parent().find(".table-text").removeClass("hidden");

                        IssueAdvQuery.prototype.renderAdvQuery(adv_details);
                    });

                    $(document).on("blur", "#adv-query-box .table-form input:not(.laydate_input)", function () {
                        var $self = $(this);
                        var index = $self.data("index");
                        var field_name = $self.data("name");
                        var value = $self.val();

                        adv_details[index][field_name] = value;
                        adv_details[index].display_html = value;

                        IssueAdvQuery.prototype.renderAdvQuery(adv_details);
                    });


                    $(document).on("click", function (e) {
                        var $form = $(".table-form");
                        if (!$form.is(e.target) && $form.has(e.target).length === 0) {
                            $(".table-text").removeClass("hidden");
                            $(".table-form").addClass("hidden");

                            var $date = $("#adv-query-box .table-form input.laydate_input");

                            if ($date.length > 0) {
                                $date.each(function () {
                                    var $self = $(this);
                                    var index = $self.data("index");
                                    var field_name = $self.data("name");
                                    var value = $self.val();

                                    adv_details[index][field_name] = value;
                                    IssueAdvQuery.prototype.renderAdvQuery(adv_details);
                                });
                            }
                        }
                    });

                    $(document).on("click", "#btn_adv_sort_by", function () {
                        var sort_by = $("#adv_sort_by").val();
                        if (sort_by === "asc") {
                            $("#adv-sort-by-asc").removeClass("hidden");
                            $("#adv-sort-by-desc").addClass("hidden");
                            $("#adv_sort_by").val("desc");
                            $(this).prop("title", "升序");
                        } else {
                            $("#adv-sort-by-asc").addClass("hidden");
                            $("#adv-sort-by-desc").removeClass("hidden");
                            $("#adv_sort_by").val("asc");
                            $(this).prop("title", "降序");
                        }
                    });

                    // 右侧详情上下事项切换


                    /*详情页的ajax*/
                    $('#save_filter-btn').qtip({
                        content: {
                            text: $('#save_filter_tpl').html(),
                            title: "新增过滤器",
                            button: "关闭"
                        },
                        show: 'click',
                        hide: 'click',
                        style: {
                            classes: "qtip-bootstrap",
                            width: "500px"
                        },
                        position: {
                            my: 'top left', // Position my top left...
                            at: 'bottom center', // at the bottom right of...
                            target: $('.filtered-search')
                        },
                        events: {
                            show: function (event, api) {
                                var t = setTimeout("$('#save_filter_text').focus();", 200)
                            }
                        }
                    });
                    window.qtipApi = $('#save_filter-btn').qtip('api');

                    $('#btn-save_adv_filter').qtip({
                        content: {
                            text: $('#save_adv_filter_tpl').html(),
                            title: "新增过滤器",
                            button: "关闭"
                        },
                        position: {
                            target: 'event', 
                            at: 'top left',
                            my: "right center",
                            adjust: {x: -5}
                        },
                        show: 'click',
                        hide: 'click',
                        style: {
                            classes: "qtip-bootstrap",
                            width: "500px"
                        },
                        events: {
                            show: function (event, api) {
                                var t = setTimeout("$('#save_adv_filter_text').focus();", 200)
                            }
                        }
                    });
                    window.qtipApi = $('#btn-save_adv_filter').qtip('api');
                    /*
                    $(document).click(function(event){
                            var _con = $('.qtip');  // 设置目标区域
                            var _event = $("#btn-save_adv_filter");
                            if(!_con.is(event.target) && _con.has(event.target).length === 0 && !_event.is(event.target) && _event.has(event.target).length === 0){ 
                                window.qtipApi.hide()
                                $('#btn-save_adv_filter').qtip('api').toggle(false);
                            }
                    });
                    */
                    var el_custom_filter_more = $('#custom-filter-more');
                    el_custom_filter_more.qtip({
                        content: {
                            text: $('#custom-filter-tpl').html(),
                            title: "更多过滤器",
                            button: "关闭"
                        },
                        show: 'click',
                        hide: 'click',
                        style: {
                            classes: "qtip-bootstrap",
                            width: "500px"
                        },
                        position: {
                            my: 'top right', // Position my top left...
                            at: 'bottom center', // at the bottom right of...
                        }
                    });
                    window.qtipApi = el_custom_filter_more.qtip('api');

                    // 右边悬浮层按钮事件
                    $('#btn-edit').bind('click', function () {
                        window.$IssueMain.fetchEditUiConfig(_issue_id, 'update');
                    });

                    $('#btn-copy').bind('click', function () {
                        window.$IssueMain.fetchEditUiConfig(_issue_id, 'copy');
                    });

                    keyMaster.addKeys([
                        {
                            key: "e",
                            'item-element': '.tree-item',
                            'trigger-element': '.issue_edit_href',
                            trigger: 'click'
                        },
                        {
                            key: "d",
                            'item-element': '.tree-item',
                            'trigger-element': '.issue_delete_href',
                            trigger: 'click'
                        }
                    ])

                    $("#modal-create-issue").on('show.bs.modal', function (e) {
                        keyMaster.addKeys(
                            [
                                {
                                    key: [
                                        'command+enter', 'ctrl+enter'
                                    ],
                                    'trigger-element': '#modal-create-issue .btn-save',
                                    trigger: 'click'
                                }, {
                                    key: 'esc',
                                    'trigger-element': '#modal-create-issue .close',
                                    trigger: 'click'
                                }
                            ]
                        )
                    })

                    $("#modal-edit-issue").on('show.bs.modal', function (e) {
                        keyMaster.addKeys([
                            {
                                key: [
                                    'command+enter', 'ctrl+enter'
                                ],
                                'trigger-element': '#modal-edit-issue .btn-save',
                                trigger: 'click'
                            }
                        ])
                    })

                    $("#modal-export_excel").on('show.bs.modal', function (e) {
                        keyMaster.addKeys([
                            {
                                key: [
                                    'command+enter', 'ctrl+enter'
                                ],
                                'trigger-element': '.js-key-modal-enter1',
                                trigger: 'click'
                            }, {
                                key: 'esc',
                                'trigger-element': '.js-key-modal-close1',
                                trigger: 'click'
                            }
                        ])
                    });
{% verbatim %}
                    // 转换为子任务时，要选择父事项
                    $('#parent_select_issue_id').select2({
                      language: "zh-CN",
                      ajax: {
                        url: '/issue/main/autocomplete',
                        data: function (params) {
                          var query = {
                            query: params.term,
                            project_id: _cur_project_id
                          }
                          return query;
                        },
                        processResults: function (resp) {
                              return {
                                results: resp.data
                              };
                        }
                      }
                    });
{% endverbatim %}
                    // 提交导出 excel 表单
                    $("#btn-export_excel").click(function () {
                        // 当前查询参数字符串
                        // alert(_issue_cur_page);
                        var curUrlParams = window.location.search;
                        curUrlParams = curUrlParams.substr(1);
                        var exportRangeType = $("input[name='radio-export_range']:checked").val();

                        if (exportRangeType == 'project_all') {
                            curUrlParams = '';
                        }

                        var formParams = $("#form-export_excel").serialize();
                        var action = "/project/export/issue?" + curUrlParams + "&" + formParams + "&cur_page=" + _issue_cur_page + '&project_id=' + window.cur_project_id;
                        // alert(action);
                        $("#form-export_excel").attr("action", action);
                        $("#form-export_excel").submit();
                        $('#modal-export_excel').modal('hide');
                        notify_success('请稍后,等待文件自动下载');
                    });

                    $('#import_excel_file').fileupload({
                        url: '/issue/main/importExcel?project_id=' + window.cur_project_id,
                        singleFileUploads: true,
                        done: function (e, uploadObj) {
                            var resp = uploadObj.result;
                            console.log(resp)
                            if (resp.ret == '200') {
                                notify_success(resp.msg);
                            } else {
                                notify_error(resp.msg, resp.data);
                            }
                            $('#import_excel_result').html(resp.data);
                        },
                        fail: function (e, uploadObj) {
                            var resp = uploadObj.result;
                            // alert(resp.msg);
                            console.log(resp)
                            notify_error(resp.msg, resp.data);
                            $('#import_excel_result').html(resp.data);
                        },
                        progressall: function (e, data) { // console.log(data)
                            var progress = parseInt(data.loaded / data.total * 100, 10);
                            $('#import_excel_progress .progress-bar').css('width', progress + '%');
                        }
                    }).prop('disabled', !$.support.fileInput).parent().addClass($.support.fileInput ? undefined : 'disabled');
                });

                // 获取详情页信息
                function getRightPartData(dataId) {
                    $('.maskLayer').removeClass('hide'); // 可以不要，但是由于跳转的时候速度太慢，所以防止用户乱点击
                    _issue_id = dataId;

                    IssueMain.prototype.initIssueItem();

                    $IssueDetail = new IssueDetail({});
                    $IssueDetail.fetchIssue(dataId, true);
                }

                // 获取上传插件
                function getFineUploader(issue_id, sum = "121") {
                    _fineUploader = null;
                    $("#issue_right_attachments_uploder").html("");
                    _fineUploader = new qq.FineUploader({
                        element: document.getElementById('issue_right_attachments_uploder'),
                        template: 'qq-template-gallery',
                        multiple: true,
                        request: {
                            endpoint: '/issue/main/upload?project_id=' + _cur_project_id + '&issue_id=' + issue_id + '&summary=' + sum + '&_csrftoken=' + encodeURIComponent(document.getElementById('csrf_token').value)
                        },
                        deleteFile: {
                            enabled: true,
                            forceConfirm: true,
                            endpoint: "/issue/main/upload_delete/" + _cur_project_id
                        },
                        validation: {
                            allowedExtensions: [
                                'mp3',
                                'aac',
                                'wma',
                                'avi',
                                'rm',
                                'rmvb',
                                'flv',
                                'mpg',
                                'mov',
                                'mkv',
                                'mp4',
                                'jpeg',
                                'jpg',
                                'gif',
                                'png',
                                '7z',
                                'zip',
                                'rar',
                                'bmp',
                                'csv',
                                'doc',
                                'docx',
                                'xls',
                                'xlsx',
                                'ppt',
                                'pdf',
                                'xlt',
                                'xltx',
                                'txt'
                            ]
                        }
                    });
                }

                //startWS();关闭websocket

                var _curFineAttachmentUploader = null;
                var _curIssueId = null;
                var _curTmpIssueId = null;
                var _curQrToken = null;
                var mobileUploadInterval = null;
            </script>
</body>
</html>
