collaboration.js 5.46 KB
Newer Older
1 2
var CollaborationUI = {};

3
document.addEventListener("DOMContentLoaded", function () {
Kim Peace committed
4
  CollaborationUI.disableScroll();
Kim Peace committed
5

6
  // メニューオーバーレイ表示
Kim Peace committed
7 8 9 10 11 12 13 14
  CollaborationUI.bindMenuButton();

  // ユーザーリストオーバーレイ表示
  CollaborationUI.bindDisplayUsersButton();

  // モーダルonモーダル(前のモーダルを非表示に)
  // ホスト変更ボタン押下イベント
  CollaborationUI.bindChangeHostButton();
15
});
Kim Peace committed
16

17 18 19 20 21 22 23 24
document.addEventListener("readystatechange", () => {
  if (document.readyState === "complete") {
    CollaborationUI.initialBindAddUserButton();
    // 閉じるイベント
    CollaborationUI.bindCloseButton();
    // ユーザー追加イベント
    CollaborationUI.bindInviteButton();
  }
Kim Peace committed
25 26 27 28 29 30
});

/*********************************
 *  Buttons binding events
 ********************************/
CollaborationUI.bindMenuButton = function () {
31 32 33 34
  $(".menu_btn").click(function () {
    $(this).toggleClass("hide");
    $("#overlay_menu .item").toggleClass("hide");
  });
Kim Peace committed
35
};
Kim Peace committed
36

Kim Peace committed
37
CollaborationUI.bindDisplayUsersButton = function () {
38
  $(".user_btn").click(function () {
Kim Peace committed
39 40
    const width = $(this).width();
    $("#overlay_user_list.overlay").stop();
41 42 43
    $(this).toggleClass("hide");
    $("#overlay_user_list.overlay")
      .toggleClass("slidein")
Kim Peace committed
44 45 46
      .animate({ left: "+=width" }, 500, function () {
        scrollTo(0, 0);
      });
47 48

    if ($(this).hasClass("hide")) {
Kim Peace committed
49
      CollaborationUI.enableScroll();
50
    } else {
Kim Peace committed
51
      CollaborationUI.disableScroll();
Kim Peace committed
52
    }
53
  });
Kim Peace committed
54
};
Kim Peace committed
55

56
CollaborationUI.userListSlideOut = function () {
Kim Peace committed
57
  const userButtonWidth = $(".user_btn").width();
58 59 60
  $(".user_btn").removeClass("hide");
  $("#overlay_user_list.overlay")
    .removeClass("slidein")
Kim Peace committed
61
    .css({ transform: "translateX(" & -userButtonWidth & ")" });
62
  scrollTo(0, 0);
Kim Peace committed
63
  CollaborationUI.disableScroll();
64 65
};

Kim Peace committed
66
CollaborationUI.bindChangeHostButton = function () {
67
  $(".ch_host_btn").click(function () {
68
    const target = $(this).val();
Kim Peace committed
69 70 71 72 73
    const beforeModal = $(target);
    const afterModal = $("#changeHostModal");
    /* モーダルの切り替え */
    beforeModal.modal("hide");
    afterModal.modal("show");
74
  });
Kim Peace committed
75
};
Kim Peace committed
76

Kim Peace committed
77
CollaborationUI.bindCloseButton = function () {
78
  $(".close_btn").click(function () {
79
    scrollTo(0, 0);
Kim Peace committed
80
    CollaborationUI.disableScroll();
Kim Peace committed
81
  });
Kim Peace committed
82
};
Kim Peace committed
83

Kim Peace committed
84
CollaborationUI.bindInviteButton = function () {
85
  $(".inv_btn").click(function () {
86
    scrollTo(0, 0);
Kim Peace committed
87
  });
Kim Peace committed
88
};
Kim Peace committed
89

Kim Peace committed
90 91 92
/*********************************
 *  Scroll Controls
 ********************************/
Kim Peace committed
93
CollaborationUI.disableScroll = function () {
Kim Peace committed
94 95 96 97 98 99 100
  document.addEventListener("mousewheel", CollaborationUI.scrollControl, {
    passive: false,
  });
  document.addEventListener("touchmove", CollaborationUI.scrollControl, {
    passive: false,
  });
};
Kim Peace committed
101

