feedbackform.html 6.46 KB
Newer Older
1
<!-- Let's split this page in two -->
okhin's avatar
okhin committed
2 3
    <div class="row">
        <div class="col s6">
4 5
            <include href="argumentation.html">
        </div>
okhin's avatar
okhin committed
6 7 8
        <div class="col s6">
            <div class="card">
                <div class="card-image">
okhin's avatar
okhin committed
9
                    <img src="<check if="{{ @contact.photo == '' }}">/static/img/placeholder.jpg<false>{{ @contact.photo }}</false></check>">
okhin's avatar
okhin committed
10
                    <span class="card-title">{{ @contact.first_name }} {{ @contact.last_name }}</span>
11
                </div>
okhin's avatar
okhin committed
12
                <div class="card-content">
okhin's avatar
okhin committed
13 14 15 16 17 18 19 20 21 22 23 24 25
                    <p>{{ _("Phone number") }}: <a href="tel:{{ @contact.phone }}">{{ @contact.phone }}</a></p>
                    <repeat group="{{ @group_types }}" value="{{ @group_type }}">
                    <ul class="groups">{{ @group_type.name }}
                        <repeat group="{{ @contact.groups }}" value="{{ @group }}">
                        <check if="{{ @group.type == @group_type }}">
                        <li class="chip">
                            <check if="{{ @group.media }} != ''">
                            <img src="{{ @group.media }}" alt="{{ @group.type }}">
                            </check>
                            {{ @group.name }}
                        </li>
                        </repeat>
                    </ul>
okhin's avatar
okhin committed
26
                    </repeat>
okhin's avatar
okhin committed
27 28
                    <h5 id="step_init" class="light text-lighten-2">{{ _("0. Initialising the call") }}</h5>
                    <h5 id="step_caller" class="light text-lighten-2">{{ _("1. Calling you") }}</h5>
okhin's avatar
okhin committed
29
                    <h5 id="step_wait" class="light text-lighten-2">{{ _("2. When ready, please dial 1 on your phone") }}</h3>
okhin's avatar
okhin committed
30 31
                    <h5 id="step_callee" class="light text-lighten-2">{{ _("3. Calling ")}}{{ @contact.full_name }}</h5>
                    <h5 id="step_connected" class="light text-lighten-2">{{ _("4. Connected to ") }}{{ @contact.full_name }}</h5>
okhin's avatar
okhin committed
32
                </div>
okhin's avatar
okhin committed
33
                <div class="card-action">
okhin's avatar
okhin committed
34 35 36 37 38
                    <h4>{{ _("Feedback Form") }}</h4>
                    <p class="small">{{ _("Please tell us what happened if you were able to talk to someone. Your feedback is important to us.") }}</p>
                    <form class="form" method="post" action="/feedback/" >
                        <input type="hidden" id="contact_id" name="contact_id" value="{{ @contact_id }}" />
                        <repeat group="{{ @feedback_categories }}" value="{{ @feedback_category }}">
okhin's avatar
okhin committed
39 40 41 42
                        <span>
                            <input required type="radio" name="feedback_category" value="{{ @feedback_category.id }}" id="f{{ @feedback_category.id }}" />
                            <label for="f{{ @feedback_category.id }}">{{ @feedback_category.name }}</label>
                        </span>
okhin's avatar
okhin committed
43
                        </repeat>
okhin's avatar
okhin committed
44 45 46
                        <div class="input-field">
                            <textarea class="materialize-textarea" id="feedback" name="feedback"></textarea>
                        </div>
okhin's avatar
okhin committed
47 48
                        <input type="submit" class="btn btn-primary" name="go" value="{{ _("Send my feedback") }}" />
                    </form>
49 50 51 52 53
                </div>
            </div>
        </div>
    </div>
</div>
okhin's avatar
okhin committed
54 55 56 57
<!-- Let's include a script -->
<script type="text/javascript">
    var call = JSON.parse('{{ @call | raw }}');
    var call_url = call['data']['url'];
okhin's avatar
okhin committed
58
    var interval = '';
