Merge branch 'wordh' into develop

Conflicts:
	app/views/layouts/base_users.html.erb
This commit is contained in:
yanxd 2013-12-26 11:36:09 +08:00
commit 7b895e5cde
21 changed files with 333 additions and 116 deletions

View File

@ -222,10 +222,9 @@ class UsersController < ApplicationController
# modified by fq
def user_newfeedback
@jours = @user.journals_for_messages.reverse
@jours.each do |jour|
jour.update_attribute(:status, false)
end
@jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
@jours.update_all(:is_readed => true, :status => false)
@limit = 10
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']

View File

@ -1,3 +1,4 @@
# encoding: utf-8
#####leave message fq
class WordsController < ApplicationController
@ -25,7 +26,7 @@ class WordsController < ApplicationController
# @message_count = a_message.count
end
end
@jours = @user.journals_for_messages.reverse
@jours = @user.journals_for_messages.where('m_parent_id IS NULL').reverse
@limit = 10
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@ -39,6 +40,38 @@ class WordsController < ApplicationController
end
end
def create_reply
# deny api. api useless
user_id = request.headers["Referer"].match((%r|/([0-9]{1,})/|))[1]
@user = User.find(user_id)
parent_id = params[:reference_id]
author_id = User.current.id
reply_user_id = params[:reference_user_id]
reply_id = params[:reference_message_id] # 暂时不实现
content = params[:user_notes]
options = {:user_id => author_id,
:m_parent_id => parent_id,
:m_reply_id => reply_id,
:reply_id => reply_user_id,
:notes => content,
:is_readed => false}
@jfm = @user.add_jour(nil, nil, nil, options)
respond_to do |format|
# format.html {
# if @jfm.errors.empty?
# flash.now.notice = l(:label_feedback_success)
# else
# flash.now.errors = l(:label_feedback_fail)
# end
# render 'test/index'
# }
format.js{
@save_succ = true if @jfm.errors.empty?
}
end
end
def destroy
if User.current.admin? || User.current.id == @user.id
JournalsForMessage.delete_message(params[:object_id])

View File

@ -43,5 +43,14 @@ module WordsHelper
# content.present? ? content_tag('ul', content, :class => 'watchers') : content
content
end
end
def fetch_user_leaveWord_reply leaveWordObj
if leaveWordObj.kind_of? JournalsForMessage
leaveWordObj.children
elsif leaveWordObj.kind_of? Fixnum
JournalsForMessage.find(leaveWordObj).children
else
[]
end
end
end

View File

@ -1,12 +1,33 @@
# fq
# 数据库字段中带有m前缀和is_readed是二次开发添加之前的字段基本复用
# 注意reply_id 是提到人的id不是留言id, Base中叫做 at_user
class JournalsForMessage < ActiveRecord::Base
attr_accessible :jour_id, :jour_type, :notes, :reply_id, :status, :user_id
attr_accessor :indice
validates :notes, presence: true
include Redmine::SafeAttributes
safe_attributes "jour_type", # 留言所属类型
"jour_id", # 留言所属类型的id
"notes", # 留言内容
"reply_id", # 留言被回复留言者的用户id(用户a回复了用户b这是b的id用以查询谁给b留言了)
"status", # 留言是否被查看(弃用)
"user_id", # 留言者的id
"m_parent_id", # 留言信息的父留言id
"is_readed", # 留言是否已读
"m_reply_count", # 留言的回复数量
"m_reply_id" # 回复某留言的留言id(a留言回复了b留言这是b留言的id)
acts_as_tree :foreign_key => 'm_parent_id', :counter_cache => :m_reply_count, :order => "#{JournalsForMessage.table_name}.created_on ASC"
belongs_to :jour, :polymorphic => true
belongs_to :user
belongs_to :at_user, :class_name => "User", :foreign_key => 'reply_id'
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
has_many :reply_for_journals, :dependent => :destroy
validates :notes, presence: true
after_create :act_as_activity #huang
after_create :reset_counters!
after_destroy :reset_counters!
# default_scope { where('m_parent_id IS NULL') }
def self.delete_message(message_id)
self.delete_all "id = #{message_id}"
@ -24,9 +45,18 @@ class JournalsForMessage < ActiveRecord::Base
def act_as_activity
if self.jour_type == 'Principal'
unless self.user_id == self.jour.id && self.user_id != self.reply_id && self.reply_id !=0
unless self.user_id == self.jour.id && self.user_id != self.reply_id && self.reply_id != 0
self.acts << Activity.new(:user_id => self.user_id)
end
end
end
def reset_counters!
self.class.reset_counters!(self)
end
def self.reset_counters! journals_for_messages
# jfm_id = journals_for_messages.id.to_i
count = find_all_by_m_parent_id(journals_for_messages.m_parent_id).count #(SELECT COUNT(*) FROM #{JournalsForMessage.table_name} WHERE m_parent_id = #{jfm_id} )
update_all("m_reply_count = #{count.to_i}", ["id = ?", journals_for_messages.m_parent_id])
end
end

View File

@ -6,7 +6,7 @@ class Memo < ActiveRecord::Base
validates_presence_of :author_id, :forum_id, :subject
validates :content, presence: true
validates_length_of :subject, maximum: 50
validates_length_of :content, maximum: 3072
#validates_length_of :content, maximum: 3072
validate :cannot_reply_to_locked_topic, :on => :create
acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC"

View File

@ -0,0 +1,4 @@
class ReplyForJournal < ActiveRecord::Base
# attr_accessible :title, :body
belongs_to :journals_for_messages
end

View File

@ -164,8 +164,14 @@ class User < Principal
###添加留言 fq
def add_jour(user, notes, reference_user_id = 0)
self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id, :status => true)
def add_jour(user, notes, reference_user_id = 0, options = {})
if options.count == 0
self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id, :status => true)
else
jfm = self.journals_for_messages.build(options)
jfm.save
jfm
end
end
# 判断用户是否加入了竞赛中 fq
@ -205,6 +211,11 @@ class User < Principal
count = self.new_jours.count
end
#added by nie
def count_new_journal_reply
count = self.journal_reply.count
end
def set_mail_notification
##add byxianbo
thread=Thread.new do

View File

@ -67,14 +67,10 @@
</table></td>
</tr>
</table>
<div>
<strong class="font_small_watch"><%= link_to l(:label_user_watcher)+"("+User.watched_by(@user.id).count.to_s+")" ,:controller=>"users", :action=>"user_watchlist"%></strong> &nbsp;
<strong class="font_small_watch"><%= link_to l(:label_x_user_fans, :count => User.current.watcher_users(User.current.id).count)+"("+@user.watcher_users(@user.id).count.to_s+")", :controller=>"users", :action=>"user_fanslist" %></strong>&nbsp;
<strong class="font_small_watch"><%= link_to l(:label_requirement_focus)+"("+Bid.watched_by(@user).where('reward_type = ?', 1).count.to_s+")" ,:controller=>"users", :action=>"watch_bids"%></strong> &nbsp; <!-- added by huang -->
<!-- added by bai 个人签名-->
<% if @user.id == User.current.id %>
<p>
@ -89,9 +85,7 @@
<div id="introduction" style="display: none">
<%= form_for('new_form', :method => :post,
:url => {:controller => 'words', :action => 'add_brief_introdution'}) do |f|%>
<table border="0" width="100%" align="center" >
<tr>
<td><%= f.text_area 'user_introduction', :rows => 3,
:cols => 65,
@ -109,9 +103,7 @@
<% end %>
</div>
<!-- end -->
</div>
</div>
<div class="user_underline"></div>
<!--info-->
@ -126,10 +118,8 @@
<tr>
<td valign="top" style="padding-left: 5px;"><%= l(:label_user_mail) %></td><td class="font_lighter_sidebar" style="padding-left: 0px; word-wrap: break-word; word-break: break-all"><%= mail_to(h(@user.mail), nil, :encode => 'javascript') %></td>
</tr>
<!-- added by bai 在个人主页里显示“工作单位”“地区”"教师的职称"-->
<!-- modified by linchun 在个人主页里显示“加入时间”,“最后登录”,“邮件地址”后面添加冒号-->
<% unless @user.user_extensions.nil? %>
<% unless @user.user_extensions.identity == 2 %>
<tr>

View File

@ -1,3 +1,3 @@
<h3>test</h3>
<%= debug @params %>

View File

@ -0,0 +1,7 @@
<% id = "journal_reply_ul_" + journal.id.to_s%>
<ul class="messages-for-user-reply" id = <%= id %> >
<% fetch_user_leaveWord_reply(journal).each do |reply|%>
<%= render :partial => "words/journal_reply_items", :locals => {:reply => reply, :journal => journal, :m_reply_id => reply.id} %>
<% end %>
</ul>

View File

@ -0,0 +1,24 @@
<li>
<span class="portrait">
<%= image_tag url_to_avatar(reply.user), :class => "avatar-3" %>
</span>
<div class="body">
<% id = 'project_respond_form_'+ reply.id.to_s %>
<span><%= link_to reply.user.name, user_path(reply.user) %>:&nbsp;</span>
<span class="message-notes"> <%= reply.notes %></span>
<% ids = 'project_respond_form_'+ journal.id.to_s%>
<p style="margin-top: 4px; font-size: 9pt;">
<span class="time"><%= format_time reply.created_on %></span>
<span style="float: right;">
<%#= toggle_link l(:label_projects_feedback_respond), id, {:focus => 'project_respond'} %>
<%= link_to l(:label_projects_feedback_respond),'',
{:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{id}'), $('##{id} textarea'), '#{l(:label_reply_plural)} #{reply.user.show_name}: '); return false;"}
%>
</span>
</p>
</div>
<div id='<%=id%>' class="respond-form">
<%= render :partial => "words/new_respond", :locals => {:journal => journal, :m_reply_id => m_reply_id} %>
</div>
<div style="clear: both;"></div>
</li>

View File

@ -1,45 +1,37 @@
<!-- fq -->
<% if jour.size >0 %>
<% remove_allowed = (User.current.id == jour.first.user_id) %>
<ul class="message-for-user">
<% for journal in jour%>
<table width="660px" border="0" align="center">
<tr>
<td colspan="2" valign="top" width="50" ><%= image_tag(url_to_avatar(journal.user), :class => "avatar") %></td>
<td>
<table width="580px" border="0">
<tr>
<td colspan="2" valign="top"><strong> <%= link_to journal.user, user_path(journal.user)%></strong>
<% if @user == User.current %>
<span class="font_lighter"><%= l(:label_leave_me_message) %></span>
<% else %>
<span class="font_lighter"><%= l(:label_leave_others_message) %></span>
<% end %> </td>
</tr>
<tr>
<td colspan="2" width="580px" >
<div class="info-break">
<%= textilizable journal.notes%>
</div></td>
</tr>
<tr>
<td align="left"><span class="font_lighter"> <%= l :label_comment_time %>&nbsp; <%= format_time journal.created_on %></span></td>
<li class="outer-message-for-user">
<span class="portrait"><%= image_tag(url_to_avatar(journal.user), :class => "avatar") %></span>
<span class="body">
<span class="user"><%= link_to journal.user, user_path(journal.user)%></span>
<% if @user == User.current %>
<span class="font_lighter"><%= l(:label_leave_me_message) %></span>
<% else %>
<span class="font_lighter"><%= l(:label_leave_others_message) %></span>
<% end %>
<span>
<%= textilizable journal.notes%>
</span>
<span class="font_lighter"> <%= l :label_comment_time %>&nbsp; <%= format_time journal.created_on %></span>
<% ids = 'project_respond_form_'+ journal.id.to_s%>
<%#= toggle_link l(:label_projects_feedback_respond), ids, {:focus => 'project_respond'} %>
<td width="200" align="right" class="a"> <% if @user == User.current %>
<%= link_to(l(:label_newfeedback_quote), {:controller => 'words', :action => 'new', :id => user, :journal_id => journal}, :remote => true,
:method => 'post', :title => l(:button_quote))%>
<%= link_to(l(:label_newfeedback_delete), {:controller => 'words', :action => 'destroy', :object_id => journal, :user_id => user},
:remote => true, :confirm => l(:text_are_you_sure), :method => 'delete', :class => "delete", :title => l(:button_delete)) if remove_allowed || journal.jour_id == User.current.id %></td>
<% else %>
<%= link_to(l(:label_newfeedback_quote), {:controller => 'words', :action => 'new', :id => user, :journal_id => journal}, :remote => true,
:method => 'post', :title => l(:button_quote))%>
<% end %>
</tr>
</table>
</td>
</tr>
</table>
<div class="line_under"></div>
<%= link_to l(:label_projects_feedback_respond),'',
{:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea'), '#{l(:label_reply_plural)} #{journal.user.show_name}:'); return false;"}
%>
</span>
<div style="clear: both;"></div>
<div id=<%= ids %> class="respond-form">
<%= render :partial => 'words/new_respond', :locals => {:journal => journal, :m_reply_id => journal.id} %>
</div>
<div>
<%= render :partial => "words/journal_reply", :locals => {:journal => journal } %>
</div>
</li>
<% end %>
</ul>
<% end %>

View File

@ -0,0 +1,9 @@
<%= form_tag({:controller => 'words', :action => 'create_reply'}, :remote => true) do %>
<%= text_area_tag 'user_notes', "", :class => 'noline', :style => "resize: none;", :rows => 4, :placeholder => l(:label_projects_feedback_respond_content) %>
<%= hidden_field_tag 'reference_id', params[:reference_id], :value => journal.id %>
<%= hidden_field_tag 'reference_user_id', params[:reference_user_id], :value => journal.user.id %>
<%= hidden_field_tag 'reference_message_id', params[:reference_message_id], :value => m_reply_id %>
<%= submit_tag l(:button_projects_feedback_respond), :name => nil , :class => "bid_btn", :style => "margin-top: 1px;"%>
<% end %>

View File

@ -0,0 +1,11 @@
<% if @save_succ %>
$('#journal_reply_ul_<%=@jfm.m_parent_id%>').append(
'<%= j(
render :partial => "words/journal_reply_items",
:locals => {:reply => @jfm, :journal => @jfm.parent, :m_reply_id => @jfm.id}
) %>');
$('#project_respond_form_<%=@jfm.m_reply_id.to_s%> textarea').val('');
$('#project_respond_form_<%=@jfm.m_reply_id.to_s%>').hide();
<% else %>
alert("<%= l(:label_feedback_fail) %>");
<% end %>

View File

@ -1,3 +1,4 @@
$('#pre_show').html('<%= escape_javascript(render(:partial => 'pre_show', :locals => {:content => @content})) %>');
$('#new_form_reference_user_id').val("<%= @id %>");
showAndScrollTo("pre_show", "new_form_user_message");

View File

@ -452,6 +452,7 @@ RedmineApp::Application.routes.draw do
post 'words/new', :to => 'words#new'
post 'words/create', :to => 'words#create'
post 'words/append', :to => 'words#append'
post 'words/create_reply', :to => 'words#create_reply'
delete 'words/destroy', :to => 'words#destroy'
get 'words/more', :to => 'words#more'
get 'words/back', :to=> 'words#back'

View File

@ -0,0 +1,8 @@
class AddMissingAttributeToJournalsForMessages < ActiveRecord::Migration
def change
add_column :journals_for_messages, :m_parent_id, :string
add_column :journals_for_messages, :is_readed, :boolean
add_column :journals_for_messages, :m_reply_count, :int
add_column :journals_for_messages, :m_reply_id, :int
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20131215065910) do
ActiveRecord::Schema.define(:version => 20131224021723) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -401,8 +401,12 @@ ActiveRecord::Schema.define(:version => 20131215065910) do
t.text "notes"
t.integer "status"
t.integer "reply_id"
t.datetime "created_on", :null => false
t.datetime "updated_on", :null => false
t.datetime "created_on", :null => false
t.datetime "updated_on", :null => false
t.string "m_parent_id"
t.boolean "is_readed"
t.integer "m_reply_count"
t.integer "m_reply_id"
end
create_table "member_roles", :force => true do |t|

View File

@ -590,6 +590,11 @@ function blockEventPropagation(event) {
event.preventDefault();
}
function toggleAndSettingWordsVal(parent_widget, text_widget, value){
text_widget.val(value)
parent_widget.toggle(400)
}
$(document).ready(setupAjaxIndicator);
$(document).ready(hideOnLoad);
$(document).ready(addFormObserversForDoubleSubmit);

View File

@ -2676,3 +2676,5 @@ div.repos_explain{
#admin-index{
margin-left: -220px;
}

View File

@ -310,7 +310,7 @@ ul.projects li.root
padding:5%; /*项目界面的宽度 */
height:25px;
background-color:#0ee; /* 项目界面 #eee*/
margin:0 0 10px;
margin:0 0 0 10px;
display:inline-block;
width:90%;
vertical-align:top;
@ -2035,7 +2035,7 @@ div.avatar_user{
.teacher {
display: inline-block;
word-spacing: 22px;
width: 55px;
width: 60px;
text-justify:inter-ideograph;
text-align: justify;
}
@ -2049,3 +2049,80 @@ div.avatar_user{
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
}
/*
* *
*Designed for message.
*/
li {
list-style-type: none;
}
.avatar-3{
width: 35px;
height: 35px;
}
.inner-right{
float: left;
}
.messages-for-user-reply{
margin-top: 10px;
padding-left: 60px;
}
ul.message-for-user {
list-style-type: none;
margin: 0px;
padding: 0px;
font-family: 微软雅黑,Verdana,sans-serif,宋体;
text-align: left;
font-size: 10pt;
width: 100%;
}
ul.message-for-user li.outer-message-for-user {
margin-left: 20px;
border-bottom: 1px solid rgb(213, 222, 233);
margin-bottom: 10px;
margin-top: 10px;
}
.portrait{
float: left;
width: 40px;
padding-top: 3px;
margin: 0px;
padding: 0px;
display: block;
}
span.body{
float: left;
width: 80%;
overflow: hidden;
font-size: 9pt;
margin: 0px 10px;
padding: 0px;
display: block;
margin-left: 20px;
}
span.time{
color: rgb(172,174,174);
}
.message-notes{
max-width: 80%;
word-wrap: break-word;
}
ul.messages-for-user-reply li {
padding-bottom: 4px;
}
.respond-form{
display: none;
width: 100%;
margin: auto;
clear:both;
}