课程讨论区发布帖子、编辑帖子的实现

This commit is contained in:
cxt 2015-10-15 16:17:48 +08:00
parent 5d8ebad25c
commit 8ea5d98b6c
12 changed files with 282 additions and 133 deletions

View File

@ -96,6 +96,7 @@ class BoardsController < ApplicationController
'replies' => "#{Message.table_name}.replies_count",
'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
@is_new = params[:is_new]
@topic_count = @board ? @board.topics.count : 0
if @project
@topic_pages = Paginator.new @topic_count, per_page_option, params['page']

View File

@ -42,7 +42,9 @@
<span class="add_attachment">
<%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %>
<!--%= link_to image_tag(),"javascript:void(0)", :onclick => "_file.click()"%-->
<%= button_tag "#{l(:button_browse)}", :type=>"button", :onclick=>"file#{container.id}.click()",:class =>"sub_btn",:style => ie8? ? 'display:none' : '' %>
<%#= button_tag "#{l(:button_browse)}", :type=>"button", :onclick=>"file#{container.id}.click()",:class =>"sub_btn",:style => ie8? ? 'display:none' : '' %>
<% id ="file#{container.id}"%>
<a href="javascript:void(0);" class="AnnexBtn fl" style= "<%= ie8? ? 'display:none' : ''%>" onclick="$('#'+'<%= id %>').click();">上传附件</a>
<%= file_field_tag 'attachments[dummy][file]',
:id => "file#{container.id}",
:class => 'file_selector',
@ -63,7 +65,7 @@
<% if container.nil? %>
<span id="upload_file_count" :class="c_grey"><%= l(:label_no_file_uploaded)%></span>
<% end %>
(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)
<!--(<%#= l(:label_max_size) %>: <%#= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)-->
</span>
<% content_for :header_tags do %>

View File

@ -0,0 +1,16 @@
<script type="text/javascript">
$(function(){
$("#RSide").removeAttr("id");
$("#Container").css("width","1000px");
$("#message_subject").focus();
});
</script>
<div class="homepageRight mt0 ml10">
<div class="homepageRightBanner">
<div class="NewsBannerName">
编辑帖子
</div>
</div>
<%= render :partial => 'boards/course_new',
:locals => {:f => f, :edit_mode => edit_mode, :topic => topic} %>
</div>

View File

@ -1,12 +1,66 @@
<%= form_for @message, :url =>{:controller=>'messages',:action => 'new', :board_id => @board.id, :is_board => 'true'}, :html => {:nhname=>'form',:multipart => true, :id => 'message-form'} do |f| %>
<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>
<%= error_messages_for 'message' %>
<div class="resources mt10">
<div id="new_course_topic">
<div class="homepagePostBrief c_grey">
<div>
<input type="text" name="message[subject]" id="message_subject" class="InputBox w704" maxlength="255" onfocus="$('#topic_editor').show()" onkeyup="regexTopicSubject();" placeholder="发布帖子,请先输入帖子标题" value="<%= topic.subject%>" >
<p id="subjectmsg"></p>
</div>
<div id="topic_editor" style="display: none;">
<div class="mt10">
<%= f.check_box :sticky, :value => topic.sticky%>
<%= label_tag 'message_sticky', l(:label_board_sticky) %>
<%= f.check_box :locked, :value => topic.locked%>
<%= label_tag 'message_locked', l(:label_board_locked) %>
<div class="cl"></div>
</div>
<div class="mt10">
<div id="message_quote" class="wiki" style="width: 92%;word-break: break-all;word-wrap: break-word;margin-left: 40px;"></div>
<%= text_area :quote,:quote,:style => 'display:none' %>
<%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %>
<%= render :partial => 'form_course', :locals => {:f => f, :topic => @message} %>
<li>
<%= f.kindeditor :content, :editor_id => 'message_content_editor',
:owner_id => topic.nil? ? 0: topic.id,
:owner_type => OwnerTypeHelper::MESSAGE,
:width => '100%',
:height => 300,
:minHeight=>300,
:class => 'talk_text fl',
:input_html => { :id => 'message_content',
:class => 'talk_text fl',
:maxlength => 5000 }%>
<div class="cl"></div>
<p id="message_content_span"></p>
</div>
<div class="cl"></div>
<div class="mt10">
<div class="fl" id="topic_attachments">
<%= render :partial => 'attachments/form_course', :locals => {:container => topic, :isReply => @isReply} %>
</div>
</div>
<div class="mt5">
<%if !edit_mode %>
<a href="javascript:void(0);" class="BlueCirBtnMini fr" onclick="submit_topic();">确定</a>
<span class="fr mr10 mt3">或</span>
<a href="javascript:void(0);" class="fr mr10 mt3" onclick="reset_topic();">取消</a>
<% else %>
<a href="javascript:void(0);" class="BlueCirBtnMini fr" onclick="submit_topic();">确定</a>
<span class="fr mr10 mt3">或</span>
<%= link_to "取消",board_message_url(topic.board, topic.root, :r => (topic.parent_id && topic.id)), :class => "fr mr10 mt3"%>
<% end %>
</div>
<div class="cl"></div>
</div>
</div>
<%#= render :partial => 'course_new_topic', :locals => {:f => f, :topic => @message} %>
<!--<li>
<div class="ml55 fl" nhname="toolbar_container"></div>
<a href="javascript:void(0);" nhname="cancelbtn" class="grey_btn fr ml10"><%= l(:button_cancel) %></a>
<a href="javascript:void(0);" nhname="cancelbtn" class="grey_btn fr ml10"><%#= l(:button_cancel) %></a>
<a href="javascript:void(0);" nhname="submitbtn" class="blue_btn fr " style="margin-left: 55px">
<%= l(:button_submit)%>
<%#= l(:button_submit)%>
</a>
<div class="cl"></div>
</li>
<% end %>
</li>-->
</div>
</div>

View File

@ -1,23 +1,50 @@
<%= javascript_include_tag "/assets/kindeditor/kindeditor", '/assets/kindeditor/pasteimg', "init_activity_KindEditor" %>
<style type="text/css">
/*回复框*/
div.ke-toolbar {display: none; width: 400px; border: none; background: none; padding: 0px 0px;}
span.ke-toolbar-icon {line-height: 26px; font-size: 14px; padding-left: 26px;}
span.ke-toolbar-icon-url {background-image: url(/images/public_icon.png)}
div.ke-toolbar .ke-outline {padding: 0px 0px; line-height: 26px; font-size: 14px;}
span.ke-icon-emoticons {background-position: 0px -671px; width: 50px; height: 26px;}
span.ke-icon-emoticons:hover {background-position: -79px -671px; width: 50px; height: 26px;}
div.ke-toolbar .ke-outline {border: none;}
.ke-inline-block {display: none;}
div.ke-container {float: left;}
.homepagePostReplyInputContainer .ke-toolbar {display: none; width: 400px; border: none; background: none; padding: 0px 0px;}
.homepagePostReplyInputContainer .ke-toolbar-icon {line-height: 26px; font-size: 14px; padding-left: 26px;}
.homepagePostReplyInputContainer .ke-toolbar-icon-url {background-image: url(/images/public_icon.png)}
.homepagePostReplyInputContainer .ke-outline {padding: 0px 0px; line-height: 26px; font-size: 14px;}
.homepagePostReplyInputContainer .ke-icon-emoticons {background-position: 0px -671px; width: 50px; height: 26px;}
.homepagePostReplyInputContainer .ke-icon-emoticons:hover {background-position: -79px -671px; width: 50px; height: 26px;}
.homepagePostReplyInputContainer .ke-outline {border: none;}
.homepagePostReplyInputContainer .ke-inline-block {display: none;}
.homepagePostReplyInputContainer .ke-container {float: left;}
</style>
<script type="text/javascript">
$(function(){
$("#RSide").removeAttr("id");
$("#Container").css("width","1000px");
});
function reset_topic(){
$("#message_subject").val("");
$("#subjectmsg").text("");
document.getElementById("message_sticky").checked=false;
document.getElementById("message_locked").checked=false;
$("#topic_attachments").html("<%= escape_javascript(render :partial => 'attachments/form_course', :locals => {:container => Message.new, :isReply => @isReply})%>");
message_content_editor.html("");
$("#topic_editor").toggle();
}
<% if @is_new%>
$(function(){
$("#message_subject").focus();
});
<%end%>
</script>
<div class="homepageRight mt0 ml10">
<div class="homepageRightBanner">
<div class="NewsBannerName">
课程讨论区
</div>
</div>
<% if User.current.logged? %>
<%= labelled_form_for @message, :url =>{:controller=>'messages',:action => 'new', :board_id => @board.id, :is_board => 'true'},
:html => {:nhname=>'form',:multipart => true, :id => 'message-form'} do |f| %>
<%= render :partial => 'course_new', :locals => {:f => f, :topic => @message, :edit_mode => false} %>
<% end %>
<% end %>
<% if topics%>
<% topics.each do |topic| %>
<script>
@ -74,6 +101,7 @@
<div id="show_more_course_topic" class="loadMore mt10 f_grey">展开更多<%= link_to "", boards_topic_path(@board, :course_id => @board.course.id ,:page => page), :id => "more_topic_link", :remote => "true", :class => "none" %></div>
<% end %>
<% end%>
</div>
<script type="text/javascript">
$("#show_more_course_topic").mouseover(function () {

View File

@ -35,14 +35,7 @@
<% if @project %>
<%= render :partial => 'project_show', locals: {project: @project} %>
<% elsif @course %>
<div class="homepageRight mt0 ml10">
<div class="homepageRightBanner">
<div class="NewsBannerName">
课程讨论区
</div>
</div>
<%= render :partial => 'course_show', :locals => {:topics => @topics, :page => 0} %>
</div>
<%= render :partial => 'course_show', :locals => {:topics => @topics, :page => 0, :course => @course} %>
<% end %>

View File

@ -108,7 +108,7 @@
<div class="subNav">
<%= link_to l(:label_course_board), course_boards_path(@course), :class => "f14 c_blue02" %>
<%= link_to "(#{@course.boards.first ? @course.boards.first.topics.count : 0})", course_boards_path(@course), :class => "subnav_num c_orange" %>
<%= link_to( "+#{l(:label_message_new)}",course_boards_path(@course, :flag => true),:class => 'subnav_green ml95 c_white') if User.current.member_of_course?(@course) && @course.boards.first %>
<%= link_to( "+#{l(:label_message_new)}",course_boards_path(@course, :flag => true, :is_new => 1),:class => 'subnav_green ml95 c_white') if User.current.member_of_course?(@course) && @course.boards.first %>
</div>
<div class="subNav">
<%= link_to l(:label_course_feedback), course_feedback_path(@course), :class => "f14 c_blue02" %>

View File

@ -27,14 +27,14 @@
init_activity_KindEditor_data(<%= @topic.id%>,null,"85%");
});
</script>
<div class="postRightContainer ml10">
<div class="postRightContainer ml10" onmouseover="$('#message_setting_<%= @topic.id%>').show();" onmouseout="$('#message_setting_<%= @topic.id%>').hide();">
<div class="postThemeContainer">
<div class="postDetailPortrait">
<%= link_to image_tag(url_to_avatar(@topic.author),:width=>50,:height => 50,:alt=>'图像' ),user_path(@topic.author) %>
</div>
<div class="postThemeWrap">
<% if @topic.author.id == User.current.id%>
<div class="homepagePostSetting">
<div class="homepagePostSetting" id="message_setting_<%= @topic.id%>" style="display: none">
<ul>
<li class="homepagePostSettingIcon">
<ul class="homepagePostSettiongText">
@ -97,7 +97,7 @@
</div>
<div class="" id="reply_div_<%= @topic.id %>">
<% @replies.each_with_index do |reply,i| %>
<div class="homepagePostReplyContainer">
<div class="homepagePostReplyContainer" onmouseover="$('#reply_edit_menu_<%= reply.id%>').show();" onmouseout="$('#reply_edit_menu_<%= reply.id%>').hide();">
<div class="homepagePostReplyPortrait">
<%= link_to image_tag(url_to_avatar(reply.author), :width => 33,:height => 33), user_path(reply.author) %>
</div>
@ -112,6 +112,7 @@
<div class="homepagePostReplyContent"><%= reply.content.html_safe%></div>
<div style="margin-top: -7px; margin-bottom: 5px">
<%= format_date(reply.created_on) %>
<div class="fr" id="reply_edit_menu_<%= reply.id%>" style="display: none">
<%= link_to(
l(:button_reply),
{:action => 'quote', :id => reply},
@ -128,6 +129,7 @@
:title => l(:button_delete)
) if reply.course_destroyable_by?(User.current) %>
</div>
</div>
<p id="reply_message_<%= reply.id%>"></p>
</div>
<div class="cl"></div>

View File

@ -1,8 +1,9 @@
<% if @message.project %>
<div class="project_r_h">
<h2 class="project_h2"><%= l(:label_course_board) %></h2>
</div>
<% if @message.project %>
<%#= board_breadcrumb(@message) %>
<!--<h3><%#= avatar(@topic.author, :size => "24") %><span style = "width:100%;word-break:break-all;word-wrap: break-word;"><%#=h @topic.subject %></span></h3>-->
<div class="ml15">
@ -21,9 +22,6 @@
</div>
<% end %>
<% elsif @message.course %>
<%#= course_board_breadcrumb(@message) %>
<div class="talk_new ml15">
<ul>0
<%= form_for @message, {
:as => :message,
:url => {:action => 'edit'},
@ -31,15 +29,10 @@
:id => 'message-form',
:method => :post}
} do |f| %>
<%= render :partial => 'form_course',
:locals => {:f => f, :replying => !@message.parent.nil?} %>
<a href="javascript:void(0)" onclick="submitCoursesBoard();"class="blue_btn fl c_white"><%= l(:button_submit)%></a>
<%= link_to l(:button_cancel), board_message_url(@message.board, @message.root, :r => (@message.parent_id && @message.id)), :class => "blue_btn grey_btn fl c_white" %>
<%= render :partial => 'boards/course_message_edit',
:locals => {:f => f, :edit_mode => true, :topic => @message} %>
<% end %>
</ul>
</div>
<% end %>
<div id="preview" class="wiki"></div>

