Statistics
| Branch: | Tag: | Revision:

root / templates / name_change.html @ 064ecc91

History | View | Annotate | Download (2.5 kB)

1
<div id="user_namechange_placeholder">
2
<script>
3
        $(document).ajaxSend(function(event, xhr, settings) {
4
    function getCookie(name) {
5
        var cookieValue = null;
6
        if (document.cookie && document.cookie != '') {
7
            var cookies = document.cookie.split(';');
8
            for (var i = 0; i < cookies.length; i++) {
9
                var cookie = jQuery.trim(cookies[i]);
10
                // Does this cookie string begin with the name we want?
11
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
12
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
13
                    break;
14
                }
15
            }
16
        }
17
        return cookieValue;
18
    }
19
    function sameOrigin(url) {
20
        // url could be relative or scheme relative or absolute
21
        var host = document.location.host; // host + port
22
        var protocol = document.location.protocol;
23
        var sr_origin = '//' + host;
24
        var origin = protocol + sr_origin;
25
        // Allow absolute or scheme relative URLs to same origin
26
        return (url == origin || url.slice(0, origin.length + 1) == origin + '/') ||
27
            (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') ||
28
            // or any other URL that isn't scheme relative or absolute i.e relative.
29
            !(/^(\/\/|http:|https:).*/.test(url));
30
    }
31
    function safeMethod(method) {
32
        return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
33
    }
34

35
    if (!safeMethod(settings.type) && sameOrigin(settings.url)) {
36
        xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
37
    }
38
});
39

40
        $(function() {
41
        $('#change_name_btn').button();
42
        $('#change_name_btn').click(function() {
43
                        str = $('#change_name_form').serialize();
44
            $.ajax({
45
                type: "POST",
46
                url: "{% url name-change %}",
47
                data: str,
48
                success: function(response){
49
                        $("#user_namechange_placeholder").html(response);
50
                }
51
        });
52
    return false;
53
        });
54
        });
55
        </script>
56
        {% load i18n %}
57
<div><strong>{{user}}</strong>, {% trans "enter your first and last name" %}.</div> 
58
<div>{% trans "Your name" %}{% if changed %} {% trans "was successfully changed" %}{% endif %}: <strong>{% ifequal name|length 0 %}{% trans "we don't know your name yet" %}{% else %}{{name}}{% endifequal %}</strong></div>
59
<form method="POST" id="change_name_form">
60
{% csrf_token %}
61
        <table>
62
            {{ form.as_table }}
63
        </table>
64
<button id="change_name_btn">{% trans "Change" %}</button>
65
</form>
66

    
67
</div>