mirror of
https://github.com/wahyd4/ocelots.git
synced 2026-08-09 04:56:21 +10:00
Merge branch 'master' of https://github.com/wahyd4/ocelots
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
$ ->
|
||||
options=
|
||||
type:'post'
|
||||
clearForm: true
|
||||
beforeSubmit: ->
|
||||
if $('.message-body').val().replace(/\s+/, "") == ""
|
||||
false
|
||||
success: (data) ->
|
||||
$('.message-list').prepend(data)
|
||||
|
||||
$('.submit-mess').click ->
|
||||
$('.form-inline').ajaxSubmit options
|
||||
@@ -6,23 +6,27 @@
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
var dispatcher = new WebSocketRails('localhost:3000/websocket');
|
||||
var address = "ws://"+window.location.host+'/websocket';
|
||||
var dispatcher = new WebSocketRails(address);
|
||||
|
||||
dispatcher.on_open = function(data) {
|
||||
console.log('Connection has been established: ' + data);
|
||||
// You can trigger new server events inside this callback if you wish.
|
||||
}
|
||||
$('.submit-mess').click(function(){
|
||||
if ($('#content').val().replace(/\s+/, "") == ""){
|
||||
return ;
|
||||
}
|
||||
params= {};
|
||||
params.content = $('#content').val();
|
||||
params.slug = $('#slug').val()
|
||||
dispatcher.trigger('new_message',params);
|
||||
|
||||
var comment = {
|
||||
title: 'This post was awful',
|
||||
body: 'really awful',
|
||||
post_id: 9
|
||||
}
|
||||
|
||||
dispatcher.trigger('new_message',comment)
|
||||
});
|
||||
|
||||
dispatcher.bind('new_message', function(message) {
|
||||
console.log(message.title);
|
||||
dispatcher.bind('new_message', function(content) {
|
||||
$('#content').val("");
|
||||
$('.message-list').prepend(content).show('slow');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
require 'team_filter'
|
||||
|
||||
class Realtime_message_controller < WebsocketRails::BaseController
|
||||
include TeamFilter
|
||||
|
||||
def initialize_session
|
||||
# perform application setup here
|
||||
@message_count = 0
|
||||
end
|
||||
|
||||
def new_message
|
||||
puts "Message from UID: #{client_id}\n ,the message is #{message}"
|
||||
#puts "Message from user: #{current_user.email}"
|
||||
@message_count = @message_count + 1
|
||||
broadcast_message :new_message, message
|
||||
|
||||
with_team(message[:slug]) do
|
||||
@message = Message.create team: @team, person: current_person, content: message[:content]
|
||||
broadcast_message :new_message,render_to_string( partial: 'shared/one_message', locals: {message: @message})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,5 +1,4 @@
|
||||
- content_for :javascript_includes do
|
||||
= javascript_include_tag 'antechamber'
|
||||
= javascript_include_tag '/jquery.form.js'
|
||||
= javascript_include_tag 'message'
|
||||
|
||||
@@ -7,6 +6,7 @@
|
||||
|
||||
h1 = @team.name
|
||||
form.form-inline action="/antechamber/#{@team.slug}"
|
||||
input type="hidden" id="slug" value="#{@team.slug}"
|
||||
p #{text_area_tag :content, nil, placeholder: 'Enter Message', rows: 4,class:'message-body'}
|
||||
a.btn.submit-mess Send
|
||||
|
||||
|
||||
+6
-2
@@ -1,6 +1,10 @@
|
||||
module TeamFilter
|
||||
def with_team
|
||||
@team = Team.find_by_slug params[:slug]
|
||||
def with_team (slug = nil)
|
||||
if slug
|
||||
@team = Team.find_by_slug slug
|
||||
else
|
||||
@team = Team.find_by_slug params[:slug]
|
||||
end
|
||||
unless current_person.allowed_to_view_team?(@team)
|
||||
@team = nil
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user