archive.js 9.75 KB
Newer Older
1
// 名前空間
2
var ArchiveUI = {};
3 4 5

document.addEventListener("DOMContentLoaded", function () {
  // アーカイブ検索
Kim Peace committed
6
  ArchiveUI.bindArchiveSearch();
7
  // iOSキーボード変換検知用
Kim Peace committed
8
  ArchiveUI.bindiOSKeyBoardEvent();
9 10
});

11
ArchiveUI.refreshSearchScreen = function (keyword) {
12
  const archiveList = NativeBridgeDataSource.getArchiveByName(keyword);
Kim Peace committed
13
  const typeImage = ArchiveUI.getArchiveTypeIconURL(archive.archiveType);
14

Kim Peace committed
15
  ArchiveUI.getArchiveTemplate().then(function (archiveTemplate) {
16
    archiveList.forEach(function (archive) {
Kim Peace committed
17
      let html = ArchiveUI.renderArchiveTemplate(
18 19 20 21 22 23 24 25 26 27 28 29 30
        archiveTemplate,
        archive.archiveId,
        archive.archiveName,
        archive.archiveDate,
        typeImage
      );

      let obj = jQuery.parseHTML(html);
      $(".overlay_src_msg").append(obj);
    });
  });
};

Kim Peace committed
31
ArchiveUI.getArchiveTypeIconURL = function (type) {
32 33
  switch (type) {
    case ARCHIVE_TYPE.PICTURE:
34
      return "icon/icon_collabo_picture.svg";
35
    case ARCHIVE_TYPE.VIDEO:
36
      return "icon/icon_collabo_videocam.svg";
37
    case ARCHIVE_TYPE.VOICE:
38
      return "icon/icon_collabo_headset.svg";
39
    case ARCHIVE_TYPE.DOCUMENT:
40
      return "icon/icon_collabo_document.svg";
41 42 43 44 45
    default:
      return "";
  }
};

Kim Peace committed
46
ArchiveUI.getArchiveTemplate = function () {
47 48 49 50 51 52 53
  return new Promise(function (resolve, reject) {
    $.get({ url: TemplateURL.ARCHIVE_LIST, async: false }, function (text) {
      resolve(text);
    });
  });
};

Kim Peace committed
54
ArchiveUI.bindArchiveSearch = function () {
55 56
  const searchInput = $('#archive .search_form input[type="search"]');
  searchInput.keyup(function (e) {
Kim Peace committed
57
    const keyword = searchInput.val();
58 59 60 61 62 63 64 65 66 67 68 69 70 71
    const enterKeyPressed = e.KeyCode == 13 || e.key == "Enter";
    const keywordEmpty = keyword == "" || keyword.length < 2;
    const keywordNotEmpty = keyword.length != 0 && keyword != "";
    if (enterKeyPressed) {
      if (keywordNotEmpty) {
        searchInput.blur();
        return;
      }
    } else if (keywordEmpty) {
      $(".overlay_src_msg").empty();
      return;
    }
    $(".overlay_src_msg").empty();

72
    ArchiveUI.refreshSearchScreen(keyword);
73 74 75 76 77 78 79 80 81

    if (enterKeyPressed) {
      searchInput.blur();
      return;
    }
    // 検索結果を表示
  });
};

Kim Peace committed
82
ArchiveUI.bindiOSKeyBoardEvent = function () {
83 84 85
  const searchInput = $('#archive .search_form input[type="search"]');
  searchInput.on("compositionend", function () {
    if (deviceInfo.isiOS()) {
Kim Peace committed
86
      const keyword = searchInput.val();
87
      $(".overlay_src_msg").empty();
88
      ArchiveUI.refreshSearchScreen(keyword);
89 90 91 92
    }
  });
};

Kim Peace committed
93
ArchiveUI.renderArchiveTemplate = function (
94 95 96 97 98 99 100 101 102 103 104 105 106 107
  html,
  archiveId,
  archiveName,
  archiveDate,
  typeImageURL
) {
  return Mustache.render(html, {
    archiveId: archiveId,
    fileName: archiveName,
    insertDate: archiveDate,
    typeImage: typeImageURL,
  });
};

108 109 110 111
/*****************
 *  アーカイブ詳細
 ****************/
