课程通知改成动态的模式

This commit is contained in:
cxt 2015-12-24 09:57:32 +08:00
parent 1623d846f4
commit f26f71c07a
9 changed files with 367 additions and 136 deletions

View File

@ -27,7 +27,8 @@ class CommentsController < ApplicationController
raise Unauthorized unless @news.commentable?
@comment = Comment.new
@project ? @comment.comments = params[:comment][:comments] : @comment.comments = params[:comment]
#@project ? @comment.comments = params[:comment][:comments] : @comment.comments = params[:comment]
@comment.comments = params[:comment][:comments]
@comment.author = User.current
if @news.comments << @comment
if params[:asset_id]
@ -48,7 +49,7 @@ class CommentsController < ApplicationController
# end
# end
# # <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>̬<EFBFBD>ļ<EFBFBD>¼add end
flash[:notice] = l(:label_comment_added)
#flash[:notice] = l(:label_comment_added)
course_activity = CourseActivity.where("course_act_type='News' and course_act_id =#{@news.id}").first
if course_activity
course_activity.updated_at = Time.now

View File

@ -69,20 +69,25 @@ class NewsController < ApplicationController
elsif @course
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
scope = @course ? @course.news.course_visible : News.course_visible
news_arr = scope.map{|news| news.id}
@page = params[:page] ? params[:page].to_i + 1 : 0
news_page = @page *10
@news_count = scope.count
@is_new = params[:is_new]
@q = params[:subject]
if params[:subject].nil? || params[:subject].blank?
scope_order = scope.all(:include => [:author, :course],
:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC")
scope_order = scope.reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page).includes(:author,:course).all()
#all(:include => [:author, :course],
#:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page)
else
scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").all(:include => [:author, :course],
:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC")
scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page).includes(:author,:course).all()
#.all(:include => [:author, :course],:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC")
end
# :offset => @offset,
# :limit => @limit)
@newss = paginateHelper scope_order,10
@newss = scope_order
#@newss = paginateHelper scope_order,10
respond_to do |format|
format.html {
@news = News.new
@ -130,6 +135,7 @@ class NewsController < ApplicationController
result = cs.show_course_news params,User.current
@news = result[:news]
@comments = result[:comments]
@comment = Comment.new
#@comments = @news.comments
#@comments.reverse! if User.current.wants_comments_in_reverse_order?
#modify by nwb
@ -147,7 +153,22 @@ class NewsController < ApplicationController
@news = News.new(:project => @project, :author => User.current)
elsif @course
@news = News.new(:course => @course, :author => User.current)
render :layout => 'base_courses'
#render :layout => 'base_courses'
@news.safe_attributes = params[:news]
@news.save_attachments(params[:attachments])
if @news.save
if params[:asset_id]
ids = params[:asset_id].split(',')
update_kindeditor_assets_owner ids,@news.id,OwnerTypeHelper::NEWS
end
render_attachment_warning_if_needed(@news)
#flash[:notice] = l(:notice_successful_create)
redirect_to course_news_index_url(@course)
else
redirect_to course_news_index_url(@course)
#layout_file = 'base_courses'
#render :action => 'new', :layout => layout_file
end
end
end
@ -210,7 +231,7 @@ class NewsController < ApplicationController
@news.save_attachments(params[:attachments])
if @news.save
render_attachment_warning_if_needed(@news)
flash[:notice] = l(:notice_successful_update)
#flash[:notice] = l(:notice_successful_update)
redirect_to news_url(@news)
else
#flash[:error] = l(:notice_successful_update)

View File

@ -1,42 +1,34 @@
<%
btn_tips = l(:label_news_notice)
label_tips = l(:label_course_news)
%>
<script>
function remote_search(){
$("#news_query_form").submit();
}
<script type="text/javascript">
$(function(){
$("#RSide").removeAttr("id");
$("#Container").css("width","1000px");
});
function reset_news(){
$("#news_title").val("");
$("#title_notice_span").text("");
$("#description_notice_span").text("");
document.getElementById("news_sticky").checked=false;
$("#news_attachments").html("<%= escape_javascript(render :partial => 'attachments/new_form', :locals => {:container => News.new})%>");
news_description_editor.html("");
$("#news_editor").toggle();
}
<% if @is_new%>
$(function(){
$("#news_title").focus();
});
<%end%>
</script>
<div class="project_r_h">
<h2 class="project_h2"><%= label_tips %></h2>
</div>
<div class="talk_top">
<div class="fl">
<p class="fl">
<%= l(:label_total_news) %>
<span><%= @news_count %></span>
<%= l(:label_course_news_count) %>
</p>
<% if @course && User.current.allowed_to?(:manage_news, @course) %>
<%= link_to(btn_tips,new_course_news_path(@course),:class => 'problem_new_btn fl c_dorange')%>
<div class="cl"></div>
<% end %>
<div class="homepageRight mt0 ml10">
<div class="homepageRightBanner">
<div class="NewsBannerName">
课程通知
</div>
</div>
<div class="problem_search fr" >
<%= form_tag({:controller => 'news', :action => 'index', :course_id => @course }, :method => :get,:id=>"news_query_form", :class => 'query_form') do %>
<input class="problem_search_input fl" id="v_subject" placeholder="通知主题" type="text" name="subject" value="<%= @q%>" onkeypress="" onkeydown="">
<a href="javascript:void(0)" class="problem_search_btn fl" onclick="remote_search();" >搜索</a>
<% end %>
</div><!--problem_search end-->
<div class="cl"></div>
</div>
<div id="news_list">
<%= render :partial => 'course_news_list', :locals=>{ :newss=>@newss,:obj_pages=>@obj_pages, :obj_count=>@obj_count} %>
</div>
<% content_for :header_tags do %>
<%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :page => nil, :key => User.current.rss_key})) %>
<%= stylesheet_link_tag 'scm' %>
<% end %>
<% html_title(l(:label_course_news)) -%>
<% if @course && User.current.allowed_to?(:manage_news, @course) %>
<%= labelled_form_for @news, :url =>{:controller=>'news',:action => 'new', :course_id => @course.id},
:html => {:nhname=>'form',:multipart => true, :id => 'news-form'} do |f| %>
<%= render :partial => 'course_news_new', :locals => {:f => f, :news => @news, :edit_mode => false, :course => @course} %>
<% end %>
<% end %>
<%= render :partial=> 'course_news_detail',:locals =>{:newss => @newss, :page => 0} %>
</div>

View File

@ -0,0 +1,56 @@
<%= content_for(:header_tags) do %>
<%= import_ke(enable_at: false, prettify: false) %>
<%= javascript_include_tag "init_activity_KindEditor" %>
<% end %>
<style type="text/css">
/*回复框*/
.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>
<% if newss%>
<% newss.each do |news| %>
<script>
function expand_reply(container, btnid) {
var target = $(container);
var btn = $(btnid);
if (btn.data('init') == '0') {
btn.data('init', 1);
btn.html('收起回复');
target.show();
} else {
btn.data('init', 0);
btn.html('展开更多');
target.hide();
target.eq(0).show();
target.eq(1).show();
target.eq(2).show();
}
}
function expand_reply_input(id) {
$(id).toggle();
}
$(function () {
init_activity_KindEditor_data(<%= news.id%>, null, "87%");
showNormalImage('activity_description_<%= news.id %>');
});
</script>
<% if news %>
<%= render :partial => 'users/course_news', :locals => {:activity => news, :user_activity_id => news.id} %>
<% end %>
<% end %>
<% if newss.count == 10 %>
<%= link_to "点击展开更多",news_index_path(:course_id => @course.id ,:page => page),:id => "show_more_course_news",:remote => "true",:class => "loadMore mt10 f_grey"%>
<% end %>
<% end%>

View File

@ -0,0 +1,60 @@
<%= content_for(:header_tags) do %>
<%= import_ke(enable_at: true, prettify: false) %>
<% end %>
<div class="resources mt10">
<div id="new_course_news">
<div class="homepagePostBrief c_grey">
<div>
<input type="text" name="news[title]" id="news_title" class="InputBox w713" maxlength="60" onfocus="$('#news_editor').show()" onkeyup="regexTitle();" placeholder="发布通知,请先输入通知标题" value="<%= news.title%>" >
<p id="title_notice_span"></p>
</div>
<div id="news_editor" style="display: none;">
<div class="mt10">
<%= f.check_box :sticky, :value => edit_mode ? news.sticky : 0 %>
<%= label_tag 'news_sticky', l(:label_board_sticky) %>
<div class="cl"></div>
</div>
<div class="mt10">
<div id="news_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' %>
<%= f.kindeditor :description, :editor_id => 'news_description_editor',
:owner_id => news.nil? ? 0: news.id,
:owner_type => OwnerTypeHelper::NEWS,
:width => '100%',
:height => 300,
:minHeight=>300,
:class => 'talk_text fl',
:input_html => { :id => 'news_content',
:class => 'talk_text fl',
:maxlength => 5000 },
at_id: news.id, at_type: news.class.to_s
%>
<div class="cl"></div>
<p id="description_notice_span"></p>
</div>
<div class="cl"></div>
<div class="mt10">
<div class="fl" id="news_attachments">
<%= render :partial => 'attachments/form_course', :locals => {:container => news, :isReply => false} %>
</div>
</div>
<div class="cl"></div>
<div class="mt5">
<%if !edit_mode %>
<a href="javascript:void(0);" class="BlueCirBtnMini fr" onclick="submitNews();">确定</a>
<span class="fr mr10 mt3">或</span>
<a href="javascript:void(0);" class="fr mr10 mt3" onclick="reset_news();">取消</a>
<% else %>
<a href="javascript:void(0);" class="BlueCirBtnMini fr" onclick="submitNews();">确定</a>
<span class="fr mr10 mt3">或</span>
<%= link_to "取消",news_path(news), :class => "fr mr10 mt3"%>
<% end %>
</div>
<div class="cl"></div>
</div>
</div>
</div>
</div>

View File