okhin's avatar
okhin committed
59 60 61 62 63 64 65 66 67
    function normalize_phone(phone) {
        if (phone.startsWith('+')) {
            return phone.replace('+', '00');
        }
        return phone;
    }

    function update_call(response) {
        var call_history = response['data']['history'];
okhin's avatar
okhin committed
68
        console.log(call_history);
okhin's avatar
okhin committed
69 70 71
        var call_state = call_history.sort(function(a, b) {
            var date1 = new Date(a[1]);
            var date2 = new Date(b[1]);
okhin's avatar
okhin committed
72
            return date2 - date1;
okhin's avatar
okhin committed
73
        })[0];
okhin's avatar
okhin committed
74 75 76 77
        $('.step_text').removeClass('bold');
        $('.step_text').removeClass('text-darken-4');
        $('.step-text').addClass('light');
        $('.step-text').addClass('text-lighten-2');
okhin's avatar
okhin committed
78
        if (call_state[0].startsWith('Created:Init')) {
okhin's avatar
okhin committed
79 80 81 82
            $('#step_init').addClass('bold');
            $('#step_init').addClass('text-darken-4');
            $('#step_init').removeClass('light');
            $('#step_init').removeClass('text-lighten-2');
okhin's avatar
okhin committed
83
        };
okhin's avatar
okhin committed
84 85 86 87 88 89

        if (call_state[0].startsWith('Ringing:')) {
            phone = normalize_phone(call_state[0].split(':')[1]);
            caller = normalize_phone(response['data']['caller']);
            callee = normalize_phone(response['data']['callee']);
            if ( phone === caller) {
okhin's avatar
okhin committed
90 91 92 93
                $('#step_caller').addClass('bold');
                $('#step_caller').addClass('text-darken-4');
                $('#step_caller').removeClass('light');
                $('#step_caller').removeClass('text-lighten-2');
okhin's avatar
okhin committed
94
            } else {
okhin's avatar
okhin committed
95 96 97 98
                $('#step_callee').addClass('bold');
                $('#step_callee').addClass('text-darken-4');
                $('#step_callee').removeClass('light');
                $('#step_callee').removeClass('text-lighten-2');
okhin's avatar
okhin committed
99 100 101 102 103 104 105 106 107
            };
        };

        if (call_state[0].startsWith('Up:')) {
            // Need to check if we're caller or callee
            phone = normalize_phone(call_state[0].split(':')[1]);
            caller = normalize_phone(response['data']['caller']);
            callee = normalize_phone(response['data']['callee']);
            if ( phone === caller) {
okhin's avatar
okhin committed
108 109 110 111
                $('#step_wait').addClass('bold');
                $('#step_wait').addClass('text-darken-4');
                $('#step_wait').removeClass('light');
                $('#step_wait').removeClass('text-lighten-2');
okhin's avatar
okhin committed
112
            } else {
okhin's avatar
okhin committed
113 114 115 116
                $('#step_connected').addClass('bold');
                $('#step_connected').addClass('text-darken-4');
                $('#step_connected').removeClass('light');
                $('#step_connected').removeClass('text-lighten-2');
okhin's avatar
okhin committed
117 118
            };
        };
okhin's avatar
okhin committed
119 120 121

        if (call_state[0].startsWith('Down:')) {
            // The call as ended
okhin's avatar
okhin committed
122
            clearInterval(interval);
okhin's avatar
okhin committed
123
        };
okhin's avatar
okhin committed
124
        console.log(call_state[0]);
okhin's avatar
okhin committed
125 126 127 128 129 130
    };
    function fetch() {
        $.ajax({
            method: 'GET',
            url: call_url,
            dataType: 'json',
okhin's avatar
okhin committed
131 132 133
            complete: function(xhr, status) {
                update_call(xhr.responseJSON);
            }
okhin's avatar
okhin committed
134 135 136 137
        });
    };
    $(document).ready(function() {
        update_call(call);
okhin's avatar
okhin committed
138
        interval = window.setInterval(fetch, 3000);
okhin's avatar
okhin committed
139 140
    });
</script>