View File

@ -148,6 +148,65 @@ function submit_edit_course(id)
$("#edit_course_"+id).submit();
}
}
//课程讨论区
function regexTopicSubject() {
var name = $("#message_subject").val();
if(name.length ==0)
{
$("#subjectmsg").text("标题不能为空");
$("#subjectmsg").css('color','#ff0000');
$("#message_subject").focus();
return false;
}
else if(name.length <= 255)
{
$("#subjectmsg").text("填写正确");
$("#subjectmsg").css('color','#008000');
return true;
}
else
{
$("#subjectmsg").text("标题超过255个字符");
$("#subjectmsg").css('color','#ff0000');
$("#message_subject").focus();
return false;
}
}
function regexTopicDescription()
{
var name = message_content_editor.html();
if(name.length ==0)
{
$("#message_content_span").text("描述不能为空");
$("#message_content_span").css('color','#ff0000');
return false;
}
else if(name.length >=6000){
$("#message_content_span").text("描述最多3000个汉字(或6000个英文字符)");
$("#message_content_span").css('color','#ff0000');
return false;
}
else
{
$("#message_content_span").text("填写正确");
$("#message_content_span").css('color','#008000');
return true;
}
}
function submit_topic()
{
if(regexTopicSubject() && regexTopicDescription())
{
message_content_editor.sync();
$("#message-form").submit();
}
}
function reset_topic(){
}
///////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////课程讨论区

View File

@ -904,6 +904,7 @@ a:hover.BlueCirBtn{ background:#269ac9; color:#fff;}
.w720{width:721px;}
.w709{width: 709px;}
.w701{width: 701px;}
.w704{width: 704px;}
a.AnnexBtn{ background: url(images/homepage_icon2.png) 0px -343px no-repeat !important; height:20px; display:block; padding-left:20px; color:#888888;}
a:hover.AnnexBtn{background: url(images/homepage_icon2.png) -90px -343px no-repeat !important; color:#3598db;}
a.FilesBtn{ background: url(../images/homepage_icon2.png) 0px -373px no-repeat; width:70px; height:20px; display:block; padding-left:20px; color:#888888;}