diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 664dc4cf5..9ce76dca8 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -242,6 +242,8 @@ class AttachmentsController < ApplicationController format.html { redirect_to_referer_or mobile_version_path } elsif !@attachment.container.nil? && @attachment.container.is_a?(OrgSubfield) format.html {redirect_to_referer_or org_subfield_files_path(@attachment.container)} + elsif !@attachment.container.nil? && @attachment.container.is_a?(OrgDocumentComment) + format.html {redirect_to_referer_or org_document_comment_path(@attachment.container)} else if @project.nil? format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) } diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 0c3236d4e..291593fc5 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -18,8 +18,8 @@ class BoardsController < ApplicationController layout 'base_projects'#by young default_search_scope :messages - before_filter :find_project_by_project_id, :find_board_if_available - before_filter :authorize, :except => [:new, :show, :create, :index] + before_filter :find_project_by_project_id, :find_board_if_available, :except => [:join_to_org_subfields] + before_filter :authorize, :except => [:new, :show, :create, :index, :join_to_org_subfields] accept_rss_auth :index, :show @@ -225,6 +225,16 @@ class BoardsController < ApplicationController redirect_to_settings_in_projects end + def join_to_org_subfields + if params[:id] + @board = Board.find(params[:id]) + @org_subfield_ids = params[:org_subfield_ids] + @org_subfield_ids.each do |id| + OrgSubfieldBoard.create(:org_subfield_id => id.to_i, :board_id => params[:id].to_i) + end + end + end + private def redirect_to_settings_in_projects redirect_to settings_project_url(@project, :tab => 'boards') diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 6f173b7c2..d5ce9e0eb 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -22,7 +22,7 @@ class MessagesController < ApplicationController default_search_scope :messages before_filter :find_board, :only => [:new, :preview,:edit] before_filter :find_attachments, :only => [:preview] - before_filter :find_message, :except => [:new, :preview] + before_filter :find_message, :except => [:new, :preview, :join_org_subfield, :get_subfield_on_click_org, :join_org_subfields] before_filter :authorize, :except => [:preview, :edit, :destroy, :new] helper :boards @@ -301,6 +301,31 @@ class MessagesController < ApplicationController render :partial => 'common/preview' end + def join_org_subfield + @message = Message.find(params[:message_id]) + @organizations = User.current.organizations + end + + def get_subfield_on_click_org + @org = Organization.find(params[:organization_id]) + end + + def join_org_subfields + org_subfield_ids = params[:org_subfields] + @message = Message.find(params[:id]) + # @message.update_attribute(:updated_on, Time.now) + type = @message.board.course_id.nil? ? "Project":"Course" + org_subfield_ids.each do |field_id| + OrgSubfieldMessage.create(:org_subfield_id => field_id.to_i, :message_id => @message.id, :message_type => type) + org_acts = OrgActivity.where("container_type='OrgSubfield' and container_id=? and org_act_type='Message' and org_act_id=?", field_id.to_i, @message.id) + if org_acts.all.size() > 0 + org_acts.first.update_attribute(:updated_at, Time.now) + else + OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'Message', :org_act_id => @message.id, :user_id => User.current.id) + end + end + end + private def find_message return unless find_board diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index b8584fea3..fee4ec60f 100644 --- a/app/controllers/org_document_comments_controller.rb +++ b/app/controllers/org_document_comments_controller.rb @@ -1,163 +1,166 @@ -class OrgDocumentCommentsController < ApplicationController - before_filter :find_organization, :only => [:new, :create, :show, :index] - - layout 'base_org' - - def new - @org_document_comment = OrgDocumentComment.new - end - - def create - @org_document_comment = OrgDocumentComment.new(:organization_id => @organization.id, :creator_id => User.current.id) - @org_document_comment.title = params[:org_document_comment][:title] - @org_document_comment.content = params[:org_document_comment][:content] - if params[:field_id] - @org_document_comment.org_subfield_id = params[:field_id].to_i - end - if @org_document_comment.save - flash.keep[:notice] = l(:notice_successful_create) - EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document_comment.id, :created_at => @org_document_comment.updated_at) - if params[:field_id] - redirect_to organization_path(@organization, :org_subfield_id => params[:field_id]) - else - redirect_to organization_org_document_comments_path(@organization) - end - else - redirect_to new_org_document_comment_path(:organization_id => @organization.id) - end - end - def show - @document = OrgDocumentComment.find(params[:id]) - end - - def index - if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) - @documents = @organization.org_document_comments.where("parent_id is null").order("created_at desc") - else - render_403 - end - end - def update - @org_document = OrgDocumentComment.find(params[:id]) - @org_document.update_attributes(:title => params[:org_document_comment][:title], :content => params[:org_document_comment][:content]) - if @org_document.parent.nil? - act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", @org_document.id).first - act.update_attributes(:updated_at => @org_document.updated_at) - EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document.id, :created_at => Time.now) - end - respond_to do |format| - format.html { - if params[:flag].to_i == 0 - redirect_to organization_org_document_comments_path(:organization_id => @org_document.organization.id) - else - if params[:flag].to_i == 1 - redirect_to org_document_comment_path(@org_document.root.id, :organization_id => @org_document.organization.id) - else - redirect_to organization_path(@org_document.organization.id, :org_subfield_id => params[:org_subfield_id]) - end - end - } - end - end - - def edit - @org_document = OrgDocumentComment.find(params[:id]) - @flag = params[:flag] - @organization = Organization.find(params[:organization_id]) - end - - def add_reply - @document = OrgDocumentComment.find(params[:id]).root - @act = OrgActivity.find(params[:id]) - @comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id]) - @comment.content = params[:org_content] - @document.children << @comment - @document.save - end - - def add_reply_in_doc - @document = OrgDocumentComment.find(params[:id]).root - @comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id]) - @comment.content = params[:org_comment][:org_content] - @document.children << @comment - @document.save - respond_to do |format| - format.html {redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)} - end - end - - def find_organization - @organization = Organization.find(params[:organization_id]) - end - - def destroy - @org_document_comment = OrgDocumentComment.find(params[:id]) - org = @org_document_comment.organization - if @org_document_comment.id == org.home_id - org.update_attributes(:home_id => nil) - end - if @org_document_comment.destroy - end - respond_to do |format| - format.js - end - end - - def delete_reply - @org_document_comment = OrgDocumentComment.find(params[:id]) - @document = @org_document_comment.root - org = @org_document_comment.organization - @org_document_comment.destroy - respond_to do |format| - format.html {redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)} - end - end - def quote - @org_comment = OrgDocumentComment.find(params[:id]) - @subject = @org_comment.content - @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:') - - @content = "> #{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)}\n> " - @temp = OrgDocumentComment.new - #@course_id = params[:course_id] - @temp.content = "
#{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)}".html_safe - respond_to do | format| - format.js - end - end - - def reply - @document = OrgDocumentComment.find(params[:id]).root - @quote = params[:quote][:quote] - @org_document = OrgDocumentComment.new(:creator_id => User.current.id, :reply_id => params[:id]) - - # params[:blog_comment][:sticky] = params[:blog_comment][:sticky] || 0 - # params[:blog_comment][:locked] = params[:blog_comment][:locked] || 0 - @org_document.title = params[:org_document_comment][:title] - @org_document.content = params[:org_document_comment][:content] - @org_document.content = @quote + @org_document.content - #@org_document.title = "RE: #{@article.title}" unless params[:blog_comment][:title] - @document.children << @org_document - # @user_activity_id = params[:user_activity_id] - # user_activity = UserActivity.where("act_type='BlogComment' and act_id =#{@article.id}").first - # if user_activity - # user_activity.updated_at = Time.now - # user_activity.save - # end - # attachments = Attachment.attach_files(@org_document, params[:attachments]) - # render_attachment_warning_if_needed(@org_document) - #@article.save - # redirect_to user_blogs_path(:user_id=>params[:user_id]) - respond_to do |format| - format.html { - # if params[:course_id] #如果呆了course_id过来了,那么这是要跳到课程大纲去的 - # redirect_to syllabus_course_path(:id=>params[:course_id]) - # else - redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id) - # end - - } - format.js - end - end -end +class OrgDocumentCommentsController < ApplicationController + before_filter :find_organization, :only => [:new, :create, :show, :index] + helper :attachments + layout 'base_org' + + def new + @org_document_comment = OrgDocumentComment.new + end + + + def create + @org_document_comment = OrgDocumentComment.new(:organization_id => @organization.id, :creator_id => User.current.id) + @org_document_comment.title = params[:org_document_comment][:title] + @org_document_comment.content = params[:org_document_comment][:content] + @org_document_comment.save_attachments(params[:attachments]) + if params[:field_id] + @org_document_comment.org_subfield_id = params[:field_id].to_i + end + if @org_document_comment.save + flash.keep[:notice] = l(:notice_successful_create) + EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document_comment.id, :created_at => @org_document_comment.updated_at) + if params[:field_id] + redirect_to organization_path(@organization, :org_subfield_id => params[:field_id]) + else + redirect_to organization_org_document_comments_path(@organization) + end + else + redirect_to new_org_document_comment_path(:organization_id => @organization.id) + end + end + def show + @document = OrgDocumentComment.find(params[:id]) + end + + def index + if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) + @documents = @organization.org_document_comments.where("parent_id is null").order("created_at desc") + else + render_403 + end + end + def update + @org_document = OrgDocumentComment.find(params[:id]) + @org_document.update_attributes(:title => params[:org_document_comment][:title], :content => params[:org_document_comment][:content]) + @org_document.save_attachments(params[:attachments]) + if @org_document.parent.nil? + act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", @org_document.id).first + act.update_attributes(:updated_at => @org_document.updated_at) + EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document.id, :created_at => Time.now) + end + respond_to do |format| + format.html { + if params[:flag].to_i == 0 + redirect_to organization_org_document_comments_path(:organization_id => @org_document.organization.id) + else + if params[:flag].to_i == 1 + redirect_to org_document_comment_path(@org_document.root.id, :organization_id => @org_document.organization.id) + else + redirect_to organization_path(@org_document.organization.id, :org_subfield_id => params[:org_subfield_id]) + end + end + } + end + end + + def edit + @org_document = OrgDocumentComment.find(params[:id]) + @flag = params[:flag] + @organization = Organization.find(params[:organization_id]) + end + + def add_reply + @document = OrgDocumentComment.find(params[:id]).root + @act = OrgActivity.find(params[:id]) + @comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id]) + @comment.content = params[:org_content] + @document.children << @comment + @document.save + end + + def add_reply_in_doc + @document = OrgDocumentComment.find(params[:id]).root + @comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id]) + @comment.content = params[:org_comment][:org_content] + @document.children << @comment + @document.save + respond_to do |format| + format.html {redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)} + end + end + + def find_organization + @organization = Organization.find(params[:organization_id]) + end + + def destroy + @org_document_comment = OrgDocumentComment.find(params[:id]) + org = @org_document_comment.organization + if @org_document_comment.id == org.home_id + org.update_attributes(:home_id => nil) + end + if @org_document_comment.destroy + end + respond_to do |format| + format.js + end + end + + def delete_reply + @org_document_comment = OrgDocumentComment.find(params[:id]) + @document = @org_document_comment.root + org = @org_document_comment.organization + @org_document_comment.destroy + respond_to do |format| + format.html {redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)} + end + end + def quote + @org_comment = OrgDocumentComment.find(params[:id]) + @subject = @org_comment.content + @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:') + + @content = "> #{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)}\n> " + @temp = OrgDocumentComment.new + #@course_id = params[:course_id] + @temp.content = "
#{@org_comment.content.html_safe}
#{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)}".html_safe + respond_to do | format| + format.js + end + end + + def reply + @document = OrgDocumentComment.find(params[:id]).root + @quote = params[:quote][:quote] + @org_document = OrgDocumentComment.new(:creator_id => User.current.id, :reply_id => params[:id]) + + # params[:blog_comment][:sticky] = params[:blog_comment][:sticky] || 0 + # params[:blog_comment][:locked] = params[:blog_comment][:locked] || 0 + @org_document.title = params[:org_document_comment][:title] + @org_document.content = params[:org_document_comment][:content] + @org_document.content = @quote + @org_document.content + #@org_document.title = "RE: #{@article.title}" unless params[:blog_comment][:title] + @document.children << @org_document + # @user_activity_id = params[:user_activity_id] + # user_activity = UserActivity.where("act_type='BlogComment' and act_id =#{@article.id}").first + # if user_activity + # user_activity.updated_at = Time.now + # user_activity.save + # end + # attachments = Attachment.attach_files(@org_document, params[:attachments]) + # render_attachment_warning_if_needed(@org_document) + #@article.save + # redirect_to user_blogs_path(:user_id=>params[:user_id]) + respond_to do |format| + format.html { + # if params[:course_id] #如果呆了course_id过来了,那么这是要跳到课程大纲去的 + # redirect_to syllabus_course_path(:id=>params[:course_id]) + # else + redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id) + # end + + } + format.js + end + end +end diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index 1dc7885fe..66a236b5b 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -1,24 +1,32 @@ -class OrgSubfieldsController < ApplicationController - def create - @subfield = OrgSubfield.create(:name => params[:name]) - @organization = Organization.find(params[:organization_id]) - @organization.org_subfields << @subfield - @subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type]) - end - - def destroy - @subfield = OrgSubfield.find(params[:id]) - @organization = Organization.find(@subfield.organization_id) - @subfield.destroy - end - - def update - @subfield = OrgSubfield.find(params[:id]) - @organization = Organization.find(@subfield.organization_id) - @subfield.update_attributes(:name => params[:name]) - end - - def show - - end -end +class OrgSubfieldsController < ApplicationController + def create + @subfield = OrgSubfield.create(:name => params[:name]) + @organization = Organization.find(params[:organization_id]) + @organization.org_subfields << @subfield + @subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type]) + end + + def show + @org_subfield = OrgSubfield.find(params[:id]) + @organization = @org_subfield.organization.id + @messages = [] + @messages << @org_subfield.org_document_comments + @messages << @org_subfield.messages + @messages.sort{|a, b| b.updated_at <=> a.updated_at} + respond_to do |format| + format.html{render :layout => 'base_org'} + end + end + def destroy + @subfield = OrgSubfield.find(params[:id]) + @organization = Organization.find(@subfield.organization_id) + @subfield.destroy + end + + def update + @subfield = OrgSubfield.find(params[:id]) + @organization = Organization.find(@subfield.organization_id) + @subfield.update_attributes(:name => params[:name]) + end + +end diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 38402f68e..aba656750 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -1,284 +1,284 @@ -# encoding: utf-8 -class OrganizationsController < ApplicationController - - - helper :sort - include SortHelper - helper :custom_fields - include CustomFieldsHelper - include AvatarHelper - include WordsHelper - include GitlabHelper - include UserScoreHelper - - include PollHelper - helper :user_score - helper :journals - - # added by liuping 关注 - - helper :watchers - helper :activities - - ### added by william - include ActsAsTaggableOn::TagsHelper - - # fq - helper :words - helper :project_score - helper :issues - include UsersHelper - before_filter :find_organization, :only => [:show, :members] - layout 'base_org' - def index - - end - def new - @organization = Organization.new - render :layout => 'new_base' - end - - def edit - @organization = Organization.find(params[:id]) - end - - def destroy - @organization = Organization.find(params[:id]) - @organization.destroy - respond_to do |format| - format.html{ redirect_to admin_organization_path } - end - end - - def create - @organization = Organization.new - @organization.name = params[:organization][:name] - @organization.description = params[:organization][:description] - @organization.is_public = params[:organization][:is_public] - @organization.creator_id = User.current.id - member = OrgMember.new(:user_id => User.current.id) - - @organization.org_members << member - if @organization.save - OrgMemberRole.create(:org_member_id => member.id, :role_id => 11) - redirect_to organization_path(@organization) - end - end - - def show - if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) - @organization = Organization.find(params[:id]) - if params[:org_subfield_id] - @org_subfield = OrgSubfield.find(params[:org_subfield_id]) - @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0 - @org_activities = OrgActivity.where("org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})").order('updated_at desc').page(params[:page] || 1).per(10) - else - project_ids = @organization.projects.map(&:id) << 0 - course_ids = @organization.courses.map(&:id) << 0 - course_types = "('Message','News','HomeworkCommon','Poll','Course')" - case params[:type] - when nil - @org_activities = OrgActivity.where("(container_id =? and container_type =?) " + - "or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+ - "or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))", - @organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) - when 'project_issue' - @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Issue' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - when 'project_message' - @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Message' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - when 'org' - @org_activities = OrgActivity.where("container_id =? and container_type =?",@organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) - when 'course_homework' - @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'HomeworkCommon' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - when 'course_news' - @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'News' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - when 'course_message' - @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Message' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - when 'course_poll' - @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Poll' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - end - end - @page = params[:page] - respond_to do |format| - format.html - format.js - end - else - render_403 - end - end - - def update - @organization = Organization.find(params[:id]) - @organization.name = params[:organization][:name] - @organization.description = params[:organization][:description] - @organization.domain = params[:organization][:domain] - @organization.is_public = params[:organization][:is_public] == 'on' ? 1 : 0 - #@organization.name = params[:organization][:name] - @organization.save - respond_to do |format| - format.html { redirect_to setting_organization_path(@organization)} - end - end - - def check_uniq - @check = false; - @org_name = params[:org_name].strip - @config_page = params[:config_page] - sameName = @config_page ? Organization.where('name = ? and id != ?',params[:org_name],params[:org_id].to_i).count == 0 : Organization.where('name = ?',params[:org_name]).count == 0 - if sameName == true - @check = true - end - respond_to do |format| - format.js - end - end - - def find_organization - @organization = Organization.find(params[:id]) - end - - def setting - @organization = Organization.find(params[:id]) - - if User.current.admin? || User.current.admin_of_org?(@organization) - else - render_403 - end - end - - - def clear_org_avatar_temp - - end - - def set_homepage - @org = Organization.find(params[:id]) - @org.home_id = params[:home_id] - @org.save - # respond_to do |format| - # format.html {redirect_to organization_path(org)} - # end - end - - def cancel_homepage - @org = Organization.find(params[:id]) - @org.home_id = nil - @org.save - end - - def autocomplete_search - @project = Project.find(params[:project_id]) - #@flag = params[:flag] || false - respond_to do |format| - format.js - end - end - - def members - if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) - @members = OrgMember.where("organization_id =?", @organization.id) - else - render_403 - end - end - - def more_org_projects - @organization = Organization.find params[:id] - @page = params[:page] - @org_projects = @organization.projects.reorder('created_at').uniq.page((params[:page].to_i || 1) +1).per(5) - respond_to do |format| - format.js - end - end - - def more_org_courses - @organization = Organization.find(params[:id]) - @page = params[:page] - @org_courses = @organization.courses.reorder('created_at').uniq.page((params[:page].to_i || 1) + 1 ).per(5) - respond_to do |format| - format.js - end - end - - def join_course_menu - @organization = Organization.find(params[:id]) - respond_to do |format| - format.js - end - end - - def search_courses - @organization = Organization.find(params[:id]) - condition = '%%' - if !params[:name].nil? - condition = "%#{params[:name].strip}%".gsub(" ","") - end - sql = "select courses.* from courses inner join members on courses.id = members.course_id where members.user_id = #{User.current.id} and courses.name like '#{condition}'"+ - "and courses.id not in (select distinct org_courses.course_id from org_courses where org_courses.organization_id = #{@organization.id})" - #user_courses = Course.find_by_sql(sql) - @courses = Course.find_by_sql(sql) - # @added_course_ids = @organization.courses.map(&:id) - # @courses = [] - # user_courses.each do |course| - # if !@added_course_ids.include?(course.id) - # @courses << course - # end - # end - end - - def join_courses - @organization = Organization.find(params[:id]) - course_ids = params[:courseNames] - course_ids.each do |id| - OrgCourse.create(:organization_id => @organization.id, :course_id => id.to_i, :created_at => Time.now) - end - respond_to do |format| - format.js - end - end - - def join_project_menu - @organization = Organization.find(params[:id]) - respond_to do |format| - format.js - end - end - - def logout - logout_user - respond_to do |format| - format.html {redirect_to organization_path(params[:id])} - end - end - - def search_projects - @organization = Organization.find(params[:id]) - condition = '%%' - if !params[:name].nil? - condition = "%#{params[:name].strip}%".gsub(" ","") - end - sql = "select projects.* from projects inner join members on projects.id = members.project_id where members.user_id = #{User.current.id} and projects.status != 9 and projects.name like '#{condition}'" + - " and projects.id not in (select org_projects.project_id from org_projects where organization_id = #{@organization.id})" - #user_projects = Course.find_by_sql(sql) - @projects = Course.find_by_sql(sql) - # @added_course_ids = @organization.projects.map(&:id) - # @projects = [] - # user_projects.each do |project| - # if !@added_course_ids.include?(project.id) - # @projects << project - # end - # end - end - - def join_projects - @organization = Organization.find(params[:id]) - project_ids = params[:projectNames] - project_ids.each do |id| - OrgProject.create(:organization_id => @organization.id, :project_id => id.to_i, :created_at => Time.now) - end - respond_to do |format| - format.js - end - end -end +# encoding: utf-8 +class OrganizationsController < ApplicationController + + + helper :sort + include SortHelper + helper :custom_fields + include CustomFieldsHelper + include AvatarHelper + include WordsHelper + include GitlabHelper + include UserScoreHelper + + include PollHelper + helper :user_score + helper :journals + + # added by liuping 关注 + + helper :watchers + helper :activities + + ### added by william + include ActsAsTaggableOn::TagsHelper + + # fq + helper :words + helper :project_score + helper :issues + include UsersHelper + before_filter :find_organization, :only => [:show, :members] + layout 'base_org' + def index + + end + def new + @organization = Organization.new + render :layout => 'new_base' + end + + def edit + @organization = Organization.find(params[:id]) + end + + def destroy + @organization = Organization.find(params[:id]) + @organization.destroy + respond_to do |format| + format.html{ redirect_to admin_organization_path } + end + end + + def create + @organization = Organization.new + @organization.name = params[:organization][:name] + @organization.description = params[:organization][:description] + @organization.is_public = params[:organization][:is_public] + @organization.creator_id = User.current.id + member = OrgMember.new(:user_id => User.current.id) + + @organization.org_members << member + if @organization.save + OrgMemberRole.create(:org_member_id => member.id, :role_id => 11) + redirect_to organization_path(@organization) + end + end + + def show + if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) + @organization = Organization.find(params[:id]) + if params[:org_subfield_id] + @org_subfield = OrgSubfield.find(params[:org_subfield_id]) + @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0 + @org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10) + else + project_ids = @organization.projects.map(&:id) << 0 + course_ids = @organization.courses.map(&:id) << 0 + course_types = "('Message','News','HomeworkCommon','Poll','Course')" + case params[:type] + when nil + @org_activities = OrgActivity.where("(container_id =? and container_type =?) " + + "or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+ + "or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))", + @organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) + when 'project_issue' + @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Issue' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + when 'project_message' + @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Message' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + when 'org' + @org_activities = OrgActivity.where("container_id =? and container_type =?",@organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) + when 'course_homework' + @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'HomeworkCommon' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + when 'course_news' + @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'News' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + when 'course_message' + @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Message' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + when 'course_poll' + @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Poll' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + end + end + @page = params[:page] + respond_to do |format| + format.html + format.js + end + else + render_403 + end + end + + def update + @organization = Organization.find(params[:id]) + @organization.name = params[:organization][:name] + @organization.description = params[:organization][:description] + @organization.domain = params[:organization][:domain] + @organization.is_public = params[:organization][:is_public] == 'on' ? 1 : 0 + #@organization.name = params[:organization][:name] + @organization.save + respond_to do |format| + format.html { redirect_to setting_organization_path(@organization)} + end + end + + def check_uniq + @check = false; + @org_name = params[:org_name].strip + @config_page = params[:config_page] + sameName = @config_page ? Organization.where('name = ? and id != ?',params[:org_name],params[:org_id].to_i).count == 0 : Organization.where('name = ?',params[:org_name]).count == 0 + if sameName == true + @check = true + end + respond_to do |format| + format.js + end + end + + def find_organization + @organization = Organization.find(params[:id]) + end + + def setting + @organization = Organization.find(params[:id]) + + if User.current.admin? || User.current.admin_of_org?(@organization) + else + render_403 + end + end + + + def clear_org_avatar_temp + + end + + def set_homepage + @org = Organization.find(params[:id]) + @org.home_id = params[:home_id] + @org.save + # respond_to do |format| + # format.html {redirect_to organization_path(org)} + # end + end + + def cancel_homepage + @org = Organization.find(params[:id]) + @org.home_id = nil + @org.save + end + + def autocomplete_search + @project = Project.find(params[:project_id]) + #@flag = params[:flag] || false + respond_to do |format| + format.js + end + end + + def members + if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) + @members = OrgMember.where("organization_id =?", @organization.id) + else + render_403 + end + end + + def more_org_projects + @organization = Organization.find params[:id] + @page = params[:page] + @org_projects = @organization.projects.reorder('created_at').uniq.page((params[:page].to_i || 1) +1).per(5) + respond_to do |format| + format.js + end + end + + def more_org_courses + @organization = Organization.find(params[:id]) + @page = params[:page] + @org_courses = @organization.courses.reorder('created_at').uniq.page((params[:page].to_i || 1) + 1 ).per(5) + respond_to do |format| + format.js + end + end + + def join_course_menu + @organization = Organization.find(params[:id]) + respond_to do |format| + format.js + end + end + + def search_courses + @organization = Organization.find(params[:id]) + condition = '%%' + if !params[:name].nil? + condition = "%#{params[:name].strip}%".gsub(" ","") + end + sql = "select courses.* from courses inner join members on courses.id = members.course_id where members.user_id = #{User.current.id} and courses.name like '#{condition}'"+ + "and courses.id not in (select distinct org_courses.course_id from org_courses where org_courses.organization_id = #{@organization.id})" + #user_courses = Course.find_by_sql(sql) + @courses = Course.find_by_sql(sql) + # @added_course_ids = @organization.courses.map(&:id) + # @courses = [] + # user_courses.each do |course| + # if !@added_course_ids.include?(course.id) + # @courses << course + # end + # end + end + + def join_courses + @organization = Organization.find(params[:id]) + course_ids = params[:courseNames] + course_ids.each do |id| + OrgCourse.create(:organization_id => @organization.id, :course_id => id.to_i, :created_at => Time.now) + end + respond_to do |format| + format.js + end + end + + def join_project_menu + @organization = Organization.find(params[:id]) + respond_to do |format| + format.js + end + end + + def logout + logout_user + respond_to do |format| + format.html {redirect_to organization_path(params[:id])} + end + end + + def search_projects + @organization = Organization.find(params[:id]) + condition = '%%' + if !params[:name].nil? + condition = "%#{params[:name].strip}%".gsub(" ","") + end + sql = "select projects.* from projects inner join members on projects.id = members.project_id where members.user_id = #{User.current.id} and projects.status != 9 and projects.name like '#{condition}'" + + " and projects.id not in (select org_projects.project_id from org_projects where organization_id = #{@organization.id})" + #user_projects = Course.find_by_sql(sql) + @projects = Course.find_by_sql(sql) + # @added_course_ids = @organization.projects.map(&:id) + # @projects = [] + # user_projects.each do |project| + # if !@added_course_ids.include?(project.id) + # @projects << project + # end + # end + end + + def join_projects + @organization = Organization.find(params[:id]) + project_ids = params[:projectNames] + project_ids.each do |id| + OrgProject.create(:organization_id => @organization.id, :project_id => id.to_i, :created_at => Time.now) + end + respond_to do |format| + format.js + end + end +end diff --git a/app/models/message.rb b/app/models/message.rb index 4cdae1f6e..19531e270 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -23,6 +23,8 @@ class Message < ActiveRecord::Base belongs_to :board,:touch => true belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_many :org_subfield_messages, :dependent => :destroy + has_many :org_subfields, :through => :org_subfield_messages acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC" acts_as_attachable diff --git a/app/models/org_document_comment.rb b/app/models/org_document_comment.rb index e2ce350ce..c1619fc6e 100644 --- a/app/models/org_document_comment.rb +++ b/app/models/org_document_comment.rb @@ -1,20 +1,26 @@ -class OrgDocumentComment < ActiveRecord::Base - attr_accessible :content, :creator_id, :organization_id, :parent_id, :reply_id, :title,:sticky,:locked - include Redmine::SafeAttributes - belongs_to :organization - belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id' - has_many :editor_of_documents, :dependent => :destroy - acts_as_tree :order => "#{OrgDocumentComment.table_name}.sticky asc, #{OrgDocumentComment.table_name}.created_at desc" - has_many :org_acts, :class_name => 'OrgActivity',:as =>:org_act ,:dependent => :destroy - after_create :document_save_as_org_activity - - def document_save_as_org_activity - if(self.parent().nil?) - self.org_acts << OrgActivity.new(:user_id => User.current.id, :container_id => self.organization.id, :container_type => 'Organization') - else - act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", self.root.id).first - act.update_attributes(:updated_at => self.updated_at) - end - end - -end +class OrgDocumentComment < ActiveRecord::Base + attr_accessible :content, :creator_id, :organization_id, :parent_id, :reply_id, :title,:sticky,:locked + include Redmine::SafeAttributes + belongs_to :organization + belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id' + has_many :editor_of_documents, :dependent => :destroy + acts_as_tree :order => "#{OrgDocumentComment.table_name}.sticky asc, #{OrgDocumentComment.table_name}.created_at desc" + acts_as_attachable + has_many :org_acts, :class_name => 'OrgActivity',:as =>:org_act ,:dependent => :destroy + after_create :document_save_as_org_activity + + def document_save_as_org_activity + if(self.parent().nil?) + self.org_acts << OrgActivity.new(:user_id => User.current.id, :container_id => self.organization.id, :container_type => 'Organization') + else + act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", self.root.id).first + act.update_attributes(:updated_at => self.updated_at) + end + end + + + def project + + end + +end diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb index f95bb3eba..6a31203b0 100644 --- a/app/models/org_subfield.rb +++ b/app/models/org_subfield.rb @@ -1,9 +1,11 @@ -class OrgSubfield < ActiveRecord::Base - belongs_to :organization, :foreign_key => :organization_id - has_many :org_document_comments, :dependent => :destroy - has_many :files - acts_as_attachable - - def project - end +class OrgSubfield < ActiveRecord::Base + belongs_to :organization, :foreign_key => :organization_id + has_many :org_document_comments, :dependent => :destroy + has_many :files + has_many :org_subfield_messages, :dependent => :destroy + has_many :messages, :through => :org_subfield_messages + acts_as_attachable + + def project + end end \ No newline at end of file diff --git a/app/models/org_subfield_message.rb b/app/models/org_subfield_message.rb new file mode 100644 index 000000000..64dbdfdf5 --- /dev/null +++ b/app/models/org_subfield_message.rb @@ -0,0 +1,3 @@ +class OrgSubfieldMessage < ActiveRecord::Base + # attr_accessible :title, :body +end diff --git a/app/views/boards/_project_new_topic.html.erb b/app/views/boards/_project_new_topic.html.erb index 00a3d2016..7a211e25d 100644 --- a/app/views/boards/_project_new_topic.html.erb +++ b/app/views/boards/_project_new_topic.html.erb @@ -1,11 +1,65 @@ -<%= form_for @message, :url =>{:controller=>'messages',:action => 'new', :board_id => @board.id, :is_board => 'true'},:html => {:nhname=>'form', :multipart => true, :id => 'message-form', :name=>'message-form'} do |f| %> - - <%= render :partial => 'form_project', :locals => {:f => f, :topic => @message} %> -
#{@org_comment.content.html_safe}
讨论区共有<%= @topic_count %>个帖子
- <% if @topics.any? %> - <% @topics.each do |topic| %> -:
- - - - <% if topic.editable_by?(User.current) %> - <%= l(:button_edit) %> - <% end %> - <%= link_to(l(:button_delete), {:controller =>'messages',:action => 'destroy', :id => topic.id, :board_id => topic.board_id, :is_board=>'true'}, - :method => :post, - :data => {:confirm => l(:text_are_you_sure)}, - :class => 'talk_edit fr', - :style => ' margin-right: 10px;') if topic.destroyable_by?(User.current) %> - <% if topic.sticky? %> - <%= l(:label_board_sticky)%> - <% end %> - - - -<%= l(:label_no_data) %>
- <% end %> -- <%= @topic.subject %>
-由<%= link_to_user_header @topic.author,false,:class=> 'problem_name c_orange' %> 添加于<%= format_time(@topic.created_on) %>
-<%= textAreailizable message,:content,:attachments => message.attachments %>
- <%= link_to_attachments_course message, :author => false %> -