ArchiveUI.refreshArchiveDetailScreen = function (archiveId) {
112 113 114 115 116 117
  // loadingIndicatorを表示
  Common.showLoadingIndicator();

  // 初期化
  $("#archiveDetail").html("");

118
  if (serverInfo.isOnline == true) {
119 120
    NativeBridgeDelegate.updateArchiveDetail(archiveId);
  }
121

122 123 124
  // アーカイブ詳細取得
  const archive = NativeBridgeDataSource.getArchiveDetail(archiveId);

125
  // template archive detail
Kim Peace committed
126
  ArchiveUI.appendArchiveDetailScreen(archive);
127 128

  // setup player
Kim Peace committed
129
  ArchiveUI.appendPlayer(archive);
130 131

  // append attended users
Kim Peace committed
132
  ArchiveUI.appendAttendUsers(archive.attendUserIds);
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153

  // set languages
  currentUserInfo.configureLanguage();

  // TODO: peacekim:: check localization works or not
  $(".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"));

  // チャットルームへのリンク付け
  document.getElementById("joinChatRoom").onclick = function () {
    NativeBridgeDelegate.joinRoom(archive.roomId, archive.roomName);
  };

  // loadingIndicatorを非表示
  Common.dismissLoadingIndicator();
};

Kim Peace committed
154
ArchiveUI.appendArchiveDetailScreen = function (archive) {
155 156 157 158
  // 保存ユーザ情報を取得
  const userInfo = NativeBridgeDataSource.getUserInfo(archive.saveUserId);
  userInfo.profileUrl = Common.getProfileImgUrl(userInfo.profileUrl);

159
  // アーカイブ詳細の様式を読み込む
Kim Peace committed
160
  const archiveDetailTemplate = getTemplate(TemplateURL.ARCHIVE_DETAIL);
161

162 163 164 165 166 167 168 169 170 171 172 173 174
  // アーカイブ情報を表示
  const html = Mustache.render(archiveDetailTemplate, {
    fileName: archive.archiveName,
    insertDate: archive.archiveDate,
    chatRoomName: archive.roomName,
    chatRoomId: archive.roomId,
    profileImage: userInfo.profileUrl,
    userName: userInfo.shopMemberName,
    userId: userInfo.shopMemberId,
  });

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

Kim Peace committed
177
ArchiveUI.appendPlayer = function (archive) {
178
  // プレイヤーの切り替え
179
  const archiveFilePath = ArchiveUI.createGetDataUrl(
180 181 182 183 184 185 186
    archive.filePath,
    archive.roomId
  );

  switch (archive.archiveType) {
    case "0": // 画像
    case 0:
Kim Peace committed
187
      ArchiveUI.appendImageTypePlayer(archiveFilePath);
188 189 190
      break;
    case "1": // 動画
    case 1:
Kim Peace committed
191
      ArchiveUI.appendVideoTypePlayer(archiveFilePath);
192 193 194
      break;
    case "2": // 音声
    case 2:
Kim Peace committed
195
      ArchiveUI.appendVoiceTypePlayer(archiveFilePath);
196 197 198 199 200 201 202 203
      break;
    case "3": // 文書
    case 3:
      // リリースに文書とその他は含めないため今回は非表示
      break;
    default:
    // リリースに文書とその他は含めないため今回は非表示
  }
204 205
};

Kim Peace committed
206
ArchiveUI.appendImageTypePlayer = function (filePath) {
207 208 209 210
  $("#archive_player").prepend(
    '<img class="archive_player" src="' + filePath + '" />'
  );
};
211

Kim Peace committed
212
ArchiveUI.appendVideoTypePlayer = function (filePath) {
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
  if (deviceInfo.isiOS()) {
    $("#archive_player").prepend(
      '<video class="archive_player" controls autoplay muted playsinline controlsList="nodownload"><source src="' +
        filePath +
        '" type="video/mp4"><source src="' +
        filePath +
        '" type="video/ogv"><source src="' +
        filePath +
        '" type="video/webm"></video>'
    );
  } else {
    $("#archive_player").prepend(
      '<video class="archive_player" src=' +
        filePath +
        ' controls autoplay muted playsinline controlsList="nodownload"></video>'
    );
  }
};

Kim Peace committed
232
ArchiveUI.appendVoiceTypePlayer = function (filePath) {
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
  if (deviceInfo.isiOS()) {
    $("#archive_player").prepend(
      '<audio class="archive_audio_player" controls controlsList="nodownload"><source src="' +
        filePath +
        '" type="audio/wav"><source src="' +
        filePath +
        '" type="audio/ogg"></audio>'
    );
  } else {
    $("#archive_player").prepend(
      '<audio class="archive_audio_player" src=' +
        filePath +
        ' controls controlsList="nodownload"></audio>'
    );
  }
  $("#archive_player").prepend(
    '<img class="archive_player" src=' + "./img/capture.png" + " />"
  );
};

Kim Peace committed
253
ArchiveUI.appendAttendUsers = function (attendedUserList) {
254
  // ユーザの様式を読み込む
Kim Peace committed
255
  const archiveUserTemplate = getTemplate(TemplateURL.ARCHIVE_USER);
256 257 258

  if (typeof android != "undefined") {
    // ios実装不要
Kim Peace committed
259
    attendedUserList = JSON.parse(attendedUserList);
260 261
  }

Kim Peace committed
262
  attendedUserList.forEach(function (user) {
263 264 265
    if (user == "") {
      return;
    }
Kim Peace committed
266
    const userInfo = NativeBridgeDataSource.getUserInfo(user);
267 268 269 270 271 272 273 274
    userInfo.profileUrl = Common.getProfileImgUrl(userInfo.profileUrl);
    const html = Mustache.render(archiveUserTemplate, {
      profileImage: userInfo.profileUrl,
      userName: userInfo.shopMemberName,
    });

    const obj = $(jQuery.parseHTML(html)).on("click", function () {
      // ネームカード表示
275
      Namecard.makeNameCard(user);
276 277 278 279 280 281
    });

    $("#attendUser").append(obj);
  });
};

282
ArchiveUI.createGetDataUrl = function (fileName, roomId) {
Kim Peace committed
283
  return (
284 285 286 287 288 289
    serverInfo.cmsURL +
    "/chatapi/file/getImage?sid=" +
    currentUserInfo.sid +
    "&fileName=" +
    fileName +
    "&roomId=" +
Kim Peace committed
290 291
    roomId
  );
292 293 294
};

// アーカイブ一覧
295
ArchiveUI.refreshArchiveScreen = function () {
296 297 298 299 300 301 302
  // loadingIndicatorを表示
  Common.showLoadingIndicator();

  // 初期化
  $("#archiveList").html("");

  // アーカイブの様式を読み込む
Kim Peace committed
303
  const archiveTemplate = getTemplate(TemplateURL.ARCHIVE);
304 305

  // アーカイブ一覧取得
306
  if (serverInfo.isOnline == true) {
307 308 309 310
    NativeBridgeDelegate.updateArchiveList();
  }

  // ローカルDBのデータを表示
Kim Peace committed
311
  const archiveList = NativeBridgeDataSource.getArchiveList();
312 313 314 315 316 317 318
  if (typeof archiveList == "undefined") {
    Common.dismissLoadingIndicator();
    return;
  }
  archiveList.forEach(function (archive) {
    var typeImage = "";
    switch (archive.archiveType) {
319 320
      case ARCHIVE_TYPE.PICTURE: // 画像
        typeImage = "icon/icon_collabo_picture.svg";
321
        break;
322 323
      case ARCHIVE_TYPE.VIDEO: // 動画
        typeImage = "icon/icon_collabo_videocam.svg";
324
        break;
325 326
      case ARCHIVE_TYPE.VOICE: // 音声
        typeImage = "icon/icon_collabo_headset.svg";
327
        break;
328 329
      case ARCHIVE_TYPE.DOCUMENT: // 文書
        typeImage = "icon/icon_collabo_document.svg";
330 331 332 333
        break;
      default:
        // その他
        typeImage = "";
334
        break;
335
    }
Kim Peace committed
336
    const html = Mustache.render(archiveTemplate, {
337 338 339 340 341
      archiveId: archive.archiveId,
      fileName: archive.archiveName,
      insertDate: archive.archiveDate,
      typeImage: typeImage,
    });
Kim Peace committed
342
    const obj = $(jQuery.parseHTML(html)).on("click", function () {});
343 344 345 346 347 348
    $("#archiveList").append(obj);
  });

  // loadingIndicatorを非表示
  Common.dismissLoadingIndicator();
};