Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

添加用户头像设置 #13

Merged
merged 1 commit into from

1 participant

@songjiayang

No description provided.

@songjiayang songjiayang merged commit a54c28a into fireweb:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 7, 2013
  1. @songjiayang

    添加用户头像

    songjiayang authored
This page is out of date. Refresh to see the latest.
View
10 app/assets/javascripts/application.js
@@ -31,3 +31,13 @@ function current_time () {
context2D.fillStyle=grd;
context2D.fill();
}
+
+
+function sent_message(){
+ faye.publish('/room/<%=@room.id%>/messages/new', {
+ username: '<%= session[:username] %>',
+ msg: $('#message').val()
+ });
+ $('#message').val('');
+ return false;
+ }
View
10 app/assets/stylesheets/room.css.erb
@@ -70,7 +70,13 @@
width: 60px;
height: 60px;
padding: 5px;
- border-radius: 30px;
+ border-radius: 10px;
+}
+
+.my_avater{
+ width: 20px;
+ height: 20px;
+ padding-right: 10px;
}
.messages li .info{
@@ -94,7 +100,7 @@
margin-top: 0px;
}
-.welcome-message span{
+.welcome-message font{
color: #08C;
font-weight:bold;
}
View
1  app/controllers/sessions_controller.rb
@@ -5,6 +5,7 @@ def new
def create
session[:username] = params[:username]
+ session[:avater] = User.image_with_email(params[:email],params[:username])
redirect_to chat_rooms_path
end
end
View
13 app/models/user.rb
@@ -0,0 +1,13 @@
+class User < ActiveRecord::Base
+ include Gravtastic
+ gravtastic
+ attr_accessible :email, :username
+ validates :email, :uniqueness => true
+ validates :email, :presence => true
+
+ def self.image_with_email(email,username)
+ user = User.find_by_email(email.to_s)|| User.create({username:username.to_s,email:email.to_s})
+ user.gravatar_url
+ end
+
+end
View
44 app/views/rooms/show.html.erb
@@ -2,17 +2,15 @@
<div class="row-fluid">
<div class="span9">
<p class='alert alert-success welcome-message'>
- Welcome to the
- <span id="room_title"><%=@room.title%></span>
- chat room
- <span id="user_name"><%= session[:username] %>!</span>
+ <img src="<%=session[:avater]%>" class="my_avater" data-content='hello <%= session[:username] %>'/>
+ <span style="float:right;">Welcome to <font id="room_title"><%=@room.title%></font> room.</span>
</p>
<div class="messages">
</div>
<div id="input-area">
<textarea id="message" class="input-xlarge"></textarea>
<button class="btn btn-success" id="submit">Send</button>
- <span class="notice">支持markdown</span>
+ <span class="notice">支持快捷键'ctrl'发送消息</span>
</div>
</div>
<div class="span2">
@@ -40,25 +38,43 @@
</div>
<script>
+ function sent_message(){
+ var message = $('#message').val();
+ if (message.length<1){
+ alert("发送信息不能为空");
+ }else{
+ faye.publish('/room/<%=@room.id%>/messages/new', {
+ username: '<%= session[:username] %>',
+ msg: $('#message').val()
+ });
+ $('#message').val('');
+ }
+ return false;
+ }
$('body').css('background',"url(<%=asset_path 'bg2.jpg'%>) no-repeat fixed bottom");
$('.messages').css('height',window.screen.height-285);
$('.subject').css('max-height',window.screen.height-550);
+ $('.my_avater').mouseover(function() {
+ $('.my_avater').popover('show');
+ });
+ $('.my_avater').mouseout(function() {
+ $('.my_avater').popover('hide');
+ });
$('#submit').click(function(){
- faye.publish('/room/<%=@room.id%>/messages/new', {
- username: '<%= session[:username] %>',
- msg: $('#message').val()
- });
- $('#message').val('');
- return false;
+ sent_message();
+ });
+ $(this).keyup(function(e){
+ if (e.which ==17){sent_message()};
});
faye.subscribe("/room/<%=@room.id%>/messages/new",function(data){
- var a_new_message = ('<li><div class="user-avatar"> <img src="'+'http://l.ruby-china.org/user/large_avatar/827.jpg"');
+ var a_new_message = ('<li><div class="user-avatar"> <img src="'+'<%=session[:avater]%>"');
a_new_message +='/></div><div class="info"><span class="username">';
a_new_message +=data.username;
a_new_message +=('</span><span >'+(parseInt($('.messages li').size())+1)+' 楼</span>');
a_new_message +=('<span >'+ current_time()+'</span>');
- a_new_message +=('<p>'+data.msg+'</p></div></li>');
- $('.messages').append(a_new_message);
+ a_new_message +=('<p class="li_message">'+data.msg+'</p></div></li>');
+ $('.messages').prepend(a_new_message);
});
+
</script>
View
1  app/views/sessions/new.html.erb
@@ -2,6 +2,7 @@
<p>无需注册即可登录Chater , 轻松享受群组聊天的乐趣</p>
<%= form_tag login_path,class:'form-inline' do |f| %>
<%= text_field_tag :username,'', class:"input-small",placeholder:"Chater昵称"%>
+ <%= email_field_tag :email,'', class:"input-small",placeholder:"邮箱地址"%>
<%= submit_tag "登录",class:'btn btn-info btn-large',id:'login-button' %>
<% end %>
</div>
View
1  config/environment.rb
@@ -6,5 +6,6 @@
MyChatter::Application.initialize!
require 'will_paginate'
+require 'gravtastic'
WillPaginate::ViewHelpers.pagination_options[:previous_label] = '上一页'
WillPaginate::ViewHelpers.pagination_options[:next_label] = '下一页'
View
10 db/migrate/20130407120754_create_users.rb
@@ -0,0 +1,10 @@
+class CreateUsers < ActiveRecord::Migration
+ def change
+ create_table :users do |t|
+ t.string :username
+ t.string :email
+
+ t.timestamps
+ end
+ end
+end
Something went wrong with that request. Please try again.