feedbackform.html 6.69 KB
Newer Older
1
<!-- Let's split this page in two -->
okhin's avatar
okhin committed
2
3
4
5
6
7
8
    <div class="row green accent-4">
        <div class="col s12">
            <h4 id="step_init" class="step_text bold center white-text">{{ _("0. Initialising the call") }}</h5>
            <h4 id="step_caller" class="step_text bold center white-text">{{ _("1. Calling you") }}</h5>
            <h4 id="step_wait" class="step_text bold center white-text">{{ _("2. When ready, please dial 1 on your phone") }}</h3>
            <h4 id="step_callee" class="step_text bold center white-text">{{ _("3. Calling ")}}{{ @contact.full_name }}</h5>
            <h4 id="step_connected" class="step_text bold center white-text">{{ _("4. Connected to ") }}{{ @contact.full_name }}</h5>
9
        </div>
okhin's avatar
okhin committed
10
    </div>
11
    <div class="row">
Okhin's avatar
Okhin committed
12
13
14
15
        <div class="container">
            <div class="col s12">
                <p class="bold center">When you hear the MarioBros theme on the phone, you should press 1 to initiate the call to the representative.</p>
            </div>
16
17
        </div>
    </div>
okhin's avatar
okhin committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
    <div class="row">
        <div class="container">
            <div class="col m6 s12">
                <include href="argumentation.html">
            </div>
            <div class="col m6 s12">
                <div class="card horizontal sticky-action">
                    <div class="card-image">
                        <img src="<check if="{{ @contact.photo == '' }}">/static/img/placeholder.jpg<false>{{ @contact.photo }}</false></check>">
                        <p>{{ _("Phone number") }}: <a href="tel:{{ @contact.phone }}">{{ @contact.phone }}</a></p>
                    </div>
                    <div class="card-content">
                        <span class="card-title grey-text text-darken-4">{{ @contact.first_name }} {{ @contact.last_name }}</span>
                        <div class="groups">
                            <repeat group="{{ @contact.groups }}" value="{{ @group }}">
                            <check if="{{ @group.type == 'country' }}">
                            <span class="chip">
                                <img src="{{ 'http://www.europarl.europa.eu/ep_framework/img/flag/flag_icon_' . str_replace('/', '', strtolower(@group.name)) . '.gif'}}">
                                {{ @group.name }}
                            </span>
okhin's avatar
okhin committed
38
                            </check>
okhin's avatar
okhin committed
39
40
41
42
43
44
45
46
47
                            </repeat>
                            <repeat group="{{ @contact.groups }}" value="{{ @group }}">
                            <check if="{{ @group.type == 'group' }}">
                            <span class="chip">
                                <img src="{{ 'http://www.europarl.europa.eu/ep_framework/img/group/group_iconsmall_' . str_replace('/', '', strtolower(@group.name)) . '.png'}}">
                                {{ @group.name }}
                            </span>
                            </check>
                            </repeat>
okhin's avatar
okhin committed
48
                        </div>
okhin's avatar
okhin committed
49
50
51
52
53
54
55
56
57
58
                        <div class="groups">
                            <repeat group="{{ @contact.groups }}" value="{{ @group }}">
                            <check if="{{ @group.type == 'committee'}}">
                            <span class="chip blue white-text committee">
                                {{ @group.name }}
                            </span>
                            </check>
                            </repeat>
                        </div>
                    </div>
59
                </div>
okhin's avatar
okhin committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
                <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 }}" />
                    <select name="feedback_category" id="feedback_category" class="input-field">
                    <repeat group="{{ @feedback_categories }}" value="{{ @feedback_category }}">
                        <option value="{{ @feedback_category.id }}">{{ @feedback_category.name }}</option>
                    </repeat>
                    </select>
                    <div class="input-field">
                        <textarea class="materialize-textarea" id="feedback" name="feedback"></textarea>
                    </div>
                    <input type="submit" class="btn btn-primary" name="go" value="{{ _("Send my feedback") }}" />
                </form>
74
75
76
77
            </div>
        </div>
    </div>
</div>
okhin's avatar
okhin committed
78
79
80
81
<!-- 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
82
    var interval = '';
okhin's avatar
okhin committed
83
84
85
86
87
88
89
90
91
    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
92
        console.log(call_history);
okhin's avatar
okhin committed
93
94
95
        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
96
            return date2 - date1;
okhin's avatar
okhin committed
97
        })[0];
okhin's avatar
okhin committed
98
        $('.step_text').hide();
okhin's avatar
okhin committed
99
        if (call_state[0].startsWith('Created:Init')) {
okhin's avatar
okhin committed
100
            $('#step_init').show();
okhin's avatar
okhin committed
101
        };
okhin's avatar
okhin committed
102
103
104
105
106
107

        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
108
                $('#step_caller').show();
okhin's avatar
okhin committed
109
            } else {
okhin's avatar
okhin committed
110
                $('#step_callee').show();
okhin's avatar
okhin committed
111
112
113
114
115
116
117
118
119
            };
        };

        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
120
                $('#step_wait').show();
okhin's avatar
okhin committed
121
            } else {
Okhin's avatar
Okhin committed
122
                $('#step_callee').show();
okhin's avatar
okhin committed
123
124
            };
        };
okhin's avatar
okhin committed
125
126
127

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