{# freepost
 # http://freepo.st
 # 
 # Copyright © 2014-2015 zPlus
 # 
 # This file is part of freepost.
 # freepost is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as
 # published by the Free Software Foundation, either version 3 of the
 # License, or (at your option) any later version.
 # 
 # freepost is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 # GNU Affero General Public License for more details.
 # 
 # You should have received a copy of the GNU Affero General Public License
 # along with freepost. If not, see <http://www.gnu.org/licenses/>.
 #}

{% extends 'AppBundle:Default:User/template.html.twig' %}

{% block title %}
    Preferences: {{ user.username }}
{% endblock %}

{% block javascript %}
    {{ parent() }}
    
    {% javascripts
        '@AppBundle/Resources/public/js/User/preferences.js'
    %}
        <script src="{{ asset_url }}"></script>
    {% endjavascripts %}
{% endblock %}

{% block content %}
    
    <div class="preferences">
        
        {# Change display name #}
        
        <div class="section">
            <div class="title">
                Display name
            </div>
            <div class="options">
                <input type="text" id="displayName" name="displayName" value="{{ user.username }}" />
            </div>
        </div>
        
        {# Change email #}
        
        <div class="section">
            <div class="title">
                Email
            </div>
            <div class="options">
                <p>
                    Your email is required if you wish to change your password
                </p>
                
                <input type="text" id="email" name="email" value="{{ user.email }}" />
                
                <p style="display: none">
                    Check your email inbox to confirm your address
                </p>
                
                {# Delete email #}
                <input type="button" class="buttonAction" name="validateEmail" id="validateEmail" value="Validate email" />
                
                {# Delete email #}
                <input type="button" class="buttonActionBackground" name="deleteEmail" id="deleteEmail" value="Delete email" />
            </div>
        </div>
        
        {# Change picture #}
        
        <div class="section">
            <div class="title">
                Picture
            </div>
            <div class="options">
                <form action  = "{{ path('freepost_user_update_picture') }}"
                      enctype = "multipart/form-data"
                      id      = "pictureForm"
                      method  = "post"
                      target  = "iframenull">
                    <input type="file" id="pictureFile" name="pictureFile" />
                    
                    {# "Delete picture" button #}
                    <input type="button" class="buttonActionBackground" name="deletePictureFile" id="deletePictureFile" value="Remove picture" />
                </form>
                
                {% image '@AppBundle/Resources/public/images/loading-bar.gif' %}
                    <img id="pictureFileLoading" src="{{ asset_url }}" alt="" />
                {% endimage %}
            </div>
        </div>
        
        {# Change how posts are displayed (compact or full posts) #}
        
        <div class="section">
            <div class="title">
                Show posts
            </div>
            <div class="options">
                <select id="feedFormatSelector">
                    <option value="default" {{ user.feedFormat == 'DEFAULT' ? 'selected' }}>Default (title + post)</option>
                    <option value="compact" {{ user.feedFormat == 'COMPACT' ? 'selected' }}>Compact</option>
                </select>
            </div>
        </div>
        
        {# Close account #}
        
        <div class="section">
            <div class="title">
                Account
            </div>
            <div class="options">
                <span id="closeAccount" class="closeAccount buttonActionBackground">
                    Close account
                </span>
                
                <form action="{{ url('freepost_user_close_account') }}"
                      id="closeAccountConfirm"
                      method="post"
                      target="_self"
                      enctype="application/x-www-form-urlencoded">
                
                    If you close your account, you will no longer be able to sign in again using this username.
                    <br /><br />
                    Are you sure?
                    <br /><br />
                    
                    <input type="button" id="closeAccountReject" class="buttonAction" value="No, keep my account open" />
                    <input type="submit" class="buttonActionBackground" value="Yes, close my account" />
                </form>
            </div>
        </div>
        
    </div>
    
    {# This iframe is used to redirect <form/> ajax request #}
    <iframe id="iframenull" name="iframenull" class="hidden"></iframe>
    
{% endblock %}




