{% init message_placeholder = "记录发生的事情/产生的想法" %}
{% init show_tag_btn = True %}
{% init show_attachment_btn = True %}
{% init default_content = "" %}
{% init filter_default_content = xutils.get_func_by_name("message.filter_default_content") %}
{% init create_tag = tag %}
{% init message_template_tab = None %}
{% init create_date = "" %}

<div class="message-input-box card">
    {% if message_template_tab %}
        <div class="row btn-line-height">
            {% render message_template_tab %}
            <div class="float-right">
                <a href="/message/template">编辑模板</a>
            </div>
        </div>
    {% end %}
    <textarea class="col-md-12 input-box" rows=3 autoHeight=true 
        placeholder="{{message_placeholder}}">{{filter_default_content(default_content)}}</textarea>

    <div class="col-md-12 btn-line-height">
        {% if show_tag_btn %}
            <!-- <input type="button" name="" class="send-button btn btn-default select-topic-btn" value="#标签" @click=""> -->
            <input type="button" class="send-button btn btn-default"
                onclick="xnote.action.message.showTopicDialog(this);" value="#标签">
        {% end %}

        {% if show_attachment_btn %}
            <input type="button" id="filePickerBtn" class="send-button btn btn-default" 
                onclick="xnote.action.message.upload(this);"
                value="添加附件"/>
        {% end %}
        
        <input type="button" name="" class="send-button btn create-btn" value="创建" 
            data-create-tag="{{create_tag}}"
            data-default-content="{{default_content}}"
            onclick="xnote.action.message.createMessage(this);">
    </div>

    {% if create_date %}
        <div class="row orange">
            创建日期 {{create_date}}
        </div>
    {% end %}

</div>

<!-- 选择话题组件 -->
{% include message/component/select_topic_dialog.html %}

<script type="text/javascript">
$(function () {
    function onFileUploaded(event) {
        var inputText = event.target;
        var oldText = $(".input-box").val();
        var newText = oldText + "\n" + inputText + "\n";
        $(".input-box").val(newText);
    }

    function onTopicSelected(event) {
        xnote.closeAllDialog();
        var topic = event.target;
        var oldText = $(".input-box").val();
        $(".input-box").val(topic + " " + oldText);
    }

    $('textarea[autoHeight]').autoHeight();    

    // 监听上传事件
    xnote.on("message.upload", onFileUploaded);
    xnote.on("message.topic.selected", onTopicSelected);
})
</script>