102
// スクロール禁止解除
Kim Peace committed
103
CollaborationUI.enableScroll = function () {
Kim Peace committed
104 105 106 107
  document.removeEventListener("mousewheel", CollaborationUI.scrollControl, {
    passive: false,
  });
  document.removeEventListener("touchmove", CollaborationUI.scrollControl, {
108 109
    passive: false,
  });
Kim Peace committed
110
};
Kim Peace committed
111

Kim Peace committed
112
CollaborationUI.scrollControl = function (event) {
113 114 115
  if (event.cancelable) {
    event.preventDefault();
  }
Kim Peace committed
116
};
117

Kim Peace committed
118 119 120
/*********************************
 *  NameCard in Collaboration
 ********************************/
121 122
CollaborationUI.makeNameCard = function (shopMemberID) {
  if (currentUserInfo.shopMemberID == shopMemberID) {
Kim Peace committed
123 124 125
    return;
  }

Kim Peace committed
126
  const namecardTemplate = getTemplate(TemplateURL.COLLABORATION_PROFILE);
Kim Peace committed
127

128
  const nameCardInfo = NativeBridgeDataSource.getNameCardData(shopMemberID);
129
  nameCardInfo.profileUrl = Common.getProfileImgUrl(nameCardInfo.profileUrl);
Kim Peace committed
130 131 132 133

  let isCollaborationHost = coview_api.getRoomUsers();

  const whosHost = $("#collaboration_user_" + nameCardInfo.loginId).hasClass(
Kim Peace committed
134 135
    "host"
  );
Kim Peace committed
136

Kim Peace committed
137
  let namecardHTML = Mustache.render(namecardTemplate, {
Kim Peace committed
138 139 140 141 142 143 144 145
    shopMemberId: nameCardInfo.shopMemberId,
    profileUrl: nameCardInfo.profileUrl,
    loginId: nameCardInfo.loginId,
    name: nameCardInfo.shopMemberName,
    groupPathList: nameCardInfo.groupPathList,
    isFavorite: nameCardInfo.isFavorite,
    isHost: isCollaborationHost,
    whosHost: whosHost,
146
    collaborationId: globalUserInfo.shopName + "_" + nameCardInfo.loginId,
Kim Peace committed
147 148
  });

Kim Peace committed
149
  let namecardObj = $(jQuery.parseHTML(namecardHTML)).on(
Kim Peace committed
150 151 152 153 154 155 156 157
    "click",
    function () {}
  );

  $("#userProfileModalInCollaboration").html(namecardObj);
  $("#userNameCardInCollaboration").modal("show");
};

158
CollaborationUI.removeFavoriteUserInCollaboration = function (shopMemberID) {
159
  Common.showLoadingIndicator();
Kim Peace committed
160
  $("#userNameCardInCollaboration").modal("hide");
161
  NativeBridgeDataSource.removeFavoriteUser(shopMemberID);
162
  Common.dismissLoadingIndicator();
Kim Peace committed
163 164
};

165
CollaborationUI.insertFavoriteUserInCollaboration = function (shopMemberID) {
Kim Peace committed
166
  $("#userNameCardInCollaboration").modal("hide");
167
  NativeBridgeDataSource.addFavoriteUser(shopMemberID);
168 169 170
  Common.dismissLoadingIndicator();
};

171
CollaborationUI.refreshForOffline = function () {
172
  serverInfo.isOnline = false;
173 174 175 176 177 178 179 180
  if (typeof coview_api == "undefined") {
    return;
  }
  const alertString = getLocalizedString("err_weak_network_exit_collaboration");
  alert(alertString);

  NativeBridgeDelegate.finishCollaboration();

181
  if (globalUserInfo.joinType != COLLABORATION_JOIN_TYPE.INVITED) {
182 183 184 185
    NativeBridgeDelegate.joinRoom(roomInfo.roomID, roomInfo.name);
  } else {
    NativeBridgeDelegate.openCommunicationHome();
  }
Kim Peace committed
186
};
Kim Peace committed
187

188 189 190 191 192
CollaborationUI.displayAddUserButtonIfNeeded = function () {
  if (roomInfo.roomType == ChatRoomType.DM) {
    $(".add_user_btn").removeClass("none");
  }
};