monitor.html 696 Bytes
Newer Older
okhin's avatar
okhin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<script>
    var call = JSON.parse("{{ @call | raw }}");
    function update_call(call) {
        var call_url = call['data']['call_url'];
        var call_history = call['data']['history'];
        // call_states is now a list of states, each of them is a
        // tuple of the form 'state, date'
        // getting the current state is a matter of sorting this list of
        // tuple on the second element of the tuple
        call_state = call_history.sort(function(a, b) {
            var date1 = new Date(a[1]);
            var date2 = new Date(b[1]);
            return date1 - date2;
        })[0];
        console.log(call_state);
    };
    $(document).ready(update_call);
</script>