feedbackform.html 7.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
<!-- Let's split this page in two -->
<div class="container">
    <div class="row">
        <div class="col-md-6">
            <include href="argumentation.html">
        </div>
        <div class="col-md-6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4>{{ _("Currently calling") }}</h4>
                </div>
                <div class="panel-body">
                        <p class="text-center">{{ @contact.first_name }} {{ @contact.last_name }}</p>
                        <p class="lead text-center">
                            <abbr title="{{ _("Phone number") }}">{{ _("Phone number") }}:</abbr> <a href="tel: {{ @contact.phone }}">{{ @contact.phone }}</a>
                        </p>
                        <dl class="dl-horizontal hidden-xs">
                        <repeat group="{{ @contact.groups }}" value="{{ @group }}">
                        <check if="{{ @group.type!='committee' }}">
                            <dt>{{ @group.type }}:</dt>
                            <dd><a href="#">{{ @group.name }}</a></dd>
                        </check>
                        </repeat>
                        </dl>
                        <ul class="list-inline">
                        <repeat group="{{ @contact.groups }}" value="{{ @group }}">
                        <check if="{{ @group.type=='committee' }}">
                                <li><abbr title="{{ @group.name }}" class="initialism"><ahref="https://memopol.lqdn.fr/europe/parliament/committee/{{ @group.name }}/"><div class="well well-sm">{{ @group.name }}</div></a></abbr></li>
                        </check>
                        </repeat>
                        </ul>
okhin's avatar
okhin committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
                        <p id="step_init" class="step_text text-center">{{ _("Initialising the call") }}</p>
                        <p id="step_caller" class="step_text text-center">{{ _("Calling you") }}</p>
                        <p id="step_wait" class="step_text text-center">{{ _("When ready, please dial 1 on your phone") }}</p>
                        <p id="step_callee" class="step_text text-center">{{ _(" Calling ")}}{{ @contact.full_name }}</p>
                        <p id="step_connected" class="step_text text-center">{{ _("Connected to ") }}{{ @contact.full_name }}</p>
                        <h3 aria-hidden="true" class="step_bar lead text-center">
                            <span id="caller" class="step glyphicon glyphicon-earphone"></span>
                            <span id="step1" class="step">&#x25CF;</span>
                            <span id="step2" class="step">&#x25CF;</span>
                            <span id="step3" class="step">&#x25CF;</span>
                            <span id="wait" class="step glyphicon glyphicon-time"></span>
                            <span id="step4" class="step">&#x25CF;</span>
                            <span id="step5" class="step">&#x25CF;</span>
                            <span id="step6" class="step">&#x25CF;</span>
                            <span id="callee" class="step glyphicon glyphicon-earphone"></span>
                        </h3>
                </div>
            </div>
            <div class="feedback panel panel-default">
                <!-- Form in order to feedback your call -->
                <div class="panel-heading">
                    <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>
                </div>
                <div class="panel-body">
                    <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 }}">
                        <div class="form-group">
                            <label><input required class="form-control" type="radio" name="feedback_category" value="{{ @feedback_category.id }}"/>{{ @feedback_category.name }}</label>
                        </div>
                        </repeat>
                        <textarea class="form-control" id="feedback" name="feedback"></textarea>
                        <input type="submit" class="btn btn-primary" name="go" value="{{ _("Send my feedback") }}" />
                    </form>
67 68 69 70 71
                </div>
            </div>
        </div>
    </div>
</div>
okhin's avatar
okhin committed
72 73 74 75
<!-- 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
76
    var interval = None;
okhin's avatar
okhin committed
77 78 79 80 81 82 83 84 85
    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
86
        console.log(call_history);
okhin's avatar
okhin committed
87 88 89
        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
90
            return date2 - date1;
okhin's avatar
okhin committed
91 92 93 94 95
        })[0];
        $('.step_text').removeClass('visible');
        if (call_state[0].startsWith('Created:Init')) {
            $('#step_init').addClass('visible');
        };
okhin's avatar
okhin committed
96 97 98 99 100 101 102 103 104 105 106 107 108

        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) {
                $('#caller').addClass('outline_green');
                $('#step_caller').addClass('visible');
            } else {
                $('#step1').addClass('green');
                $('#step2').addClass('green');
                $('#step3').addClass('green');
                $('#wait').addClass('green');
okhin's avatar
okhin committed
109 110 111
                $('#callee').addClass('outline_green');
                $('#step4').addClass('outline_green');
                $('#step5').addClass('outline_green');
okhin's avatar
okhin committed
112
                $('#step6').addClass('outline_green');
okhin's avatar
okhin committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
                $('#step_callee').addClass('visible');
            };
        };

        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) {
                $('#caller').addClass('green');
                $('#step1').addClass('outline_green');
                $('#step2').addClass('outline_green');
                $('#step3').addClass('outline_green');
                $('#wait').addClass('outline_green');
                $('#step_wait').addClass('visible');
            } else {
okhin's avatar
okhin committed
130 131 132 133
                $('#callee').addClass('green');
                $('#step4').addClass('green');
                $('#step5').addClass('green');
                $('#step6').addClass('green');
okhin's avatar
okhin committed
134 135 136
                $('#step_connected').addClass('visible');
            };
        };
okhin's avatar
okhin committed
137 138 139

        if (call_state[0].startsWith('Down:')) {
            // The call as ended
okhin's avatar
okhin committed
140 141 142 143
            $('#caller').addClass('red');
            $('#step1').addClass('red');
            $('#step2').addClass('red');
            $('#step3').addClass('red');
okhin's avatar
okhin committed
144
            $('#wait').addClass('red');
okhin's avatar
okhin committed
145 146 147 148 149
            $('#step4').addClass('red');
            $('#step5').addClass('red');
            $('#step6').addClass('red');
            $('#callee').addClass('red');
            clearInterval(interval);
okhin's avatar
okhin committed
150
        };
okhin's avatar
okhin committed
151
        console.log(call_state[0]);
okhin's avatar
okhin committed
152 153 154 155 156 157
    };
    function fetch() {
        $.ajax({
            method: 'GET',
            url: call_url,
            dataType: 'json',
okhin's avatar
okhin committed
158 159 160
            complete: function(xhr, status) {
                update_call(xhr.responseJSON);
            }
okhin's avatar
okhin committed
161 162 163 164
        });
    };
    $(document).ready(function() {
        update_call(call);
okhin's avatar
okhin committed
165
        interval = window.setInterval(fetch, 3000);
okhin's avatar
okhin committed
166 167
    });
</script>