archive.js 1.83 KB
Newer Older
Takatoshi Miura committed
1 2 3
// 名前空間
var ARCHIVE_UI = {};

藤川諒 committed
4 5
$(function() {
  // アーカイブ検索
6 7
  $('#archive .search_form input[type="search"]').keyup(function(e) {

Takatoshi Miura committed
8 9

    var keyword = $('#archive .search_form input[type="search"]').val();
10 11 12 13 14 15 16 17 18 19
    if (e.KeyCode == 13 || e.key == "Enter") {
        if (keyword.length != 0 && keyword != '') {
            $('#archive .search_form input[type="search"]').blur();
            return;
        }
    } else if (keyword == '' || keyword.length < 2) {
        $('.overlay_src_msg').empty();
        return;
    }
    $('.overlay_src_msg').empty();
Takatoshi Miura committed
20

21 22
    ARCHIVE_UI.refreshSearchScreen(keyword);
    
23 24 25 26
    if (e.KeyCode == 13 || e.key == "Enter") {
       $('#archive .search_form input[type="search"]').blur();
       return;
    }
Takatoshi Miura committed
27 28 29
    // 検索結果を表示
  });
});
Takatoshi Miura committed
30

Takatoshi Miura committed
31 32 33 34 35 36 37
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;
  });
Takatoshi Miura committed
38

Takatoshi Miura committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
  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 = "";
    }
Takatoshi Miura committed
57

Takatoshi Miura committed
58 59 60 61 62 63 64 65 66
    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);
藤川諒 committed
67
  });
Takatoshi Miura committed
68
};