2014-07-03 00:17:05 +08:00
|
|
|
|
Template.messageBar.helpers
|
|
|
|
|
getMessagesInChat: ->
|
|
|
|
|
messages = Meteor.Chat.find("meetingId": getInSession("currentChatId"))
|
|
|
|
|
console.log messages
|
|
|
|
|
messages
|
|
|
|
|
|
2014-07-02 23:41:12 +08:00
|
|
|
|
# Must be be called when template is finished rendering or will not work
|
|
|
|
|
Template.messageBar.rendered = -> # Scroll down the messages box the amount of its height, which places it at the bottom
|
|
|
|
|
height = $("#chatScrollWindow").height()
|
|
|
|
|
$("#chatScrollWindow").scrollTop(height)
|
2014-06-25 21:28:15 +08:00
|
|
|
|
|
2014-07-02 23:41:12 +08:00
|
|
|
|
Template.tabButtons.events
|
|
|
|
|
"click .publicChatTab": (event) ->
|
2014-07-04 01:56:16 +08:00
|
|
|
|
Session.set "display_chatPane", true
|
2014-06-24 21:46:42 +08:00
|
|
|
|
|
2014-07-02 23:41:12 +08:00
|
|
|
|
"click .optionsChatTab": (event) ->
|
2014-07-04 01:56:16 +08:00
|
|
|
|
Session.set "display_chatPane", false
|
|
|
|
|
|
|
|
|
|
"click .privateChatTab": (event) ->
|
|
|
|
|
Session.set "display_chatPane", true
|
2014-06-24 21:46:42 +08:00
|
|
|
|
|
2014-07-02 23:41:12 +08:00
|
|
|
|
Template.chatInput.events
|
|
|
|
|
'keypress #newMessageInput': (event) ->
|
|
|
|
|
if event.which is 13 # Check for pressing enter to submit message
|
2014-06-27 01:13:19 +08:00
|
|
|
|
|
2014-07-02 23:41:12 +08:00
|
|
|
|
messageForServer = { # construct message for server
|
|
|
|
|
"message": $("#newMessageInput").val()
|
|
|
|
|
"chat_type": "PUBLIC_CHAT"
|
|
|
|
|
"from_userid": Session.get "userId"
|
|
|
|
|
"from_username": Session.get "userName"
|
|
|
|
|
"from_tz_offset": "240"
|
|
|
|
|
"to_username": "public_chat_username"
|
|
|
|
|
"to_userid": "public_chat_userid"
|
|
|
|
|
"from_lang": "en"
|
|
|
|
|
"from_time": "1.403794169042E12"
|
|
|
|
|
"from_color": "0"
|
|
|
|
|
}
|
|
|
|
|
console.log "Sending message to server: '#{messageForServer.message}'"
|
|
|
|
|
Meteor.call "sendChatMessagetoServer", Session.get("meetingId"), messageForServer
|
|
|
|
|
$('#newMessageInput').val '' # Clear message box
|
2014-07-04 01:56:16 +08:00
|
|
|
|
#sendChatMessagetoServer(null)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Template.optionsBar.events
|
|
|
|
|
'click .private-chat-user-entry': (event) -> # clicked a user's name to begin private chat
|
|
|
|
|
|
|
|
|
|
messageForServer = {
|
|
|
|
|
"message": "You are now in a private chat"
|
|
|
|
|
"chat_type": "PRIVATE_CHAT"
|
|
|
|
|
"from_userid": Session.get "userId"
|
|
|
|
|
"from_username": Session.get "userName"
|
|
|
|
|
"from_tz_offset": "240"
|
|
|
|
|
"to_username": @user.name
|
|
|
|
|
"to_userid": @userId
|
|
|
|
|
"from_lang": "en"
|
|
|
|
|
"from_time": "1.403794169042E12"
|
|
|
|
|
"from_color": "0"
|
|
|
|
|
}
|
|
|
|
|
console.log "Sending private message to server: '#{messageForServer.message}'"
|
|
|
|
|
Meteor.call "sendChatMessagetoServer", Session.get("meetingId"), messageForServer
|
|
|
|
|
|
|
|
|
|
# only trigger a reaction is new private chat was added
|
|
|
|
|
if addNewTab @user.name, true, "privateChatTab"
|
|
|
|
|
# Hackish way to go about this
|
2014-07-04 23:00:46 +08:00
|
|
|
|
# Coffeescript variables and arays inside the session are not reactive
|
2014-07-04 01:56:16 +08:00
|
|
|
|
# So have a session variable that we change everytime we want our dependent templates to be force rendered
|
|
|
|
|
Session.set "chatTabsReactivity", (Session.get "chatTabsReactivity")+1 # change value to cause a refresh for dependencies
|
|
|
|
|
Session.set "display_chatPane", true
|
|
|
|
|
|
|
|
|
|
Template.tabButtons.getChatbarTabs = ->
|
|
|
|
|
Session.get "chatTabsReactivity" # pulling from session causes reactive template refresh
|
|
|
|
|
ChatbarTabs
|
|
|
|
|
|
2014-07-04 23:00:46 +08:00
|
|
|
|
Template.tabButtons.makeTabButton = ->
|
|
|
|
|
button = '<li class="'
|
|
|
|
|
button += 'active ' if this.isActive
|
|
|
|
|
button += "#{this.class}\"><a href=\"#\" data-toggle=\"tab\">#{this.name}"
|
|
|
|
|
button += ' <button class="close closeTab" type="button" >×</button>' if this.name isnt 'Public' and this.name isnt 'Options'
|
|
|
|
|
button += '</a></li>'
|
|
|
|
|
console.log button
|
|
|
|
|
button
|
2014-07-04 01:56:16 +08:00
|
|
|
|
|