user_edit.jinja 3.61 KB
Newer Older
1
{% extends "core/base.jinja" %}
Skia's avatar
Skia committed
2

Skia's avatar
Skia committed
3
4
5
6
{% block title %}
{% trans %}Edit user{% endtrans %}
{% endblock %}

7
{% block content %}
Skia's avatar
Skia committed
8
<h2>{% trans %}Edit user profile{% endtrans %}</h2>
9
<form action="" method="post" enctype="multipart/form-data" id="user_edit">
Skia's avatar
Skia committed
10
    {% csrf_token %}
11
12
    {% for field in form %}
    <p>{{ field.errors }}<label for="{{ field.name }}">{{ field.label }}
13
    {%- if field.name == "profile_pict" -%}
14
    <br>{% trans %}Current profile: {% endtrans %}
15
    {% if form.instance.profile_pict %}
16
    <img src="{{ form.instance.profile_pict.get_download_url() }}" title="{% trans %}Profile{% endtrans %}" /><br>
17
18
19
20
21
22
23
24
25
26
27
    {% if user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) %}
    <a href="{{ url('core:file_delete', file_id=form.instance.profile_pict.id, popup="") }}">{% trans %}Delete{% endtrans %}</a>
    {% endif %}
    {% else %}
    <img src="{{ static('core/img/unknown.jpg') }}" title="-" crossOrigin="Anonymous" id="new_profile"/><br>
    <div id="take_picture">
        <div id="camera_canvas" style="width:320; height:240; margin: 0px auto;"></div>
        <a href="javascript:void(take_snapshot())">{% trans %}Take picture{% endtrans %}</a>
    </div>
    <p>
    {% endif %}<br>
28
29
    {%- elif field.name == "avatar_pict" and form.instance.avatar_pict -%}
    <br>{% trans %}Current avatar: {% endtrans %}
30
    <img src="{{ form.instance.avatar_pict.get_download_url() }}" title="{% trans %}Avatar{% endtrans %}" /><br>
31
32
    {%- elif field.name == "scrub_pict" and form.instance.scrub_pict -%}
    <br>{% trans %}Current scrub: {% endtrans %}
33
    <img src="{{ form.instance.scrub_pict.get_download_url() }}" title="{% trans %}Scrub{% endtrans %}" /><br>
34
35
    {%- endif %}</label> {{ field }}</p>
    {% endfor %}
Skia's avatar
Skia committed
36
    <p><input type="submit" value="{% trans %}Update{% endtrans %}" /></p>
37
38
39
40
41
42
    <p>{% trans %}Username: {% endtrans %}{{ form.instance.username }}</p>
    {% if form.instance.customer %}
    <p>{% trans %}Account number: {% endtrans %}{{ form.instance.customer.account_id }}</p>
    {% endif %}
    {% if form.instance == user %}
    <p><a href="{{ url('core:password_change') }}">{% trans %}Change my password{% endtrans %}</a></p>
Skia's avatar
Skia committed
43
    {% elif user.is_root %}
Skia's avatar
Skia committed
44
    <p><a href="{{ url('core:password_root_change', user_id=form.instance.id) }}">{% trans %}Change user password{% endtrans %}</a></p>
45
    {% endif %}
Skia's avatar
Skia committed
46
</form>
Skia's avatar
Skia committed
47
48
{% endblock %}

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{% block script %}
    {{ super() }}
    {% if not form.instance.profile_pict %}
    <script src="{{ static('core/js/webcam.js') }}"></script>
    <script language="JavaScript">
        Webcam.set({
                width: 320,
                height: 240,
                dest_width: 320,
                dest_height: 240,
                image_format: 'jpeg',
                jpeg_quality: 90,
                force_flash: false
            });
        Webcam.attach( '#camera_canvas' );

        function take_snapshot() {
            var data_uri = Webcam.snap();
            var url = "{{ url('core:user_profile_upload', user_id=form.instance.id) }}";
            Webcam.upload( data_uri, url, function(code, text) {
Skia's avatar
Skia committed
69
                            if (code == 302 || code == 200) {
70
71
72
73
74
75
76
77
78
79
80
81
                                $('#new_profile').attr('src', data_uri);
                                $('#take_picture').remove();
                                $('#id_profile_pict').remove();
                            } else {
                                console.log("Unknown error: ");
                                console.log(text);
                            }
                        }, "new_profile_pict", {name: 'csrfmiddlewaretoken', value: '{{ csrf_token }}'});
        }
    </script>
    {% endif %}
{% endblock %}
Skia's avatar
Skia committed
82
83
84