{% extends "two_column_body.html" %}
{% import "macros.html" as macros %}
<!-- template ask.html -->
{% block title %}{% spaceless %}{% trans %}Ask Your Question{% endtrans %}{% endspaceless %}{% endblock %}
{% block forestyle %}
    <link rel="stylesheet" type="text/css" href="{{"/js/wmd/wmd.css"|media}}" />
{% endblock %}
{# main contents of ask form is in the template input_bar #}
{% block sidebar %}
    {% if settings.EDITOR_TYPE == 'markdown' %}
        {% include "/widgets/markdown_help.html" %}
    {% endif %}
{% endblock %}
{% block content %}
    <div class="question-instructions">
        {% if settings.QUESTION_INSTRUCTIONS %}
            {{ settings.QUESTION_INSTRUCTIONS|safe }}
        {% else %}
            <ul>
                {% if not request.user.is_authenticated() %}
                <li class="warning">{% trans %}since you are not logged in right now, you will be asked to sign in or register after posting your question{% endtrans %}</li>
                {% else %}
                    {% if settings.EMAIL_VALIDATION %}
                        {% if not request.user.email_isvalid %}
                        <li class="warning">{% trans email=request.user.email %}YYour email, %(email)s has not yet been validated. To post messages you must verify your email, please see <a href='%(email_validation_faq_url)s'>more details here</a>. You can submit your question now and validate email after that. Meanwhile, your question will saved as pending.{% endtrans %}</li>
                        {% endif %}
                    {% endif %}
                {% endif %}
                <li>{% trans %}please, try to make your question interesting to this community{% endtrans %}</li>
                <li>{% trans %}provide enough details{% endtrans %}</li>
                <li>{% trans %}be clear and concise{% endtrans %}</li>
            </ul>
        {% endif %}
        <p class='info-box-follow-up-links'>
    <!-- will be change to a popup windows
            <a href="{% url faq %}" target="_blank" title="{% trans %}see frequently asked questions{% endtrans %}">{% trans %}FAQ{% endtrans %} »</a>
    -->
        </p>
    </div>
    {% include "widgets/ask_form.html" %}
{% endblock %}
{% block endjs %}
    <script type='text/javascript' src='{{"/js/editor.js"|media}}'></script>
    <script type='text/javascript' src='{{"/js/jquery.validate.js"|media}}'></script>
    <script type='text/javascript' src='{{"/js/post.js"|media}}'></script>
    {% if settings.EDITOR_TYPE == 'markdown' %}
        <script type='text/javascript' src='{{"/js/wmd/showdown.js"|media}}'></script>
        <script type='text/javascript' src='{{"/js/wmd/wmd.js"|media}}'></script>
    {% endif %}
    {% include "meta/editor_data.html" %}
    {% if mandatory_tags %}
        {% include "meta/mandatory_tags_js.html" %}
    {% endif %}
    {% if settings.TAG_SOURCE == 'category-tree' %}
        {% include "meta/category_tree_js.html" %}
    {% endif %}
    <script type='text/javascript'>
        askbot['urls']['saveDraftQuestion'] = '{% url save_draft_question %}';
        {% if settings.ENABLE_MATHJAX or settings.MARKUP_CODE_FRIENDLY %}
            var codeFriendlyMarkdown = true;
        {% else %}
            var codeFriendlyMarkdown = false;
        {% endif %}
        $().ready(function(){
            //set current module button style
            $('#editor').TextAreaResizer();
            //highlight code synctax when editor has new text
            $("#editor").typeWatch({highlight: false, wait: 3000,
                             captureLength: 5, callback: lanai.highlightSyntax});

            //toggle preview of editor
            //todo remove copy-paste
            var display = true;
            var txt = "[{% trans %}hide preview{% endtrans %}]";
            $('#pre-collapse').text(txt);
            $('#pre-collapse').bind('click', function(){
                txt = display ? "[{% trans %}show preview{% endtrans %}]" : "[{% trans %}hide preview{% endtrans %}]";
                display = !display;
                $('#previewer').toggle();
                $('#pre-collapse').text(txt);
            });
            //Tags autocomplete

            {{ macros.tag_autocomplete_js(id = '#id_tags') }}

            setupFormValidation($("#fmask"), CPValidator.getQuestionFormRules(), CPValidator.getQuestionFormMessages());
            lanai.highlightSyntax();

            if (askbot['data']['userIsAuthenticated']) {
                var draftHandler = new DraftQuestion();
                draftHandler.decorate($(document));
                window.onbeforeunload = function() {
                    var saveHandler = draftHandler.getSaveHandler();
                    saveHandler(true);
                    //var msg = gettext("%s, we've saved your draft, but...");
                    //return interpolate(msg, [askbot['data']['userName']]);
                };
            }
        });
    </script>
{% endblock %}

<!-- end template ask.html -->
