修改课程讨论区视图,从项目中分离

This commit is contained in:
nwb 2014-06-05 15:42:49 +08:00
parent d22ffa84b4
commit c1f9f389b7
3 changed files with 129 additions and 66 deletions

View File

@ -387,6 +387,30 @@ class CoursesController < ApplicationController
end end
end end
def feedback
page = params[:page]
# Find the page of the requested reply
@jours = @course.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
@limit = 10
if params[:r] && page.nil?
offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i])
page = 1 + offset / @limit
end
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, page
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@state = false
@base_courses_tag = @course.course_type
respond_to do |format|
format.html{render :layout => 'base_courses' if @base_courses_tag==1}
format.api
end
end
private private
def allow_join def allow_join
@ -405,72 +429,7 @@ class CoursesController < ApplicationController
end end
def index1
per_page_option = 10
#当前所有的活动课程
@courses_all = Course.active.visible.
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.couse_id")
@course_count = @courses_all.count
@course_pages = Paginator.new @course_count, per_page_option, params['page']
#gcm activity count
@course_activity_count=Hash.new
@courses_all.each do |course|
@course_activity_count[course.id]=0
end
@course_activity_count=get_course_activity @courses_all, @course_activity_count
#gcm end
case params[:course_sort_type]
when '0'
@courses = @courses_all.order("created_on desc")
@s_type = 0
when '1'
@courses = @courses_all.order("grade desc")
@s_type = 1
when '2'
@courses = @courses_all.order("watchers_count desc")
@s_type = 2
#gcm
when '3'
#@courses=desc_sort_course_by_avtivity(@course_activity_count_array,@course_all_array)
@courses=handle_course @courses_all, @course_activity_count
@s_type = 3
@courses = @courses[@course_pages.offset, @course_pages.per_page]
else
@courses = @courses = @courses_all.order("grade desc")
@s_type = 1
end
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
respond_to do |format|
format.html {
render :layout => 'base'
# scope = Project
# unless params[:closed]
# scope = scope.active
# end
}
format.api {
# @offset, @limit = api_offset_and_limit
# @course_count = Project.visible.count
# @courses = Project.visible.offset(@offset).limit(@limit).order('lft').all
}
format.atom {
courses = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}")
}
end
end
end end

View File

@ -0,0 +1,102 @@
<script>
var W3CDOM = document.createElement && document.getElementsByTagName;
window.onload = setMaxLength;
function setMaxLength() {
if (!W3CDOM) return;
var textareas = document.getElementsByTagName('textarea');
for (var i=0;i<textareas.length;i++) {
var textarea = textareas[i];
setMaxLengthItem(textareas[i]);
}
}
function setMaxLengthItem(textarea){
if (textarea.getAttribute('maxlength')) {
var counter = document.createElement('div');
counter.className = 'counter';
var counterClone = counter.cloneNode(true);
counterClone.innerHTML = '<span>0</span>/'+textarea.getAttribute('maxlength');
textarea.parentNode.insertBefore(counterClone,textarea.nextSibling);
textarea.relatedElement = counterClone.getElementsByTagName('span')[0];
textarea.onkeyup = textarea.onchange = checkMaxLength;
textarea.onkeyup();
}
}
function checkMaxLength() {
var maxLength = this.getAttribute('maxlength');
var currentLength = this.value.length;
if (currentLength > maxLength)
this.relatedElement.className = 'toomuch';
else
this.relatedElement.className = '';
this.relatedElement.firstChild.nodeValue = currentLength;
}
</script>
<!-- fq -->
<% reply_allow = JournalsForMessage.create_by_user? User.current %>
<h3><%= l(:label_user_response) %></h3>
<% if !User.current.logged?%>
<div style="font-size: 14px;margin:20px;">
<%= l(:label_user_login_tips) %>
<%= link_to l(:label_user_login_new), signin_path %>
<hr/>
</div>
<% else %>
<div style="width: 80%; margin-left:10%;">
<%= form_for('new_form', :method => :post,
:url => {:controller => 'words', :action => 'leave_course_message'}) do |f|%>
<%= f.text_area 'course_message', :rows => 3, :cols => 65,
:placeholder => "#{l(:label_welcome_my_respond)}",
:style => "resize: none; width: 98%",
:class => 'noline'%>
<%= submit_tag l(:button_leave_meassge), :name => nil , :class => "enterprise" , :style => "display: block; float: right; margin-right: 1%; margin-top: 1px;"%>
<% end %>
</div>
<% end %>
<div style="clear: both;"></div>
<% if @jour.size >0 %>
<ul class="message-for-user">
<% for journal in @jour%>
<li id='word_li_<%=journal.id.to_s%>' class="outer-message-for-user">
<span class="portrait"><%= image_tag(url_to_avatar(journal.user), :class => "avatar") %></span>
<span class="body">
<span class="user"><%= link_to journal.user, user_path(journal.user)%></span>
<%= textilizable journal.notes%>
<span class="font_lighter"> <%= l :label_update_time %>: <%= format_time journal.created_on %></span>
<% id = 'course_respond_form_'+journal.id.to_s%>
<span>
<% if reply_allow %>
<%= link_to l(:label_projects_feedback_respond),'#',
{:focus => 'course_respond',
:onclick => "toggleAndSettingWordsVal($('##{id}'),
$('##{id} textarea'),
'#{l(:label_reply_plural)} #{journal.user.name}: ');
return false;"} %>
<% end %>
</span>
</span>
<div style="clear: both;"></div>
<% if reply_allow %>
<div id='<%= id %>' class="respond-form">
<%= render :partial => 'words/new_respond', :locals => {:journal => journal, :m_reply_id => journal} %>
</div>
<% end %>
<div style="clear: both;"></div>
<div>
<%= render :partial => "words/journal_reply", :locals => {:journal => journal } %>
</div>
</li>
<% end %>
</ul>
<% end %>
<div class="pagination" style="float:left;">
<ul>
<%= pagination_links_full @feedback_pages %>
</ul>
</div>

View File

@ -554,13 +554,15 @@ RedmineApp::Application.routes.draw do
post 'finishcourse' post 'finishcourse'
post 'restartcourse' post 'restartcourse'
end end
resources :boards
resources :files, :only => [:index, :new, :create] do resources :files, :only => [:index, :new, :create] do
collection do collection do
match "getattachtype" , via: [:get, :post] match "getattachtype" , via: [:get, :post]
end end
end end
end end
match 'courses/:id/feedback', :to => 'courses#feedback', :via => :get, :as => 'course_feedback'
match '/courses/search', :controller => 'courses', :action => 'search', :via => [:get, :post] match '/courses/search', :controller => 'courses', :action => 'search', :via => [:get, :post]
#match 'project/enterprise_course', :to => 'projects#enterprise_course' #match 'project/enterprise_course', :to => 'projects#enterprise_course'
#match 'project/course_enterprise', :to => 'projects#course_enterprise' #match 'project/course_enterprise', :to => 'projects#course_enterprise'