完成问吧 memo新建及 forum详情页面相关功能

This commit is contained in:
huang 2016-12-28 15:24:26 +08:00
parent c3aa69029e
commit da88c43e95
12 changed files with 181 additions and 96 deletions

View File

@ -191,16 +191,17 @@ class ForumsController < ApplicationController
@memo = Memo.new(:forum => @forum)
@topic_count = Memo.count
@topic_pages = Paginator.new @topic_count, per_page_option, params['page']
@memos = Memo.includes(:last_reply).
@memos = @forum.topics.includes(:last_reply).
limit(@topic_pages.per_page).
offset(@topic_pages.offset).
reorder(order).
preload(:author, {:last_reply => :author}).
all
@forums = Forum.includes(:memos).preload(:topics)
@my_topic_count = Memo.where("author_id = #{User.current.id} and parent_id is null").count
@my_replies_count = Memo.where("author_id = #{User.current.id} and parent_id is not null").count
@errors = params[:errors]
# 推荐贴吧
@forums = Forum.where("id !=?", @forum.id).reorder("topic_count desc,updated_at desc").first(3)
respond_to do |format|
format.js
format.html {

View File

@ -29,30 +29,22 @@ class MemosController < ApplicationController
def new
@memo = Memo.new
@memo.forum_id = @forum.id
@my_forums_count = Forum.where(:creator_id => User.current.id).count
@my_memos_count = Memo.where(:author_id => User.current.id).count
respond_to do |format|
format.html {
render action: :new ,layout: 'base'
}
format.js
format.html {render layout: 'base_new_forum'}
format.json { render json: @memo }
end
end
def create
if params[:quote].nil?
@quote = ""
else
@quote = params[:quote]
end
#unless params[:quote].nil?
# @quote = params[:quote][:quote]
#end
@memo = Memo.new(params[:memo])
@memo.forum_id = params[:forum_id]
@memo.author_id = User.current.id
@ -78,17 +70,14 @@ class MemosController < ApplicationController
asset.save
end
end
#end
format.js
format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" }
format.json { render json: @memo, status: :created, location: @memo }
format.js
format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" }
format.json { render json: @memo, status: :created, location: @memo }
else
flash.now[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}"
format.js
format.html { redirect_to( forum_path(Forum.find(params[:forum_id]),:errors=>@memo.errors.full_messages[0])) }
format.json { render json: @memo.errors, status: :unprocessable_entity }
#end
end
end
end

View File

@ -47,7 +47,8 @@
<%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %>
<!--%= link_to image_tag(),"javascript:void(0)", :onclick => "_file.click()"%-->
<%#= button_tag "文件浏览", :type=>"button", :onclick=>"$('#_file').click();",:onmouseover => 'this.focus()',:class => 'AnnexBtn fl mt3' %>
<a href="javascript:void(0);" onclick="_file.click();" class="AnnexBtn fl mr15">上传附件</a>
<%= button_tag "上传附件", :id => "upload_attachments", :type=>"button", :onclick=>"$('#_file').click();",:onmouseover => 'this.focus()',:class => 'sub_btn' %>
<!--<a href="javascript:void(0);" onclick="_file.click();" class="AnnexBtn fl mr15">上传附件</a>-->
<%= file_field_tag 'attachments[dummy][file]',
:id => '_file',
:class => 'file_selector',

View File

@ -0,0 +1,16 @@
<div class="postDetailContainer mb10 fl" style="width: 208px;">
<div class="fl mr10"><%= link_to image_tag(url_to_avatar(User.current), :width => 50, :height => 50, :alt=>'贴吧图像'), user_path(User.current) %></div>
<div class="mt8 fl">
<div class="f16 fontGrey2">我在贴吧</div>
<div class="homepageImageBlock" style="width: 68px !important;">
<div><a href="javascript:void(0);" class="homepageImageNumber" style="cursor: default"><%= @my_forums_count %></a></div>
<div class="homepageImageText">回答</div>
</div>
<div class="homepageVerDiv"></div>
<div class="homepageImageBlock" style="width: 68px !important;">
<div><a href="javascript:void(0);" class="homepageImageNumber" style="cursor: default"><%= @my_memos_count %></a></div>
<div class="homepageImageText">发帖</div>
</div>
</div>
<div class="cl"></div>
</div>

View File

@ -1,8 +1,4 @@
<div class="wenba-rightbar">
<div class="wenba-rightbar-top clearfix">
<h3 class="fl ml10">问吧</h3>
<%= link_to "新建贴吧", new_forum_path, :class => "btn-blue btn fr mt5 mr5", :remote => true %>
</div>
<% @forums.each do |forum| %>
<div class="wenba-rightbar-li clearfix">
<h4 class="fl wenba-rightbar-title mt5 ml5"><%= link_to forum.name, forum_path(forum), :class => "" %></h4>
@ -16,6 +12,4 @@
</ul>
</div>
<% end %>
<a href="javascript:void(0);" class="wenba-rightbar-more linkBlue2">点击展开更多</a>
</div>

View File

@ -54,7 +54,14 @@
</div>
<div class="homepageLeft-new" id="forum_right_bar">
<%= render :partial => "forums/right_bar" %>
<div class="wenba-rightbar">
<div class="wenba-rightbar-top clearfix">
<h3 class="fl ml10">问吧</h3>
<%= link_to "新建贴吧", new_forum_path, :class => "btn-blue btn fr mt5 mr5", :remote => true %>
</div>
<%= render :partial => "forums/right_bar" %>
<a href="javascript:void(0);" class="wenba-rightbar-more linkBlue2">点击展开更多</a>
</div>
</div>
<script>
function add_class(id){

View File

@ -6,7 +6,7 @@
<div class="postRightContainer mr10">
<div id="create_memo_div" style="display: none">
<div id="error" class="red fl mb10" style="display: none">error</div>
<%= labelled_form_for(@memo, :url => forum_memos_path(@forum),:remote=>true) do |f| %>
<%= labelled_form_for(@memo, :url => forum_memos_path(@forum), :remote => true) do |f| %>
<div>
<textarea type="text" name="memo[subject]" id="memo_subject" maxlength="50" onblur="check_memo_name();" onfocus="$('#error').hide();" onmouseover="this.style.borderColor='#d9d9d9'" class="postDetailInput" placeholder="输入帖子标题" ></textarea>
<script>
@ -38,46 +38,25 @@
<div class="postSort" id="complex"><a href="javascript:void(0);" class="linkGrey2 fl">综合</a><a href="javascript:void(0);" id="reorder_complex" class=""></a><!--<a href="javascript:void(0);" class="sortArrowActiveD"></a>--></div>
<div class="creatPost" id="create_memo_btn">
<%= link_to "发布新帖", new_forum_path(@forums), :class => "c_white db creatPostIcon bBlue", :remote => true %>
<!--<a href="javascript:void(0);" class="c_white db creatPostIcon bBlue" onclick="$('#error').hide();$('#create_memo_div').slideToggle();$(this).parent().slideToggle();">发布新帖</a>-->
<%= link_to "我要提问", new_forum_memo_path(:forum_id => @forum), :class => "c_white db creatPostIcon bBlue" %>
<a href="javascript:void(0);" class="c_white db creatPostIcon bBlue" onclick="$('#error').hide();$('#create_memo_div').slideToggle();$(this).parent().slideToggle();">发布新帖</a>
</div>
<div class="cl"></div>
</div>
<div id="topics_list">
<%= render :partial => 'show_topics',:locals => {:memos=>@memos}%>
</div>
<!--<div class="pageRoll">-->
<!--<div class="pageCell"><a href="javascript:void(0);" class="linkBlue">上一页</a></div>-->
<!--<div class="pageCell pageCellActive"><a href="javascript:void(0);" class="c_white">1</a></div>-->
<!--<div class="pageCell"><a href="javascript:void(0);" class="fontBlue">2</a></div>-->
<!--<div class="pageCell"><a href="javascript:void(0);" class="fontBlue">3</a></div>-->
<!--<div class="pageCell"><a href="javascript:void(0);" class="fontBlue">...</a></div>-->
<!--<div class="pageCell"><a href="javascript:void(0);" class="fontBlue">14</a></div>-->
<!--<div class="pageCell"><a href="javascript:void(0);" class="linkBlue">下一页</a></div>-->
<!--</div>-->
<!--<div class="cl"></div>-->
</div>
<div class="postDetailContainer mb10 fl" style="width: 208px;">
<div class="fl mr10"><%= link_to image_tag(url_to_avatar(User.current),:width=>50,:height => 50,:alt=>'贴吧图像' ), user_path( User.current) %></div>
<div class="mt8 fl">
<div class="f16 fontGrey2">我在贴吧</div>
<div class="homepageImageBlock" style="width: 68px !important;">
<div><a href="javascript:void(0);" class="homepageImageNumber" style="cursor: default"><%= @my_replies_count %></a></div>
<div class="homepageImageText">回答</div>
</div>
<div class="homepageVerDiv"></div>
<div class="homepageImageBlock" style="width: 68px !important;">
<div><a href="javascript:void(0);" class="homepageImageNumber" style="cursor: default"><%= @my_topic_count %></a></div>
<div class="homepageImageText">发帖</div>
</div>
</div>
<div class="cl"></div>
</div>
<%= render :partial => "forums/my_count_message" %>
<div class="homepageLeft-new" id="forum_right_bar">
<div class="wenba-rightbar">
<div class="wenba-rightbar-top clearfix">
<h3 class="fl ml10">推荐问吧</h3>
</div>
<%= render :partial => "forums/right_bar" %>
</div>
</div>
<script>
function add_class(id){

View File

@ -1,3 +1,96 @@
<%= error_messages_for 'bid' %>
<p><%= f.text_field :content, :required => true, :size => 60, :style => "width:150px;" %></p>
<p><%= hidden_field_tag 'subject'||=@memo.subject %>
<%= content_for(:header_tags) do %>
<%= import_ke(enable_at: false, prettify: false, init_activity: false) %>
<% end %>
<div class="wenba-tiwenbox fl mr10 mb10">
<%= labelled_form_for(@memo, :url => forum_memos_path(@forum)) do |f| %>
<div class="wenba-tiwen-con">
<ul >
<li class="mb10">
<input type="text" name="memo[subject]" id="memo_subject" maxlength="50" onblur="check_memo_name();" onfocus="$('#error').hide();" onmouseover="this.style.borderColor='#d9d9d9'" class="wenba-tiwen-input" placeholder="请输入标题">
<!--<input type="text" placeholder="请输入标题" class="wenba-tiwen-input">-->
<script>
var textarea1 = document.getElementById('memo_subject');
autoTextarea(textarea1);
</script>
</li>
<li class="mb10">
<%= kindeditor_tag 'memo[content]','', :height => 300, :editor_id => 'memo_content' %>
<!--<textarea placeholder="请输入描述详情" class="wenba-tiwen-textarea"></textarea>-->
</li>
<li class="clear mb10">
<%= render :partial => 'forums/file_form', :locals => {:container => @memo} %>
<!--<button class="sub_btn fl" name="button" type="button">上传附件</button>-->
<!--<p class="fl ml5 mt3 c_grey">(未选择文件) 您可以上传小于<span class="c_red">50MB</span>的文件</p>-->
</li>
</ul>
<ul class="wenba-tagbox clearfix">
<h3 class="mb5">请选择分类(<span class="c_red">1</span>个)</h3>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag wenba-tiwen-tag-active">新手讨论吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">网站建议吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">技术动态吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">教程共享吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">创业吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">互联网新闻</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">开源创新吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">网站新闻吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">技术知识交流</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">假日问候吧</a></li>
</ul>
<div class="clear ">
<%= link_to "取消", forum_path(@forum), :class => "btn fr" %>
<a href="javascript:void(0);" class="btn btn-blue fr mr5" onclick="memo_commit();">确定</a>
</div>
</div>
<% end %>
</div>
<script>
function check_memo_name(){
if($("#memo_subject").val().trim().length > 50){
$("#error").html("主题 过长(最长为 50 个字符)").show();
return false;
}
if(memo_content.html().length > 20000){
$("#error").html("内容 过长(最长为 20000 个字符)").show();
$("html,body").animate({scrollTop:$("#error").offset().top},1000)
return false;
}
return true;
}
var first_click = true;
function check_and_submit(){
if(!check_memo_name()){
return;
}
if($("textarea[name='memo[subject]']").val().trim() != "" && !memo_content.isEmpty() && first_click){
first_click = false;
memo_content.sync();
$.ajax({
url:'/forums/'+'<%= @forum.id.to_s%>'+'/memos',
type:'post',
data:$("#new_memo").serialize(),
success:function(data){
},
error:function(){
alert('请检查当前网络连接')
}
});
//$("#new_memo").submit();
}else if($("textarea[name='memo[subject]']").val().trim() == "" && memo_content.isEmpty()){
$("#error").html("主题和内容不能为空").show();
}
else if($("textarea[name='memo[subject]']").val().trim() == "" && !memo_content.isEmpty() ){
$("#error").html("主题不能为空").show();
}else if($("textarea[name='memo[subject]']").val().trim() != "" && memo_content.isEmpty()){
$("#error").html("内容不能为空").show();
}
}
function memo_commit(){
memo_content.sync();
$("#new_memo").submit();
}
</script>

View File

@ -0,0 +1,33 @@
<div class="wenba-tiwenbox">
<div class="wenba-tiwen-con" >
<ul>
<li class="mb10 ">
<input type="text" placeholder="请输入标题" class="wenba-tiwen-input ">
</li>
<li class="mb10">
<textarea placeholder=" 请输入描述详情" class="wenba-tiwen-textarea"></textarea>
</li>
<li class="clear mb10">
<button class="sub_btn fl " name="button" type="button">上传附件</button>
<p class="fl ml5 mt3 c_grey">(未选择文件) 您可以上传小于<span class="c_red">50MB</span>的文件</p>
</li>
</ul>
<ul class="wenba-tagbox clearfix">
<h3 class="mb5">请选择分类(<span class="c_red">1</span>个)</h3>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag wenba-tiwen-tag-active">新手讨论吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">网站建议吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">技术动态吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">教程共享吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">创业吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">互联网新闻</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">开源创新吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">网站新闻吧</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">技术知识交流</a></li>
<li><a href="javascript:void(0);" class="wenba-tiwen-tag">假日问候吧</a></li>
</ul>
<div class="clear ">
<button class=" btn btn-blue fr ">确定</button >
<button class=" btn fr mr5">取消</button >
</div>
</div>
</div>

View File

@ -1,35 +1,5 @@
<% @nav_dispaly_home_path_label = 1
@nav_dispaly_main_course_label = 1
@nav_dispaly_main_project_label = 1
@nav_dispaly_main_contest_label = 1 %>
<% @nav_dispaly_forum_label = 1%>
<!-- <h1>New memo</h1> -->
<%= content_for(:header_tags) do %>
<%= import_ke(enable_at: false, prettify: false, init_activity: false) %>
<% end %>
<div class="banner-big f16 fontGrey3 mb10">问吧 > 我要提问</div>
<%= render :partial => "memos/form" %>
<div class="top-content">
<table>
<tr>
<td class="info_font" style="width: 240px; color: #15bccf"><%= l(:label_projects_community)%></td>
<td style="width: 430px; color: #15bccf"><strong><%= l(:label_user_location) %> : </strong></td>
<td rowspan="2" width="250px">
<div class="top-content-search">
</div>
</td>
</tr>
<tr>
<td style="padding-left: 8px"><%= link_to request.host()+"/forums", forums_path %></td>
<td><p class="top-content-list"><%=link_to l(:label_home),home_path %> > <%=link_to l(:label_forum), :controller => 'forums', :action => 'index' %> > <%=link_to @forum.name %></p></td>
</tr>
</table>
</div>
<h3><%=l(:label_memo_new)%></h3>
<div class="box tabular">
<div style="width:780px">
<%= render :partial => 'memos/topic_form' %>
</div>
</div>
<%= render :partial => "forums/my_count_message" %>

View File

View File

@ -21,4 +21,6 @@ a:hover.wenba-tiwen-tag,a.wenba-tiwen-tag-active{ background: #3b94d6; color: #f
.btn-green{background: #60b25e; color: #fff;}
.btn-green:hover{background: #51a74f; color: #fff;}
.btn-blue{background: #3b94d6; color: #fff;}
.btn-blue:hover{background: #2788d0; color: #fff;}
.btn-blue:hover{background: #2788d0; color: #fff;}
.banner-big {width:968px; background-color: #ffffff; padding:10px 15px; border:1px solid #dddddd;}