This commit is contained in:
szpyxlwoni
2012-12-06 11:12:07 +08:00
5 changed files with 31 additions and 30 deletions
@@ -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
+14 -10
View File
@@ -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');
});
});
+10 -5
View File
@@ -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 -1
View File
@@ -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
View File
@@ -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