chat-management-common.js 5.97 KB
Newer Older
1 2 3 4 5 6 7 8
var ChatManagementCommon = {};

//招待するメンバーを保存する変数
ChatManagementCommon.selectedUserList = new Array();

ChatManagementCommon.showMakeRoomConfirmView = function () {
  $("#selectedUserList").html("");

Kim Peace committed
9
  const userTemplate = getTemplate(TemplateURL.MAKE_ROOM_CONFIRM_USER_LIST);
10

Kim Peace committed
11
  const selectedUserList = NativeBridgeDataSource.loadSelectedUsers();
12 13

  selectedUserList.forEach(function (user) {
Kim Peace committed
14
    const html = Mustache.render(userTemplate, {
15 16 17 18
      id: user.shopMemberId,
      profileImage: Common.getProfileImgUrl(user.profileUrl),
      name: user.shopMemberName,
    });
Kim Peace committed
19
    const obj = jQuery.parseHTML(html);
20 21 22 23 24 25 26 27 28 29 30
    $("#selectedUserList").append(obj);
  });

  $("#makeRoomBtn")
    .off()
    .on("click", function () {
      // #36130に対応
      const trimmedRoomName = $("#newRoomName").val().trim();
      if (trimmedRoomName.length == 0) {
        // loadingIndicatorを表示
        Common.showLoadingIndicator();
Kim Peace committed
31
        let userIDList = new Array();
32 33 34
        let userNameList = new Array();

        selectedUserList.forEach(function (user) {
Kim Peace committed
35
          userIDList.push(user.shopMemberId);
36 37 38 39 40
          userNameList.push(user.shopMemberName);
        });

        // 参加ユーザ名でルーム名を生成
        let newRoomName =
41
          currentUserInfo.loginID + "," + userNameList.join(",");
42 43
        NativeBridgeDelegate.createChatRoom(
          ChatRoomType.DM,
Kim Peace committed
44
          userIDList.join(","),
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
          newRoomName,
          MakeRoomFlag.MAKE_ROOM,
          false
        );
      } 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を表示
        Common.showLoadingIndicator();
108
        let userIdList = selectedUserList.map((user) => user.shopMemberId);
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128

        // TODO: check why here using trimmedroomname instead of encodedRoomName
        // ルーム名のtrimmingした後、URIencodingを行う
        const encodedRoomName = encodeURIComponent(trimmedRoomName);
        NativeBridgeDelegate.createChatRoom(
          ChatRoomType.DM,
          userIdList.join(","),
          trimmedRoomName,
          MakeRoomFlag.MAKE_ROOM,
          false
        );
      }
    });

  $("#newRoomName").attr("placeholder", getLocalizedString("newRoomName"));
};

ChatManagementCommon.showAddUserConfirmView = function () {
  $("#selectedUserList").html("");

Kim Peace committed
129 130
  const userTemplate = getTemplate(TemplateURL.ADD_USER_CONFIRM_USER_LIST);
  const selectedUserList = NativeBridgeDataSource.loadSelectedUsers();
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153

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

  $("#addUserBtn")
    .off()
    .on("click", function () {
      Common.showLoadingIndicator();
      let userIdList = new Array();
      selectedUserList.forEach(function (user) {
        userIdList.push(user.shopMemberId);
      });
      NativeBridgeDelegate.inviteUsers(userIdList.join(","));
    });
};

Kim Peace committed
154
ChatManagementCommon.checkForMakeChat = function (checkMemberID) {
155
  let findObj = ChatManagementCommon.selectedUserList.find(function (
Kim Peace committed
156
    shopMemberID
157
  ) {
Kim Peace committed
158
    return shopMemberID == checkMemberID;
159
  });
Kim Peace committed
160

161 162 163
  if (findObj) {
    // remove
    ChatManagementCommon.selectedUserList =
Kim Peace committed
164 165
      ChatManagementCommon.selectedUserList.filter(function (shopMemberID) {
        return checkMemberID != shopMemberID;
166
      });
Kim Peace committed
167
    ChatManagementCommon.updateCheckBox(checkMemberID, false);
168 169
  } else {
    // add
Kim Peace committed
170 171
    ChatManagementCommon.selectedUserList.push(checkMemberID);
    ChatManagementCommon.updateCheckBox(checkMemberID, true);
172 173
  }

Kim Peace committed
174
  const cnt = ChatManagementCommon.selectedUserList.length;
175 176 177 178 179 180
  if (ChatManagementCommon.selectedUserList.length > 0) {
    $(".select_member_num").text(cnt);
  } else {
    $(".select_member_num").text("0");
  }
};
Kim Peace committed
181 182 183 184 185 186

ChatManagementCommon.updateCheckBox = function (checkMemberID, checked) {
  $(".checkbox" + checkMemberID)
    .prop("checked", checked)
    .trigger("change");
};