collaboration-add-user.js 12.3 KB
Newer Older
Kim Peace committed
1
CollaborationUI.initialBindAddUserButton = function () {
Kim Peace committed
2
  console.log("peacekim:: CollaborationUI.initialBindAddUserButton");
Kim Peace committed
3 4
  // ユーザー招待メンバー検索
  $(".add_user_btn").click(function () {
5 6 7
    console.log(
      "peacekim:: CollaborationUI.initialBindAddUserButton add_user_btn clicked"
    );
Kim Peace committed
8
    CollaborationUI.enableScroll();
Kim Peace committed
9 10 11 12 13 14 15
    Common.showLoadingIndicator();
    ChatManagementCommon.selectedUserList = [];
    CollaborationUI.refreshMyGroupForAddUserInCollaboration();
    $("#addUserConfirmBtnInCollaboration")
      .off()
      .on("click", function () {
        $("#addUserInCollaboration").modal("hide");
16 17 18 19
        console.log(
          "peacekim:: CollaborationUI.initialBindAddUserButton addUserConfirmBtnInCollaboration clicked ChatManagementCommon.selectedUserList: " +
            ChatManagementCommon.selectedUserList
        );
20 21 22 23

        if (ChatManagementCommon.selectedUserList.length == 0) {
          return;
        }
24

Kim Peace committed
25 26 27 28 29 30 31 32 33
        const selectedUserList =
          ChatManagementCommon.selectedUserList.join(",");
        NativeBridgeDelegate.saveSelectedUserList(selectedUserList);
        CollaborationUI.confirmInviteUserListInCollaboration();
      });
  });
};

$("#tabMyGroupOnAddUserInCollaboration").on("click", function (e) {
34 35 36
  console.log(
    "peacekim:: CollaborationUI.initialBindAddUserButton tabMyGroupOnAddUserInCollaboration clicked"
  );
Kim Peace committed
37 38 39 40
  CollaborationUI.refreshMyGroupForAddUserInCollaboration();
});

$("#tabAllGroupOnAddUserInCollaboration").on("click", function (e) {
41 42 43
  console.log(
    "peacekim:: CollaborationUI.initialBindAddUserButton tabAllGroupOnAddUserInCollaboration clicked"
  );
Kim Peace committed
44 45 46 47
  CollaborationUI.refreshAllGroupForAddUserInCollaboration("0");
});

CollaborationUI.refreshMyGroupForAddUserInCollaboration = function () {
48 49 50
  console.log(
    "peacekim:: CollaborationUI.initialBindAddUserButton refreshMyGroupForAddUserInCollaboration"
  );
Kim Peace committed
51 52 53 54 55 56 57 58 59 60
  if (ChatManagementCommon.selectedUserList.length > 0) {
    $(".select_member_num").text(ChatManagementCommon.selectedUserList.length);
  } else {
    $(".select_member_num").text("0");
  }
  $("#favoriteListForAddUserInCollaboration").html("");
  $("#myGroupListForAddUserInCollaboration").html("");

  $("#tabMyGroupOnAddUserInCollaboration").prop("checked", true);

Kim Peace committed
61
  NativeBridgeDelegate.updateContactInfo();
Kim Peace committed
62

Kim Peace committed
63
  CollaborationUI.appendFavoriteGroupList();
Kim Peace committed
64

Kim Peace committed
65
  CollaborationUI.appendFavoriteUserList();
Kim Peace committed
66

Kim Peace committed
67 68 69 70 71
  CollaborationUI.appendMyGroupList();

  $("#addUserInCollaboration").modal("show");
  Common.dismissLoadingIndicator();
};
Kim Peace committed
72

Kim Peace committed
73
CollaborationUI.appendFavoriteGroupList = function () {
Kim Peace committed
74
  console.log("peacekim:: CollaborationUI.appendFavoriteGroupList");
Kim Peace committed
75 76 77 78
  // グループの様式を読み込む
  const groupTemplate = getTemplate(
    TemplateURL.ADD_USER_GROUP_LIST_IN_COLLABORATION
  );
Kim Peace committed
79 80 81 82 83 84 85 86 87 88 89
  //お気に入りグループ取得。
  const favoriteGroupList = NativeBridgeDataSource.getFavoriteGroups();
  favoriteGroupList.forEach(function (favoriteGroup) {
    let html = Mustache.render(groupTemplate, {
      name: favoriteGroup.groupName,
      id: favoriteGroup.groupId,
    });

    let obj = $(jQuery.parseHTML(html)).on("click", function () {});
    $("#favoriteListForAddUserInCollaboration").append(obj);
  });
Kim Peace committed
90 91 92
};

CollaborationUI.appendFavoriteUserList = function () {
Kim Peace committed
93
  console.log("peacekim:: CollaborationUI.appendFavoriteUserList");
Kim Peace committed
94 95 96 97
  // ユーザの様式を読み込む
  const userTemplate = getTemplate(
    TemplateURL.ADD_USER_USER_LIST_IN_COLLABORATION
  );
Kim Peace committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
  //お気に入りユーザ取得。
  const favoriteUserList = NativeBridgeDataSource.getFavoriteUsersNotInRoom();
  favoriteUserList.forEach(function (favoriteUser) {
    favoriteUser.profileUrl = Common.getProfileImgUrl(favoriteUser.profileUrl);
    let findObj = ChatManagementCommon.selectedUserList.find(function (
      shopMemberId
    ) {
      return shopMemberId == favoriteUser.shopMemberId;
    });
    if (findObj) {
      favoriteUser.checked = "checked";
    }
  });
  let html = Mustache.render(userTemplate, {
    userList: favoriteUserList,
  });
  let obj = jQuery.parseHTML(html);
  $("#favoriteListForAddUserInCollaboration").append(obj);
Kim Peace committed
116
};
Kim Peace committed
117

Kim Peace committed
118
CollaborationUI.appendMyGroupList = function () {
Kim Peace committed
119
  console.log("peacekim:: CollaborationUI.appendMyGroupList");
Kim Peace committed
120 121 122
  const groupUserTemplate = getTemplate(
    TemplateURL.ADD_USER_GROUP_USER_LIST_IN_COLLABORATION
  );
Kim Peace committed
123 124 125 126 127
  const myGroupList = NativeBridgeDataSource.getMyGroupUsersNotInRoom();
  myGroupList.forEach(function (myGroup) {
    myGroup.groupUserList.forEach(function (groupUser) {
      groupUser.profileUrl = Common.getProfileImgUrl(groupUser.profileUrl);
      let findObj = ChatManagementCommon.selectedUserList.find(function (
Kim Peace committed
128
        shopMemberID
Kim Peace committed
129
      ) {
Kim Peace committed
130
        return shopMemberID == groupUser.shopMemberId;
Kim Peace committed
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
      });
      if (findObj) {
        groupUser.checked = "checked";
      }
    });
    let html = Mustache.render(groupUserTemplate, {
      groupName: myGroup.groupName,
      groupUserList: myGroup.groupUserList,
    });
    let obj = $(jQuery.parseHTML(html)).on("click", function () {});

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

Kim Peace committed
146
CollaborationUI.refreshAllGroupForAddUserInCollaboration = function (groupID) {
147 148 149
  console.log(
    "peacekim:: CollaborationUI.refreshAllGroupForAddUserInCollaboration"
  );
Kim Peace committed
150 151 152 153
  $(".content").removeClass("none");

  $("#tabAllGroupOnAddUserInCollaboration").prop("checked", true);

Kim Peace committed
154
  NativeBridgeDelegate.updateGroupInfo(groupID);
Kim Peace committed
155 156 157 158 159 160 161 162 163

  //画面エリアを初期化。
  $("#parentGroupBtnForAddUserInCollaboration").off();
  $("#rootGroupBtnForAddUserInCollaboration").off();
  $("#childGroupListAreaForAddUserInCollaboration").html("");
  $("#userInGroupListForAddUserInCollaboration").html("");
  $("#groupPathAreaForAddUserInCollaboration").html("");

  //DBからグループ情報を取得。
Kim Peace committed
164 165
  const result = NativeBridgeDataSource.getGroupInfoForAddUser(groupID);

Kim Peace committed
166
  //上位グループ、トップグループ遷移ボタンのイベント追加。
Kim Peace committed
167 168 169 170 171 172 173 174 175 176 177 178 179
  CollaborationUI.appendRootGroupAndParentGroupIfNeeded(
    result.rootGroupId,
    result.parentGroupId,
    groupID
  );

  //該当グループのパースを表示。
  CollaborationUI.appendGroupPath(result.groupPathList);

  //該当グループの下位グループ表示。
  CollaborationUI.appendChildGroups(result.childGroupList);

  //該当グループの所属ユーザを表示。
180
  CollaborationUI.appendUsers(result.groupUserList);
Kim Peace committed
181 182 183
};

CollaborationUI.bindOnClickParentGroup = function (parentGroupID) {
Kim Peace committed
184
  console.log("peacekim:: CollaborationUI.bindOnClickParentGroup");
Kim Peace committed
185
  $("#parentGroupBtnForAddUserInCollaboration").on("click", function () {
186 187 188
    console.log(
      "peacekim:: CollaborationUI.bindOnClickParentGroup parentGroupBtnForAddUserInCollaboration clicked"
    );
Kim Peace committed
189 190 191 192 193
    CollaborationUI.refreshAllGroupForAddUserInCollaboration(parentGroupID);
  });
};

CollaborationUI.bindOnClickRootGroup = function (rootGroupID) {
Kim Peace committed
194
  console.log("peacekim:: CollaborationUI.bindOnClickRootGroup");
Kim Peace committed
195
  $("#rootGroupBtnForAddUserInCollaboration").on("click", function () {
196 197 198
    console.log(
      "peacekim:: CollaborationUI.bindOnClickRootGroup rootGroupBtnForAddUserInCollaboration clicked"
    );
Kim Peace committed
199 200 201 202 203 204 205 206
    CollaborationUI.refreshAllGroupForAddUserInCollaboration(rootGroupID);
  });
};

CollaborationUI.displayRootGroupAndParentGroupIfNeeded = function (
  rootGroupID,
  groupID
) {
207 208 209
  console.log(
    "peacekim:: CollaborationUI.displayRootGroupAndParentGroupIfNeeded"
  );
210
  if (typeof rootGroupID !== "undefined" && rootGroupID == 0) {
Kim Peace committed
211
    groupID = rootGroupID;
Kim Peace committed
212
  }
Kim Peace committed
213 214

  if (groupID == rootGroupID || groupID == "0") {
Kim Peace committed
215 216 217 218 219 220
    $("#rootGroupAreaInCollaboration").addClass("none");
    $("#parentGroupAreaInCollaboration").addClass("none");
  } else {
    $("#rootGroupAreaInCollaboration").removeClass("none");
    $("#parentGroupAreaInCollaboration").removeClass("none");
  }
Kim Peace committed
221 222 223
};

CollaborationUI.appendGroupPath = function (groupPathList) {
224 225 226
  console.log(
    "peacekim:: CollaborationUI.appendGroupPath groupPathList: " + groupPathList
  );
Kim Peace committed
227
  const groupPathTemplate = getTemplate(
Kim Peace committed
228 229 230
    TemplateURL.ADD_USER_GROUP_PATH_IN_COLLABORATION
  );

Kim Peace committed
231 232 233
  let groupPathCount = 0;
  groupPathList.forEach(function (groupPath) {
    if (!(groupPathCount < groupPathList.length - 3)) {
Kim Peace committed
234 235 236 237 238 239 240 241 242
      let html = Mustache.render(groupPathTemplate, {
        name: groupPath.groupName,
        id: groupPath.groupId,
      });
      let obj = jQuery.parseHTML(html);
      $("#groupPathAreaForAddUserInCollaboration").append(obj);
    }
    groupPathCount++;
  });
Kim Peace committed
243
};
Kim Peace committed
244

Kim Peace committed
245
CollaborationUI.appendChildGroups = function (chidGroups) {
246 247 248
  console.log(
    "peacekim:: CollaborationUI.appendChildGroups chidGroups: " + chidGroups
  );
Kim Peace committed
249
  const groupTemplate = getTemplate(
Kim Peace committed
250 251 252
    TemplateURL.ADD_USER_GROUP_LIST_IN_COLLABORATION
  );

Kim Peace committed
253
  chidGroups.forEach(function (childGroup) {
Kim Peace committed
254 255 256 257 258 259 260 261
    let html = Mustache.render(groupTemplate, {
      name: childGroup.groupName,
      id: childGroup.groupId,
    });

    let obj = $(jQuery.parseHTML(html)).on("click", function () {});
    $("#childGroupListAreaForAddUserInCollaboration").append(obj);
  });
Kim Peace committed
262
};
Kim Peace committed
263

Kim Peace committed
264
CollaborationUI.appendUsers = function (userList) {
265
  console.log("peacekim:: CollaborationUI.appendUsers userList: " + userList);
Kim Peace committed
266
  const userTemplate = getTemplate(
Kim Peace committed
267 268 269
    TemplateURL.ADD_USER_USER_LIST_IN_COLLABORATION
  );

Kim Peace committed
270
  userList.forEach(function (groupUser) {
Kim Peace committed
271 272
    groupUser.profileUrl = Common.getProfileImgUrl(groupUser.profileUrl);
    let findObj = ChatManagementCommon.selectedUserList.find(function (
Kim Peace committed
273
      shopMemberID
Kim Peace committed
274
    ) {
Kim Peace committed
275
      return shopMemberID == groupUser.shopMemberId;
Kim Peace committed
276 277 278 279 280 281
    });
    if (findObj) {
      groupUser.checked = "checked";
    }
  });
  let html = Mustache.render(userTemplate, {
Kim Peace committed
282
    userList: userList,
Kim Peace committed
283 284 285 286 287
  });
  let obj = jQuery.parseHTML(html);
  $("#userInGroupListForAddUserInCollaboration").append(obj);
};

Kim Peace committed
288 289 290 291 292
CollaborationUI.appendRootGroupAndParentGroupIfNeeded = function (
  rootGroupID,
  parentGroupID,
  groupID
) {
293 294 295
  console.log(
    "peacekim:: CollaborationUI.appendRootGroupAndParentGroupIfNeeded"
  );
Kim Peace committed
296 297 298 299 300 301 302 303 304 305 306
  if (typeof parentGroupID !== "undefined") {
    CollaborationUI.bindOnClickParentGroup(parentGroupID);
  }

  if (typeof rootGroupID !== "undefined") {
    CollaborationUI.bindOnClickRootGroup(rootGroupID);
  }

  CollaborationUI.displayRootGroupAndParentGroupIfNeeded(rootGroupID, groupID);
};

Kim Peace committed
307
CollaborationUI.confirmInviteUserListInCollaboration = function () {
308 309 310
  console.log(
    "peacekim:: CollaborationUI.confirmInviteUserListInCollaboration"
  );
Kim Peace committed
311 312 313 314 315 316 317 318
  const selectedUsers = NativeBridgeDataSource.loadSelectedUsers();
  if (selectedUsers != "") {
    $("#selectedUserListinCollaboration").html("");

    selectedUsers.forEach(function (user) {
      user.profileUrl = Common.getProfileImgUrl(user.profileUrl);
    });

Kim Peace committed
319 320 321
    const modalTemplate = getTemplate(TemplateURL.MODAL_ADD_USER_CONFIRM);

    const html = Mustache.render(modalTemplate, {
Kim Peace committed
322 323 324 325 326 327 328
      userList: selectedUsers,
    });
    let obj = jQuery.parseHTML(html);
    $("#modal_add_user_confirm").html(obj);
    $("#modalAddUserConfirm").modal("show");
  }

Kim Peace committed
329 330 331 332 333 334
  CollaborationUI.bindCancelAddUserButton();

  CollaborationUI.bindAddUserButton(selectedUsers);
};

CollaborationUI.bindCancelAddUserButton = function () {
Kim Peace committed
335
  console.log("peacekim:: CollaborationUI.bindCancelAddUserButton");
Kim Peace committed
336 337 338
  $("#cancelAddUserBtn")
    .off()
    .on("click", function () {
339 340 341
      console.log(
        "peacekim:: CollaborationUI.bindCancelAddUserButton cancelAddUserBtn clicked"
      );
Kim Peace committed
342 343 344
      $("#modalAddUserConfirm").modal("hide");
      $("#addUserInCollaboration").modal("show");
    });
Kim Peace committed
345
};
Kim Peace committed
346

Kim Peace committed
347
CollaborationUI.bindAddUserButton = function (selectedUsers) {
Kim Peace committed
348
  console.log("peacekim:: CollaborationUI.bindAddUserButton");
Kim Peace committed
349 350 351
  $("#addUserBtn")
    .off()
    .on("click", function () {
352 353 354
      console.log(
        "peacekim:: CollaborationUI.bindAddUserButton addUserBtn clicked"
      );
Kim Peace committed
355 356 357
      Common.showLoadingIndicator();
      let userIDList = selectedUsers.map((user) => user.shopMemberId);
      const commaJoinedUserIDList = userIDList.join(",");
358
      const collaborationType = globalUserInfo.collaborationType;
359
      scrollTo(0, 0);
Kim Peace committed
360 361 362 363 364 365 366 367 368 369 370
      NativeBridgeDelegate.inviteCollaboration(
        commaJoinedUserIDList,
        collaborationType
      );

      Common.dismissLoadingIndicator();
      $("#modalAddUserConfirm").modal("hide");
    });
};

CollaborationUI.toggleCategory = function (category) {
Kim Peace committed
371
  console.log("peacekim:: CollaborationUI.toggleCategory");
Kim Peace committed
372 373
  $(category).toggleClass("open");
  $(category).next().slideToggle();
Kim Peace committed
374
};