contact.js 3.36 KB
Newer Older
Kim Peace committed
1
$(function () {
Lee Munkyeong committed
2
    // メンバー検索
3
    $('#contact .search_form input[type="search"]').keyup(function(e) {
Lee Munkyeong committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
        var groupList;
        var keyword = $('#contact .search_form input[type="search"]').val();
        if (e.key == "Enter" || e.KeyCode == 13) {
            if (keyword != '' && keyword.length != 0) {
                $('#contact .search_form input[type="search"]').blur();
                return;
            }
        } else if (keyword == '' || keyword.length < 2) {
            $('.overlay_src_msg').empty();
            return;
        }
        $('.overlay_src_msg').empty();
        var isAllGroup = $('#tabAllGroup').is(':checked');
        //全グループ検索画面
        if (isAllGroup) {
            //グループデータ検索
            groupList = CHAT_DB.getGroupByName(keyword);
            var groupTemplate;
            $.get({ url: "./template/template_group_list.html", async: false }
                , function(text) {
                    groupTemplate = text;
            });
26

Lee Munkyeong committed
27 28 29 30 31 32 33 34 35
            groupList.forEach(function(group) {
                let html = Mustache.render(groupTemplate, {
                    name: group.groupName,
                    id: group.groupId,
                    isFavorite: group.isFavorite
                });
                let obj = jQuery.parseHTML(html);
                $('.overlay_src_msg').append(obj);
            })
Lee Munkyeong committed
36

Lee Munkyeong committed
37 38 39 40 41 42 43 44 45 46 47 48
            //ユーザデータ検索
            var userList = CHAT_DB.getAllGroupShopMemberByName(keyword);
            var userTemplate;
            $.get({ url: "./template/template_user_list.html", async: false }
                , function(text) {
                    userTemplate = text;
            });
            userList.forEach(function(user) {
                user.profileUrl = CHAT.getProfileImgUrl(user.profileUrl);
            });
            let html = Mustache.render(userTemplate, {
                userList: userList
Lee Munkyeong committed
49 50 51
            });
            let obj = jQuery.parseHTML(html);
            $('.overlay_src_msg').append(obj);
Lee Munkyeong committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
            if (userList.length == 0 && groupList.length == 0) {
                const noResultMsg = $('<div/>',{width:'auto', style:'text-align: center'});
                noResultMsg.append(getLocalizedString("noResult"))
                $('.overlay_src_msg').append(noResultMsg);
            }
        //連絡先画面
        } else {
            var userList = CHAT_DB.getMyGroupShopMemberByName(keyword);
            var userTemplate;
            $.get({ url: "./template/template_user_list.html", async: false }
                , function(text) {
                    userTemplate = text;
            });
            userList.forEach(function(user) {
                user.profileUrl = CHAT.getProfileImgUrl(user.profileUrl);
            });
            let html = Mustache.render(userTemplate, {
                userList: userList
            });
            let obj = jQuery.parseHTML(html);
            $('.overlay_src_msg').html(obj);
            if (userList.length == 0) {
                const noResultMsg = $('<div/>',{width:'auto', style:'text-align: center'});
                noResultMsg.append(getLocalizedString("noResult"))
                $('.overlay_src_msg').append(noResultMsg);
            }
Lee Munkyeong committed
78
        }
Lee Munkyeong committed
79 80
        if (e.key == "Enter" || e.KeyCode == 13) {
            $('#contact .search_form input[type="search"]').blur();
Lee Munkyeong committed
81 82
            return;
        }
Lee Munkyeong committed
83
    });
藤川諒 committed
84
});