feedbackform.html 6.47 KB
Newer Older
1
<!-- Let's split this page in two -->
okhin's avatar
okhin committed
2
<main>
3 4
<div class="container">
    <div class="row">
okhin's avatar
okhin committed
5 6 7 8 9 10 11 12 13
        <div class="section indigo">
            <div class="container">
                <h1 class="header white-text center-on-small-only">{{ @campaign.title }}</h1>
                <h4 class="light indigo-text text-accent-1 center-on-small-only">{{ @campaign.description }}</h4>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col s6">
14 15
            <include href="argumentation.html">
        </div>
okhin's avatar
okhin committed
16 17 18 19 20
        <div class="col s6">
            <div class="card">
                <div class="card-image">
                    <img src="/static/img/124786.jpg">
                    <span class="card-title">{{ @contact.first_name }} {{ @contact.last_name }}</span>
21
                </div>
okhin's avatar
okhin committed
22 23 24 25 26 27
                <div class="card-content">
                    <p>{{ _("Phone number") }}:</abbr> <a href="tel: {{ @contact.phone }}">{{ @contact.phone }}</a></p>
                    <repeat group="{{ @contact.groups }}" value="{{ @group }}">
                    <div class="chip">
                        <check if="{{ @group.media }}">
                        <img src="{{ @group.media }}" alt="{{ @group.type }}">
28
                        </check>
okhin's avatar
okhin committed
29 30 31 32 33 34 35 36
                        {{ @group.name }}
                    </div>
                    </repeat>
                    <h5 id="step_init" class="light text-lighten-2">{{ _("0. Initialising the call") }}</h3>
                    <h5 id="step_caller" class="light text-lighten-2">{{ _("1. Calling you") }}</h3>
                    <h5 id="step_wait" class="light text-lighten-2">{{ _("2. When ready, please dial 1 on your phone") }}</h3>
                    <h5 id="step_callee" class="light text-lighten-2">{{ _("3. Calling ")}}{{ @contact.full_name }}</h3>
                    <h5 id="step_connected" class="light text-lighten-2">{{ _("4. Connected to ") }}{{ @contact.full_name }}</h3>
okhin's avatar
okhin committed
37
                </div>
okhin's avatar
okhin committed
38
                <div class="card-action">
okhin's avatar
okhin committed
39 40 41 42 43
                    <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
44 45 46 47
                        <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
48
                        </repeat>
okhin's avatar
okhin committed
49 50 51
                        <div class="input-field">
                            <textarea class="materialize-textarea" id="feedback" name="feedback"></textarea>
                        </div>
okhin's avatar
okhin committed
52 53
                        <input type="submit" class="btn btn-primary" name="go" value="{{ _("Send my feedback") }}" />
                    </form>
54 55 56 57 58
                </div>
            </div>
        </div>
    </div>
</div>
okhin's avatar
okhin committed
59 60 61 62
<!-- 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
63
    var interval = '';
okhin's avatar
okhin committed
64 65 66 67 68 69 70 71 72
    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
73
        console.log(call_history);
okhin's avatar
okhin committed
74 75 76
        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
77
            return date2 - date1;
okhin's avatar
okhin committed
78
        })[0];
okhin's avatar
okhin committed
79 80 81 82
        $('.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
83
        if (call_state[0].startsWith('Created:Init')) {
okhin's avatar
okhin committed
84 85 86 87
            $('#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
88
        };
okhin's avatar
okhin committed
89 90 91 92 93 94

        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
95 96 97 98
                $('#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
99
            } else {
okhin's avatar
okhin committed
100 101 102 103
                $('#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
104 105 106 107 108 109 110 111 112
            };
        };

        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
113 114 115 116
                $('#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
117
            } else {
okhin's avatar
okhin committed
118 119 120 121
                $('#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
122 123
            };
        };
okhin's avatar
okhin committed
124 125 126

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