chat-ui.js 104 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// 名前空間
var CHAT_UI = {};

// Rotate
$(window).on('resize', function() {
    if (CHAT_UTIL.isMobile()) {
        return;
    }

    console.log(`width : ${$(this).width()}`);
    console.log(`height : ${$(this).height()}`);

13
    /*if(CHAT_UI.isLandscapeMode()) {
14 15 16 17 18 19 20 21 22 23 24 25 26
        $(".group_list").addClass("col-6").removeClass("col-12");
        $(".user_list").addClass("col-6").removeClass("col-12");
        $(".chat_list").addClass("col-6").removeClass("col-12");
        $(".squareBoxContent span").addClass("landscape_span");

        $(".mesgs").addClass("landscape_mesgs");
    } else {

        $(".group_list").removeClass("col-6").addClass("col-12");
        $(".user_list").removeClass("col-6").addClass("col-12");
        $(".chat_list").removeClass("col-6").addClass("col-12");
        $(".squareBoxContent span").removeClass("landscape_span");

Lee Munkyeong committed
27 28 29 30 31 32 33 34 35 36
        $(".mesgs").removeClass("landscape_mesgs");
    }*/

    if (CHAT_UTIL.isIOS()) {
        if (isLandscape == true) {
            $(".mesgs").addClass("landscape_mesgs");
        } else if (isLandscape == false) {
            $(".mesgs").removeClass("landscape_mesgs");
        }
    }
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 67 68 69 70 71 72 73 74 75
})

// New Room
// チャットルーム生成ボタン処理
$('#createChatRoom').on('click', function() {
    //loadingIndicatorを表示
    CHAT_UI.showLoadingIndicator();

    let isInvite = false;
    CHAT.globalIsInvite = isInvite;
    socket.emit('getGroupList', isInvite);
});

// Room Delete
// チャットルーム削除ボタン処理
$('#roomDeleteButton').on('click', function(e) {
    if ($('.deleteBox').is(':visible')) {
        // チャットルーム削除アイコンが表示されている時、ブラインド処理を行う
        $('.deleteBox').finish().show().fadeTo('slow', 0, function() {
            $(this).hide();
        });
        // チャットリストについてクリックイベントを与える
        $('.chat_list').off('click');
        $('.chat_list:not(.active_chat)').on('click', function(e) {
            //loadingIndicatorを表示
            CHAT_UI.showLoadingIndicator();
            let roomId = $(this).data('roomId');
            let roomName = $(this).data('roomname');
            socket.emit('joinRoom', roomId, roomName, function() {
                $('#messages').html('');
                $('.titleRoomName').text(roomName).data('roomName', roomName);
                $('#pills-chat-tab').tab('show');
                $("#message-search").attr("placeholder", getLocalizedString("chat_search_placeholder"));
            });
        });

        let roomListTitle = getLocalizedString("roomListTitle")
        $('.titleRoomName').text(roomListTitle)

Lee Munkyeong committed
76
        $('.chat_list.active_chat').on('click', function(e) {
77 78 79 80 81 82 83 84 85 86 87 88 89
            $('#pills-chat-tab').tab('show');
        });
    } else {
        // チャットルーム削除アイコンが表示されていない場合、表示する
        $('.deleteBox').finish().hide().fadeTo('slow',1).show();
        // #36129に対応
        let deleteRoomTitle = getLocalizedString("deleteRoomTitle")
        $('.titleRoomName').text(deleteRoomTitle)
        // 重複処理を防ぐためにチャットリストのクリックイベントを消す
        $('.chat_list').off('click');

        // チャットルームの削除アイコンにクリックイベントを与える
        $('.deleteBox').off('click');
Lee Munkyeong committed
90
        $('.deleteBox').on('click', function(e) {
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
            // #36174
            let roomId = $(this).data('roomId');
            let activeRoom = $(this).data('activeRoom');
            $("#roomDeleteTitle").text(getLocalizedString("roomDeleteTitle"));
            $("#roomDelete").text(getLocalizedString("roomDelete"));
            $("#cancelTitle").text(getLocalizedString("cancelTitle"));

            // #36128
            $('#roomDeleteConfirm').appendTo("body").modal({
                backdrop: 'static',
                keyboard: false
            })
            .on('click', '#roomDelete', function(e) {
                //loadingIndicatorを表示
                CHAT_UI.showLoadingIndicator();
                // 現在接続されているチャットルームを離れるとメッセージテップを初期化する
                if (activeRoom) {
                    $('#messages').html('');
                    CHAT.saveRoomInfo('', '');
                }
                // チャットルームから退場する
                socket.emit('exitRoom', roomId);

                // #36129に対応
                let roomListTitle = getLocalizedString("roomListTitle")
                $('.titleRoomName').text(roomListTitle)
            });
        });
    }
});

$('#room-search').on('input', function(event) {
    if ($('#room-search').val().length > 0) {
        // 検索結果が有る場合、結果を表示する
        socket.emit('roomSearch', encodeURIComponent($('#room-search').val()));
    } else {
        if (IS_ONLINE == 'true') {
Takatoshi Miura committed
128 129 130 131 132
            if (typeof(android) != "undefined") {
                android.updateRoomList();
            } else {
                webkit.messageHandlers.updateRoomList.postMessage({});
            }
133 134 135 136 137 138 139
            CHAT_UI.refreshRoomList(chatRoomType.DM);
            CHAT_UI.dismissLoadingIndicator();
        }
    }
});

//上にスクロールすると新しいメッセージを呼ぶ処理。
Lee Munkyeong committed
140
$('#messages').scroll(function() {
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
    if ($(this).scrollTop() === 0) {
        if (!$('#chatLoader').is(':visible')) {
            // 現在、メッセージの個数以前をメッセージを読み込む
            // ローディングアイコンを追加する
            let loader = $('<div id="chatLoader" class="text-center"><div class="spinner-grow spinner-grow-sm" role="status" /></div>')
            $('#messages').prepend(loader)
            loader.remove();
//            socket.emit('getMessages', $(this).children().length, function() {
//                // ローディングアイコンを削除する
//                loader.remove();
//            });
        }
    }
});

// UIの位置調整(キーボード出現時)
Lee Munkyeong committed
157
$('#message-form').on('focus', function() {
158 159 160 161 162 163 164
    if (CHAT_UTIL.isIOS()) {
        // メッセージ入力欄の位置指定
        document.querySelector('.fixed-bottom').style.bottom = 10000 + 'px';
        setTimeout(function() {
            document.querySelector('.fixed-bottom').style.bottom = 0 + 'px';
        },200);
    }
165 166 167
});

CHAT_UI.setNavigationPosition = function(y) {
168 169 170 171 172 173 174 175 176
    if (document.activeElement.id == 'message-form') {
        $('.navbar').css('position','absolute');
        $('.navbar').css('top', (y) + 'px');
        $('.tab-pane').css('margin-top', y + 'px');
        var height = document.getElementById("messages").getBoundingClientRect().height;
        $('.msg_history').css('height', height - y + 'px');
    } else if (document.activeElement.id == 'message-search') {
        $('.msg_history').css('height', '');
    }
177 178 179
}

CHAT_UI.resetNavigationPosition = function() {
180 181 182 183
    $('.navbar').css('position','');
    $('.navbar').css('top', '');
    $('.tab-pane').css('margin-top','');
    $('.msg_history').css('height', '');
184 185 186 187
}

// 端末の向きを記録(キーボード出現時にLandscapeModeと判定する対策)
var isLandscape;
Lee Munkyeong committed
188
CHAT_UI.setOrientation = function(isLandscapeMode) {
189 190 191 192 193 194 195
    if (isLandscapeMode == 'false') {
        $(".mesgs").removeClass("landscape_mesgs");
        isLandscape = false;
    } else {
        $(".mesgs").addClass("landscape_mesgs");
        isLandscape = true;
    }
196 197
}

Lee Munkyeong committed
198 199
CHAT_UI.sendMessage = function(e) {
    const messageTextBox = $('#messageInput');
200
    const message = messageTextBox.val().length > 0 ? encodeURIComponent(messageTextBox.val()) : "";
201 202 203 204
    messageTextBox.val('');

    if (message.length > 0) {
        socket.emit(
Lee Munkyeong committed
205
            'createMessage', { text: message + messageSeperator + messageType.TEXT }
206 207 208
            , 0
        );
    }
209
    $('.message_input_form').focus();
Lee Munkyeong committed
210 211 212 213 214 215 216
}
//メッセージ送信
$('#messageInput').on('keypress', function(event) {
    if (event.which == 13) {
        // Enterキーの処理
        $('#messageSend').click();
    }
217 218 219
});

// 写真アップロード
Lee Munkyeong committed
220
$('#imageInputButton').on('click', function() {
221 222 223 224
    $('#imageInputTag').click();
});

// 動画アップロード
Lee Munkyeong committed
225 226
$('#videoUploadButton').on('click', function() {
    $('#videoInputTag').click();
227 228
});

Lee Munkyeong committed
229
$('#imageInputTag').on('change', function() {
230 231 232
    $('#image-form').submit();
});

Lee Munkyeong committed
233 234
$('#videoInputTag').on('change', function() {
    $('#video-form').submit();
235 236
});

Lee Munkyeong committed
237
$('#image-form').on('submit', function(e) {
238 239 240 241 242 243 244 245 246 247
    e.preventDefault();
    const imageInputTag = $('#imageInputTag');
    const file = imageInputTag.prop('files')[0];
    if (file) {
        $('.overlay').addClass('active undismissable');
        $('.loader').addClass('active');
        CHAT_UI.showLoadingIndicator();
        var fd = new FormData($(this)[0]);

        //画像の大きさが500pixelより大きかったら、thumbnailを生成
Lee Munkyeong committed
248
        CHAT.createThumbnailAndUpload(file, function(resizeFile, thumbnailCreated) {
249 250 251 252 253 254 255 256 257 258 259 260
            if (resizeFile && thumbnailCreated) {
                //ただ、画像の大きさが500pixel以下の場合はthumbnailは生成されない
                fd.append('thumb', resizeFile)
            }

            // イメージをアップロード
            CHAT.uploadImage(fd)

        })
    }
});

Lee Munkyeong committed
261
$('#video-form').on('submit', function(e) {
262
    e.preventDefault();
Lee Munkyeong committed
263 264
    const videoInputTag = $('#videoInputTag');
    const file = videoInputTag.prop('files')[0];
265 266 267 268 269 270 271
    if (file) {
        $('.overlay').addClass('active undismissable');
        $('.loader').addClass('active');
        CHAT_UI.showLoadingIndicator();
        var fd = new FormData($(this)[0]);

        if(!file.type.includes("image")) { // video 保存
272 273 274 275 276 277 278 279
            // CHAT.createVideoThumbnailAndUpload(file, function(resizeFile, thumbnailCreated) {
            //     if(resizeFile && thumbnailCreated) {
            //         //ただ、画像の大きさが500pixel以下の場合はthumbnailは生成されない
            //         fd.append('thumb', resizeFile)
            //     }
            //     CHAT.uploadImage(fd);
            // })
            CHAT.uploadImage(fd);
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
            return;
        }
    }
});

/* --------------------------------------------------- */
/* Nav Bar Functions                                                                     */
/* --------------------------------------------------- */

$('#message-search').on('input', function(event) {
    // チャットキーワードを入力するとページ内にある単語をハイライトする。(mark.js 使用)
    if ($(this).val()) {
        $('.message_content').unmark();
        $('.message_content').mark($(this).val());

        if ($('[data-markjs=true]').length > 0) {
            // マーキングされている単語があった場合、最後の単語にスクロールを移動する。
            CHAT_UI.scrollToLastMarkedUnseen($(this).val());
        } else {
            // マーキングされている単語がない場合、下段にスクロールする。
            CHAT_UI.scrollToBottom();
        }
    } else {
        // チャットキーワードが空欄になるとマーキングを解除し、下段にスクロールする。
        $('.message_content').unmark();
        CHAT_UI.scrollToBottom();
    }
});

//次のマーキングされた単語にスクロールを移動する。
$('#pre-search').on('click', function(event) {
    CHAT_UI.scrollToLastMarkedUnseen(jQuery('#message-search').val());
});

// Exit Room
Lee Munkyeong committed
315
$('#exitRoom').on('click', function(event) {
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
    // 36174
    $("#exitRoomTitle").text(getLocalizedString("exitRoomTitle"));
    $("#exitRoomOk").text(getLocalizedString("yesTitle"));
    $("#noExit").text(getLocalizedString("cancelTitle"));

    $('#exitRoomConfirm').appendTo("body").modal({
        backdrop: 'static',
        keyboard: false
    })
    .on('click', '#exitRoomOk', function(e) {
        //loadingIndicatorを表示
        CHAT_UI.showLoadingIndicator();
        // チャットルームから退場する
        socket.emit('exitRoom');
        $('#dismiss').click();
        CHAT.saveRoomInfo('', '');
    });
});

// Side Bar
Lee Munkyeong committed
336
$('#sidebarCollapse').on('click', function() {
337 338 339 340 341 342 343 344
    // open sidebar
    $('#sidebar').addClass('active');
    // fade in the overlay
    $('.overlay').addClass('active');
    $('.collapse.in').toggleClass('in');
    $('a[aria-expanded=true]').attr('aria-expanded', 'false');
});

Lee Munkyeong committed
345
$('#dismiss, .overlay').on('click', function() {
346 347 348 349 350 351 352 353
    // hide sidebar
    $('#sidebar').removeClass('active');
    // hide overlay if dismissable
    $('.overlay:not(.undismissable)').removeClass('active');
});

//Invite User
//招待ボタンを押すとグループリストを持ってくる。(ボタンを動的に追加して微動作中)
Lee Munkyeong committed
354
$('#addUser').on('click', function(event) {
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
    //loadingIndicatorを表示
    CHAT_UI.showLoadingIndicator();
    let isInvite = true;
    CHAT.globalIsInvite = isInvite;
    socket.emit('getGroupList', isInvite);
});

//グループ画面での検索
$('#groupListKeyword').on('input', function(event) {
    // data-name値で当該キーワードが入っているグループのみを表示する。
    if ($(this).val()) {
        $('.group_list:not([data-name*="'+$(this).val()+'" i])').hide();
        $('.group_list[data-name*="'+$(this).val()+'" i]').show();
    } else {
        $('.group_list').show();
    }
});

$('#userListKeyword').on('input', function(event) {
    // data-name値で当該キーワードが入っているユーザーのみを表示する。
    if ($(this).val()) {
        $('.user_list:not([data-name*="'+$(this).val()+'" i])').hide();
        $('.user_list[data-name*="'+$(this).val()+'" i]').show();
    } else {
        $('.user_list').show();
    }
});

$('#selectListKeyword').on('input', function(event) {
    if ($(this).val()) {
        $('.select_user_list:not([data-name*="'+$(this).val()+'" i])').hide();
        $('.select_user_list[data-name*="'+$(this).val()+'" i]').show();
    } else {
        $('.select_user_list').show();
    }
});

/* ---------------------------------------------------------------------- */
/*                                                                                                                                                */
/*                                                                     Etc                                                                    */
/*                                                                                                                                                */
/* ---------------------------------------------------------------------- */

// Tab Open/Shown Event
Lee Munkyeong committed
399
$('a[data-toggle="pill"]').on('show.bs.tab', function(e) {
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
    var target = $(e.target).attr("href"); // e.target : activated tab
    switch(target) {
        case '#pills-chat':
            if (CHAT_UI.isLandscapeMode()) {
                $(".mesgs").addClass("landscape_mesgs");
            } else {
                $(".mesgs").removeClass("landscape_mesgs");
            }
            CHAT.globalIsInvite = true;
            $('.chatRoomIcon, .titleRoomName, #backButton').show();
            $('.roomListIcon, #userSelectionConfirmBtn, #newRoomName, #userSelectionDeleteBtn').hide();
            $('#homeButton').hide();

            $('.titleRoomName').text($('.titleRoomName').data('roomName'));
            $('#newRoomName').val('');
            $('#userSelectionLength').text('');
            CHAT.globalSelectedUserList = [];
            $('#bottomNav').hide();
            $('#backButton').off().on('click', function() {
                //loadingIndicatorを表示
                CHAT_UI.showLoadingIndicator();
                CHAT.saveRoomInfo();
                if (IS_ONLINE == 'true') {
                    socket.emit('leaveRoom', function() {
Takatoshi Miura committed
424 425 426 427 428
                        if (typeof(android) != "undefined") {
                            android.updateRoomList();
                        } else {
                            webkit.messageHandlers.updateRoomList.postMessage({"groupId":"0"});
                        }
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
                    });
                }
                CHAT_UI.refreshRoomList(chatRoomType.DM);
                CHAT_UI.dismissLoadingIndicator();
            });
            //loadingIndicatorを表示しない
            CHAT_UI.dismissLoadingIndicator();
            break;
        case '#pills-chatlist':
            $('.titleRoomName, #backButton').show();
            $('.chatRoomIcon, #backButton, #userSelectionConfirmBtn, #newRoomName, #userSelectionDeleteBtn').hide();
            $('#homeButton').show();
            $('#room-search').val('');
            $('#room-search').show();
            $('#room_list').show();
            // set Title
            let roomListTitle = getLocalizedString("roomListTitle")
            $('#bottomNav').show();
            $('.titleRoomName').text(roomListTitle);
            $('#newRoomName').val('');
            $('#userSelectionLength').text('');
            CHAT.globalSelectedUserList = [];

            break;
            
        case '#pills-contact':
            $('#myNamecard').html('');
            $('#homeButton').show();
            $("#backButton").hide();
            $('.titleRoomName').show();
            $('#myGroupArea').show();
            $('#allGroupArea').hide();
            $('#my_info').show();
            $('#bottomNav').show();
            break;

        case '#pills-user':
            $("#backButton").show();
            $("#userSelectionDeleteBtn").hide();
            $('#homeButton').hide();
            $('#bottomNav').hide();
            //loadingIndicatorを表示しない
            CHAT_UI.dismissLoadingIndicator();
            break;
        case '#pills-group':
            $("#backButton").show();
            $("#userSelectionDeleteBtn").hide();
            $('#homeButton').hide();
            $('#bottomNav').hide();
            //loadingIndicatorを表示しない
            CHAT_UI.dismissLoadingIndicator();
            break;
        case '#pills-confirm':
            $("#backButton").show();
            //loadingIndicatorを表示しない
            CHAT_UI.dismissLoadingIndicator();
            $('#homeButton').hide();
            $('#bottomNav').hide();
            $('.user_people').css("paddingLeft", "0px");
            break;
        case '#pills-communication':    // コミュニケーションのタブ
        case '#pills-setting':    // 設定のタブ
        case '#pills-profile':    // ユーザプロファイルのタブ
            $('#bottomNav').hide();
            $('.titleRoomName').show();
            $('.roomListIcon, .chatRoomIcon, #userSelectionConfirmBtn, #newRoomName, #userSelectionDeleteBtn').hide();
            $('#backButton').hide();
            break;
        default:
            $('.titleRoomName').show();
            $('.roomListIcon, .chatRoomIcon, #userSelectionConfirmBtn, #newRoomName, #userSelectionDeleteBtn').hide();
            $('#backButton').hide();
            break;
    }
});

// Tab Close/Hidden Event
$('a[data-toggle="pill"]').on('hide.bs.tab', function(e) {
    var target = $(e.target).attr("href"); // e.target : activated tab
    switch(target) {
        case '#pills-chat':
            $('#message-search').val('');
            break;
        case '#pills-chatlist':
            $('#room-search').val('');
            $('#room-search').show();
            break;
        case '#pills-group':
            $('#groupListKeyword').val('');
            break;
        case '#pills-contact':
            break;
        case '#pills-user':
            $('#userListKeyword').val('');
            break;
        case '#pills-confirm':
            $('#select_user_list').html('');
            $('#selectUserListKeyword').val('');
            $('.titleRoomName').show();
            $('.user_people').css("paddingLeft", "12%");
            break;
        case '#pills-communication':
        case '#pills-setting':
        case '#pills-profile':
            break;
        default:
            break;
    }
});

Lee Munkyeong committed
539
$('#pills-chat-tab').on('shown.bs.tab', function(e) {
540 541 542
    CHAT_UI.scrollToBottom();
});

Lee Munkyeong committed
543
$('#pills-user-tab').on('shown.bs.tab', function(e) {
544 545 546
    $('#userSelectionConfirmBtn').show();
});

Lee Munkyeong committed
547
$('#pills-confirm-tab').on('shown.bs.tab', function(e) {
548 549 550 551 552 553
    $('#userSelectionConfirmBtn').show();
    $('#userSelectionLength').text('');
    $('#userSelectionDeleteBtn').hide();
});

CHAT_UI.scrollToBottom = function() {
Lee Munkyeong committed
554
    const messages = $('.room_contents');
555
    const scrollHeight = messages.prop('scrollHeight');
Lee Munkyeong committed
556 557 558
    //messages.scrollTop(scrollHeight);
    $('html, body').animate({
        scrollTop: scrollHeight
559
    }, 100);
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
};

CHAT_UI.scrollToLastMarkedUnseen = function(value) {
    let target = $('[data-markjs=true]:not([data-seen=true])').last();
    let messages = $('#messages');
    if (target.length > 0) {
        messages.scrollTop(target.prop('offsetTop') - target.prop('offsetHeight') - messages.prop('offsetHeight') + target.parent().parent().height());
        target.attr('data-seen', true);
    } else {
        messages.scrollTop(0);
        $('.message_content').unmark();
        $('.message_content').mark(value);
    }
};

//loadingIndicatorを表示
CHAT_UI.showLoadingIndicator = function() {
Lee Munkyeong committed
577 578
    var h = $(window).height();
    $('#loader-bg ,#loader').height(h).css('display','block');
579 580 581 582
}

//loadingIndicatorを表示しない
CHAT_UI.dismissLoadingIndicator = function() {
Lee Munkyeong committed
583 584
    var h = $(window).height();
    $('#loader-bg ,#loader').height(h).css('display','none');
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
}

//画面の方向をcheck
CHAT_UI.isLandscapeMode = function() {
    if (CHAT_UTIL.isMobile()) {
        return false;
    }

    return $(window).width() > $(window).height()
}

CHAT_UI.setConfirmButtonEvent = function(isInvite) {
    let titleText = isInvite ? getLocalizedString("inviteUsersSubtitle") : getLocalizedString("createRoomSubtitle")
    let invitedUserText = getLocalizedString("invitedUser")
    if (!isInvite) {
        $('#newRoomName').show();
    }

    $('#userSelectionConfirmBtn').off().on('click', function(event) {
        //loadingIndicatorを表示
        CHAT_UI.showLoadingIndicator();
        CHAT_UI.showConfirmView(isInvite);
    });

    CHAT_UI.showConfirmView(isInvite);
    $('#inviteStatus').text(titleText);
    $('#invitedUsers').text(invitedUserText);
    $('#pills-confirm-tab').tab('show');
}

//ConfirmView initialize
CHAT_UI.showConfirmView = function(isInvite) {
    const template = $('#user-template').html();
    $('#select_user_list').html('');

Lee Munkyeong committed
620
    CHAT.globalSelectedUserList.forEach(function(user) {
621 622 623 624 625 626 627 628
        let html = Mustache.render(template, {
            id: user.shopMemberId,
            profileImage: user.profileImagePath,
            name: user.loginId
        });
        // TODO 次のコミットに参考事項
        // チャットルーム開設画面で参加ユーザー削除用チェックロジックが残っているので
        // 影響テスト後、削除予定。 kang-dh
Lee Munkyeong committed
629
        let obj = $(jQuery.parseHTML(html)).on('click',function() {
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
            $(this).find('.userCheckBox').toggleClass('active');
        });

        $('#select_user_list').append(obj);
    });

    let roomListTitle = getLocalizedString("createRoomTitle")
    $('.titleRoomName').text(roomListTitle)

    // Rotate
    if (CHAT_UI.isLandscapeMode()) {
        $(".user_list").addClass("col-6").removeClass("col-12");
        $(".squareBoxContent span").addClass("landscape_span");
    }

    $('#backButton').off().on('click', function() {
        //loadingIndicatorを表示
        CHAT_UI.showLoadingIndicator();
        socket.emit('getGroupList', isInvite)
    });

Lee Munkyeong committed
651
    $("#userSelectionConfirmBtn").off().on('click', function() {
652
        if (isInvite) {
Lee Munkyeong committed
653
            let userIdList = jQuery.makeArray($('#select_user_list .user_list').find('.userCheckBox')).map(function(e) {
654 655 656
                return e.dataset.id;
            });
            // ユーザーの名前(login id)リスト。
Lee Munkyeong committed
657
            let loginIdList = jQuery.makeArray($('#select_user_list .user_list').find('.userCheckBox')).map(function(e) {
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
                return e.dataset.name;
            });

            if(userIdList.length > 0 && loginIdList.length > 0) {
                //loadingIndicatorを表示
                CHAT_UI.showLoadingIndicator();
                socket.emit('inviteUsers', userIdList, loginIdList, function() {
                    $("#userSelectionDeleteBtn").hide();
                    $('#pills-chat-tab').tab('show');
                });
            }
        } else {
            if ($('#select_user_list .user_list').find('.userCheckBox').length > 0) {
                // #36130に対応
                const trimmedRoomName = $('#newRoomName').val().trim()
                if (trimmedRoomName.length == 0) {

                    // loadingIndicatorを表示
                    CHAT_UI.showLoadingIndicator();
Lee Munkyeong committed
677
                    let userIdList = jQuery.makeArray($('#select_user_list .user_list').find('.userCheckBox')).map(function(e) {
678 679
                        return e.dataset.id;
                    });
Lee Munkyeong committed
680
                    let userNameList = jQuery.makeArray($('#select_user_list .user_list').find('.userCheckBox')).map(function(e) {
681 682 683 684 685 686 687 688 689 690 691 692 693
                        return e.dataset.name;
                    });

                    //TODO DB作業が終わったら自分のユーザ名を表示するかを判断し、修正予定。
                    // 参加ユーザ名でルーム名を生成
                    let newRoomName = CHAT.globalLoginParameter.loginId + ',' + userNameList.join(',');

                    // ルーム名のURIencodingを行う
                    //const encodedRoomName = encodeURIComponent(newRoomName);



                    //todo android create room api
Takatoshi Miura committed
694
                    if (typeof(android) != "undefined") {
695
                        android.createChatRoom("1", userIdList.join(','), newRoomName, makeRoomFlg.MAKE_ROOM, false);
Takatoshi Miura committed
696
                    } else {
697
                        webkit.messageHandlers.createChatRoom.postMessage({"roomType": "1", "userIdList": userIdList.join(','), "roomName": newRoomName, "screenFlg": makeRoomFlg.MAKE_ROOM, "isVoice": false});
698 699
                    }

700 701

                    /*socket.emit('createNewRoom', userIdList, encodedRoomName, function(newRoomId) {
Lee Munkyeong committed
702
                        socket.emit('joinRoom', newRoomId, newRoomName, function() {
703 704 705 706 707 708 709 710 711 712
                            CHAT.saveRoomInfo(newRoomId, newRoomName);
                            $('#messages').html('');
                            $('.titleRoomName').text(newRoomName).data('roomName', newRoomName);
                            $("#userSelectionDeleteBtn").hide();
                            $('#pills-chat-tab').tab('show');
                        });
                    });*/

                    /*socket.on('createNewRoom', (shopMemberIdList, newRoomName, callback) => {
                        const user = onlineUsers.getUser(socket.id)
Lee Munkyeong committed
713
                        if(user) {
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781
                            var loginIdListObj = new Object();
                            var newRoomNameObj = new Object();

                            loginIdListObj.type = 'loginIdList'
                            loginIdListObj.value = shopMemberIdList

                            newRoomNameObj.type = 'newRoomName'
                            newRoomNameObj.value = newRoomName

                                    var path = httpRequest.makeChatRoomManageUrlPath(user.shopName, constant.ROOM_CREATENEWROOM, user.sid, loginIdListObj, newRoomNameObj)
                                    winston.info('path' + path)
                                    httpRequest.readResult(path, (res) =>{
                                        const error = serverErrorHandler(res)
                                        if(error.errorFlag) {
                                            winston.error("Failed to [createNewRoom] process.")
                                            socket.emit("showServerError", error.errorMessage);
                                            return;
                                        }
                                        winston.info('create new room from server '+ util.inspect(res, false, null, false))
                                        callback(res.roomId)

                                        // ユーザーリストをアップデートする
                                        socket.emit(res.roomId).emit('updateUserList', res.userList, [user.shop_member_id])
                                    })
                                } else {
                                    socket.emit("retryJoinProcess")
                                    //join process
                                }
                    })*/





                } else if(trimmedRoomName.includes(';') || trimmedRoomName.includes('/') || trimmedRoomName.includes('?') || trimmedRoomName.includes(':') || trimmedRoomName.includes("@")
                     || trimmedRoomName.includes('&') || trimmedRoomName.includes('=') || trimmedRoomName.includes("+") || trimmedRoomName.includes('$') || trimmedRoomName.includes(",") || trimmedRoomName.includes('-')
                     || trimmedRoomName.includes('_') || trimmedRoomName.includes('.') || trimmedRoomName.includes('!') || trimmedRoomName.includes('~') || trimmedRoomName.includes('*') || trimmedRoomName.includes("\'")
                     || trimmedRoomName.includes('(') || trimmedRoomName.includes(')') || trimmedRoomName.includes('#') || trimmedRoomName.includes("\\") || trimmedRoomName.includes("\"") || trimmedRoomName.includes("`")) {
                    // #36147
                    // #36174
                    $("#customAlertTitle").text(getLocalizedString("invalidCharacter"));
                    $("#customAlertOk").text(getLocalizedString("yesTitle"));

                    $('#customAlert').appendTo("body").modal({
                        backdrop: 'static',
                        keyboard: false
                    })
                    .on('click', '#customAlertOk', function(e) {
                    });
                } else if (trimmedRoomName.length > 20) {
                    // #36142
                    var inputText = $('#newRoomName').val().trim(); // #36142 文字列の前又は後の空白文字列を削除

                    // #36174
                    $("#customAlertTitle").text(getLocalizedString("nameTooLong"));
                    $("#customAlertOk").text(getLocalizedString("yesTitle"));

                    $('#customAlert').appendTo("body").modal({
                        backdrop: 'static',
                        keyboard: false
                    })
                    .on('click', '#customAlertOk', function(e) {
                        $('#newRoomName').val(inputText.substr(0, $('#newRoomName').prop("maxlength")));
                    });

                } else {
                    //loadingIndicatorを表示
                    CHAT_UI.showLoadingIndicator();
Lee Munkyeong committed
782
                    let userIdList = jQuery.makeArray($('#select_user_list .user_list').find('.userCheckBox')).map(function(e) {
783 784 785 786 787
                        return e.dataset.id;
                    });

                    // ルーム名のtrimmingした後、URIencodingを行う
                    const encodedRoomName = encodeURIComponent(trimmedRoomName);
Takatoshi Miura committed
788
                    if (typeof(android) != "undefined") {
789
                        android.createChatRoom("1", userIdList.join(','), encodedRoomName, makeRoomFlg.MAKE_ROOM, false);
Takatoshi Miura committed
790
                    } else {
791
                        webkit.messageHandlers.createChatRoom.postMessage({"roomType": "1", "userIdList": userIdList.join(','), "roomName": newRoomName, "screenFlg": makeRoomFlg.MAKE_ROOM, "isVoice": false});
Takatoshi Miura committed
792
                    }
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818
                }
            }
        }
    });

    $("#userSelectionDeleteBtn").hide();

    $("#userSelectionDeleteBtn").off().on('click', function() {
        // #36174
        $("#customConfirmTitle").text(getLocalizedString("memberDeleteTitle"));
        $("#customConfirmOk").text(getLocalizedString("roomDelete"));
        $("#customAlertCancel").text(getLocalizedString("cancelTitle"));

        $('#customConfirm').appendTo("body").modal({
            backdrop: 'static',
            keyboard: false
        })
        .on('click', '#customConfirmOk', function(e) {
            CHAT_UI.deleteButtonAction(isInvite);
        });

    });
}

CHAT_UI.deleteButtonAction = function(isInvite) {
    //配列の整理
Lee Munkyeong committed
819
    jQuery.makeArray($('#select_user_list .user_list').find(".userCheckBox.active")).map(function(e) {
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
        CHAT.globalSelectedUserList = CHAT.globalSelectedUserList.filter(function(element) {
            return e.dataset.name != element.loginId;
        });
    });

    CHAT_UI.showConfirmView(isInvite)
    $('#select_user_list .user_list').find('.userCheckBox').show();
}

CHAT_UI.htmlElementTextInitialize = function(languageCode) {
    moment.locale(languageCode);
    setLanguage(languageCode);
    $(".titleRoomName").text(getLocalizedString("roomListTitle"));
    $("#message-form").attr("placeholder", getLocalizedString("chat_placeholder"));
    $("#message-search").attr("placeholder",getLocalizedString("chat_search_placeholder"));
    $("#exitRoom").text(getLocalizedString("exitRoom")).append("<i class='fas fa-door-open'></i>")
    $("#participants").text(getLocalizedString("participants"))

Lee Munkyeong committed
838 839
    //$("#fileUploadButton").text(getLocalizedString("photo"))
    //$("#fileUploadButton2").text(getLocalizedString("video"))
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858

    $("#okayLabel").text(getLocalizedString("okayLabel"))
    $("#completeLabel").text(getLocalizedString("completeLabel"))
    $("#thankLabel").text(getLocalizedString("thankLabel"))
    $("#startToWorkLabel").text(getLocalizedString("startToWorkLabel"))


    $("#groupListKeyword").attr("placeholder", getLocalizedString("groupSearch"))
    $("#contactListKeyword").attr("placeholder", getLocalizedString("contactSearch"))
    $("#room-search").attr("placeholder",$("#room-search").attr("placeholder")+getLocalizedString("room_search_placeholder"));
    $("#userListKeyword").attr("placeholder", getLocalizedString("userSearch"))
    $("#newRoomName").attr("placeholder", getLocalizedString("newRoomName"))

    $("#dmBtn").text(getLocalizedString("directMessageChatRoom"))
    $("#groupBtn").text(getLocalizedString("groupChatRoom"))

    $("#myGroupBtn").text(getLocalizedString("myGroup"))
    $("#allGroupBtn").text(getLocalizedString("allGroup"))

Lee Munkyeong committed
859 860 861 862 863 864
    //$("#groupPathSeperator").text(getLocalizedString("groupPath"))
    //$("#moveBtnSeperator").text(getLocalizedString("quickBtn"))
    //$("#rootGroupBtn").text(getLocalizedString("returnToRootGroup"))
    //$("#parentGroupBtn").text(getLocalizedString("returnToParentGroup"))
    //$("#childGroupSeperator").text(getLocalizedString("childGroup"))
    //$("#groupUserSeperator").text(getLocalizedString("groupUser"))
865 866 867 868 869 870




    $("#favorite-seperator").text(getLocalizedString("favorite"))
    $("#mygroup-seperator").text(getLocalizedString("mygroup"))
871 872 873 874 875 876 877 878

    $(".ttl_archive").text(getLocalizedString("archive"))
    $(".ttl_detail").text(getLocalizedString("detail"))
    $("#archiveFileName").text(getLocalizedString("archiveFileName"))
    $("#archiveInsertDate").text(getLocalizedString("archiveInsertDate"))
    $("#archiveRoomName").text(getLocalizedString("archiveRoomName"))
    $("#archiveSaveUser").text(getLocalizedString("archiveSaveUser"))
    $("#archiveAttendUser").text(getLocalizedString("archiveAttendUser"))
879 880 881 882
}

// 画像の読み込みが全て終わったタイミングでコールバック実行
// FIXME 追加読み込みの場合は差分の画像のみ監視すべきだが、現状新規入室時にしか対応出来ていない。
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900
CHAT_UI.waitForLoadingVideo = function(div, callback) {
    CHAT_UI.showLoadingIndicator();
//    var imgs = document.getElementsByTagName("video");
    var video = div.find("video");
    var count = video.length;
    if (count==0) callback();
    var loaded = 0;
    video.each( function() {
        this.addEventListener('loadeddata', function(e) {
                 loaded++;
                 if ( loaded === count ) {
                     callback();
                     CHAT_UI.dismissLoadingIndicator();
                 }
        });
    });
}

901 902
CHAT_UI.waitForLoadingImage = function(div, callback) {
    var imgs = div.find("img");
903
    console.log(imgs);
904 905 906 907
    var count = imgs.length;
    if (count==0)
        callback();
    var loaded = 0;
Lee Munkyeong committed
908
    imgs.one( "load" , function( e ) {
909 910
        // イメージが読み込まれた
        loaded++;
911
        console.log('++');
912 913 914
        if ( loaded === count ) {
            callback();
        }
Lee Munkyeong committed
915
    }).each( function() {
916 917 918 919 920
        if ( this.complete || this.readyState === readyState.COMPLETED ) {
            $(this).trigger("load");
        }
    });
}
Lee Munkyeong committed
921
$('#contactButton').on('click', function(event) {
922 923 924
    CHAT_UI.refreshContactScreen();
});

Lee Munkyeong committed
925
$('#chatButton').on('click', function(event) {
926 927 928 929
    CHAT_UI.refreshRoomList(chatRoomType.DM);
});

CHAT_UI.refreshContactScreen = function() {
930
    CHAT_UI.showLoadingIndicator();
Lee Munkyeong committed
931
    $('#userNameCard').modal('hide');
Lee Munkyeong committed
932 933
    $('#favoriteList').html('');
    $('#myGroupList').html('');
934 935 936 937
    //画面タイトル設定
    let contactListTitle = getLocalizedString("contactListTitle");
    $('#title').text(contactListTitle);

Lee Munkyeong committed
938

939
    // グループの様式を読み込む
Lee Munkyeong committed
940 941 942 943 944
    var groupTemplate;
    $.get({ url: "./template/template_group_list.html", async: false }
      , function(text) {
        groupTemplate = text;
    });
945 946 947 948 949 950 951 952 953 954 955 956 957 958

    // ユーザの様式を読み込む
    var userTemplate;
    $.get({ url: "./template/template_user_list.html", async: false }
      , function(text) {
        userTemplate = text;
    });

    var myNamecardTemplate;
    $.get({ url: "./template/template_my_name_card.html", async: false }
      , function(text) {
        myNamecardTemplate = text;
    });

Lee Munkyeong committed
959 960 961 962 963 964
    var groupUserTemplate;
    $.get({ url: "./template/template_group_user_list.html", async: false }
      , function(text) {
        groupUserTemplate = text;
    });

965
    if (IS_ONLINE == 'true') {
Takatoshi Miura committed
966
        if (typeof(android) != "undefined") {
967 968 969 970
            android.updateGroupInfo('0');
            android.updateMyInfo();
            android.updateGroupUser();
            android.updateFavorite();
Takatoshi Miura committed
971 972
        } else {
            webkit.messageHandlers.updateGroupInfo.postMessage("0");
973 974 975
            webkit.messageHandlers.updateMyInfo.postMessage({});
            webkit.messageHandlers.updateGroupUser.postMessage({});
            webkit.messageHandlers.updateFavorite.postMessage({});
976
        }
977 978 979 980 981 982 983 984 985 986 987 988 989
    }

    var myInfo = CHAT_DB.getMyInfo();
    myInfo.profileImagePath = CHAT.getProfileImgUrl(myInfo.profileUrl)



    let myNamecardHtml = Mustache.render(myNamecardTemplate, {
        loginId: myInfo.shopMemberId,
        profileImage: myInfo.profileImagePath,
        name: myInfo.shopMemberName,
        groupPathList: myInfo.groupPathList
    });
Lee Munkyeong committed
990
    let myNamecardObj = $(jQuery.parseHTML(myNamecardHtml)).on('click', function() {
991 992

    });
Lee Munkyeong committed
993

Lee Munkyeong committed
994
    $('#myProfileModal').html(myNamecardObj);
995 996 997
    $('#myName').text(myInfo.shopMemberName);
    $('#myImg').attr('src',myInfo.profileImagePath);

Lee Munkyeong committed
998 999
    //お気に入りグループ取得。
    var favoriteGroupList = CHAT_DB.getFavoriteGroups();
1000 1001
    favoriteGroupList.forEach(function(favoriteGroup) {
        let html = Mustache.render(groupTemplate, {
Lee Munkyeong committed
1002 1003 1004
            name: favoriteGroup.groupName,
            id: favoriteGroup.groupId,
            isFavorite: true
1005 1006
        });

Lee Munkyeong committed
1007
        let obj = $(jQuery.parseHTML(html)).on('click', function() {
1008
        });
Lee Munkyeong committed
1009 1010 1011
        $('#favoriteList').append(obj);
    })
    //お気に入りユーザ取得。
1012 1013
    var favoriteUserList = CHAT_DB.getFavoriteUsers();
    favoriteUserList.forEach(function(favoriteUser) {
Lee Munkyeong committed
1014 1015 1016 1017 1018 1019 1020 1021 1022
        favoriteUser.profileUrl = CHAT.getProfileImgUrl(favoriteUser.profileUrl);
        favoriteUser.isFavorite = true;
    });
    let html = Mustache.render(userTemplate, {
        userList: favoriteUserList
    });
    let obj = jQuery.parseHTML(html);
    $('#favoriteList').append(obj);

Lee Munkyeong committed
1023 1024 1025
    var myGroupList = CHAT_DB.getMyGroupUsers();
    myGroupList.forEach(function(myGroup) {

Lee Munkyeong committed
1026 1027
        myGroup.groupUserList.forEach(function(groupUser) {
            groupUser.profileUrl = CHAT.getProfileImgUrl(groupUser.profileUrl)
Lee Munkyeong committed
1028 1029 1030 1031 1032
        })
        let html = Mustache.render(groupUserTemplate, {
            groupName: myGroup.groupName,
            groupUserList: myGroup.groupUserList
        });
Lee Munkyeong committed
1033
        let obj = $(jQuery.parseHTML(html)).on('click', function() {
Lee Munkyeong committed
1034 1035 1036 1037
        });

        $('#myGroupList').append(obj);
    })
1038
    CHAT_UI.dismissLoadingIndicator();
1039 1040 1041
}

CHAT_UI.refreshRoomList = function(roomType) {
1042 1043 1044 1045 1046
    if (IS_ONLINE == 'true') {
        CHAT_UI.refreshForOnline();
    } else {
        CHAT_UI.refreshForOffline();
    }
Lee Munkyeong committed
1047 1048 1049
    var beforeRoomType;
    if (typeof(android) != "undefined") {
        beforeRoomType = android.getBeforeRoomType();
1050 1051
    } else {
        beforeRoomType = CHAT_DB.getBeforeRoomType();
Lee Munkyeong committed
1052 1053 1054 1055 1056
    }
    if (beforeRoomType != null) {
        roomType = beforeRoomType;
        if (typeof(android) != "undefined") {
            android.clearBeforeRoomType();
1057 1058
        } else {
            webkit.messageHandlers.clearBeforeRoomType.postMessage({});
Lee Munkyeong committed
1059 1060
        }
    }
Lee Munkyeong committed
1061
    CHAT_UI.showLoadingIndicator();
Lee Munkyeong committed
1062 1063 1064 1065 1066 1067
    if (roomType == chatRoomType.DM) {
        $('#tabDM').prop('checked', true);
    } else {
        $('#tabGroup').prop('checked', true);
    }

1068
    if (IS_ONLINE == 'true') {
Takatoshi Miura committed
1069
        if (typeof(android) != "undefined") {
1070
            android.updateRoomList();
Takatoshi Miura committed
1071 1072
        } else {
            webkit.messageHandlers.updateRoomList.postMessage({});
1073
        }
1074
    }
1075
    var rooms = CHAT_DB.getRoomList(roomType, null);
1076 1077
    CHAT.globalIsInvite = false;
    // #36146に対応
Lee Munkyeong committed
1078 1079
   $('#groupChatList').empty();
   $('#dmChatList').empty();
1080
    let roomListTitle = getLocalizedString("roomListTitle");
1081
    $('#chatTitle').text(roomListTitle);
1082 1083
    if (rooms.length === 0) {
        // 検索結果がない場合のメッセージを追加
Lee Munkyeong committed
1084 1085
        let emptyListString = getLocalizedString("roomListEmptyString")
        switch(roomType) {
Lee Munkyeong committed
1086 1087 1088 1089 1090 1091 1092 1093
            case chatRoomType.GROUP:
                $('#groupChatList').append(`<center class="text-secondary">${emptyListString}</center>`);
                break;
            case chatRoomType.DM:
                $('#dmChatList').append(`<center class="text-secondary">${emptyListString}</center>`);
                break;
            default:
        }
1094
    }
1095 1096 1097 1098 1099 1100

    var template;
    $.get({ url: "./template/template_room_list.html", async: false }
      , function(text) {
        template = text;
    });
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
    rooms.forEach(function(room) {
        room.profileImagePath = ASSET_PATH + 'images/user-profile.png'
        if (room.message) {
            room.message = room.message.toString()
        } else {
            room.message = getLocalizedString("noMessages")
        }
        var displayMsg;
        //TODO 協業の場合処理追加必要
        if (room.messageType == messageType.TEXT || room.messageType == messageType.TEXT) displayMsg = room.message;
1111 1112
        if (room.messageType == messageType.IMAGE) displayMsg = getLocalizedString("image");
        if (room.messageType == messageType.VIDEO) displayMsg = getLocalizedString("video");
1113 1114
        if (room.messageType == messageType.COMMUNICATIONSTART) displayMsg = getLocalizedString("collaboration_start");
        if (room.messageType == messageType.COMMUNICATIONEND) displayMsg = getLocalizedString("collaboration_end");
Lee Munkyeong committed
1115
        var attendUserName = [];
1116

Lee Munkyeong committed
1117 1118 1119 1120 1121 1122 1123 1124
        room.attendUsers.forEach(function(user) {
            user.profileUrl = CHAT.getProfileImgUrl(user.profileUrl);
            attendUserName.push(user.shopMemberName);
        });
        var thumbnailCount = room.attendUsers.length > 4 ? 4 : room.attendUsers.length;
        if (room.chatRoomName == "") {
            room.chatRoomName = attendUserName.join(', ');
        }
1125 1126 1127 1128
        var unreadMessageCount = room.unreadCount == 0 ? '' : room.unreadCount;
        if (unreadMessageCount > 999) {
            unreadMessageCount = '999+';
        }
1129
        let html = Mustache.render(template, {
Lee Munkyeong committed
1130
            thumbnailCount: thumbnailCount,
1131 1132 1133 1134 1135
            roomName: room.chatRoomName,
            roomId: room.chatRoomId,
            profileImage: room.profileImagePath,
            lastMessage: displayMsg ,
            time: room.insertDate ? CHAT_UTIL.formatDate(room.insertDate).createdAt : '',
1136
            unreadMsgCnt: unreadMessageCount,
Lee Munkyeong committed
1137 1138
            userCnt: room.attendUsers.length + 1,
            attendUsers: room.attendUsers
1139 1140 1141
        });
        // Click event
        let obj = $(jQuery.parseHTML(html)).on('click', function() {
1142
           /* let roomId = $(this).data('roomId');
1143
            let roomName = $(this).data('roomname');
1144
            CHAT_UI.joinRoom(roomId,roomName);*/
1145 1146
            //TODO ルームに入る処理追加必要
        });
1147 1148
        // ルームグループごとに追加。
        switch(roomType) {
Lee Munkyeong committed
1149 1150 1151 1152 1153 1154 1155 1156
            case chatRoomType.GROUP:
                $('#groupChatList').append(obj);
                break;
            case chatRoomType.DM:
                $('#dmChatList').append(obj);
                break;
            default:
        }
1157
    });
1158
    
Lee Munkyeong committed
1159 1160
    console.log('DONE');
    CHAT_UI.dismissLoadingIndicator();
1161 1162 1163
};

CHAT_UI.joinRoom = function(roomId,roomName) {
Lee Munkyeong committed
1164
    //native側に入場対象のroomId,roomNameを保存。(ルーム詳細画面初期化の時に使用。)
Takatoshi Miura committed
1165 1166 1167
    if (typeof(android) != "undefined") {
        android.joinRoom(roomId,roomName);
    } else {
Takatoshi Miura committed
1168
        webkit.messageHandlers.joinRoom.postMessage({"roomId": roomId, "roomName": roomName});
Takatoshi Miura committed
1169
    }
Lee Munkyeong committed
1170 1171 1172
};

CHAT_UI.loadMessages = function(roomId, roomName) {
1173
    var now = new Date();
1174
    if (IS_ONLINE == 'true') {
Lee Munkyeong committed
1175
        CHAT_UI.refreshForOnline();
Takatoshi Miura committed
1176 1177 1178
        if (typeof(android) != "undefined") {
            android.updateMessages(roomId);
        } else {
Takatoshi Miura committed
1179
            webkit.messageHandlers.updateMessages.postMessage(roomId);
Takatoshi Miura committed
1180
        }
Lee Munkyeong committed
1181 1182
    } else {
        CHAT_UI.refreshForOffline();
1183
    }
1184 1185 1186 1187 1188 1189
    var roomType;
    if (typeof(android) != "undefined") {
        roomType = android.getRoomType();
    } else {
        roomType = CHAT_DB.getRoomType();
    }
Lee Munkyeong committed
1190 1191 1192
    if (roomType == chatRoomType.DM) {
        $('#roomMenu').removeClass('none');
    }
1193
    var messages = CHAT_DB.getMessages(roomId);
Lee Munkyeong committed
1194
    var usersInRoom = CHAT_DB.getUsersInRoom(roomId);
1195

Lee Munkyeong committed
1196
    $('#roomTitle').text(roomName).data('roomName', roomName);
1197
    let jQueryMessages = $('#messages');
Lee Munkyeong committed
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
    // スクロールの変化を防ぐため以前画面の高さを保存する
    let beforeHeight = jQueryMessages.prop('scrollHeight');
    // メッセージ文字列の生成
    let workVal = "";
    var userTemplate;
    $.get({ url: "./template/template_user_list.html", async: false }
      , function(text) {
        userTemplate = text;
    });
    var userMessageTemplate;
    $.get({ url: "./template/template_user_message.html", async: false }
      , function(text) {
        userMessageTemplate = text;
    });
    var myMessageTemplate;
    $.get({ url: "./template/template_my_message.html", async: false }
      , function(text) {
        myMessageTemplate = text;
    });
    var systemMessageTemplate;
    $.get({ url: "./template/template_system_message.html", async: false }
      , function(text) {
        systemMessageTemplate = text;
    });
Lee Munkyeong committed
1222 1223 1224 1225 1226
    var openCollaborationMessageTemplate;
    $.get({ url: "./template/template_open_collaboration_message.html", async: false }
      , function(text) {
        openCollaborationMessageTemplate = text;
    });
Lee Munkyeong committed
1227 1228 1229 1230 1231
    var topUserListTemplate;
    $.get({ url: "./template/template_chatroom_user_list.html", async: false }
      , function(text) {
        topUserListTemplate = text;
    });
Lee Munkyeong committed
1232 1233 1234 1235 1236 1237
    var filterUserListTemplate;
    $.get({ url: "./template/template_chatroom_user_filter_list.html", async: false }
      , function(text) {
        filterUserListTemplate = text;
    });

1238

Lee Munkyeong committed
1239 1240 1241 1242 1243 1244 1245 1246
    usersInRoom.forEach(function(user) {
        user.profileUrl = CHAT.getProfileImgUrl(user.profileUrl);
    });
    let html = Mustache.render(topUserListTemplate, {
         userList: usersInRoom
    });
    let obj = jQuery.parseHTML(html);
    $('#user_list').append(obj);
Lee Munkyeong committed
1247 1248 1249 1250 1251 1252 1253

    let filterHtml = Mustache.render(filterUserListTemplate, {
         userList: usersInRoom
    });
    let filterObj = jQuery.parseHTML(filterHtml);
    $('#filter').append(filterObj);

1254 1255
    var checkBeforeDate = "";
    var beforeDate = "";
Lee Munkyeong committed
1256 1257 1258 1259 1260 1261 1262 1263
    messages.forEach(function(message) {
        let template = userMessageTemplate;
        if (message.shopMemberId == CHAT.globalLoginParameter.shopMemberId) {
             template = myMessageTemplate;
        }
        if (message.messageType == messageType.SYSTEM) {
            template = systemMessageTemplate;
        }
Lee Munkyeong committed
1264 1265 1266
        if (message.messageType == messageType.COMMUNICATIONSTART) {
            template = openCollaborationMessageTemplate;
        }
Lee Munkyeong committed
1267 1268
        let messageTime = CHAT_UTIL.formatDate(message.insertDate);
        // ユーザの様式を読み込む
1269

Lee Munkyeong committed
1270
        if (message.profileUrl) {
Lee Munkyeong committed
1271
            message.profileUrl = CHAT.getProfileImgUrl(message.profileUrl)
1272
        } else {
Lee Munkyeong committed
1273
            message.profileUrl = CHAT.getProfileImgUrl("")
1274 1275
        }

Lee Munkyeong committed
1276 1277 1278
         // #36147
         message.message = message.message.toString();
         var replacePath = message.message;
1279
         replacePath = replacePath.replaceAll('?fileName=', '?sid=' + CHAT.globalLoginParameter.sid + '&fileName=');
Lee Munkyeong committed
1280
         message.message = replacePath;
Lee Munkyeong committed
1281 1282
        /* if (message.message contain) {
         }*/
1283
         var isOtherYear = false;
Lee Munkyeong committed
1284 1285 1286 1287
         var isToday = false;
         if (messageTime.createdAt.includes(':')) {
            isToday = true;
         }
1288 1289 1290
         if (now.getFullYear() != message.insertDate.substring(0,4)) {
            isOtherYear = true;
         }
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
         if (messageTime.createdAtDay != checkBeforeDate && checkBeforeDate != "") {
            let messageDay = CHAT_UTIL.systemDay(beforeDate);
            let html = Mustache.render(systemMessageTemplate, {
                year: messageDay.year + getLocalizedString('year'),
                month: messageDay.month + getLocalizedString('month'),
                day: messageDay.day + getLocalizedString('day'),
                dow: CHAT_UTIL.findDow(messageDay.dow)

            });
             workVal = html + workVal;
         }
         checkBeforeDate = messageTime.createdAtDay;
         beforeDate = message.insertDate;
1304

Lee Munkyeong committed
1305
        if (message.messageType == messageType.COMMUNICATIONSTART || message.messageType == messageType.COMMUNICATIONEND) {
Takatoshi Miura committed
1306 1307 1308
            var collaborationInfo;
            var userInCollaboration;
            if (CHAT_UTIL.isIOS()) {
1309
                collaborationInfo = JSON.parse(message.message);
Takatoshi Miura committed
1310 1311 1312 1313 1314
                userInCollaboration = JSON.parse(CHAT_DB.getUserInfoList(collaborationInfo.userList));
            } else if (CHAT_UTIL.isAndroid()) {
                collaborationInfo = JSON.parse(message.message);
                userInCollaboration = JSON.parse(android.getUserInfoList(collaborationInfo.userList));
            }
Lee Munkyeong committed
1315 1316 1317 1318
            var meetingId = 0;
            if (typeof collaborationInfo.meetingId != 'undefined') {
                meetingId = collaborationInfo.meetingId;
            }
Lee Munkyeong committed
1319 1320 1321 1322 1323 1324 1325
            userInCollaboration.forEach(function(user) {
                user.profileUrl = CHAT.getProfileImgUrl(user.profileUrl);
            })
            let html = Mustache.render(template, {
                 roomName: roomName,
                 userCount: userInCollaboration.length,
                 userList: userInCollaboration.length > 3 ? userInCollaboration.slice(0, 3) : userInCollaboration,
Lee Munkyeong committed
1326 1327
                 insertDate: message.insertDate,
                 collaborationType: collaborationInfo.collaborationType,
Lee Munkyeong committed
1328
                 meetingId: meetingId,
Lee Munkyeong committed
1329 1330
                 isToday: isToday,
                 createdAtDay: messageTime.createdAtDay,
Lee Munkyeong committed
1331
                 createdAtTime: messageTime.createdAtTime,
1332 1333
                 createdAtYear: message.insertDate.substring(0,4) + getLocalizedString('year') + ' ',
                 isOtherYear: isOtherYear
Lee Munkyeong committed
1334 1335 1336
             });
             html = message.message.includes('attachedImages') || message.message.includes('attachedVideos') ? CHAT_UTIL.htmlDecode(html) : html;
             workVal = html + workVal;
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351
        } else {
           let html = Mustache.render(template, {
                text: message.message,
                from: message.loginId,
                shopMemberId: message.shopMemberId,
                profileImage: message.profileUrl,
                createdAtDay: messageTime.createdAtDay,
                createdAtTime: messageTime.createdAtTime,
                createdAtYear: message.insertDate.substring(0,4) + getLocalizedString('year') + ' ',
                unreadCount: message.unreadCount,
                isOtherYear: isOtherYear,
                isToday: isToday
            });
            html = message.message.includes('attachedImages') || message.message.includes('attachedVideos') ? CHAT_UTIL.htmlDecode(html) : html;
            workVal = html + workVal;
Lee Munkyeong committed
1352
        }
Lee Munkyeong committed
1353 1354 1355
    })
    // メッセージの画面描画
    jQueryMessages.prepend(workVal);
1356
    CHAT_UI.waitForLoadingImage(jQueryMessages, CHAT_UI.scrollToBottom);
1357
    CHAT_UI.waitForLoadingVideo(jQueryMessages, CHAT_UI.scrollToBottom);
Lee Munkyeong committed
1358 1359
    // ユーザ削除ボタン表示しない
    $("#userSelectionDeleteBtn").hide();
1360 1361 1362
};


Lee Munkyeong committed
1363
$('#tabDM').on('click', function(e) {
1364 1365 1366
    CHAT_UI.refreshRoomList(chatRoomType.DM);
});

Lee Munkyeong committed
1367
$('#tabGroup').on('click', function(e) {
1368 1369 1370
    CHAT_UI.refreshRoomList(chatRoomType.GROUP);
});

Lee Munkyeong committed
1371

Lee Munkyeong committed
1372 1373
$('#tabAllGroup').on('click', function(e) {
    CHAT_UI.refreshAllGroupSearch('0');
Lee Munkyeong committed
1374
});
1375

Lee Munkyeong committed
1376
$('#tabMyGroup').on('click', function(e) {
Lee Munkyeong committed
1377
    $('#contactSearch').attr('placeholder', getLocalizedString('userSearch'));
Lee Munkyeong committed
1378
    CHAT_UI.refreshContactScreen();
Lee Munkyeong committed
1379
});
1380

Kang Donghun committed
1381 1382 1383 1384 1385 1386 1387 1388
$('#tabMyGroupOnMakeRoom').on('click', function(e) {
    CHAT_UI.refreshMyGroupForMakeRoom();
});

$('#tabAllGroupOnMakeRoom').on('click', function(e) {
    CHAT_UI.refreshAllGroupForMakeRoom('0');
});

1389 1390 1391 1392 1393 1394 1395
$('#tabMyGroupOnAddUser').on('click', function(e) {
    CHAT_UI.refreshMyGroupForAddUser();
});

$('#tabAllGroupOnAddUser').on('click', function(e) {
    CHAT_UI.refreshAllGroupForAddUser('0');
});
1396 1397 1398 1399 1400 1401 1402 1403 1404

$('#tabMyGroupOnAddUserInCollaboration').on('click', function(e) {
    CHAT_UI.refreshMyGroupForAddUserInCollaboration();
});

$('#tabAllGroupOnAddUserInCollaboration').on('click', function(e) {
    CHAT_UI.refreshAllGroupForAddUserInCollaboration('0');
});

Kang Donghun committed
1405
$('#makeRoomConfirmBtn').on('click', function(e) {
Takatoshi Miura committed
1406 1407 1408
    if (typeof(android) != "undefined") {
        android.saveSelectedUserList(CHAT.globalSelectedUserList.join(","));
    } else {
1409
        webkit.messageHandlers.saveSelectedUserList.postMessage(CHAT.globalSelectedUserList.join(","));
Takatoshi Miura committed
1410
    }
Kang Donghun committed
1411 1412 1413
    $('#makeRoomForm').submit();
});

Lee Munkyeong committed
1414
$('#addUserConfirmBtn').on('click', function(e) {
Takatoshi Miura committed
1415 1416 1417
    if (typeof(android) != "undefined") {
        android.saveSelectedUserList(CHAT.globalSelectedUserList.join(","));
    } else {
1418
        webkit.messageHandlers.saveSelectedUserList.postMessage(CHAT.globalSelectedUserList.join(","));
Takatoshi Miura committed
1419
    }
Lee Munkyeong committed
1420 1421 1422
    $('#addUserForm').submit();
});

Lee Munkyeong committed
1423
CHAT_UI.roomDisplayOff = function() {
1424 1425 1426 1427 1428
    if (typeof(android) != "undefined") {
        android.roomDisplayOff();
    } else {
        webkit.messageHandlers.roomDisplayOff.postMessage({});
    }
Lee Munkyeong committed
1429 1430
}

Lee Munkyeong committed
1431 1432 1433 1434 1435 1436 1437
CHAT_UI.favoriteUserChange = function(shopMemberId, star) {
    if ($(star).hasClass('active')) {
        CHAT_UI.removeFavoriteUser(shopMemberId);
    } else if ($(star).hasClass('disable')) {
        CHAT_UI.insertFavoriteUser(shopMemberId);
    }
}
1438

Lee Munkyeong committed
1439 1440 1441 1442 1443 1444
CHAT_UI.favoriteGroupChange = function(groupId, star) {
    if ($(star).hasClass('active')) {
        CHAT_UI.removeFavoriteGroup(groupId);
    } else if ($(star).hasClass('disable')) {
        CHAT_UI.insertFavoriteGroup(groupId);
    }
1445 1446
}

Lee Munkyeong committed
1447
CHAT_UI.removeFavoriteUser = function(shopMemberId) {
1448
    CHAT_UI.showLoadingIndicator();
Lee Munkyeong committed
1449 1450
    $('#userNameCard').modal('hide');
    $('#myNameCard').modal('hide');
1451
    var result;
Takatoshi Miura committed
1452
    if (typeof(android) != "undefined") {
1453 1454 1455 1456 1457 1458 1459
        result = android.removeFavoriteUser(shopMemberId);
    } else {
        result = CHAT_DB.removeFavoriteUser(shopMemberId);
    }
    if (!result) {
        $('.shopmember_'+shopMemberId).addClass('active');
        $('.shopmember_'+shopMemberId).removeClass('disable');
Takatoshi Miura committed
1460
    } else {
Lee Munkyeong committed
1461 1462
        $('.shopmember_'+shopMemberId).removeClass('active');
        $('.shopmember_'+shopMemberId).addClass('disable');
Takatoshi Miura committed
1463
    }
1464
    CHAT_UI.dismissLoadingIndicator();
Lee Munkyeong committed
1465
};
1466

Lee Munkyeong committed
1467 1468 1469
CHAT_UI.insertFavoriteUser = function(shopMemberId) {
    $('#userNameCard').modal('hide');
    $('#myNameCard').modal('hide');
1470 1471 1472 1473 1474 1475
    var result;
    if (typeof(android) != "undefined") {
        result = android.addFavoriteUser(shopMemberId);
    } else {
        result = CHAT_DB.addFavoriteUser(shopMemberId);
    }
Lee Munkyeong committed
1476
    if (!result) {
Lee Munkyeong committed
1477 1478
        $('.shopmember_'+shopMemberId).addClass('disable');
        $('.shopmember_'+shopMemberId).removeClass('active');
Lee Munkyeong committed
1479 1480 1481
        CHAT_UI.dismissLoadingIndicator();
        return;
    } else {
Lee Munkyeong committed
1482 1483
        $('.shopmember_'+shopMemberId).removeClass('disable');
        $('.shopmember_'+shopMemberId).addClass('active');
Lee Munkyeong committed
1484
    }
1485
    CHAT_UI.dismissLoadingIndicator();
Lee Munkyeong committed
1486
};
1487

Lee Munkyeong committed
1488
CHAT_UI.removeFavoriteGroup = function(groupId) {
1489 1490
    CHAT_UI.showLoadingIndicator();
    var result;
Takatoshi Miura committed
1491
    if (typeof(android) != "undefined") {
1492
        result = android.removeFavoriteGroup(groupId);
Takatoshi Miura committed
1493
    } else {
1494
        result = CHAT_DB.removeFavoriteGroup(groupId);
1495 1496 1497 1498 1499 1500 1501
    }
    if (!result) {
        $('.group_'+groupId).addClass('active');
        $('.group_'+groupId).removeClass('disable');
    } else {
        $('.group_'+groupId).removeClass('active');
        $('.group_'+groupId).addClass('disable');
Takatoshi Miura committed
1502
    }
1503
    CHAT_UI.dismissLoadingIndicator();
Lee Munkyeong committed
1504
};
1505

Lee Munkyeong committed
1506
CHAT_UI.insertFavoriteGroup = function(groupId) {
1507
    CHAT_UI.showLoadingIndicator();
1508 1509 1510 1511 1512 1513
    var result;
    if (typeof(android) != "undefined") {
        result = android.addFavoriteGroup(groupId);
    } else {
        result = CHAT_DB.addFavoriteGroup(groupId);
    }
Lee Munkyeong committed
1514 1515 1516 1517 1518 1519 1520
    if (!result) {
        $('.group_'+groupId).addClass('disable');
        $('.group_'+groupId).removeClass('active');
    } else {
        $('.group_'+groupId).removeClass('disable');
        $('.group_'+groupId).addClass('active');
    }
1521
    CHAT_UI.dismissLoadingIndicator();
Lee Munkyeong committed
1522 1523 1524
};

//全グループ検索画面表示。
1525 1526
CHAT_UI.refreshAllGroupSearch = function(paramGroupId) {
    var groupId = paramGroupId;
1527 1528
    if (window.location.pathname.includes("chat_room")) {
        if (groupId == "") return;
1529 1530 1531 1532 1533
        if (typeof(android) != "undefined") {
            android.setToMoveGroupId(groupId);
        } else {
            webkit.messageHandlers.setToMoveGroupId.postMessage(groupId);
        }
1534 1535 1536
        window.location.href = "contact.html";
    }

1537
    CHAT_UI.showLoadingIndicator();
1538
    $('#userNameCard').modal('hide');
Lee Munkyeong committed
1539 1540 1541 1542 1543 1544
    $('.cancel').addClass('none');
    $('.search_form input').removeClass('focus');
    $('.search_form input').val('');
    $('.search_form form').removeClass();
    $('.content').removeClass('none');
    $('.overlay_src_msg').empty();
Lee Munkyeong committed
1545
    $('#contactSearch').attr('placeholder', getLocalizedString('searchUserAndGroup'));
Lee Munkyeong committed
1546
    $('#tabAllGroup').prop('checked', true);
Lee Daehyun committed
1547
    
Lee Munkyeong committed
1548
    //オンライン状態であればサーバから情報更新。
1549
    if (IS_ONLINE == 'true') {
Takatoshi Miura committed
1550
        if (typeof(android) != "undefined") {
1551
            android.updateGroupInfo(groupId);
Takatoshi Miura committed
1552
        } else {
Takatoshi Miura committed
1553
            webkit.messageHandlers.updateGroupInfo.postMessage(groupId);
1554
        }
1555
    }
Lee Munkyeong committed
1556 1557

    //画面エリアを初期化。
1558 1559
    $('#rootGroupBtn').off();
    $('#parentGroupBtn').off();
Lee Munkyeong committed
1560
    $('#childGroupListArea').html('');
1561 1562 1563
    $('#userInGroupList').html('');
    $('#groupPathArea').html('');

Lee Munkyeong committed
1564 1565 1566 1567
    //DBからグループ情報を取得。
    var result = CHAT_DB.getGroupInfo(groupId);

    //上位グループ、トップグループ遷移ボタンのイベント追加。
1568 1569
    if (typeof result.parentGroupId !== 'undefined') {
        $('#parentGroupBtn').on('click', function() {
Lee Munkyeong committed
1570
            CHAT_UI.refreshAllGroupSearch(result.parentGroupId);
1571 1572 1573
        });
    }
    if (typeof result.rootGroupId !== 'undefined') {
1574
        if (paramGroupId == 0) { groupId = result.rootGroupId }
1575
        $('#rootGroupBtn').on('click', function() {
Lee Munkyeong committed
1576
            CHAT_UI.refreshAllGroupSearch(result.rootGroupId);
1577 1578
        });
    }
1579 1580 1581 1582 1583 1584 1585
    if (groupId == result.rootGroupId || paramGroupId == '0') {
        $('#rootGroupArea').addClass('none');
        $('#parentGroupArea').addClass('none');
    } else {
        $('#rootGroupArea').removeClass('none');
        $('#parentGroupArea').removeClass('none');
    }
Lee Munkyeong committed
1586 1587 1588 1589 1590 1591
    //該当グループのパースを表示。
    var groupPathTemplate;
    $.get({ url: "./template/template_group_path.html", async: false }
      , function(text) {
        groupPathTemplate = text;
    });
1592 1593

    result.groupPathList.forEach(function(groupPath) {
Lee Munkyeong committed
1594 1595 1596 1597 1598 1599
        let html = Mustache.render(groupPathTemplate, {
            name: groupPath.groupName,
            id: groupPath.groupId
        });
        let obj = jQuery.parseHTML(html);
        $('#groupPathArea').append(obj);
Lee Munkyeong committed
1600
    })
1601

Lee Munkyeong committed
1602
    //該当グループの下位グループ表示。
Lee Munkyeong committed
1603 1604 1605 1606 1607
    var groupTemplate;
    $.get({ url: "./template/template_group_list.html", async: false }
      , function(text) {
        groupTemplate = text;
    });
1608
    result.childGroupList.forEach(function(childGroup) {
Lee Munkyeong committed
1609 1610
        let html = Mustache.render(groupTemplate, {
            name: childGroup.groupName,
1611 1612
            id: childGroup.groupId,
            isFavorite: childGroup.isFavorite
Lee Munkyeong committed
1613
        });
1614

Lee Munkyeong committed
1615
        let obj = $(jQuery.parseHTML(html)).on('click', function() {
1616

Lee Munkyeong committed
1617 1618 1619
        });
        $('#childGroupListArea').append(obj);
    })
1620

Lee Munkyeong committed
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634
    //該当グループの所属ユーザを表示。
    var userTemplate;
    $.get({ url: "./template/template_user_list.html", async: false }
      , function(text) {
        userTemplate = text;
    });
    result.groupUserList.forEach(function(groupUser) {
        groupUser.profileUrl = CHAT.getProfileImgUrl(groupUser.profileUrl)
    })
    let html = Mustache.render(userTemplate, {
        userList: result.groupUserList
    });
    let obj = jQuery.parseHTML(html);
    $('#userInGroupList').append(obj);
1635
    CHAT_UI.dismissLoadingIndicator();
1636 1637
}

Lee Munkyeong committed
1638
CHAT_UI.startChat = function(userShopMemberId,userName) {
1639 1640 1641 1642 1643 1644
    CHAT_UI.showLoadingIndicator();
    var userIdList = [];
    userIdList.push(userShopMemberId);

    // 参加ユーザ名でルーム名を生成
    let newRoomName = CHAT.globalLoginParameter.loginId + ',' +userName;
Takatoshi Miura committed
1645
    if (typeof(android) != "undefined") {
1646
        android.createChatRoom(chatRoomType.DM, userIdList.join(','),newRoomName, makeRoomFlg.NAME_CARD, false);
Takatoshi Miura committed
1647
    } else {
1648
        webkit.messageHandlers.createChatRoom.postMessage({"roomType": "1", "userIdList": userIdList.join(','), "roomName": newRoomName, "screenFlg": makeRoomFlg.NAME_CARD, "isVoice": false});
Takatoshi Miura committed
1649
    }
1650 1651
};

1652 1653 1654 1655 1656 1657 1658 1659
CHAT_UI.startVoice = function(userShopMemberId, userName) {
      CHAT_UI.showLoadingIndicator();
      var userIdList = [];
      userIdList.push(userShopMemberId);

      // 参加ユーザ名でルーム名を生成
      let newRoomName = CHAT.globalLoginParameter.loginId + ',' +userName;
      if (typeof(android) != "undefined") {
1660
          android.createChatRoom(chatRoomType.DM, userIdList.join(','),newRoomName, makeRoomFlg.NAME_CARD, true);
1661
      } else {
1662
          webkit.messageHandlers.createChatRoom.postMessage({"roomType": "1", "userIdList": userIdList.join(','), "roomName": newRoomName, "screenFlg": makeRoomFlg.NAME_CARD, "isVoice": true});
1663 1664 1665
      }
      CHAT_UI.startCollaboration(collaborationType.AUDIO);
}
1666

Lee Munkyeong committed
1667
CHAT_UI.makeNameCard = function(shopMemberId) {
1668 1669 1670
    if (CHAT.globalLoginParameter.shopMemberId == shopMemberId) {
        return;
    }
1671
    var nameCardInfo = CHAT_DB.getNameCardData(shopMemberId);
Lee Munkyeong committed
1672 1673 1674 1675 1676
    var namecardTemplate;
    $.get({ url: "./template/template_user_name_card.html", async: false }
      , function(text) {
        namecardTemplate = text;
    });
1677
    nameCardInfo.profileUrl = CHAT.getProfileImgUrl(nameCardInfo.profileUrl);
Lee Munkyeong committed
1678 1679
    let namecardHtml = Mustache.render(namecardTemplate, {
        shopMemberId: nameCardInfo.shopMemberId,
1680
        profileUrl: nameCardInfo.profileUrl,
1681 1682 1683 1684
        name: nameCardInfo.shopMemberName,
        groupPathList: nameCardInfo.groupPathList,
        chat: getLocalizedString("chat"),
        voice: getLocalizedString("voice"),
Lee Munkyeong committed
1685 1686
        favorite: getLocalizedString("addFavorite"),
        isFavorite: nameCardInfo.isFavorite
1687 1688
    });

Lee Munkyeong committed
1689
    let namecardObj = $(jQuery.parseHTML(namecardHtml)).on('click', function() {
1690 1691
    });

Lee Munkyeong committed
1692 1693
    $('#userProfileModal').html(namecardObj);
    $('#userNameCard').modal('show');
1694 1695
};

Lee Munkyeong committed
1696 1697 1698
CHAT_UI.toggleCategory = function(category) {
  $(category).toggleClass("open");
  $(category).next().slideToggle();
1699
};
1700 1701 1702 1703


// アーカイブ一覧
CHAT_UI.refreshArchiveScreen = function() {
1704 1705
    // loadingIndicatorを表示
    CHAT_UI.showLoadingIndicator();
1706

1707 1708
    // 初期化
    $('#archiveList').html('');
1709

1710 1711
    // アーカイブの様式を読み込む
    const archiveTemplate = $('#archive-template').html();
1712

1713 1714
    // アーカイブ一覧取得
    if (IS_ONLINE == 'true') {
1715 1716
        CHAT_DB.updateArchiveList();
    }
1717

1718 1719
    // ローカルDBのデータを表示
    var archiveList = CHAT_DB.getArchiveList();
Lee Munkyeong committed
1720 1721 1722 1723
    if (typeof archiveList == 'undefined') {
        CHAT_UI.dismissLoadingIndicator();
        return;
    }
Lee Munkyeong committed
1724
    archiveList.forEach(function(archive) {
1725
        var typeImage = "";
1726 1727
        switch(archive.archiveType) {
            case 0: // 画像
1728
                typeImage = "icon/icon_collabo_picture.png";
1729 1730
                break;
            case 1: // 動画
1731
                typeImage = "icon/icon_collabo_videocam.png";
1732 1733
                break;
            case 2: // 音声
1734
                typeImage = "icon/icon_collabo_headset.png";
1735 1736
                break;
            case 3: // 文書
1737
                typeImage = "icon/icon_collabo_document.png";
1738 1739
                break;
            default: // その他
1740
                typeImage = "";
1741 1742
        }
        let html = Mustache.render(archiveTemplate, {
1743 1744 1745
            archiveId: archive.archiveId,
            fileName: archive.archiveName,
            insertDate: archive.archiveDate,
1746
            typeImage: typeImage
1747 1748 1749 1750 1751 1752
        });
        let obj = $(jQuery.parseHTML(html)).on('click', function() {
        });
        $('#archiveList').append(obj);
    });
    
1753
    // loadingIndicatorを非表示
1754
    CHAT_UI.dismissLoadingIndicator();
1755 1756 1757 1758 1759
};


// アーカイブ詳細
CHAT_UI.refreshArchiveDetailScreen = function(archiveId) {
1760 1761
    // loadingIndicatorを表示
    CHAT_UI.showLoadingIndicator();
1762

1763 1764 1765 1766
    // 初期化
    $('#archiveDetail').html('');
    // アーカイブ詳細の様式を読み込む
    const archiveDetailTemplate = $('#archive-detail-template').html();
1767
    if (IS_ONLINE == 'true') {
1768 1769
        CHAT_DB.updateArchiveDetail(archiveId);
    }
1770
    
1771 1772
    // アーカイブ詳細取得
    var archive = CHAT_DB.getArchiveDetail(archiveId);
1773

1774 1775
    // チャットルーム情報を取得
    var roomId = archive.roomId;
1776

1777
    //保存ユーザ情報を取得
Lee Munkyeong committed
1778 1779
    var userInfo = CHAT_DB.getUserInfo(archive.saveUserId);
    userInfo.profileUrl = CHAT.getProfileImgUrl(userInfo.profileUrl);
1780
    // アーカイブ情報を表示
1781
    var html = Mustache.render(archiveDetailTemplate, {
1782 1783 1784 1785 1786
        fileName: archive.archiveName,
        insertDate: archive.archiveDate,
        chatRoomName: archive.roomName,
        chatRoomId: archive.roomId,
        profileImage: userInfo.profileUrl,
1787
        userName: userInfo.shopMemberName,
1788
        userId: userInfo.shopMemberId
1789
    });
1790 1791 1792 1793 1794 1795

    var obj = $(jQuery.parseHTML(html)).on('click', function() {
    });
    $('#archiveDetail').append(obj);

    // プレイヤーの切り替え
1796
    var archiveFilePath = CHAT.createGetDataUrl(archive.filePath, archive.roomId);
1797 1798
    switch(archive.archiveType) {
        case "0": // 画像
1799 1800
        case 0:
            $('#archive_player').prepend('<img class="archive_player" src="'+archiveFilePath+'" />');
1801 1802
            break;
        case "1": // 動画
1803
        case 1:
1804
            $('#archive_player').prepend('<video class="archive_player" src=' + archiveFilePath + ' controls autoplay muted playsinline controlsList="nodownload"></video>');
1805 1806
            break;
        case "2": // 音声
1807
        case 2:
1808
            $('#archive_player').prepend('<audio class="archive_audio_player" src=' + archiveFilePath + ' controls controlsList="nodownload"></audio>');
1809
            $('#archive_player').prepend('<img class="archive_player" src=' + "./img/capture.png" + ' />');
1810 1811
            break;
        case "3": // 文書
1812
        case 3:
1813 1814 1815 1816 1817 1818 1819 1820
            // リリースに文書とその他は含めないため今回は非表示
            break;
        default:
            // リリースに文書とその他は含めないため今回は非表示
    }

    // ユーザの様式を読み込む
    const archiveUserTemplate = $('#archive-user-template').html();
1821 1822

    // 参加ユーザ情報を表示
1823
    let attendUserList = archive.attendUserIds;
1824 1825 1826 1827
    if (typeof(android) != "undefined") {
        // ios実装不要
        attendUserList = JSON.parse(archive.attendUserIds);
    }
1828

1829
    attendUserList.forEach(function(user) {
1830 1831 1832

        var userInfo = CHAT_DB.getUserInfo(user);
        userInfo.profileUrl = CHAT.getProfileImgUrl(userInfo.profileUrl);
1833
        var html = Mustache.render(archiveUserTemplate, {
1834 1835
            profileImage: userInfo.profileUrl,
            userName: userInfo.shopMemberName
1836 1837 1838 1839
        });

        var obj = $(jQuery.parseHTML(html)).on('click', function() {
            // ネームカード表示
1840
            CHAT_UI.makeNameCard(user);
1841
        });
1842

1843 1844
        $('#attendUser').append(obj);
    })
1845 1846 1847 1848

    CHAT_UI.htmlElementTextInitialize(navigator.language);

    // チャットルームへのリンク付け
1849
    document.getElementById('joinChatRoom').onclick = function() {
Lee Munkyeong committed
1850
        CHAT_UI.joinRoom(archive.roomId, archive.roomName);
1851
    }
Lee Munkyeong committed
1852

1853 1854 1855 1856 1857
    // loadingIndicatorを非表示
    CHAT_UI.dismissLoadingIndicator();
};


Kang Donghun committed
1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886
CHAT_UI.refreshMyGroupForMakeRoom = function() {
    $(".modal-backdrop").remove();
    $('#favoriteListForMakeRoom').html('');
    $('#myGroupListForMakeRoom').html('');
    //画面タイトル設定
    let contactListTitle = getLocalizedString("userSearch");
    $('#title').text(contactListTitle);

    // グループの様式を読み込む
    var groupTemplate;
    $.get({ url: "./template/template_make_room_group_list.html", async: false }
      , function(text) {
        groupTemplate = text;
    });

    // ユーザの様式を読み込む
    var userTemplate;
    $.get({ url: "./template/template_make_room_user_list.html", async: false }
      , function(text) {
        userTemplate = text;
    });

    var groupUserTemplate;
    $.get({ url: "./template/template_make_room_group_user_list.html", async: false }
      , function(text) {
        groupUserTemplate = text;
    });

    if (IS_ONLINE == 'true') {
Takatoshi Miura committed
1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897
        if (typeof(android) != "undefined") {
            android.updateGroupInfo('0');
            android.updateMyInfo();
            android.updateGroupUser();
            android.updateFavorite();
        } else {
            webkit.messageHandlers.updateGroupInfo.postMessage("0");
            webkit.messageHandlers.updateMyInfo.postMessage({});
            webkit.messageHandlers.updateGroupUser.postMessage({});
            webkit.messageHandlers.updateFavorite.postMessage({});
        }
Kang Donghun committed
1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
    }

    //お気に入りグループ取得。
    var favoriteGroupList = CHAT_DB.getFavoriteGroups();
    favoriteGroupList.forEach(function(favoriteGroup) {
        let html = Mustache.render(groupTemplate, {
            name: favoriteGroup.groupName,
            id: favoriteGroup.groupId,
        });

        let obj = $(jQuery.parseHTML(html)).on('click', function() {
        });
        $('#favoriteListForMakeRoom').append(obj);
    })
    //お気に入りユーザ取得。
    var favoriteUserList = CHAT_DB.getFavoriteUsers();
    favoriteUserList.forEach(function(favoriteUser) {
        favoriteUser.profileUrl = CHAT.getProfileImgUrl(favoriteUser.profileUrl);
        let findObj = CHAT.globalSelectedUserList.find(function(shopMemberId) {
            return shopMemberId == favoriteUser.shopMemberId;
        })
        if (findObj) {
            favoriteUser.checked = 'checked';
        }
    });
    let html = Mustache.render(userTemplate, {
        userList: favoriteUserList
    });
    let obj = jQuery.parseHTML(html);
    $('#favoriteListForMakeRoom').append(obj);

    /*favoriteUserList.forEach(function(favoriteUser) {
        favoriteUser.profileImagePath = CHAT.getProfileImgUrl(favoriteUser.profileUrl)
        let html = Mustache.render(userTemplate, {
            shopMemberId: favoriteUser.shopMemberId,
            profileImage: favoriteUser.profileImagePath,
            name: favoriteUser.shopMemberName,
            isFavorite: true
        });

        let obj = $(jQuery.parseHTML(html)).on('click', function() {
        });

        $('#favoriteList').append(obj);
    })*/

    var myGroupList = CHAT_DB.getMyGroupUsers();
    myGroupList.forEach(function(myGroup) {

        myGroup.groupUserList.forEach(function(groupUser) {
            groupUser.profileUrl = CHAT.getProfileImgUrl(groupUser.profileUrl)
            let findObj = CHAT.globalSelectedUserList.find(function(shopMemberId) {
                return shopMemberId == groupUser.shopMemberId;
            })
            if (findObj) {
                groupUser.checked = 'checked';
            }
        })
        let html = Mustache.render(groupUserTemplate, {
            groupName: myGroup.groupName,
            groupUserList: myGroup.groupUserList
        });
        let obj = $(jQuery.parseHTML(html)).on('click', function() {
        });

        $('#myGroupListForMakeRoom').append(obj);
    })
}

1967 1968
CHAT_UI.refreshAllGroupForMakeRoom = function(paramGroupId) {
    var groupId = paramGroupId;
Kang Donghun committed
1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979
    $('.cancel').addClass('none');
    $('.search_form input').removeClass('focus');
    $('.search_form input').val('');
    $('.search_form form').removeClass();
    $('.content').removeClass('none');
    $('.overlay_src_msg').empty();

    $('#tabAllGroupOnMakeRoom').prop('checked', true);

    //オンライン状態であればサーバから情報更新。
    if (IS_ONLINE == 'true') {
1980 1981
        if (typeof(android) != "undefined") {
            android.updateGroupInfo(groupId);
1982
        } else {
1983
            webkit.messageHandlers.updateGroupInfo.postMessage(groupId);
1984
        }
Kang Donghun committed
1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003
    }

    //画面エリアを初期化。
    $('#parentGroupBtnForMakeRoom').off();
    $('#rootGroupBtnForMakeRoom').off();
    $('#childGroupListAreaForMakeRoom').html('');
    $('#userInGroupListForMakeRoom').html('');
    $('#groupPathAreaForMakeRoom').html('');

    //DBからグループ情報を取得。
    var result = CHAT_DB.getGroupInfo(groupId);

    //上位グループ、トップグループ遷移ボタンのイベント追加。
    if (typeof result.parentGroupId !== 'undefined') {
        $('#parentGroupBtnForMakeRoom').on('click', function() {
            CHAT_UI.refreshAllGroupForMakeRoom(result.parentGroupId);
        });
    }
    if (typeof result.rootGroupId !== 'undefined') {
2004
        if (paramGroupId == 0) { groupId = result.rootGroupId }
Kang Donghun committed
2005 2006 2007 2008
        $('#rootGroupBtnForMakeRoom').on('click', function() {
            CHAT_UI.refreshAllGroupForMakeRoom(result.rootGroupId);
        });
    }
2009 2010 2011 2012 2013 2014 2015
    if (groupId == result.rootGroupId || paramGroupId == '0') {
        $('#rootGroupArea').addClass('none');
        $('#parentGroupArea').addClass('none');
    } else {
        $('#rootGroupArea').removeClass('none');
        $('#parentGroupArea').removeClass('none');
    }
Kang Donghun committed
2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085
    //該当グループのパースを表示。
    var groupPathTemplate;
    $.get({ url: "./template/template_make_room_group_path.html", async: false }
      , function(text) {
        groupPathTemplate = text;
    });

    var groupPathCount = 0;
    result.groupPathList.forEach(function(groupPath) {
        if (!(groupPathCount < (result.groupPathList.length - 3))) {
            let html = Mustache.render(groupPathTemplate, {
                name: groupPath.groupName,
                id: groupPath.groupId
            });
            let obj = jQuery.parseHTML(html);
            $('#groupPathAreaForMakeRoom').append(obj);
        }
        groupPathCount++;
    })

    //該当グループの下位グループ表示。
    var groupTemplate;
    $.get({ url: "./template/template_make_room_group_list.html", async: false }
      , function(text) {
        groupTemplate = text;
    });

    result.childGroupList.forEach(function(childGroup) {
        let html = Mustache.render(groupTemplate, {
            name: childGroup.groupName,
            id: childGroup.groupId,
        });

        let obj = $(jQuery.parseHTML(html)).on('click', function() {

        });
        $('#childGroupListAreaForMakeRoom').append(obj);
    })

    //該当グループの所属ユーザを表示。
    var userTemplate;
    $.get({ url: "./template/template_make_room_user_list.html", async: false }
      , function(text) {
        userTemplate = text;
    });
    result.groupUserList.forEach(function(groupUser) {
        groupUser.profileUrl = CHAT.getProfileImgUrl(groupUser.profileUrl)
        let findObj = CHAT.globalSelectedUserList.find(function(shopMemberId) {
            return shopMemberId == groupUser.shopMemberId;
        })
        if (findObj) {
            groupUser.checked = 'checked';
        }
    })
    let html = Mustache.render(userTemplate, {
        userList: result.groupUserList
    });
    let obj = jQuery.parseHTML(html);
    $('#userInGroupListForMakeRoom').append(obj);
};

CHAT_UI.checkForMakeChat = function(checkMemberId) {
    let findObj = CHAT.globalSelectedUserList.find(function(shopMemberId) {
        return shopMemberId == checkMemberId;
    })
    if (findObj) {
        // remove
        CHAT.globalSelectedUserList = CHAT.globalSelectedUserList.filter(function(shopMemberId) {
            return checkMemberId != shopMemberId;
        });
2086
        $('.checkbox' + checkMemberId).prop("checked", false).trigger("change");
Kang Donghun committed
2087 2088
    } else {
        // add
2089
        CHAT.globalSelectedUserList.push(checkMemberId);
2090
        $('.checkbox' + checkMemberId).prop("checked", true).trigger("change");
Kang Donghun committed
2091
    }
2092

Kang Donghun committed
2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138
    let cnt = CHAT.globalSelectedUserList.length;
    if (CHAT.globalSelectedUserList.length > 0) {
        $('.select_member_num').text(cnt);
    } else {
        $('.select_member_num').text('0');
    }
};

