diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index f250b46de..d1a8b23dd 100644 --- a/app/controllers/org_document_comments_controller.rb +++ b/app/controllers/org_document_comments_controller.rb @@ -1,6 +1,6 @@ class OrgDocumentCommentsController < ApplicationController before_filter :find_organization, :only => [:new, :create, :show, :index] - helper :attachments + helper :attachments,:organizations layout 'base_org' def new diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index 9337c5fd2..ba4c1f18f 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -5,9 +5,8 @@ class OrgSubfieldsController < ApplicationController def create if OrgSubfield.where("organization_id=#{params[:organization_id]} and name=?",params[:name]).count == 0 @res = true - @subfield = OrgSubfield.create(:name => params[:name]) @organization = Organization.find(params[:organization_id]) - @organization.org_subfields << @subfield + @subfield = OrgSubfield.create(:name => params[:name], :organization_id => params[:organization_id],:priority => @organization.org_subfields.order("priority").last.priority + 1) if !params[:sub_dir].blank? sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+ "and org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir]}'" @@ -15,7 +14,7 @@ class OrgSubfieldsController < ApplicationController SubfieldSubdomainDir.create(:org_subfield_id => @subfield.id, :name => params[:sub_dir]) end end - @subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type]) + @subfield.update_attributes(:field_type => params[:field_type]) else @res = false end @@ -125,6 +124,12 @@ class OrgSubfieldsController < ApplicationController end end + def update_priority + @org_subfield = OrgSubfield.find(params[:id]) + @org_subfield.update_attribute(:priority, params[:priority].to_i) + @organization = @org_subfield.organization + end + def show_attachments obj @attachments = [] obj.each do |container| diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 711663c3d..239253d82 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -317,7 +317,7 @@ class OrganizationsController < ApplicationController @organization = Organization.find(params[:id]) admins = User.where("admin=1") admins.each do |admin| - OrgMessage.create(:user_id => admin.id, :organization_id => @organization.id, :message_type => 'ApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:domain]) + OrgMessage.create(:user_id => admin.id, :organization_id => @organization.id, :message_type => 'ApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:domain].downcase) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cc093ad7a..42911cc33 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2069,7 +2069,7 @@ module ApplicationHelper candown = User.current.member_of?(project) || (project.is_public && attachment_history.is_public == 1) elsif attachment_history.container_type == "OrgSubfield" org = OrgSubfield.find(attachment_history.container_id) - candown = User.current.member_of_org?(org) || (org.organization.is_public && attachment_history.is_public == 1) + candown = User.current.member_of_org?(org) || (org.organization.is_public && attachment_history.is_public == 1 && (User.current.logged? || org.organization.allow_guest_download?)) end end @@ -2943,37 +2943,86 @@ int main(int argc, char** argv){ end def user_url_in_org(user_id) - if Rails.env.development? - return "http://localhost:3000/users/" + user_id.to_s - else - return "https://" + Setting.host_name + "/users/" + user_id.to_s - end + Setting.protocol + "://" + Setting.host_name + "/users/" + user_id.to_s +end + +def project_issues_url_in_org(project_id) + Setting.protocol + "://" + Setting.host_name + "/projects/" + project_id.to_s + "/issues" +end + +def issue_url_in_org(id) + Setting.protocol + "://" + Setting.host_name + "/issues/" + id.to_s +end + +def project_boards_url_in_org(id) + Setting.protocol + "://" + Setting.host_name + "/projects/" + id.to_s + "/boards" +end + +def board_message_url_in_org(board_id, message_id) + Setting.protocol + "://" + Setting.host_name + "/boards/" + board_id.to_s + "/topics/" + message_id.to_s +end + +def project_url_in_org(id) + Setting.protocol + "://" + Setting.host_name + "/projects/" + id.to_s +end + +def homework_common_index_url_in_org(course_id) + Setting.protocol + "://" + Setting.host_name + "/homework_common?course=" + course_id.to_s +end + +def student_work_index_url_in_org(homework_id) + Setting.protocol + "://" + Setting.host_name + "/student_work?homework=" + homework_id.to_s +end + +def course_url_in_org(course_id) + Setting.protocol + "://" + Setting.host_name + "/courses/" + course_id.to_s +end + +def user_watchlist_url_in_org(id) + Setting.protocol + "://" + Setting.host_name + "/users/" + id.to_s + "/user_watchlist" +end + +def user_fanslist_url_in_org(id) + Setting.protocol + "://" + Setting.host_name + "/users/" + id.to_s + "/user_fanslist" +end + +def user_blogs_url_in_org(user_id) + Setting.protocol + "://" + Setting.host_name + "/users/" + user_id.to_s + "/blogs" +end + +def feedback_url_in_org(user_id) + Setting.protocol + "://" + Setting.host_name + "/users/" + user_id.to_s + "/user_newfeedback" +end + +def user_activities_url_in_org(user_id) + Setting.protocol + "://" + Setting.host_name + "/users/" + user_id.to_s + "/user_activities" +end + +def course_news_index_url_in_org(course_id) + Setting.protocol + "://" + Setting.host_name + "/courses/" + course_id.to_s + "/news" +end + +def news_url_in_org(news_id) + Setting.protocol + "://" + Setting.host_name + "/news/" + news_id.to_s +end + +def course_boards_url_in_org(course_id) + Setting.protocol + "://" + Setting.host_name + "/courses/" + course_id.to_s + "/boards" end def logout_url_without_domain - if Rails.env.development? - return "http://localhost:3000/logout" - else - return "https://" + Setting.host_name + "/logout" - end + Setting.protocol + "://" + Setting.host_name + "/logout" end def signin_url_without_domain - if Rails.env.development? - return "http://localhost:3000/login?login=true" - elsif Rails.env.test? - return "https://test.forge.trustie.net/login?login=true" - else - return "https://www.trustie.net/login?login=true" - end + Setting.protocol + "://" + Setting.host_name + "/login?login=true" end def register_url_without_domain - if Rails.env.development? - return "http://localhost:3000/login?login=false" - elsif Rails.env.test? - return "https://test.forge.trustie.net/login?login=false" - else - return "https://www.trustie.net/login?login=false" - end + Setting.protocol + "://" + Setting.host_name + "/login?login=false" end +#判断是否为默认的组织栏目 +def is_default_field? field + (field.name == 'activity' || field.name == 'course' || field.name == 'project') && field.field_type == 'default' +end + diff --git a/app/models/course_activity.rb b/app/models/course_activity.rb index 94eb097b8..a02eb750c 100644 --- a/app/models/course_activity.rb +++ b/app/models/course_activity.rb @@ -5,7 +5,7 @@ class CourseActivity < ActiveRecord::Base belongs_to :course belongs_to :user has_many :user_acts, :class_name => 'UserAcivity',:as =>:act - after_save :add_user_activity, :add_course_activity + after_save :add_user_activity, :add_org_activity after_create :add_course_lead before_destroy :destroy_user_activity, :destroy_org_activity @@ -31,14 +31,16 @@ class CourseActivity < ActiveRecord::Base end end - def add_course_activity + def add_org_activity org_activity = OrgActivity.where("org_act_type = '#{self.course_act_type.to_s}' and org_act_id = '#{self.course_act_id}'").first if org_activity + org_activity.updated_at = self.updated_at org_activity.save else if self.course_act_type == 'Message' && !self.course_act.parent_id.nil? org_activity = OrgActivity.where("org_act_type = 'Message' and org_act_id = #{self.course_act.parent.id}").first org_activity.created_at = self.created_at + org_activity.updated_at = self.updated_at org_activity.save else OrgActivity.create(:user_id => self.user_id, @@ -66,7 +68,7 @@ class CourseActivity < ActiveRecord::Base # 导语要放置在课程创建信息之后 # 导语 def add_course_lead - if self.course_act_type == "Course" + if self.course_act_type == "Course" and Message.where("id=12440").any? lead_message = Message.find(12440) name = lead_message.subject content = lead_message.content diff --git a/app/models/forge_activity.rb b/app/models/forge_activity.rb index c98c5475b..c044392a0 100644 --- a/app/models/forge_activity.rb +++ b/app/models/forge_activity.rb @@ -48,7 +48,7 @@ class ForgeActivity < ActiveRecord::Base def add_org_activity org_activity = OrgActivity.where("org_act_type = '#{self.forge_act_type.to_s}' and org_act_id = #{self.forge_act_id}").first if org_activity - org_activity.created_at = self.created_at + org_activity.updated_at = self.updated_at org_activity.save else if self.forge_act_type == 'Message' && !self.forge_act.parent_id.nil? diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb index c62cbf4f8..8cec49686 100644 --- a/app/models/org_subfield.rb +++ b/app/models/org_subfield.rb @@ -9,6 +9,7 @@ class OrgSubfield < ActiveRecord::Base has_many :news, :dependent => :destroy acts_as_attachable after_create :create_board_sync + after_destroy :update_priority # 创建资源栏目讨论区 def create_board_sync @board = self.boards.build @@ -25,4 +26,11 @@ class OrgSubfield < ActiveRecord::Base def project end + + def update_priority + OrgSubfield.where("organization_id=? and priority>?", self.organization_id, self.priority).each do |field| + field.decrement(:priority) + field.save + end + end end \ No newline at end of file diff --git a/app/models/organization.rb b/app/models/organization.rb index fcb777fb6..248783a26 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -16,8 +16,8 @@ class Organization < ActiveRecord::Base end def add_default_subfields - OrgSubfield.create(:organization_id => self.id, :name => 'activity', :field_type => 'default') - OrgSubfield.create(:organization_id => self.id, :name => 'course', :field_type => 'default') - OrgSubfield.create(:organization_id => self.id, :name => 'project', :field_type => 'default') + OrgSubfield.create(:organization_id => self.id, :name => 'activity', :field_type => 'default', :priority => 1) + OrgSubfield.create(:organization_id => self.id, :name => 'course', :field_type => 'default', :priority => 2) + OrgSubfield.create(:organization_id => self.id, :name => 'project', :field_type => 'default', :priority => 3) end end diff --git a/app/models/user.rb b/app/models/user.rb index abae2438a..78d823ea7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -822,6 +822,9 @@ class User < Principal end def member_of_org?(org) + if !self.logged? + return false + end OrgMember.where("user_id =? and organization_id =?", self.id, org.id).count > 0 end diff --git a/app/views/courses/private_or_public.js.erb b/app/views/courses/private_or_public.js.erb index 10b787dd4..4e512a6a0 100644 --- a/app/views/courses/private_or_public.js.erb +++ b/app/views/courses/private_or_public.js.erb @@ -9,10 +9,10 @@ } <% else %> <% if @course.is_public? %> - $("#set_course_public_<%= @course.id %>").text("设为私有"); $("#show_course_<%= @course.id %>").attr("title","公开课程:<%= @course.name %>(<%= @course.time.to_s+ @course.term %>)"); <% else %> - $("#set_course_public_<%= @course.id %>").text("设为公开"); $("#show_course_<%= @course.id %>").attr("title","私有课程:<%= @course.name %>(<%= @course.time.to_s+ @course.term %>)"); <% end %> + $("#set_course_public_<%= @course.id %>").replaceWith('<%= escape_javascript(link_to @course.is_public == 0 ? "设为公开" : "设为私有", {:controller => "courses", :action => "private_or_public", :id => @course,:user_page => true}, + :id => "set_course_public_#{@course.id.to_s}",:remote=>true,:confirm=>"您确定要设置为"+(@course.is_public == 0 ? "公开" : "私有")+"吗") %>'); <% end %> \ No newline at end of file diff --git a/app/views/files/_subfield_files.html.erb b/app/views/files/_subfield_files.html.erb index 7fb9e2e0a..9e0dd41d0 100644 --- a/app/views/files/_subfield_files.html.erb +++ b/app/views/files/_subfield_files.html.erb @@ -41,9 +41,10 @@ <%= text_field_tag 'name', params[:name], name: "name", :class => 'researchBox fl',:style=>"padding: 0px"%> <%= submit_tag "栏目内搜索", :class => "blueBtn mr5 fl",:style => 'width:72px;',:name => "inorg_subfield",:id => "inorg_subfield", :onmouseover => "presscss('inorg_subfield')",:onmouseout =>"buttoncss()" %> <%#= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite",:onmouseover => "presscss('insite')",:onmouseout =>"buttoncss()" %> - - <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :subfield_file_id => @org_subfield.id), :class => "blue-btn fr mr5", :remote => true) %> - <%#= link_to "上传资源",subfield_upload_file_org_subfield_files_path(@org_subfield.id, :in_org => 1),:method => "post",:class=>"blueBtn fr mr5",:remote => true %> + <% if User.current.member_of_org?(org_subfield.organization) %> + + <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :subfield_file_id => @org_subfield.id), :class => "blue-btn fr mr5", :remote => true) %> + <% end %> <% end %>
diff --git a/app/views/layouts/_org_courses.html.erb b/app/views/layouts/_org_courses.html.erb index 648f62ecf..282447f0f 100644 --- a/app/views/layouts/_org_courses.html.erb +++ b/app/views/layouts/_org_courses.html.erb @@ -1,7 +1,7 @@ <% courses.each do |course|%> <%# pro = Project.find course.course_id %># <%=time_from_now last_score.created_at %> - <%= link_to last_score.user.show_name, user_activities_path(last_score.user_id), :class => "newsBlue ml5 mr5"%>评阅了作品,优秀排行: + <%= link_to last_score.user.show_name, user_activities_url_in_org(last_score.user_id), :class => "newsBlue ml5 mr5"%>评阅了作品,优秀排行:
分数:<%=format("%.1f",score.to_i<0 ? 0 : score.to_i) %>分
@@ -175,7 +165,7 @@ <% end %> <% end %> <% if student_works.count > 5 %> - <%= link_to "更多>>", student_work_index_path(:homework => activity.id),:class=>'linkGrey2 fl ml50',:style=>'margin-top:60px;'%> + <%= link_to "更多>>", student_work_index_url_in_org(activity.id),:class=>'linkGrey2 fl ml50',:style=>'margin-top:60px;'%> <% end %><%= string %>
- <% end %> - <% end %> -<%= reply.notes.nil? ? "" : reply.notes.html_safe %>
-<%= string %>
+ <% end %> + <% end %> +<%= reply.notes.nil? ? "" : reply.notes.html_safe %>
+