contactslist.html 2.66 KB
Newer Older
okhin's avatar
okhin committed
1 2 3 4 5 6 7 8
<div class="col s12 m4">
    <ul class="collection contact">
        <nav class="nav-extended teal">
            <div class="nav-wrapper">
                <div class="input-field">
                    <input type="search" id="search" class="autocomplete">
                    <label class="label-icon" for="search"><i class="material-icons">search</i></label>
                </div>
okhin's avatar
okhin committed
9
            </div>
okhin's avatar
okhin committed
10
        </nav>
okhin's avatar
okhin committed
11
        <repeat group="{{ @contacts }}" value="{{ @contact }}">
okhin's avatar
okhin committed
12 13 14 15 16 17 18 19 20
        <li class="collection-item avatar" data-json='{{ json_encode(@contact) }}'>
            <img src="<check if="{{ @contact.photo == '' }}">/static/img/placeholder.jpg<false>{{ @contact.photo }}</false></check>" class="circle">
            <span class="title">{{ @contact.last_name }} {{ @contact.full_name }}</span>
            <ul>
                <repeat group="{{ @contact.groups }}" value="{{ @group }}">
                <li class="chip">{{ @group.name }}</li>
                </repeat>
            </ul>
        </li>
okhin's avatar
okhin committed
21
        </repeat>
okhin's avatar
okhin committed
22 23
    </ul>
</div>
24
<!-- contacts list -->
okhin's avatar
okhin committed
25 26 27 28 29 30 31 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
<script>
$(document).ready(function() {
    $('input.autocomplete').autocomplete({
        data: {
            <repeat group="{{ @contacts }}" value="{{ @contact }}">
                "{{ @contact.first_name }} {{ @contact.last_name }}": <check if="{{ @contact.photo == '' }}">null<false>{{ @contact.photo }}</false></check>,
            </repeat>
        },
        limit: 20,
    });
    var random = Math.floor((Math.random() * $('.collection-item').length));
    $('.collection-item').click(function(){
        update_mep($(this));
    });

    function update_mep(element) {
        var contact = JSON.parse($(element).attr('data-json'));
        if (contact['photo'] !== '') {
            $('#contact-image').attr('src', contact['photo']);
        };
        $('#contact-full_name').html(contact['first_name'] + ' ' + contact['last_name']);
        $('#form-contact').attr('action', '/call/' + contact['id']);
        $('#contact_id').attr('value', contact['id']);
        $('.groups').each(function() {
            var group_type = $(this).attr('data-name');
            var content = '<ul class="groups" data-name="' + group_type + '">' + group_type;
            contact['groups'].forEach(function(group) {
                if ( group['type'] === group_type ) {
                    content += '<li class="chip">' + group['name'] + '</li>';
                }
            });
            content += '</ul>';
            $(this).html(content);
        });
        $('#contact-phone').attr('href', 'tel:' + contact['phone']);
        $('#contact-phone').text(contact['phone']);
    };
    update_mep($('.collection-item').eq(random));
});
</script>