CHAT_UI.showMakeRoomConfirmView = function() {
    $('#selectedUserList').html('');

    var userTemplate;
    $.get({ url: "./template/template_make_room_confirm_user_list.html", async: false }
      , function(text) {
        userTemplate = text;
    });

    var selectedUserList = CHAT_DB.loadSelectedUsers();

    selectedUserList.forEach(function(user){
         let html = Mustache.render(userTemplate, {
                     id: user.shopMemberId,
                     profileImage: CHAT.getProfileImgUrl(user.profileUrl),
                     name: user.shopMemberName
                 });
         let obj = jQuery.parseHTML(html);
         $('#selectedUserList').append(obj);
     })

     $("#makeRoomBtn").off().on('click', function() {
                 // #36130に対応
         const trimmedRoomName = $('#newRoomName').val().trim();
         if (trimmedRoomName.length == 0) {

             // loadingIndicatorを表示
             CHAT_UI.showLoadingIndicator();
             let userIdList = new Array();
             let userNameList = new Array();

             selectedUserList.forEach(function(user){
                userIdList.push(user.shopMemberId);
                userNameList.push(user.shopMemberName);
             })

             // 参加ユーザ名でルーム名を生成
             let newRoomName = CHAT.globalLoginParameter.loginId + ',' + userNameList.join(',');
Takatoshi Miura committed
2139
             if (typeof(android) != "undefined") {
2140
                 android.createChatRoom("1", userIdList.join(','), newRoomName, makeRoomFlg.MAKE_ROOM, false);
Takatoshi Miura committed
2141
             } else {
2142
                webkit.messageHandlers.createChatRoom.postMessage({"roomType": "1", "userIdList": userIdList.join(','), "roomName": newRoomName, "screenFlg": makeRoomFlg.MAKE_ROOM, "isVoice": false});
Takatoshi Miura committed
2143
             }
Kang Donghun committed
2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185
         } else if(trimmedRoomName.includes(';') || trimmedRoomName.includes('/') || trimmedRoomName.includes('?') || trimmedRoomName.includes(':') || trimmedRoomName.includes("@")
              || trimmedRoomName.includes('&') || trimmedRoomName.includes('=') || trimmedRoomName.includes("+") || trimmedRoomName.includes('$') || trimmedRoomName.includes(",") || trimmedRoomName.includes('-')
              || trimmedRoomName.includes('_') || trimmedRoomName.includes('.') || trimmedRoomName.includes('!') || trimmedRoomName.includes('~') || trimmedRoomName.includes('*') || trimmedRoomName.includes("\'")
              || trimmedRoomName.includes('(') || trimmedRoomName.includes(')') || trimmedRoomName.includes('#') || trimmedRoomName.includes("\\") || trimmedRoomName.includes("\"") || trimmedRoomName.includes("`")) {
             // #36147
             // #36174
             $("#customAlertTitle").text(getLocalizedString("invalidCharacter"));
             $("#customAlertOk").text(getLocalizedString("yesTitle"));

             $('#customAlert').appendTo("body").modal({
                 backdrop: 'static',
                 keyboard: false
             })
             .on('click', '#customAlertOk', function(e) {
             });
         } else if (trimmedRoomName.length > 20) {
             // #36142
             var inputText = $('#newRoomName').val().trim(); // #36142 文字列の前又は後の空白文字列を削除

             // #36174
             $("#customAlertTitle").text(getLocalizedString("nameTooLong"));
             $("#customAlertOk").text(getLocalizedString("yesTitle"));

             $('#customAlert').appendTo("body").modal({
                 backdrop: 'static',
                 keyboard: false
             })
             .on('click', '#customAlertOk', function(e) {
                 $('#newRoomName').val(inputText.substr(0, $('#newRoomName').prop("maxlength")));
             });

         } else {
             //loadingIndicatorを表示
             CHAT_UI.showLoadingIndicator();
             let userIdList = new Array();

             selectedUserList.forEach(function(user){
                userIdList.push(user.shopMemberId);
             })

             // ルーム名のtrimmingした後、URIencodingを行う
             const encodedRoomName = encodeURIComponent(trimmedRoomName);
Takatoshi Miura committed
2186
             if (typeof(android) != "undefined") {
2187
                android.createChatRoom("1", userIdList.join(','), trimmedRoomName, makeRoomFlg.MAKE_ROOM, false);
Takatoshi Miura committed
2188
             } else {
2189
                webkit.messageHandlers.createChatRoom.postMessage({"roomType": "1", "userIdList": userIdList.join(','), "roomName": trimmedRoomName, "screenFlg": makeRoomFlg.MAKE_ROOM, "isVoice": false});
Takatoshi Miura committed
2190
             }
Kang Donghun committed
2191 2192
         }
     });
Lee Munkyeong committed
2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222
}

CHAT_UI.showAddUserConfirmView = function() {
    $('#selectedUserList').html('');

    var userTemplate;
    $.get({ url: "./template/template_add_user_confirm_user_list.html", async: false }
        , function(text) {
            userTemplate = text;
        }
    );

    var selectedUserList = CHAT_DB.loadSelectedUsers();

    selectedUserList.forEach(function(user){
         let html = Mustache.render(userTemplate, {
                 id: user.shopMemberId,
                 profileImage: CHAT.getProfileImgUrl(user.profileUrl),
                 name: user.shopMemberName
         });
         let obj = jQuery.parseHTML(html);
         $('#selectedUserList').append(obj);
    })

    $("#addUserBtn").off().on('click', function() {
        CHAT_UI.showLoadingIndicator();
        let userIdList = new Array();
        selectedUserList.forEach(function(user){
            userIdList.push(user.shopMemberId);
        })
Takatoshi Miura committed
2223
        if (typeof(android) != "undefined") {
2224
            android.inviteUsers(userIdList.join(','), false);
Takatoshi Miura committed
2225 2226 2227
        } else {
            webkit.messageHandlers.inviteUsers.postMessage({"userIdList": userIdList.join(',')});
        }
Lee Munkyeong committed
2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240
     });
}

CHAT_UI.refreshMyGroupForAddUser = function() {
    $(".modal-backdrop").remove();
    $('#favoriteListForMakeRoom').html('');
    $('#myGroupListForMakeRoom').html('');
    //画面タイトル設定
    let contactListTitle = getLocalizedString("userSearch");
    $('#title').text(contactListTitle);

    // グループの様式を読み込む
    var groupTemplate;
2241
    $.get({ url: "./template/template_add_user_group_list.html", async: false }
Lee Munkyeong committed
2242 2243 2244 2245 2246 2247
      , function(text) {
        groupTemplate = text;
    });

    // ユーザの様式を読み込む
    var userTemplate;
2248
    $.get({ url: "./template/template_add_user_user_list.html", async: false }
Lee Munkyeong committed
2249 2250 2251 2252 2253
      , function(text) {
        userTemplate = text;
    });

    var groupUserTemplate;
2254
    $.get({ url: "./template/template_add_user_group_user_list.html", async: false }
Lee Munkyeong committed
2255 2256 2257 2258 2259
      , function(text) {
        groupUserTemplate = text;
    });

    if (IS_ONLINE == 'true') {
Takatoshi Miura committed
2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270
        if (typeof(android) != "undefined") {
            android.updateGroupInfo('0');
            android.updateMyInfo();
            android.updateGroupUser();
            android.updateFavorite();
        } else {
            webkit.messageHandlers.updateGroupInfo.postMessage("0");
            webkit.messageHandlers.updateMyInfo.postMessage({});
            webkit.messageHandlers.updateGroupUser.postMessage({});
            webkit.messageHandlers.updateFavorite.postMessage({});
        }
Lee Munkyeong committed
2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321
    }

    //お気に入りグループ取得。
    var favoriteGroupList = CHAT_DB.getFavoriteGroups();
    favoriteGroupList.forEach(function(favoriteGroup) {
        let html = Mustache.render(groupTemplate, {
            name: favoriteGroup.groupName,
            id: favoriteGroup.groupId,
        });

        let obj = $(jQuery.parseHTML(html)).on('click', function() {
        });
        $('#favoriteListForMakeRoom').append(obj);
    })
    //お気に入りユーザ取得。
    var favoriteUserList = CHAT_DB.getFavoriteUsersNotInRoom();
    favoriteUserList.forEach(function(favoriteUser) {
        favoriteUser.profileUrl = CHAT.getProfileImgUrl(favoriteUser.profileUrl);
        let findObj = CHAT.globalSelectedUserList.find(function(shopMemberId) {
            return shopMemberId == favoriteUser.shopMemberId;
        })
        if (findObj) {
            favoriteUser.checked = 'checked';
        }
    });
    let html = Mustache.render(userTemplate, {
        userList: favoriteUserList
    });
    let obj = jQuery.parseHTML(html);
    $('#favoriteListForMakeRoom').append(obj);

    var myGroupList = CHAT_DB.getMyGroupUsersNotInRoom();
    myGroupList.forEach(function(myGroup) {

        myGroup.groupUserList.forEach(function(groupUser) {
            groupUser.profileUrl = CHAT.getProfileImgUrl(groupUser.profileUrl)
            let findObj = CHAT.globalSelectedUserList.find(function(shopMemberId) {
                return shopMemberId == groupUser.shopMemberId;
            })
            if (findObj) {
                groupUser.checked = 'checked';
            }
        })
        let html = Mustache.render(groupUserTemplate, {
            groupName: myGroup.groupName,
            groupUserList: myGroup.groupUserList
        });
        let obj = $(jQuery.parseHTML(html)).on('click', function() {
        });

        $('#myGroupListForMakeRoom').append(obj);
2322
    });
Lee Munkyeong committed
2323 2324
}

2325 2326 2327 2328 2329 2330 2331 2332 2333
CHAT_UI.refreshAllGroupForAddUser = function(paramGroupId) {
    var groupId = paramGroupId;
    $('.cancel').addClass('none');
    $('.search_form input').removeClass('focus');
    $('.search_form input').val('');
    $('.search_form form').removeClass();
    $('.content').removeClass('none');
    $('.overlay_src_msg').empty();

2334
    $('#tabAllGroupOnAddUser').prop('checked', true);
2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345

    //オンライン状態であればサーバから情報更新。
    if (IS_ONLINE == 'true') {
        if (typeof(android) != "undefined") {
            android.updateGroupInfo(groupId);
        } else {
            webkit.messageHandlers.updateGroupInfo.postMessage(groupId);
        }
    }

    //画面エリアを初期化。
2346 2347 2348 2349 2350
    $('#parentGroupBtnForAddUser').off();
    $('#rootGroupBtnForAddUser').off();
    $('#childGroupListAreaForAddUser').html('');
    $('#userInGroupListForAddUser').html('');
    $('#groupPathAreaForAddUser').html('');
2351 2352 2353 2354 2355 2356

    //DBからグループ情報を取得。
    var result = CHAT_DB.getGroupInfoForAddUser(groupId);

    //上位グループ、トップグループ遷移ボタンのイベント追加。
    if (typeof result.parentGroupId !== 'undefined') {
2357
        $('#parentGroupBtnForAddUser').on('click', function() {
2358 2359 2360 2361 2362
            CHAT_UI.refreshAllGroupForAddUser(result.parentGroupId);
        });
    }
    if (typeof result.rootGroupId !== 'undefined') {
        if (paramGroupId == 0) { groupId = result.rootGroupId }
2363
        $('#rootGroupBtnForAddUser').on('click', function() {
2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375
            CHAT_UI.refreshAllGroupForAddUser(result.rootGroupId);
        });
    }
    if (groupId == result.rootGroupId || paramGroupId == '0') {
        $('#rootGroupArea').addClass('none');
        $('#parentGroupArea').addClass('none');
    } else {
        $('#rootGroupArea').removeClass('none');
        $('#parentGroupArea').removeClass('none');
    }
    //該当グループのパースを表示。
    var groupPathTemplate;
2376
    $.get({ url: "./template/template_add_user_group_path.html", async: false }
2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388
      , function(text) {
        groupPathTemplate = text;
    });

    var groupPathCount = 0;
    result.groupPathList.forEach(function(groupPath) {
        if (!(groupPathCount < (result.groupPathList.length - 3))) {
            let html = Mustache.render(groupPathTemplate, {
                name: groupPath.groupName,
                id: groupPath.groupId
            });
            let obj = jQuery.parseHTML(html);
2389
            $('#groupPathAreaForAddUser').append(obj);
2390 2391 2392 2393 2394 2395
        }
        groupPathCount++;
    })

    //該当グループの下位グループ表示。
    var groupTemplate;
2396
    $.get({ url: "./template/template_add_user_group_list.html", async: false }
2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409
      , function(text) {
        groupTemplate = text;
    });

    result.childGroupList.forEach(function(childGroup) {
        let html = Mustache.render(groupTemplate, {
            name: childGroup.groupName,
            id: childGroup.groupId,
        });

        let obj = $(jQuery.parseHTML(html)).on('click', function() {

        });
2410
        $('#childGroupListAreaForAddUser').append(obj);
2411 2412 2413 2414
    })

    //該当グループの所属ユーザを表示。
    var userTemplate;
2415
    $.get({ url: "./template/template_add_user_user_list.html", async: false }
2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431
      , function(text) {
        userTemplate = text;
    });
    result.groupUserList.forEach(function(groupUser) {
        groupUser.profileUrl = CHAT.getProfileImgUrl(groupUser.profileUrl)
        let findObj = CHAT.globalSelectedUserList.find(function(shopMemberId) {
            return shopMemberId == groupUser.shopMemberId;
        })
        if (findObj) {
            groupUser.checked = 'checked';
        }
    })
    let html = Mustache.render(userTemplate, {
        userList: result.groupUserList
    });
    let obj = jQuery.parseHTML(html);
2432
    $('#userInGroupListForAddUser').append(obj);
2433 2434
};

Lee Munkyeong committed
2435 2436 2437
CHAT_UI.refreshForOnline = function() {
    IS_ONLINE = 'true';
    $('.craeteRoomButton').show();
2438 2439 2440 2441 2442 2443 2444
    $('.footer_item a').removeClass('ui-state-disabled');
    $('#videoUploadButton').removeClass('ui-state-disabled');
    $('#imageInputButton').removeClass('ui-state-disabled');
    $('#messageSend').prop('disabled', false);
    $('#messageInput').prop('disabled', false);
    $('#messageInput').prop('placeholder', 'メッセージを入力してください');
    $('#favoriteButton').prop('disabled', false);
Lee Munkyeong committed
2445
    $('#roomMenu').show();
Lee Munkyeong committed
2446
    $('.fa-download').show();
Lee Munkyeong committed
2447 2448
    if (typeof $('#roomTitle').val() != 'undefined') {
        CHAT_SOCKET.connectSocket();
Lee Munkyeong committed
2449
        socket.emit('join', CHAT.globalLoginParameter, function() {
Lee Munkyeong committed
2450 2451 2452 2453 2454 2455 2456
        });
    }
}

CHAT_UI.refreshForOffline = function() {
    IS_ONLINE = 'false';
    $('.craeteRoomButton').hide();
2457 2458 2459 2460 2461
    $('.footer_item a').addClass('ui-state-disabled');
    $('#videoUploadButton').addClass('ui-state-disabled');
    $('#imageInputButton').addClass('ui-state-disabled');
    $('#messageSend').prop('disabled', true);
    $('#messageInput').prop('disabled', true);
2462
    $('#messageInput').prop('placeholder', '');
2463
    $('#favoriteButton').prop('disabled', true);
Lee Munkyeong committed
2464
    $('#roomMenu').hide();
Lee Munkyeong committed
2465
    $('.fa-download').hide();
2466 2467 2468 2469
}

CHAT_UI.displayExistRoom = function(roomId) {
    if (confirm('error_already_exist_same_user')) {
2470 2471 2472 2473 2474
        if (CHAT_UTIL.isIOS()) {
            webkit.messageHandlers.joinRoom.postMessage({"roomId": roomId});
        } else if (CHAT_UTIL.isAndroid()) {
            android.joinRoom(roomId, '');
        }
2475 2476
    }
    return;
Lee Munkyeong committed
2477 2478
}

Lee Munkyeong committed
2479
CHAT_UI.joinCollaboration = function(collaborationType, meetingId = 0) {
Lee Munkyeong committed
2480
    if (CHAT_UTIL.isIOS()) {
2481
        webkit.messageHandlers.joinCollaboration.postMessage({"collaborationType": collaborationType, "meetingId": meetingId});
Lee Munkyeong committed
2482
    } else if (CHAT_UTIL.isAndroid()) {
Lee Munkyeong committed
2483
        android.joinCollaboration(collaborationType, meetingId);
Lee Munkyeong committed
2484 2485 2486 2487 2488
    }
}

CHAT_UI.startCollaboration = function(collaborationType) {
    if (CHAT_UTIL.isIOS()) {
Takatoshi Miura committed
2489
        webkit.messageHandlers.startCollaboration.postMessage(collaborationType);
Lee Munkyeong committed
2490 2491 2492
    } else if (CHAT_UTIL.isAndroid()) {
        android.startCollaboration(collaborationType);
    }
Lee Munkyeong committed
2493
}
Lee Munkyeong committed
2494

2495

2496
CHAT_UI.refreshJoinedCollaboration = function(loginIdList) {
2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534
    CHAT_UI.showLoadingIndicator();
    $('#collaboration_overlay_user_list').html('');

    var joinedUserListTemplate;
    $.get({ url: "./collaboration_overlay_user_list.html", async: false }
      , function(text) {
        joinedUserListTemplate = text;
    });

    var joinedUserList = CHAT_DB.getUserListByLoginId(loginIdList);

    joinedUserList.forEach(function(user) {
        user.profileUrl = CHAT.getProfileImgUrl(user.profileUrl);
    })

    let html = Mustache.render(joinedUserListTemplate, {
        joinedUserList: joinedUserList
    });

    let obj = jQuery.parseHTML(html);
    $('#collaboration_overlay_user_list').append(obj);

    CHAT_UI.dismissLoadingIndicator();
}

CHAT_UI.refreshMyGroupForAddUserInCollaboration = function() {
    if (CHAT.globalSelectedUserList.length > 0) {
        $('.select_member_num').text(CHAT.globalSelectedUserList.length);
    } else {
        $('.select_member_num').text('0');
    }
    $('#favoriteListForAddUserInCollaboration').html('');
    $('#myGroupListForAddUserInCollaboration').html('');

    $('#tabMyGroupOnAddUserInCollaboration').prop('checked', true);

    // グループの様式を読み込む
    var groupTemplate;
2535
    $.get({ url: "./template/template_add_user_group_list_in_collaboration.html", async: false }
2536 2537 2538 2539 2540 2541
      , function(text) {
        groupTemplate = text;
    });

    // ユーザの様式を読み込む
    var userTemplate;
2542
    $.get({ url: "./template/template_add_user_user_list_in_collaboration.html", async: false }
2543 2544 2545 2546 2547
      , function(text) {
        userTemplate = text;
    });

    var groupUserTemplate;
2548
    $.get({ url: "./template/template_add_user_group_user_list_in_collaboration.html", async: false }
2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616
      , function(text) {
        groupUserTemplate = text;
    });

    if (IS_ONLINE == 'true') {
        if (typeof(android) != "undefined") {
            android.updateGroupInfo('0');
            android.updateMyInfo();
            android.updateGroupUser();
            android.updateFavorite();
        } else {
            webkit.messageHandlers.updateGroupInfo.postMessage("0");
            webkit.messageHandlers.updateMyInfo.postMessage({});
            webkit.messageHandlers.updateGroupUser.postMessage({});
            webkit.messageHandlers.updateFavorite.postMessage({});
        }
    }

    //お気に入りグループ取得。
    var favoriteGroupList = CHAT_DB.getFavoriteGroups();
    favoriteGroupList.forEach(function(favoriteGroup) {
        let html = Mustache.render(groupTemplate, {
            name: favoriteGroup.groupName,
            id: favoriteGroup.groupId,
        });

        let obj = $(jQuery.parseHTML(html)).on('click', function() {
        });
        $('#favoriteListForAddUserInCollaboration').append(obj);
    })
    //お気に入りユーザ取得。
    var favoriteUserList = CHAT_DB.getFavoriteUsersNotInRoom();
    favoriteUserList.forEach(function(favoriteUser) {
        favoriteUser.profileUrl = CHAT.getProfileImgUrl(favoriteUser.profileUrl);
        let findObj = CHAT.globalSelectedUserList.find(function(shopMemberId) {
            return shopMemberId == favoriteUser.shopMemberId;
        })
        if (findObj) {
            favoriteUser.checked = 'checked';
        }
    });
    let html = Mustache.render(userTemplate, {
        userList: favoriteUserList
    });
    let obj = jQuery.parseHTML(html);
    $('#favoriteListForAddUserInCollaboration').append(obj);

    var myGroupList = CHAT_DB.getMyGroupUsersNotInRoom();
    myGroupList.forEach(function(myGroup) {

        myGroup.groupUserList.forEach(function(groupUser) {
            groupUser.profileUrl = CHAT.getProfileImgUrl(groupUser.profileUrl)
            let findObj = CHAT.globalSelectedUserList.find(function(shopMemberId) {
                return shopMemberId == groupUser.shopMemberId;
            })
            if (findObj) {
                groupUser.checked = 'checked';
            }
        })
        let html = Mustache.render(groupUserTemplate, {
            groupName: myGroup.groupName,
            groupUserList: myGroup.groupUserList
        });
        let obj = $(jQuery.parseHTML(html)).on('click', function() {
        });

        $('#myGroupListForAddUserInCollaboration').append(obj);
    });
2617
    $('#addUserInCollaboration').modal('show');
2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666
    CHAT_UI.dismissLoadingIndicator();
}

CHAT_UI.refreshAllGroupForAddUserInCollaboration = function(paramGroupId) {

    var groupId = paramGroupId;
    $('.content').removeClass('none');

    $('#tabAllGroupOnAddUserInCollaboration').prop('checked', true);

    //オンライン状態であればサーバから情報更新。
    if (IS_ONLINE == 'true') {
        if (typeof(android) != "undefined") {
            android.updateGroupInfo(groupId);
        } else {
            webkit.messageHandlers.updateGroupInfo.postMessage(groupId);
        }
    }

    //画面エリアを初期化。
    $('#parentGroupBtnForAddUserInCollaboration').off();
    $('#rootGroupBtnForAddUserInCollaboration').off();
    $('#childGroupListAreaForAddUserInCollaboration').html('');
    $('#userInGroupListForAddUserInCollaboration').html('');
    $('#groupPathAreaForAddUserInCollaboration').html('');

    //DBからグループ情報を取得。
    var result = CHAT_DB.getGroupInfoForAddUser(groupId);
    //上位グループ、トップグループ遷移ボタンのイベント追加。
    if (typeof result.parentGroupId !== 'undefined') {
        $('#parentGroupBtnForAddUserInCollaboration').on('click', function() {
            CHAT_UI.refreshAllGroupForAddUserInCollaboration(result.parentGroupId);
        });
    }
    if (typeof result.rootGroupId !== 'undefined') {
        if (paramGroupId == 0) { groupId = result.rootGroupId }
        $('#rootGroupBtnForAddUserInCollaboration').on('click', function() {
            CHAT_UI.refreshAllGroupForAddUserInCollaboration(result.rootGroupId);
        });
    }
    if (groupId == result.rootGroupId || paramGroupId == '0') {
        $('#rootGroupAreaInCollaboration').addClass('none');
        $('#parentGroupAreaInCollaboration').addClass('none');
    } else {
        $('#rootGroupAreaInCollaboration').removeClass('none');
        $('#parentGroupAreaInCollaboration').removeClass('none');
    }
    //該当グループのパースを表示。
    var groupPathTemplate;
2667
    $.get({ url: "./template/template_add_user_group_path_in_collaboration.html", async: false }
2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686
      , function(text) {
        groupPathTemplate = text;
    });

    var groupPathCount = 0;
    result.groupPathList.forEach(function(groupPath) {
        if (!(groupPathCount < (result.groupPathList.length - 3))) {
            let html = Mustache.render(groupPathTemplate, {
                name: groupPath.groupName,
                id: groupPath.groupId
            });
            let obj = jQuery.parseHTML(html);
            $('#groupPathAreaForAddUserInCollaboration').append(obj);
        }
        groupPathCount++;
    })

    //該当グループの下位グループ表示。
    var groupTemplate;
2687
    $.get({ url: "./template/template_add_user_group_list_in_collaboration.html", async: false }
2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705
      , function(text) {
        groupTemplate = text;
    });

    result.childGroupList.forEach(function(childGroup) {
        let html = Mustache.render(groupTemplate, {
            name: childGroup.groupName,
            id: childGroup.groupId,
        });

        let obj = $(jQuery.parseHTML(html)).on('click', function() {

        });
        $('#childGroupListAreaForAddUserInCollaboration').append(obj);
    })

    //該当グループの所属ユーザを表示。
    var userTemplate;
2706
    $.get({ url: "./template/template_add_user_user_list_in_collaboration.html", async: false }
2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726
      , function(text) {
        userTemplate = text;
    });
    result.groupUserList.forEach(function(groupUser) {
        groupUser.profileUrl = CHAT.getProfileImgUrl(groupUser.profileUrl)
        let findObj = CHAT.globalSelectedUserList.find(function(shopMemberId) {
            return shopMemberId == groupUser.shopMemberId;
        })
        if (findObj) {
            groupUser.checked = 'checked';
        }
    })
    let html = Mustache.render(userTemplate, {
        userList: result.groupUserList
    });
    let obj = jQuery.parseHTML(html);
    $('#userInGroupListForAddUserInCollaboration').append(obj);

}

2727
CHAT_UI.makeNameCardInCollaboration = function(shopMemberId) {
2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740
    if (CHAT.globalLoginParameter.shopMemberId == shopMemberId) {
        return;
    }
    var nameCardInfo = CHAT_DB.getNameCardData(shopMemberId);
    var namecardTemplate;
    var changeHostTemplate;


    $.get({ url: "./modal_collabo_profile.html", async: false }
      , function(text) {
        namecardTemplate = text;
    });

2741
    let isCollaborationHost = coview_api.getRoomUsers();
2742 2743 2744 2745
    nameCardInfo.profileUrl = CHAT.getProfileImgUrl(nameCardInfo.profileUrl);
    let namecardHtml = Mustache.render(namecardTemplate, {
        shopMemberId: nameCardInfo.shopMemberId,
        profileUrl: nameCardInfo.profileUrl,
2746
        loginId: nameCardInfo.loginId,
2747 2748 2749
        name: nameCardInfo.shopMemberName,
        groupPathList: nameCardInfo.groupPathList,
        isFavorite: nameCardInfo.isFavorite,
2750
        isHost: isCollaborationHost
2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780
    });

    let namecardObj = $(jQuery.parseHTML(namecardHtml)).on('click', function() {
    });

    $('#userProfileModalInCollaboration').html(namecardObj);
    $('#userNameCardInCollaboration').modal('show');
};

CHAT_UI.removeFavoriteUserInCollaboration = function(shopMemberId) {
    CHAT_UI.showLoadingIndicator();
    $('#userNameCardInCollaboration').modal('hide');
    var result;
    if (typeof(android) != "undefined") {
        result = android.removeFavoriteUser(shopMemberId);
    } else {
        result = CHAT_DB.removeFavoriteUser(shopMemberId);
    }
    CHAT_UI.dismissLoadingIndicator();
};

CHAT_UI.insertFavoriteUserInCollaboration = function(shopMemberId) {
    $('#userNameCardInCollaboration').modal('hide');
    var result;
    if (typeof(android) != "undefined") {
        result = android.addFavoriteUser(shopMemberId);
    } else {
        result = CHAT_DB.addFavoriteUser(shopMemberId);
    }
    CHAT_UI.dismissLoadingIndicator();
2781 2782
};

2783 2784 2785 2786 2787 2788 2789
CHAT_UI.startPipMode() = function() {
    if (CHAT_UTIL.isIOS()) {
    } else if (CHAT_UTIL.isAndroid()) {
        android.startPipMode();
    }
}

2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813
CHAT_UI.confirmInviteUserListInCollaboration = function() {
    var selectedUsers = CHAT_DB.loadSelectedUsers();
    if (selectedUsers != "") {
        $('#selectedUserListinCollaboration').html('');

        var selectedUserList = CHAT_DB.loadSelectedUsers();
        selectedUserList.forEach(function(user) {
            user.profileUrl = CHAT.getProfileImgUrl(user.profileUrl);
        });

        var modalTemplate;
        $.get({ url: "./modal_add_user_confirm.html", async: false }
            , function(text) {
            modalTemplate = text;
        });
        let html = Mustache.render(modalTemplate, {
            userList: selectedUserList
        });
        let obj = jQuery.parseHTML(html);
        $('#modal_add_user_confirm').html(obj);
        $('#modalAddUserConfirm').modal('show');
    } else {

    }
2814 2815 2816 2817 2818
    $("#cancelAddUserBtn").off().on('click', function() {
        console.log('cancelClick');
        $('#modalAddUserConfirm').modal('hide');
        $('#addUserInCollaboration').modal('show');
    });
2819 2820 2821 2822 2823 2824 2825 2826

    $("#addUserBtn").off().on('click', function() {
        CHAT_UI.showLoadingIndicator();
        let userIdList = new Array();
        selectedUserList.forEach(function(user){
            userIdList.push(user.shopMemberId);
        })
        if (typeof(android) != "undefined") {
2827
            android.inviteCollaboration(userIdList.join(','), CHAT_UTIL.getCollaborationType(globalUserInfo.coWorkType));
2828
        } else {
2829
            webkit.messageHandlers.inviteCollaboration.postMessage({"userIdList": userIdList.join(','), "collaborationType": CHAT_UTIL.getCollaborationType(globalUserInfo.coWorkType)});
2830 2831 2832
        }
        $('#modalAddUserConfirm').modal('hide');
     });
2833
}