{% extends 'base/base.html' %}
{% block script %}
{{ super()}}
<script type=text/javascript>
 $(document).ready(function(){
     $('button#editform').click(function() {
         var data = JSON.stringify({
             name:$('#name').val(),
             description:$('#description').val(),
             is_privacy:$("input[name='is_privacy']:checked").val()
         });
         $.ajax ({
             type : "PUT",
             url : "{{ url_for('mine.collect',uid = collect.id)}}",
             data:data,
             contentType: 'application/json;charset=UTF-8',
             success: function(result) {
                 if (result.judge == true)
                 {
                     window.location = '{{ url_for('mine.collect',uid = collect.id)}}';
                 }
                 else
                 {
                     alert(result.error);
                     alert(data)
                 }
             }
         });
     });
     $('button#deleteform').click(function() {
         /* var data = JSON.stringify({
            name:$('#name').val(),
            description:$('#description').val(),
            is_privacy:$("input[name='is_privacy']:checked").val()
            }); */
         $.ajax ({
             type : "DELETE",
             url : "{{ url_for('mine.collect',uid = collect.id)}}",
             data:JSON.stringify(),
             contentType: 'application/json;charset=UTF-8',
             success: function(result) {
                 if (result.judge == true)
                 {
                     window.location = '{{ url_for('mine.collect')}}';
                 }
                 else
                 {
                     alert(result.error);
                     alert(data)
                 }
             }
         });
     });
 });
</script>
{% endblock %}
{% block content %}
{{ breadcrumb(hrefs={'我的收藏':url_for('mine.collect')},active=collect.name)}}
<div class="row">
    <div class="col-md-9">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4>{{ collect.name }}</h4>
                <a class="btn btn-default btn-sm" href="javascript:void(0)" data-toggle="modal" data-target="#editcollect">编辑</a>
                <a class="btn btn-default btn-sm" href="javascript:void(0)" data-toggle="modal" data-target="#deletecollect">删除</a>
            </div>
            {% if topics.items %}
            {% for topic in topics.items %}
            <div class="panel-body" style="border-bottom:1px solid #eee">
                <a href="{{ url_for('topic.topic',uid=topic.uid)}}">{{ topic.title}}</a>
                <span class="pull-right btn btn-sm btn-danger">删除</span>
            </div>
            {% endfor %}
            {% else %}
            <div class="panel-body">
                <span class="text-center" style="display:block;width:100%;color:#999">
                    暂无收藏
                </span>
            </div>
            {% endif %}
        </div>
    </div>
    <div class="col-md-3" style="padding-left:0">
        {% include 'base/panel.html' %}
    </div>
</div>
<div class="modal fade" id="editcollect" tabindex="-1" role="dialog" aria-labelledby="editcollectLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="editcollectLabel">编辑收藏夹</h4>
            </div>
            <form id="editcollectform">
                <div class="modal-body">
                    <div class="form-group">
                        {{ form.name.label }}
                        {{ form.name(class="form-control")}}
                    </div>
                    <div class="form-group">
                        {{ form.description.label }}
                        {{ form.description(class="form-control")}}
                    </div>
                    {% for subfield in form.is_privacy %}
                    <div class="form-group">
                        {{subfield}}
                        {{subfield.label}}
                    </div>
                    {% endfor %}
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" id="editform" class="btn btn-primary">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="modal fade" id="deletecollect" tabindex="-1" role="dialog" aria-labelledby="deletecollectLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="deletecollectLabel">删除收藏夹</h4>
            </div>
            <div class="modal-body">
                <p>确认要删除收藏夹「flask相关」么？</p>
                注意：收藏夹下的收藏也会被删除！
            </div>
            <div class="modal-footer" style="padding-top:5px;padding-bottom:5px;">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" id="deleteform" class="btn btn-danger">删除</button>
            </div>
        </div>
    </div>
</div>
{% endblock %}
