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

    {% include 'twig/common/header/include.twig' %}
    <script src="/dev/lib/jquery.form.min.js"></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">
    <!-- 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"></script>

    <link rel="stylesheet" href="/dev/lib/editor.md/css/editormd.css">
    <script src="/dev/lib/editor.md/editormd.js"></script>
</head>
<body class="" data-group="" data-page="projects:issues:new" 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>
<style>
    .bootstrap-select:not([class*="col-"]):not([class*="form-control"]):not(.input-group-btn) {
        width: 100% !important;
    }
</style>
<div class="page-with-sidebar">
    {% include 'twig/project/common-page-nav-project.twig' %}
    {% include 'twig/project/common-setting-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="container-fluid container-limited">
            <div class="content" id="content-body">
                <div class="row prepend-top-default">
                    <div class="col-lg-3">
                        <h4 class="prepend-top-0">基本设置</h4>
                        <p>将事项分为不同的类型, 例如 缺陷或任务等。 每个事项类型都可以分别配置不同的选项。
                         事项类型方案用于定义这个项目使用哪几种事项类型。 要改变项目的事项类型, 可以选择另一个事项类型方案, 或编辑当前的事项类型界面方案。</p>
                    </div>
                    <div class="col-lg-9">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <strong>基础设置</strong>
                            </div>
                            <div class="panel-body">
                                <div>
                                    <form id="save_project" action="/project/setting/save_settings_profile?project_id=<?=project_id?>" accept-charset="UTF-8" method="post" class="form-horizontal">
                                        <input name="utf8" type="hidden" value="✓">
                                        <input type="hidden" name="authenticity_token" value="">

                                        <div class="form-group">
                                            <label class="control-label" for="project_namespace_id">
                                                <span>项目名称 <i class="required">*</i></span>
                                            </label>
                                            <div class="col-sm-10">
                                                <input value="<?=info['name']?>" placeholder="请输入名称" class="form-control" tabindex="1" required="required" type="text" name="params[name]" id="project_name" >
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label" for="project_namespace_id">
                                                <span>组织 <i class="required">*</i></span>
                                            </label>
                                            <div class="col-sm-10">
                                                {% if (not is_admin) %}
                                                    <input value="<?=info['org_name']?>" class="form-control" type="text" disabled>
                                                {% else %}
                                                    <div class="select2-container">
                                                        <select class="selectpicker" id="org_id"  name="params[org_id]">
                                                            {% for org in org_list %}
                                                                <option data-tokens="<?=org['name']?>" data-org_path="<?=org['path']?>" value="<?=org['id']?>"><?=org['name']?></option>
                                                            {% endfor %}
                                                        </select>
                                                    </div>
                                                {% endif %}
                                            </div>
                                        </div>
                                        <div class="form-group project-path">
                                            <label class="control-label" for="project_namespace_id">
                                                <span>项目KEY <i class="required"></i></span>
                                            </label>
                                            <div class="col-sm-10">
                                                <input value="<?=info['key']?>" placeholder="必须英文字符,最大长度20" class="form-control" tabindex="3"required="required" type="text" name="params[key]" id="project_key" disabled>
                                            </div>
                                        </div>

                                        <div class="form-group clearfix">
                                            <label class="control-label" for="project_visibility_level">
                                                项目模板 <i class="required"></i>
                                            </label>
                                            <div class="col-sm-10 radio-with">
                                                <input value="<?=info['project_tpl_text']?>"  class="form-control"   type="text" name="params[project_tpl_text]" id="project_tpl_text" disabled>
                                            </div>
                                        </div>


                                        <div class="form-group">
                                            <label class="control-label" for="issue_type_scheme_id">
                                                <span>项目负责人 <i class="required">*</i></span>
                                            </label>
                                            <div class="col-sm-10">
                                                <div class="select2-container">
                                                    <select  name="params[lead]" id="project_lead" title="项目负责人" class="selectpicker">
                                                        {% for row in users %}
                                                            {% set  display_name = row['display_name'] %}
                                                            <option {% if row.uid==info.lead %} selected {% endif %} value="<?=row.uid?>"  data-content="<img width='20px' height='20px' class=' float-none' style='border-radius: 50%;' src='/attachment/avatar/<?=row.uid?>.png' > <?=display_name?>"  ><?=display_name?></option>
                                                        {% endfor %}
                                                    </select>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="control-label" for="project_description">项目描述</label>
                                            <div class="col-sm-10">
                                                <textarea class="form-control" rows="3" maxlength="250" name="params[description]" id="project_description"><?=info['description']?></textarea>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="control-label" for="project_detail">项目详情</label>
                                            <div class="col-sm-10">
                                                <div id="editor_md">
                                                    <textarea style="display:none;" name="params[detail]" id="project_detail"><?=info['detail']?></textarea>
                                                </div>
                                                <div class="help-block"><a href="https://zh.wikipedia.org/wiki/Markdown" target="_blank">help</a></div>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="control-label" for="project_url">
                                                <span>URL</span>
                                            </label>
                                            <div class="col-sm-10">
                                                <input value="<?=info['url']?>" placeholder="URL" class="form-control"  type="text" name="params[url]" id="project_url">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="control-label" for="project_avatar">
                                                <span>头像</span>
                                            </label>
                                            <div class="col-sm-10">
                                                <img id="avatar_display" class="avatar s40" alt="" src="<?=attachment_url?><?=info['avatar']?>">
                                                <input type="hidden"  name="params[avatar_relate_path]" id="avatar"  value="<?=info['avatar']?>" />
                                                <div id="fine-uploader-gallery"></div>
                                                <div class="help-block">图片大小被限制为500KB.</div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label"></label>
                                            <div class="col-sm-10">
                                                <input type="submit" name="commit" value="保存" class="btn btn-create project-submit js-key-enter" tabindex="4">
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>

                        <!--div class="panel panel-default">
                            <div class="panel-heading">
                                <strong>重命名KEY</strong>
                            </div>
                            <div class="panel-body">
                                <div>
                                    <form id="update_key_from" action="/project/setting/update_project_key?project_id=<?=project_id?>" accept-charset="UTF-8" method="post" class="form-horizontal">
                                        <input name="utf8" type="hidden" value="✓">
                                        <input type="hidden" name="_method" value="patch">
                                        <input type="hidden" name="authenticity_token" value="qGi0NPGi5k0taFq/z4qSkPLv23LTIN8106xSE+XR0JfrqvSBZINwUkRX3DTB+12SGo41k/n2lqBcZ2oiLkbTSQ==">
                                        <div class="form-group project_name_holder">
                                            <label class="control-label" for="project_name">原KEY</label>
                                            <div class="col-sm-10">
                                                <input class="form-control" type="text" value="<?=info['key']?>" name="params[key]">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label" for="project_path"><span>新KEY</span></label>
                                            <div class="col-sm-10">
                                                <input class="form-control" type="text" value="" name="params[new_key]">
                                                <ul style="color: #999;">
                                                    <li>注意，重命名KEY可能会产生意想不到的副作用。</li>
                                                    <li>您需要更新本地KEY以指向新的位置。</li>
                                                </ul>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label"></label>
                                            <div class="col-sm-10">
                                                <input type="submit" name="commit" value="重命名KEY" class="btn btn-warning">
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div-->

                    </div>
                </div>


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

    </div>
</section>

<!-- Fine Uploader Gallery template
    ====================================================================== -->
<script type="text/template" id="qq-template-gallery">
    <div class="qq-uploader-selector qq-uploader qq-gallery" qq-drop-area-text="将文件拖放到此处以上传项目图标">
        <div class="qq-total-progress-bar-container-selector qq-total-progress-bar-container">
            <div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-total-progress-bar-selector qq-progress-bar qq-total-progress-bar"></div>
        </div>
        <div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone>
            <span class="qq-upload-drop-area-text-selector"></span>
        </div>
        <div class="qq-upload-button-selector qq-upload-button">
            <div>选择图片</div>
        </div>
        <span class="qq-drop-processing-selector qq-drop-processing">
                <span>Processing dropped files...</span>
                <span class="qq-drop-processing-spinner-selector qq-drop-processing-spinner"></span>
            </span>
        <ul class="qq-upload-list-selector qq-upload-list" role="region" aria-live="polite" aria-relevant="additions removals">
            <li>
                <span role="status" class="qq-upload-status-text-selector qq-upload-status-text"></span>
                <div class="qq-progress-bar-container-selector qq-progress-bar-container">
                    <div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-progress-bar-selector qq-progress-bar"></div>
                </div>
                <span class="qq-upload-spinner-selector qq-upload-spinner"></span>
                <div class="qq-thumbnail-wrapper">
                    <a href="javascript:;" class="qq-file-link qq-upload-file-url">
                    <img class="qq-thumbnail-selector" qq-max-size="198" qq-server-scale>
                    </a>
                </div>
                <button type="button" class="qq-upload-cancel-selector qq-upload-cancel">X</button>
                <button type="button" class="qq-upload-retry-selector qq-upload-retry">
                    <span class="qq-btn qq-retry-icon" aria-label="Retry"></span>
                    重试
                </button>

                <div class="qq-file-info">
                    <div class="qq-file-name">
                        <span class="qq-upload-file-selector qq-upload-file"></span>
                        <span class="qq-edit-filename-icon-selector qq-edit-filename-icon" aria-label="Edit filename"></span>
                    </div>
                    <input class="qq-edit-filename-selector qq-edit-filename" tabindex="0" type="text">
                    <span class="qq-upload-size-selector qq-upload-size"></span>
                    <button type="button" class="qq-btn qq-upload-delete-selector qq-upload-delete">
                        <span class="qq-btn qq-delete-icon" aria-label="Delete"></span>
                    </button>
                    <button type="button" class="qq-btn qq-upload-pause-selector qq-upload-pause">
                        <span class="qq-btn qq-pause-icon" aria-label="Pause"></span>
                    </button>
                    <button type="button" class="qq-btn qq-upload-continue-selector qq-upload-continue">
                        <span class="qq-btn qq-continue-icon" aria-label="Continue"></span>
                    </button>
                </div>
            </li>
        </ul>

        <dialog class="qq-alert-dialog-selector">
            <div class="qq-dialog-message-selector"></div>
            <div class="qq-dialog-buttons">
                <button type="button" class="qq-cancel-button-selector">Close</button>
            </div>
        </dialog>

        <dialog class="qq-confirm-dialog-selector">
            <div class="qq-dialog-message-selector"></div>
            <div class="qq-dialog-buttons">
                <button type="button" class="qq-cancel-button-selector">否</button>
                <button type="button" class="qq-ok-button-selector">是</button>
            </div>
        </dialog>

        <dialog class="qq-prompt-dialog-selector">
            <div class="qq-dialog-message-selector"></div>
            <input type="text">
            <div class="qq-dialog-buttons">
                <button type="button" class="qq-cancel-button-selector">Cancel</button>
                <button type="button" class="qq-ok-button-selector">Ok</button>
            </div>
        </dialog>
    </div>
</script>


{% include 'twig/project/common-projects-json.twig' %}
<script>
    // 初始化组织值
    $("#org_id").selectpicker('val', <?= project['org_id'] ?>);
    // 初始化事项类型方案
    $("#issue_type_scheme_id").selectpicker('val', <?= issue_type_scheme_id ?>);
    // 初始化状态流方案
    $("#workflow_scheme_id").selectpicker('val', <?= project['workflow_scheme_id'] ?>);

    var editor = editormd({
        id   : "editor_md",
        placeholder : "填写项目说明...",
        width: "100%",
        height: 240,
        markdown: "",
        path: '/dev/lib/editor.md/lib/',
        imageUpload: true,
        imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
        imageUploadURL: "/issue/detail/editormd_upload",
        tocm: true,    // Using [TOCM]
        emoji: true,
        saveHTMLToTextarea: true,
        toolbarIcons      : "custom",
        autoFocus : false
    });


    $('#fine-uploader-gallery').fineUploader({
        template: 'qq-template-gallery',
        multiple : false,
        request: {
            endpoint: '/projects/upload' +'?_csrftoken='+encodeURIComponent(document.getElementById('csrf_token').value)
        },
        deleteFile: {
            enabled: false
        },
        retry: {
            enableAuto: true
        },
        validation: {
            allowedExtensions: ['jpeg', 'jpg', 'gif', 'png'],
            sizeLimit: 1024*500
        },
        callbacks:{
            onComplete:  function(id,  fileName,  responseJSON)  {
                //console.log(responseJSON);
                if(responseJSON.error == ''){
                    $('#avatar').val(responseJSON.relate_path);
                }
            }
        }
    });

    var options = {
        beforeSubmit: function (arr, $form, options) {
            return true;
        },
        success: function (data, textStatus, jqXHR, $form) {
            if(data.ret == 200){
                notify_success('操作成功');
            }else{
                notify_error('保存失败: ' + data.msg);
            }
            console.log(data);
        },
        type:      "post",
        dataType:  "json",
        timeout:   3000
    };

    $('#save_project').submit(function() {
        $(this).ajaxSubmit(options);
        return false;
    });


    var update_key_options = {
        beforeSubmit:  function (arr, $form, options) {
            return true;
        },
        success:       function (data, textStatus, jqXHR, $form) {
            if(data.ret == 200){
                notify_success('KEY修改成功');
                window.location.href="/projects";
            }else{
                notify_error('KEY修改失败: ' + data.msg);
            }
            //console.log(data);
        },
        type:      "post",
        dataType:  "json",
        timeout:   3000
    };

    $('#update_key_from').submit(function() {
        $(this).ajaxSubmit(update_key_options);
        return false;
    });
</script>
</body>

</html>