Commit 95d6a023 by Kim Peace

Fixed chat -add-user js

parent 582948f7
// 名前空間 // 名前空間
var CHAT_ADD_USER = {}; var CHAT_ADD_USER = {};
document.addEventListener('DOMContentLoaded', function() { document.addEventListener("DOMContentLoaded", function () {
// メンバー検索 // メンバー検索
$('#chat_add_user .search_form input[type="search"]').click(function (e) { bindMemberSearch();
// iOSキーボード変換検知用
bindiOSKeyBoardEvent();
});
// ユーザー検索
CHAT_ADD_USER.searchUser = function (keyword) {
const isAllGroup = $("#tabAllGroupOnAddUser").is(":checked");
const overlayMessage = $(".overlay_src_msg");
overlayMessage.empty();
//全グループ検索画面
if (isAllGroup) {
//グループデータ検索
const groupList = CHAT_DB.getGroupByName(keyword);
searchGroupData(groupList);
//ユーザデータ検索
var userList = CHAT_DB.getAllGroupShopMemberNotInRoomByName(keyword);
searchUserData(userList);
// Set NoResult
if (userList.length == 0 && groupList.length == 0) {
const noResultMessage = getNoResultMessage();
overlayMessage.append(noResultMessage);
} //連絡先画面
} else {
var userList = CHAT_DB.getMyGroupShopMemberNotInRoomByName(keyword);
searchUserData(userList);
if (userList.length == 0) {
const noResultMessage = getNoResultMessage();
overlayMessage.append(noResultMessage);
}
}
};
/** UTILS */
var bindMemberSearch = function () {
const searchInput = $('#chat_add_user .search_form input[type="search"]');
searchInput.click(function (e) {
//画面タイトル設定 //画面タイトル設定
let contactListTitle = getLocalizedString("userSearch"); let contactListTitle = getLocalizedString("userSearch");
$("#addUserTitle").text(contactListTitle); $("#addUserTitle").text(contactListTitle);
}); });
$('#chat_add_user .search_form input[type="search"]').keyup(function (e) { searchInput.keyup(function (e) {
var keyword = $('#chat_add_user .search_form input[type="search"]').val(); const keyword = searchInput.val();
if (e.key == "Enter" || e.KeyCode == 13) { const enterKeyPressed = e.key == "Enter" || e.KeyCode == 13;
if (keyword != "" && keyword.length != 0) { const keywordNotEmpty = keyword != "" && keyword.length != 0;
$('#chat_add_user .search_form input[type="search"]').blur(); const keywordEmpty = keyword == "" || keyword.length < 2;
if (enterKeyPressed) {
if (keywordNotEmpty) {
searchInput.blur();
return false; return false;
} }
} else if (keyword == "" || keyword.length < 2) { } else if (keywordEmpty) {
$(".overlay_src_msg").empty(); $(".overlay_src_msg").empty();
return false; return false;
} }
CHAT_ADD_USER.searchUser(keyword); CHAT_ADD_USER.searchUser(keyword);
if (e.key == "Enter" || e.KeyCode == 13) {
$('#chat_add_user .search_form input[type="search"]').blur(); if (enterKeyPressed) {
searchInput.blur();
return; return;
} }
}); });
// iOSキーボード変換検知用 };
$('#chat_add_user .search_form input[type="search"]').on(
"compositionend", var bindiOSKeyBoardEvent = function () {
function () { searchInput.on("compositionend", function () {
if (CHAT_UTIL.isIOS()) { if (CHAT_UTIL.isIOS()) {
var keyword = $( var keyword = searchInput.val();
'#chat_add_user .search_form input[type="search"]' CHAT_ADD_USER.searchUser(keyword);
).val();
CHAT_ADD_USER.searchUser(keyword);
}
} }
); });
}); };
// ユーザー検索 var searchGroupData = function (groupList) {
CHAT_ADD_USER.searchUser = function (keyword) { const groupTemplate = getGroupTemplate();
var isAllGroup = $("#tabAllGroupOnAddUser").is(":checked");
$(".overlay_src_msg").empty();
//全グループ検索画面 groupList.forEach(function (group) {
if (isAllGroup) { let html = renderGroupTemplate(
//グループデータ検索 groupTemplate,
var groupList = CHAT_DB.getGroupByName(keyword); group.groupName,
var groupTemplate; group.groupId
$.get(
{ url: "./template/template_make_room_group_list.html", async: false },
function (text) {
groupTemplate = text;
}
); );
groupList.forEach(function (group) { let obj = jQuery.parseHTML(html);
let html = Mustache.render(groupTemplate, { overlayMessage.append(obj);
name: group.groupName, });
id: group.groupId, };
});
let obj = jQuery.parseHTML(html); var getGroupTemplate = function () {
$(".overlay_src_msg").append(obj); var groupTemplate;
}); $.get(
{ url: "./template/template_make_room_group_list.html", async: false },
function (text) {
groupTemplate = text;
}
);
return groupTemplate;
};
//ユーザデータ検索 var renderGroupTemplate = function (groupTemplate, groupName, groupID) {
var userList = CHAT_DB.getAllGroupShopMemberNotInRoomByName(keyword); return Mustache.render(groupTemplate, {
var userTemplate; name: groupName,
$.get( id: groupID,
{ url: "./template/template_make_room_user_list.html", async: false }, });
function (text) { };
userTemplate = text;
} var searchUserData = function (userList) {
); const userTemplate = getUserTemplate();
userList.forEach(function (user) { userList.forEach(function (user) {
user.profileUrl = CHAT.getProfileImgUrl(user.profileUrl); setUserProfile(user);
let findObj = CHAT.globalSelectedUserList.find(function (shopMemberId) { checkUser(user);
return shopMemberId == user.shopMemberId; });
}); let html = renderUserTemplate(userTemplate, userList);
if (findObj) { let obj = jQuery.parseHTML(html);
user.checked = "checked"; overlayMessage.append(obj);
} };
});
let html = Mustache.render(userTemplate, { var getUserTemplate = function () {
userList: userList, var userTemplate;
}); $.get(
let obj = jQuery.parseHTML(html); { url: "./template/template_make_room_user_list.html", async: false },
$(".overlay_src_msg").append(obj); function (text) {
if (userList.length == 0 && groupList.length == 0) { userTemplate = text;
const noResultMsg = $("<div/>", {
width: "auto",
style: "text-align: center",
});
noResultMsg.append(getLocalizedString("noResult"));
$(".overlay_src_msg").append(noResultMsg);
} //連絡先画面
} else {
var userList = CHAT_DB.getMyGroupShopMemberNotInRoomByName(keyword);
var userTemplate;
$.get(
{ url: "./template/template_make_room_user_list.html", async: false },
function (text) {
userTemplate = text;
}
);
userList.forEach(function (user) {
user.profileUrl = CHAT.getProfileImgUrl(user.profileUrl);
let findObj = CHAT.globalSelectedUserList.find(function (shopMemberId) {
return shopMemberId == user.shopMemberId;
});
if (findObj) {
user.checked = "checked";
}
});
let html = Mustache.render(userTemplate, {
userList: userList,
});
let obj = jQuery.parseHTML(html);
$(".overlay_src_msg").html(obj);
if (userList.length == 0) {
const noResultMsg = $("<div/>", {
width: "auto",
style: "text-align: center",
});
noResultMsg.append(getLocalizedString("noResult"));
$(".overlay_src_msg").append(noResultMsg);
} }
);
return userTemplate;
};
var setUserProfile = function (user) {
user.profileUrl = CHAT.getProfileImgUrl(user.profileUrl);
};
var checkUser = function (user) {
let findObj = CHAT.globalSelectedUserList.find(function (shopMemberId) {
return shopMemberId == user.shopMemberId;
});
if (findObj) {
user.checked = "checked";
} }
}; };
var renderUserTemplate = function (userTemplate, userList) {
return Mustache.render(userTemplate, {
userList: userList,
});
};
var getNoResultMessage = function () {
const noResultMsg = $("<div/>", {
width: "auto",
style: "text-align: center",
});
noResultMsg.append(getLocalizedString("noResult"));
return noResultMsg;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment