2013-12-25 15:40:34 +08:00
|
|
|
# encoding: utf-8
|
2013-08-01 10:33:49 +08:00
|
|
|
#####leave message fq
|
|
|
|
class WordsController < ApplicationController
|
|
|
|
|
|
|
|
before_filter :find_user, :only => [:new, :create, :destroy, :more, :back]
|
|
|
|
def create
|
|
|
|
if params[:new_form][:user_message].size>0
|
|
|
|
unless params[:user_id].nil?
|
2013-08-15 09:54:08 +08:00
|
|
|
if params[:reference_content]
|
2013-08-28 15:29:18 +08:00
|
|
|
message = params[:new_form][:user_message] + "\n" + params[:reference_content]
|
2013-08-15 09:54:08 +08:00
|
|
|
else
|
|
|
|
message = params[:new_form][:user_message]
|
|
|
|
end
|
2013-08-06 22:26:52 +08:00
|
|
|
refer_user_id = params[:new_form][:reference_user_id].to_i
|
|
|
|
|
|
|
|
@user.add_jour(User.current, message, refer_user_id)
|
2013-12-09 08:36:31 +08:00
|
|
|
unless refer_user_id == 0 || refer_user_id == User.current.id
|
2013-12-05 15:50:24 +08:00
|
|
|
User.find(refer_user_id).add_jour(User.current, message, refer_user_id)
|
|
|
|
end
|
2013-08-25 20:19:44 +08:00
|
|
|
@user.count_new_jour
|
2013-08-01 10:33:49 +08:00
|
|
|
# if a_message.size > 5
|
|
|
|
# @message = a_message[-5, 5]
|
|
|
|
# else
|
|
|
|
# @message = a_message
|
|
|
|
# end
|
|
|
|
# @message_count = a_message.count
|
|
|
|
end
|
|
|
|
end
|
2013-12-26 08:43:16 +08:00
|
|
|
@jours = @user.journals_for_messages.where('m_parent_id IS NULL').reverse
|
2013-08-12 15:37:42 +08:00
|
|
|
@limit = 10
|
|
|
|
@feedback_count = @jours.count
|
|
|
|
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
|
|
|
@offset ||= @feedback_pages.offset
|
|
|
|
@jour = @jours[@offset, @limit]
|
2013-08-25 20:19:44 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
respond_to do |format|
|
|
|
|
# format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
|
|
|
|
format.js
|
|
|
|
#format.api { render_api_ok }
|
2013-08-06 22:26:52 +08:00
|
|
|
end
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
|
|
|
|
2013-12-24 16:42:56 +08:00
|
|
|
def create_reply
|
2013-12-26 08:39:43 +08:00
|
|
|
# deny api. api useless
|
|
|
|
user_id = request.headers["Referer"].match((%r|/([0-9]{1,})/|))[1]
|
2013-12-25 22:21:16 +08:00
|
|
|
@user = User.find(user_id)
|
2013-12-25 10:09:21 +08:00
|
|
|
parent_id = params[:reference_id]
|
|
|
|
author_id = User.current.id
|
|
|
|
reply_user_id = params[:reference_user_id]
|
2013-12-25 22:21:16 +08:00
|
|
|
reply_id = params[:reference_message_id] # 暂时不实现
|
2013-12-25 10:09:21 +08:00
|
|
|
content = params[:user_notes]
|
2013-12-25 15:40:34 +08:00
|
|
|
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}
|
2013-12-25 22:21:16 +08:00
|
|
|
@jfm = @user.add_jour(nil, nil, nil, options)
|
2013-12-25 10:09:21 +08:00
|
|
|
|
2013-12-24 16:42:56 +08:00
|
|
|
respond_to do |format|
|
2013-12-25 22:21:16 +08:00
|
|
|
# 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?
|
2013-12-25 15:40:34 +08:00
|
|
|
}
|
2013-12-24 16:42:56 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
def destroy
|
2013-08-28 15:29:18 +08:00
|
|
|
if User.current.admin? || User.current.id == @user.id
|
|
|
|
JournalsForMessage.delete_message(params[:object_id])
|
|
|
|
end
|
2013-08-12 15:37:42 +08:00
|
|
|
@jours = @user.journals_for_messages.reverse
|
|
|
|
@limit = 10
|
|
|
|
@feedback_count = @jours.count
|
|
|
|
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
|
|
|
@offset ||= @feedback_pages.offset
|
|
|
|
@jour = @jours[@offset, @limit]
|
2013-08-01 10:33:49 +08:00
|
|
|
# if a_message.size > 5
|
|
|
|
# @message = a_message[-5, 5]
|
|
|
|
# else
|
|
|
|
# @message = a_message
|
|
|
|
# end
|
|
|
|
# @message_count = a_message.count
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to :back }
|
|
|
|
format.js
|
|
|
|
#format.api { render_api_ok }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
|
|
|
|
if @jour
|
|
|
|
user = @jour.user
|
|
|
|
text = @jour.notes
|
|
|
|
else
|
|
|
|
user = @user
|
|
|
|
text = []
|
|
|
|
end
|
|
|
|
# Replaces pre blocks with [...]
|
|
|
|
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
|
2013-10-19 15:39:53 +08:00
|
|
|
@content = "> #{ll(User.current.language, :text_user_wrote, user)}\n> "
|
2013-08-01 10:33:49 +08:00
|
|
|
@content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
2013-08-28 15:29:18 +08:00
|
|
|
|
|
|
|
# @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
|
|
|
# @content = "> #{ll(Setting.default_language, :text_user_wrote, user)}\n> "
|
|
|
|
|
2013-08-06 22:26:52 +08:00
|
|
|
@id = user.id
|
2013-08-01 10:33:49 +08:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
|
|
|
|
def more
|
2013-08-12 15:37:42 +08:00
|
|
|
@jours = @user.journals_for_messages.reverse
|
|
|
|
@limit = 10
|
|
|
|
@feedback_count = @jours.count
|
|
|
|
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
|
|
|
@offset ||= @feedback_pages.offset
|
|
|
|
@jour = @jours[@offset, @limit]
|
2013-08-01 10:33:49 +08:00
|
|
|
@state = true
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to :back }
|
|
|
|
format.js
|
|
|
|
#format.api { render_api_ok }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def back
|
2013-08-12 15:37:42 +08:00
|
|
|
@jours = @user.journals_for_messages.reverse
|
|
|
|
@limit = 10
|
|
|
|
@feedback_count = @jours.count
|
|
|
|
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
|
|
|
@offset ||= @feedback_pages.offset
|
|
|
|
@jour = @jours[@offset, @limit]
|
2013-08-01 10:33:49 +08:00
|
|
|
@state = false
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to :back }
|
|
|
|
format.js
|
|
|
|
#format.api { render_api_ok }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-16 22:53:28 +08:00
|
|
|
def add_project_respond
|
|
|
|
user = User.current
|
|
|
|
message = params[:new_form][:project_message]
|
|
|
|
Project.add_jour(user, message)
|
|
|
|
|
|
|
|
redirect_to project_feedback_path('trustie')
|
|
|
|
# redirect_to signin_path
|
|
|
|
end
|
|
|
|
|
2013-11-07 11:02:32 +08:00
|
|
|
def leave_project_message
|
|
|
|
user = User.current
|
|
|
|
message = params[:new_form][:project_message]
|
2013-12-21 10:15:41 +08:00
|
|
|
feedback = Project.add_new_jour(user, message, params[:id])
|
|
|
|
if(feedback.errors.empty?)
|
|
|
|
redirect_to project_feedback_path(params[:id]), notice: l(:label_feedback_success)
|
|
|
|
else
|
|
|
|
flash[:error] = feedback.errors.full_messages[0]
|
|
|
|
redirect_to project_feedback_path(params[:id])
|
|
|
|
end
|
|
|
|
|
2013-11-07 11:02:32 +08:00
|
|
|
end
|
|
|
|
|
2013-09-14 17:22:44 +08:00
|
|
|
def add_brief_introdution
|
|
|
|
user = User.current
|
|
|
|
message = params[:new_form][:user_introduction]
|
|
|
|
UserExtensions.introduction(user, message)
|
|
|
|
redirect_to user_path(user.id)
|
|
|
|
end
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
def find_user
|
|
|
|
if params[:user_id]
|
|
|
|
@user = User.find(params[:user_id])
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
|
|
|
|
#######end of message
|
|
|
|
end
|