@ -2,85 +2,172 @@
<%= import_ke(enable_at: false, prettify: false, init_activity: false) %>
<% end %>
<div class="project_r_h">
<h2 class="project_h2"><%= l(:label_course_news) %></h2>
</div>
<div class="problem_main">
<%= link_to image_tag(url_to_avatar(@news.author),:width => 42,:height => 42), user_path(@news.author), :class => "problem_pic fl" %>
<div class="problem_txt fl mt5 list_style">
<h4 class="r_txt_tit mb5">
<%=h @news.title %>
</h4>
<% if @news.sticky == 1%>
<span class="sticky_btn_cir ml10 fl">置顶</span>
<% end%>
<%= link_to(l(:button_edit),
edit_news_path(@news),
:class => 'talk_edit fr') if User.current.allowed_to?(:manage_news, @course) %>
<%= delete_link(news_path(@news),:class => 'talk_edit fr') if User.current.allowed_to?(:manage_news, @course) %>
<div class="cl"></div>
<div class="mb5 upload_img">
<%= @news.description.html_safe %>
<br />
<%= l(:label_create_time) %> <%= format_time(@news.created_on) %>
<script type="text/javascript">
$(function(){
$("#RSide").removeAttr("id");
$("#Container").css("width","1000px");
});
</script>
<script>
function expand_reply(container,btnid){
var target = $(container).children();
var btn = $(btnid);
if(btn.data('init')=='0'){
btn.data('init',1);
btn.html('收起回复');
target.show();
}else{
btn.data('init',0);
btn.html('展开更多');
target.hide();
target.eq(0).show();
target.eq(1).show();
target.eq(2).show();
}
}
$(function() {
showNormalImage('message_description_<%= @news.id %>');
});
</script>
<div class="postRightContainer ml10" onmouseover="$('#message_setting_<%= @news.id%>').show();" onmouseout="$('#message_setting_<%= @news.id%>').hide();">
<div class="postThemeContainer">
<div class="postDetailPortrait">
<%= link_to image_tag(url_to_avatar(@news.author),:width=>50,:height => 50,:alt=>'图像' ),user_path(@news.author) %>
</div>
<%= link_to_attachments_course @news %>
<!--<a href="#" class=" link_file">附件爱覅俄方if.zip(27.5kB)</a> -->
<div class="postThemeWrap">
<% if User.current.allowed_to?(:manage_news, @course)%>
<div class="homepagePostSetting" id="message_setting_<%= @news.id%>" style="display: none">
<ul>
<li class="homepagePostSettingIcon">
<ul class="homepagePostSettiongText">
<li>
<%= link_to(
l(:button_edit),
{:action => 'edit', :id => @news},
:class => 'postOptionLink'
) if User.current.allowed_to?(:manage_news, @course) %>
</li>
<li>
<%= delete_link(
news_path(@news),
:data => {:confirm => l(:text_are_you_sure)},
:class => 'postOptionLink'
) if User.current.allowed_to?(:manage_news, @course) %>
</li>
</ul>
</li>
</ul>
</div>
<%end%>
<div class="postDetailTitle fl">
<a href="javascript:void(0);" class="f14 linkGrey4 fb" style="overflow:hidden;">通知: <%= @news.title%></a>
</div>
<div class="cl"></div>
<div class="postDetailCreater">
<% if @news.try(:author).try(:realname) == ' ' %>
<%= link_to @news.try(:author), user_path(@news.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %>
<% else %>
<%= link_to @news.try(:author).try(:realname), user_path(@news.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %>
<% end %>
</div>
<div class="postDetailDate mb5"><%= format_time( @news.created_on)%></div>
<div class="cl"></div>
<div class="memo-content upload_img break_word" id="message_description_<%= @news.id %>" style="word-break: break-all; word-wrap:break-word;margin-bottom: 0px !important;" >
<%= @news.description.html_safe%>
</div>
<div class="cl"></div>
<div class=" fl" style="width: 600px">
<%= link_to_attachments_course @news, :author => false %>
</div>
</div>
<div class="cl"></div>
</div>
<div class="cl"></div>
</div>
<% if @news.commentable? %>
<div class="msg_box fl">
<h4><%= l(:label_comment_add) %></h4>
<%= form_tag({:controller => 'comments', :action => 'create', :id => @news}, :id => "add_comment_form") do %>
<div class="box" id="news_comment">
<%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %>
<%= kindeditor_tag :comment, '',:height=>'100',:editor_id =>'comment_editor', :placeholder=>"最多250个字"%>
</div>
<p id="add_reply_news"></p>
<p class="mt10">
<a href="javascript:void(0)" class="grey_btn fr ml10" onclick="KindEditor.instances[0].html('');">
<%= l(:label_cancel_with_space) %>
</a>
<a href="javascript:void(0)" class="blue_btn fr" onclick="submitComment();">
<%= l(:label_comment_with_space) %>
</a>
</p>
<% end %>
</div>
<% end %>
<div class="cl"></div>
<% comments = @comments.reverse %>
<% comments.each do |comment| %>
<% next if comment.new_record? %>
<div class="ping_C mb10">
<div><%= link_to image_tag(url_to_avatar(comment.author),:width => 42,:height => 42), user_path(comment.author), :class => "problem_pic fl"%></div>
<div class="ping_discon">
<div class="ping_distop upload_img break_word list_style">
<%= link_to_user_header(comment.author,false,:class => 'c_blue fb fl mb10 ') if comment.respond_to?(:author) %>
<span class="c_grey fr">
<%= format_time(comment.created_on) %>
</span>
<div class="cl"></div>
<p><%= comment.comments.html_safe %></p>
</div>
<div class="ping_disfoot">
<%= link_to_if_authorized_course image_tag('delete.png'), {:controller => 'comments', :action => 'destroy', :id => @news, :comment_id => comment},
:data => {:confirm => l(:text_are_you_sure)}, :method => :delete, :title => l(:button_delete) %>
</div>
<div class="homepagePostReply">
<% unless @comments.empty? %>
<div class="homepagePostReplyBanner">
<div class="homepagePostReplyBannerCount">回复(<%=@comments.count %></div>
<div class="homepagePostReplyBannerTime"></div>
</div>
<div class="" id="reply_div_<%=@news.id %>">
<% @comments.each_with_index do |reply,i| %>
<script type="text/javascript">
$(function(){
showNormalImage('reply_message_description_<%= reply.id %>');
});
</script>
<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>
<div class="homepagePostReplyDes">
<div class="homepagePostReplyPublisher">
<% if reply.try(:author).try(:realname) == ' ' %>
<%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %>
<% else %>
<%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %>
<% end %>
</div>
<div class="homepagePostReplyContent upload_img break_word table_maxWidth" id="reply_message_description_<%= reply.id %>">
<%= reply.comments.html_safe%>
</div>
<div style="margin-top: -7px; margin-bottom: 5px">
<%= format_time(reply.created_on) %>
<div class="fr" id="reply_edit_menu_<%= reply.id%>" style="display: none">
<%= link_to_if_authorized_course(
l(:button_delete),
{:controller => 'comments',
:action => 'destroy', :id => @news,
:comment_id => reply},
:method => :delete,
:class => 'fr newsGrey',
:data => {:confirm => l(:text_are_you_sure)},
:title => l(:button_delete)
) %>
</div>
</div>
<p id="reply_message_<%= reply.id%>"></p>
</div>
<div class="cl"></div>
</div>
<% end %>
</div>
<div class="cl"></div>
</div>
<% end if @comments.any? %>
<!--problem_main end-->
<% content_for :header_tags do %>
<%= stylesheet_link_tag 'scm' %>
<% end %>
<% html_title @news.title -%>
<% end %>
<div class="cl"></div>
<% if @news.commentable? %>
<div class="talkWrapMsg" nhname="about_talk_reply">
<em class="talkWrapArrow"></em>
<div class="cl"></div>
<div class="talkConIpt ml5 mb10" id="reply<%= @news.id %>">
<%= form_for @comment, :url=>{:controller => 'comments', :action => 'create', :id => @news}, :html => {:multipart => true, :id => 'add_comment_form'} do |f| %>
<div class="box" id="news_comment">
<%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %>
<%= f.kindeditor :comments, :editor_id => 'comment_editor',
:owner_id => @comment.nil? ? 0: @comment.id,
:owner_type => OwnerTypeHelper::COMMENT,
:width => '99%',
:height => 100,
:minHeight=>100,
:input_html => { :id => 'comment_content',
:class => 'talk_text fl',
:maxlength => 5000 }%>
</div>
<p id="add_reply_news"></p>
<p class="mt10">
<a href="javascript:void(0)" class="grey_btn fr ml10 mr5" onclick="KindEditor.instances[0].html('');">
<%= l(:label_cancel_with_space) %>
</a>
<a href="javascript:void(0)" class="blue_btn fr" onclick="submitComment();">
<%= l(:label_comment_with_space) %>
</a>
</p>
<% end %>
<div class="cl"></div>
</div>
</div>
<% end %>
</div>
</div>

View File

@ -1,14 +1,23 @@
<%= content_for(:header_tags) do %>
<%= import_ke(enable_at: false, prettify: false, init_activity: false) %>
<% end %>
<div class="project_r_h">
<h2 class="project_h2"><%= l(:label_course_news) %></h2>
</div>
<div id="edit-news">
<script type="text/javascript">
$(function(){
$("#RSide").removeAttr("id");
$("#Container").css("width","1000px");
$("#news_title").focus();
});
</script>
<div class="homepageRight mt0 ml10">
<div class="homepageRightBanner">
<div class="NewsBannerName">
编辑通知
</div>
</div>
<%= labelled_form_for :news, @news, :url => news_path(@news),
:html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %>
<%= render :partial => 'course_form', :locals => { :f => f, :is_new => false } %>
<%#= labelled_form_for :news, :url =>{:controller=>'news',:action => 'new', :course_id => @course.id},
:html => {:nhname=>'form',:multipart => true, :id => 'news-form'} do |f| %>
<%= render :partial => 'course_news_new', :locals => {:f => f, :news => @news, :edit_mode => true, :course => @course} %>
<% end %>
<div id="preview" class="wiki"></div>
</div>

View File

@ -1 +1,5 @@
$("#news_list").html("<%= escape_javascript(render :partial => 'course_news_list', :locals=>{ :newss=>@newss,:obj_pages=>@obj_pages, :obj_count=>@obj_count})%>");
<% if @project %>
$("#news_list").html("<%= escape_javascript(render :partial => 'course_news_list', :locals=>{ :newss=>@newss,:obj_pages=>@obj_pages, :obj_count=>@obj_count})%>");
<% else %>
$("#show_more_course_news").replaceWith("<%= escape_javascript( render :partial => 'course_news_detail', :locals =>{:newss => @newss, :page => @page} )%>");
<% end %>

View File

@ -438,6 +438,7 @@ RedmineApp::Application.routes.draw do
post '/courses/:id/course_activity', :to => 'courses#show', :as => 'course_activity'
get '/boards/:id/boards_topic', :to =>'boards#show', :as => 'boards_topic'
match 'courses/:course_id/news/new', :to => 'news#new', :via => [:get, :post], :as => 'new_course_news'
#added by young
resources :users do