Commit 582948f7 by Kim Peace

Fixed archive.js

parent 3218bb7e
// 名前空間
var ARCHIVE_UI = {};
$(function () {
document.addEventListener("DOMContentLoaded", function () {
// アーカイブ検索
bindArchiveSearch();
// iOSキーボード変換検知用
bindiOSKeyBoardEvent();
});
ARCHIVE_UI.refreshSearchScreen = function (keyword) {
const archiveList = CHAT_DB.getArchiveByName(keyword);
const typeImage = getArchiveTypeIconURL(archive.archiveType);
getArchiveTemplate().then(function (archiveTemplate) {
archiveList.forEach(function (archive) {
let html = renderArchiveTemplate(
archiveTemplate,
archive.archiveId,
archive.archiveName,
archive.archiveDate,
typeImage
);
let obj = jQuery.parseHTML(html);
$(".overlay_src_msg").append(obj);
});
});
};
//* UTILS *//
const ARCHIVE_TYPE = {
PICTURE: 0,
VIDEO: 1,
VOICE: 2,
DOCUMENT: 3,
};
var getArchiveTypeIconURL = function (type) {
switch (type) {
case ARCHIVE_TYPE.PICTURE:
return "icon/icon_collabo_picture.png";
case ARCHIVE_TYPE.VIDEO:
return "icon/icon_collabo_videocam.png";
case ARCHIVE_TYPE.VOICE:
return "icon/icon_collabo_headset.png";
case ARCHIVE_TYPE.DOCUMENT:
return "icon/icon_collabo_document.png";
default:
return "";
}
};
var getArchiveTemplate = function () {
return new Promise(function (resolve, reject) {
$.get(
{ url: "./template/template_archive_list.html", async: false },
function (text) {
resolve(text);
}
);
});
};
var bindArchiveSearch = function () {
$('#archive .search_form input[type="search"]').keyup(function (e) {
var keyword = $('#archive .search_form input[type="search"]').val();
if (e.KeyCode == 13 || e.key == "Enter") {
if (keyword.length != 0 && keyword != "") {
const enterKeyPressed = e.KeyCode == 13 || e.key == "Enter";
const keywordEmpty = keyword == "" || keyword.length < 2;
const keywordNotEmpty = keyword.length != 0 && keyword != "";
if (enterKeyPressed) {
if (keywordNotEmpty) {
$('#archive .search_form input[type="search"]').blur();
return;
}
} else if (keyword == "" || keyword.length < 2) {
} else if (keywordEmpty) {
$(".overlay_src_msg").empty();
return;
}
......@@ -18,13 +81,15 @@ $(function () {
ARCHIVE_UI.refreshSearchScreen(keyword);
if (e.KeyCode == 13 || e.key == "Enter") {
if (enterKeyPressed) {
$('#archive .search_form input[type="search"]').blur();
return;
}
// 検索結果を表示
});
// iOSキーボード変換検知用
};
var bindiOSKeyBoardEvent = function () {
$('#archive .search_form input[type="search"]').on(
"compositionend",
function () {
......@@ -35,46 +100,19 @@ $(function () {
}
}
);
});
ARCHIVE_UI.refreshSearchScreen = function (keyword) {
var archiveList = CHAT_DB.getArchiveByName(keyword);
var archiveTemplate;
$.get(
{ url: "./template/template_archive_list.html", async: false },
function (text) {
archiveTemplate = text;
}
);
archiveList.forEach(function (archive) {
var typeImage = "";
switch (archive.archiveType) {
case 0: // 画像
typeImage = "icon/icon_collabo_picture.png";
break;
case 1: // 動画
typeImage = "icon/icon_collabo_videocam.png";
break;
case 2: // 音声
typeImage = "icon/icon_collabo_headset.png";
break;
case 3: // 文書
typeImage = "icon/icon_collabo_document.png";
break;
default:
// その他
typeImage = "";
}
let html = Mustache.render(archiveTemplate, {
archiveId: archive.archiveId,
fileName: archive.archiveName,
insertDate: archive.archiveDate,
typeImage: typeImage,
});
};
let obj = jQuery.parseHTML(html);
$(".overlay_src_msg").append(obj);
var renderArchiveTemplate = function (
html,
archiveId,
archiveName,
archiveDate,
typeImageURL
) {
return Mustache.render(html, {
archiveId: archiveId,
fileName: archiveName,
insertDate: archiveDate,
typeImage: typeImageURL,
});
};
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