给需求的留言添加了“确认删除”弹窗,重构了赞和踩模块,针对问题添加了赞和踩功能。粉丝数的链接问题未修改玩。
This commit is contained in:
parent
1a57b3c6a7
commit
7a0db3b3f1
|
@ -1,32 +1,10 @@
|
||||||
class PraiseTreadController < ApplicationController
|
class PraiseTreadController < ApplicationController
|
||||||
|
|
||||||
def praise_plus
|
def praise_plus
|
||||||
@obj = nil
|
@obj = nil
|
||||||
if request.get?
|
if request.get?
|
||||||
@obj = params[:obj] # 传的是对象,最后变成id了
|
@obj_id = params[:obj_id]
|
||||||
|
@obj_type = params[:obj_type]
|
||||||
#首先创建或更新praise_tread 表
|
@obj = praise_tread_plus(@obj_type,@obj_id,1)
|
||||||
@pt = PraiseTread.find_by_user_id_and_praise_tread_object_id(User.current.id,@obj)
|
|
||||||
@pt = @pt.nil? ? PraiseTread.new : @pt
|
|
||||||
|
|
||||||
@pt.user_id = User.current.id
|
|
||||||
@pt.praise_tread_object_id = @obj.to_i
|
|
||||||
@pt.praise_tread_object_type = User.find_by_id(@obj).class.name.underscore
|
|
||||||
@pt.praise_or_tread = 1
|
|
||||||
@pt.save
|
|
||||||
|
|
||||||
#再创建或更新praise_tread_cache表
|
|
||||||
@ptc = PraiseTreadCache.find_by_object_id(@obj)
|
|
||||||
@ptc = @ptc.nil? ? PraiseTreadCache.new : @ptc
|
|
||||||
@ptc.object_id = @obj.to_i
|
|
||||||
@ptc.object_type = User.find_by_id(@obj).class.name.underscore
|
|
||||||
@ptc.plus(1)
|
|
||||||
@ptc.save
|
|
||||||
end
|
|
||||||
@obj = User.find_by_id(@obj)
|
|
||||||
respond_to do |format|
|
|
||||||
format.html
|
|
||||||
format.js
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,7 +33,12 @@ class PraiseTreadController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def tread_plus
|
def tread_plus
|
||||||
|
@obj = nil
|
||||||
|
if request.get?
|
||||||
|
@obj_id = params[:obj_id]
|
||||||
|
@obj_type = params[:obj_type]
|
||||||
|
@obj = praise_tread_plus(@obj_type,@obj_id,0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def tread_minus
|
def tread_minus
|
||||||
|
@ -65,4 +48,49 @@ class PraiseTreadController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def find_object_by_type_and_id(type,id)
|
||||||
|
@obj = nil
|
||||||
|
case type
|
||||||
|
when 'User'
|
||||||
|
@obj = User.find_by_id(id)
|
||||||
|
when 'Issue'
|
||||||
|
@obj = Issue.find_by_id(id)
|
||||||
|
when 'Project'
|
||||||
|
@obj = Project.find_by_id(id)
|
||||||
|
when 'Bid'
|
||||||
|
@obj = Bid.find_by_id(id)
|
||||||
|
end
|
||||||
|
return @obj
|
||||||
|
end
|
||||||
|
|
||||||
|
def praise_tread_plus(type,id,flag)
|
||||||
|
unless id.nil? and type.nil?
|
||||||
|
#首先创建或更新praise_tread 表
|
||||||
|
@pt = PraiseTread.new
|
||||||
|
@pt.user_id = User.current.id
|
||||||
|
@pt.praise_tread_object_id = id.to_i
|
||||||
|
@pt.praise_tread_object_type = type
|
||||||
|
@pt.praise_or_tread = flag
|
||||||
|
@pt.save
|
||||||
|
# end
|
||||||
|
|
||||||
|
#再创建或更新praise_tread_cache表
|
||||||
|
@ptc = PraiseTreadCache.find_by_object_id_and_object_type(id,type)
|
||||||
|
@ptc = @ptc.nil? ? PraiseTreadCache.new : @ptc
|
||||||
|
@ptc.object_id = id.to_i
|
||||||
|
@ptc.object_type = type
|
||||||
|
@ptc.save
|
||||||
|
@ptc.plus(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
@obj = find_object_by_type_and_id(type,id)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
module PraiseTreadHelper
|
module PraiseTreadHelper
|
||||||
#added by william
|
#added by william
|
||||||
def is_praise_or_tread(object,user_id)
|
def is_praise_or_tread(object,user_id)
|
||||||
@obj_type = object.class.name.underscore
|
@obj_type = object.class
|
||||||
@obj_id = object.id
|
@obj_id = object.id
|
||||||
@is_praise = PraiseTread.find_by_sql("select * from praise_treads where user_id=#{user_id} and " +
|
@is_praise = PraiseTread.find_by_sql("select praise_or_tread from praise_treads where user_id=#{user_id} and " +
|
||||||
"praise_tread_object_type='#{@obj_type}' and praise_tread_object_id=#{@obj_id} ")
|
"praise_tread_object_type='#{@obj_type}' and praise_tread_object_id=#{@obj_id}")
|
||||||
return @is_praise
|
return @is_praise
|
||||||
end
|
end
|
||||||
#end
|
#end
|
||||||
|
|
|
@ -48,7 +48,8 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td align="left"><a class="font_lighter"> <%= journal.created_on %></a></td>
|
<td align="left"><a class="font_lighter"> <%= journal.created_on %></a></td>
|
||||||
<td width="200" align="right" class="a"><%= link_to(image_tag('comment.png'), {:controller => 'bids', :action => 'new', :id => bid, :journal_id => journal}, :remote => true,
|
<td width="200" align="right" class="a"><%= link_to(image_tag('comment.png'), {:controller => 'bids', :action => 'new', :id => bid, :journal_id => journal}, :remote => true,
|
||||||
:method => 'post', :title => l(:button_quote))%><%= link_to(image_tag('delete.png'), {:controller => 'bids', :action => 'destroy', :object_id => journal, :id => bid},
|
:method => 'post', :title => l(:button_quote))%>
|
||||||
|
<%= link_to(image_tag('delete.png'), {:controller => 'bids', :action => 'destroy', :object_id => journal, :id => bid},:confirm => l(:label_delete_confirm),
|
||||||
:remote => true, :method => 'delete', :class => "delete", :title => l(:button_delete)) if remove_allowed || journal.user_id == User.current.id %></td>
|
:remote => true, :method => 'delete', :class => "delete", :title => l(:button_delete)) if remove_allowed || journal.user_id == User.current.id %></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table></td>
|
</table></td>
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<!-- <%= avatar(@issue.author, :size => "50") %> -->
|
<!-- <%= avatar(@issue.author, :size => "50") %> -->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="subject">
|
<div class="subject">
|
||||||
<%= render_issue_subject_with_tree(@issue) %>
|
<%= render_issue_subject_with_tree(@issue) %>
|
||||||
|
@ -36,7 +34,10 @@
|
||||||
<div id="tags">
|
<div id="tags">
|
||||||
<%= render :partial => 'layouts/tag', :locals => {:obj => @issue,:object_flag => "3" }%>
|
<%= render :partial => 'layouts/tag', :locals => {:obj => @issue,:object_flag => "3" }%>
|
||||||
</div>
|
</div>
|
||||||
|
<span id="praise_tread" style="float:right;">
|
||||||
|
<%= render :partial => "/praise_tread/praise_tread",
|
||||||
|
:locals => {:obj => @issue,:user_id =>User.current.id}%>
|
||||||
|
</span>
|
||||||
<table class="attributes">
|
<table class="attributes">
|
||||||
<%= issue_fields_rows do |rows|
|
<%= issue_fields_rows do |rows|
|
||||||
rows.left l(:field_status), h(@issue.status.name), :class => 'status'
|
rows.left l(:field_status), h(@issue.status.name), :class => 'status'
|
||||||
|
|
|
@ -44,15 +44,12 @@
|
||||||
</tr>
|
</tr>
|
||||||
</table></td>
|
</table></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><td>
|
|
||||||
<span id="praise_tread" style="float:left;"> <%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => @user,:show_flag => false,:user_id =>User.current.id}%> </span>
|
|
||||||
</td></tr>
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<%= l(:label_user_watcher) %> (<strong class="font_small_watch"><%=link_to User.watched_by(@user.id).count ,:controller=>"users", :action=>"user_watchlist"%></strong>)
|
<%= l(:label_user_watcher) %> (<strong class="font_small_watch"><%=link_to User.watched_by(@user.id).count ,:controller=>"users", :action=>"user_watchlist"%></strong>)
|
||||||
<%= render :partial => "watchers/fans_num",:locals => {:fans_num => get_fans_num(@user) }%>
|
<%= render :partial => "watchers/fans_num",:locals => {:fans_num => get_fans_num(@user) }%>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,17 +1,22 @@
|
||||||
<span id="praise">
|
<span id="praise_tread">
|
||||||
<% if is_praise_or_tread(obj,user_id).size > 0 %>
|
<% @is_valuate = is_praise_or_tread(obj,user_id)%>
|
||||||
<%= image_tag("/images/praise.png") %>
|
|
||||||
<%= link_to "#{l(:label_cancel_praise)}",:controller=>"praise_tread",:action=>"praise_minus",:remote=>true,:obj => obj %>
|
<% if @is_valuate.size > 0 %>
|
||||||
(<strong class="font_small_watch"><%= get_praise_num(obj)%></strong>)
|
|
||||||
<% else %>
|
<% @flag = @is_valuate.first.praise_or_tread %>
|
||||||
<%= image_tag("/images/tread.png") %>
|
<% if @flag == 1 %> <!-- praise 1 -->
|
||||||
<%= link_to "#{l(:label_praise)}",:controller=>"praise_tread",:action=>"praise_plus",:remote=>true,:obj => obj %>
|
<%= image_tag("/images/praise_tread/praise_true.png") %> <strong class="font_small_watch"><%= get_praise_num(obj)%></strong> <%= image_tag("/images/praise_tread/tread_false.png") %>
|
||||||
(<strong class="font_small_watch"><%= get_praise_num(obj)%></strong>)
|
|
||||||
|
<% elsif @flag == 0 %> <!-- tread 0-->
|
||||||
|
<%= image_tag("/images/praise_tread/praise_false.png") %> <strong class="font_small_watch"><%= get_praise_num(obj)%></strong> <%= image_tag("/images/praise_tread/tread_true.png") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% else %>
|
||||||
|
|
||||||
|
<%= link_to image_tag("/images/praise_tread/praise_false.png"),
|
||||||
|
:controller=>"praise_tread",:action=>"praise_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class %> <strong class="font_small_watch"><%= get_praise_num(obj)%></strong> <%= link_to image_tag("/images/praise_tread/tread_false.png"),:controller=>"praise_tread",
|
||||||
|
:action=>"tread_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class %>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
</span>
|
</span>
|
||||||
<% if show_flag %>
|
|
||||||
<span id="tread">
|
|
||||||
<%= link_to image_tag("/images/tread.png"),:controller=>"praise_tread",
|
|
||||||
:action=>"tread_minus",:remote=>true,:obj => obj %>踩
|
|
||||||
</span>
|
|
||||||
<% end %>
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
$('#praise_tread').html('<%= j(
|
$('#praise_tread').html('<%= j(
|
||||||
render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:show_flag => false,:user_id => User.current.id}
|
render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id}
|
||||||
)%>');
|
)%>');
|
||||||
|
|
|
@ -23,8 +23,8 @@ RedmineApp::Application.routes.draw do
|
||||||
get "tags/show"
|
get "tags/show"
|
||||||
|
|
||||||
get "praise_tread/praise_plus"
|
get "praise_tread/praise_plus"
|
||||||
get "praise_tread/praise_minus"
|
|
||||||
get "praise_tread/tread_minus"
|
get "praise_tread/tread_plus"
|
||||||
|
|
||||||
root :to => 'welcome#index', :as => 'home'
|
root :to => 'welcome#index', :as => 'home'
|
||||||
|
|
||||||
|
@ -442,7 +442,7 @@ RedmineApp::Application.routes.draw do
|
||||||
match 'tags/delete_tag',:to => 'tags#delete_tag',:as=>"add_tag"
|
match 'tags/delete_tag',:to => 'tags#delete_tag',:as=>"add_tag"
|
||||||
match 'tags/show_all',:to => 'tags#show_all'
|
match 'tags/show_all',:to => 'tags#show_all'
|
||||||
match 'parise_tread/praise_plus',:to => 'parise_tread#praise_plus',:as=>"praise"
|
match 'parise_tread/praise_plus',:to => 'parise_tread#praise_plus',:as=>"praise"
|
||||||
match 'parise_tread/tread_minus',:to => 'parise_tread#tread_minus',:as=>"tread"
|
match 'parise_tread/tread_plus',:to => 'parise_tread#tread_plus',:as=>"tread"
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue