{#
    This template contains macros used to format the usersettings view. As shown below, the usersettings have
    several HTML forms. Most themes will display the form names as a series of tabs. Javascript will display the
    current selection and hide the other parts.

    Updates to the forms will be processed as XHR requests.
#}

{% import "forms.html" as forms with context %}

{% macro personal(form) %}
    {{ gen.form.open(form, id="usersettings_personal", method="post", action=url_for('frontend.usersettings')) }}
        {{ forms.render_errors(form) -}}
        <dl>
            {{ forms.render(form['name']) }}
            {{ forms.render(form['display_name']) }}
            {{ forms.render(form['timezone']) }}
            {{ forms.render(form['locale']) }}
        </dl>
        {{ forms.render_submit(form, 'part', 'personal') }}
    {{ gen.form.close() }}
{% endmacro %}

{% macro password(form) %}
    {{ gen.form.open(form, method="post", action=url_for('frontend.usersettings')) }}
        {{ forms.render_errors(form) -}}
        <dl>
            {{ forms.render(form['password_current']) }}
            {{ forms.render(form['password1']) }}
            {{ forms.render(form['password2']) }}
        </dl>
        {{ forms.render_submit(form, 'part', 'password') }}
    {{ gen.form.close() }}
{% endmacro %}

{% macro notification(form) %}
    {{ gen.form.open(form, method="post", action=url_for('frontend.usersettings')) }}
        {% if cfg.user_email_verification %}
            <p>{{ _("Changing your email address requires you to verify it. A link will be sent to you.") }}</p>
        {% endif %}
        {{ forms.render_errors(form) -}}
        <dl>
            {{ forms.render(form['email']) }}
        </dl>
        {{ forms.render_submit(form, 'part', 'notification') }}
    {{ gen.form.close() }}
{% endmacro %}

{% macro ui(form) %}
    {{ gen.form.open(form, id="usersettings_ui", method="post", action=url_for('frontend.usersettings')) }}
        {{ forms.render_errors(form) -}}
        <dl>
            {{ forms.render(form['theme_name']) }}
            {{ forms.render(form['css_url']) }}
            {{ forms.render(form['edit_rows']) }}
            {{ forms.render(form['results_per_page']) }}
        </dl>
        {{ forms.render_submit(form, 'part', 'ui') }}
    {{ gen.form.close() }}
{% endmacro %}

{% macro quicklinks(form) %}
    {{ gen.form.open(form, method="post", action=url_for('frontend.usersettings')) }}
        {{ forms.render_errors(form) -}}
        <dl>
            {{ forms.render(form['quicklinks']) }}
        </dl>
        <div class="tip">
            {{ _('Use the "Add Link" or "Remove Link" controls within Item Views to add or remove quick links.') }}
            <ul>
                <li>{{ _('To manually add a link to a local wiki item, prefix the item name with the wiki name: MyWiki/myitem') }}</li>
                <li>{{ _('To add a link to an external wiki page, use the wiki name as a prefix: MeatBall/RecentChanges') }}</li>
                <li>{{ _('To add a link to an external web page, use the full URL: http://google.com') }}</li>
                <li>{{ _('Other types of links, such as mailto: may be added') }}</li>
            </ul>
        </div>
        {{ forms.render_submit(form, 'part', 'quicklinks') }}
    {{ gen.form.close() }}
{% endmacro %}

{% macro options(form) %}
    {{ gen.form.open(form, method="post", action=url_for('frontend.usersettings')) }}
        {{ forms.render_errors(form) -}}
        <dl>
            {{ forms.render(form['iso_8601']) }}
            {{ forms.render(form['mailto_author']) }}
            {{ forms.render(form['edit_on_doubleclick']) }}
            {{ forms.render(form['scroll_page_after_edit']) }}
            {{ forms.render(form['show_comments']) }}
            {{ forms.render(form['disabled']) }}
        </dl>
        {{ forms.render_submit(form, 'part', 'options') }}
    {{ gen.form.close() }}
{% endmacro %}

{% macro subscriptions(form) %}
    {%- set myitemname =  _('MyItemName')  %}
    {%- set mytagname =  _('MyTagName')  %}
    {%- set mynamespace =  _('MyNameSpace')  %}
    {%- set my =  _('My')  %}
    {%- set itemid =  _('item id')  %}
    {{ gen.form.open(form, method="post", action=url_for('frontend.usersettings')) }}
        {{ forms.render_errors(form) -}}
        <dl>
            {{ forms.render(form['subscriptions']) }}
        </dl>
        <div class="tip">
            {{ _('Formats for entering subscriptions:') }}
            <ul>
                <li>name::{{ myitemname }} or name:{{ mynamespace }}:{{ myitemname }}</li>
                <li>nameprefix::{{ my }}</li>
                <li>tags::{{ mytagname }}</li>
                <li>namere::.*</li>
                <li>itemid:&lt;{{ itemid }}&gt; {{ _('is created/removed by clicking a Subscribe/Unsubscribe link') }}</li>
            </ul>
        </div>
        {{ forms.render_submit(form, 'part', 'subscriptions') }}
    {{ gen.form.close() }}
{% endmacro %}

{# javascript functions within common.js are dependent upon the structure, classes and ids defined here #}
{% macro all_usersettings_forms(form_objs) %}
    <div id="moin-usersettings">
        <div id="ui" class="moin-tab-body moin-form">
            <h2 class="moin-settings-head"><a href="#ui">{{ _("Appearance") }}</a></h2>
            {{ ui(form_objs.ui) }}
        </div>
        <div id="password" class="moin-tab-body moin-form">
            <h2 class="moin-settings-head"><a href="#password">{{ _("Change Password") }}</a></h2>
            {{ password(form_objs.password) }}
        </div>
        <div id="quicklinks" class="moin-tab-body moin-form">
            <h2 class="moin-settings-head"><a href="#quicklinks">{{ _("Quick Links") }}</a></h2>
            {{ quicklinks(form_objs.quicklinks) }}
        </div>
        <div id="notification" class="moin-tab-body moin-form">
            <h2 class="moin-settings-head"><a href="#notification">{{ _("Notifications") }}</a></h2>
            {{ notification(form_objs.notification) }}
        </div>
        <div id="options" class="moin-tab-body moin-form">
            <h2 class="moin-settings-head"><a href="#options">{{ _("Options") }}</a></h2>
            {{ options(form_objs.options) }}
        </div>
        <div id="personal" class="moin-tab-body moin-form">
            <h2 class="moin-settings-head"><a href="#personal">{{ _("Personal") }}</a></h2>
            {{ personal(form_objs.personal) }}
        </div>
        <div id="subscriptions" class="moin-tab-body moin-form">
            <h2 class="moin-settings-head"><a href="#subscriptions">{{ _("Subscriptions") }}</a></h2>
            {{ subscriptions(form_objs.subscriptions) }}
        </div>
    </div>
{% endmacro %}
