diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb
index 02527bdfc..29b728268 100644
--- a/app/controllers/org_document_comments_controller.rb
+++ b/app/controllers/org_document_comments_controller.rb
@@ -13,7 +13,7 @@ class OrgDocumentCommentsController < ApplicationController
@org_document_comment.content = params[:org_document_comment][:content]
if @org_document_comment.save
flash.keep[:notice] = l(:notice_successful_create)
- OrgActivity
+ EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document_comment.id, :created_at => @org_document_comment.updated_at)
redirect_to organization_org_document_comments_path(@organization)
else
redirect_to new_org_document_comment_path(:organization_id => @organization.id)
@@ -36,13 +36,18 @@ class OrgDocumentCommentsController < ApplicationController
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
- redirect_to org_document_comment_path(@org_document.root.id, :organization_id => @org_document.organization.id)
+ 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)
+ end
end
}
end
@@ -81,10 +86,10 @@ class OrgDocumentCommentsController < ApplicationController
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
- if @org_document_comment.id == org.id
- org.home_id == nil
- end
end
respond_to do |format|
format.js
diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb
index b326051e6..70ac952ea 100644
--- a/app/controllers/organizations_controller.rb
+++ b/app/controllers/organizations_controller.rb
@@ -142,6 +142,12 @@ class OrganizationsController < ApplicationController
# 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
diff --git a/app/models/editor_of_document.rb b/app/models/editor_of_document.rb
new file mode 100644
index 000000000..15d9e7e37
--- /dev/null
+++ b/app/models/editor_of_document.rb
@@ -0,0 +1,4 @@
+class EditorOfDocument < ActiveRecord::Base
+ belongs_to :user, :class_name => 'User', :foreign_key => 'editor_id'
+ belongs_to :org_document_comment
+end
\ No newline at end of file
diff --git a/app/models/org_document_comment.rb b/app/models/org_document_comment.rb
index 7b9f9cd75..e2ce350ce 100644
--- a/app/models/org_document_comment.rb
+++ b/app/models/org_document_comment.rb
@@ -3,7 +3,7 @@ class OrgDocumentComment < ActiveRecord::Base
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
diff --git a/app/views/org_document_comments/index.html.erb b/app/views/org_document_comments/index.html.erb
index d967c42fd..9a9f74ac6 100644
--- a/app/views/org_document_comments/index.html.erb
+++ b/app/views/org_document_comments/index.html.erb
@@ -19,6 +19,6 @@
init_activity_KindEditor_data(<%= OrgActivity.where("org_act_type='OrgDocumentComment'and org_act_id=?", document.id).first.id %>, null, "87%");
});
- <%= render :partial => 'organizations/show_org_document', :locals => {:document => document, :act => OrgActivity.where("org_act_type='OrgDocumentComment'and org_act_id=?", document.id).first} %>
+ <%= render :partial => 'organizations/show_org_document', :locals => {:document => document, :act => OrgActivity.where("org_act_type='OrgDocumentComment'and org_act_id=?", document.id).first, :flag => 0} %>
<% end %>
<% end %>
\ No newline at end of file
diff --git a/app/views/org_document_comments/show.html.erb b/app/views/org_document_comments/show.html.erb
index 31e4f7e05..7655f996e 100644
--- a/app/views/org_document_comments/show.html.erb
+++ b/app/views/org_document_comments/show.html.erb
@@ -25,7 +25,7 @@
发布时间:<%= format_activity_day(@document.created_at) %> <%= format_time(@document.created_at, false) %>
<% unless @document.content.blank? %>
-
+
<%= @document.content.html_safe %>
<% end %>
diff --git a/app/views/organizations/_org_activities.html.erb b/app/views/organizations/_org_activities.html.erb
index 33ac13e76..60238091f 100644
--- a/app/views/organizations/_org_activities.html.erb
+++ b/app/views/organizations/_org_activities.html.erb
@@ -22,7 +22,7 @@
<% end %>
<% if act.org_act_type == 'OrgDocumentComment' && act.org_act_id != @organization.home_id %>
- <%= render :partial => 'show_org_document', :locals => {:document => act.org_act, :act => act} %>
+ <%= render :partial => 'show_org_document', :locals => {:document => act.org_act, :act => act, :flag => 2} %>
<% end %>
<% end %>
<% if act.container_type == 'Project' %>
diff --git a/app/views/organizations/_show_home_page.html.erb b/app/views/organizations/_show_home_page.html.erb
new file mode 100644
index 000000000..ade3f7ba8
--- /dev/null
+++ b/app/views/organizations/_show_home_page.html.erb
@@ -0,0 +1,69 @@
+
+
+
+
+
+
<%= link_to document.title, org_document_comment_path(:id => document.id, :organization_id => document.organization.id) %>
+
+ <% unless document.content.blank? %>
+
+ <%= document.content.html_safe %>
+
+ <% end %>
+
+ 发布时间:<%= format_activity_day(document.created_at) %> <%= format_time(document.created_at, false) %>
+
+
+
+ 最后编辑:<%= User.find(EditorOfDocument.where("org_document_comment_id =?", document.id).order("created_at desc").first.editor_id).realname %>
+
+
+ <% if User.current.admin? || User.current.admin_of_org?(Organization.find(document.organization_id) || User.current.id == document.creator_id) %>
+
+
+ -
+
+ -
+ <%= form_for('new_form', :url => {:controller => 'organizations', :action => 'cancel_homepage', :id => document.organization_id, :home_id => document.id}, :method => "put", :remote => true) do |f| %>
+ 取消首页
+ <% end %>
+
+ -
+ <%= link_to "编辑首页", edit_org_document_comment_path(:id => document.id, :organization_id => document.organization_id, :flag => 2), :class => "postOptionLink" %>
+
+ -
+ <%= link_to "删除首页", org_document_comment_path(:id => document.id, :organization_id => document.organization_id), :method => 'delete',
+ :data => {:confirm => l(:text_are_you_sure)},
+ :remote => true, :class => 'postOptionLink' %>
+
+
+
+
+
+
+ <% end %>
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/views/organizations/_show_org_document.html.erb b/app/views/organizations/_show_org_document.html.erb
index 888cbbf68..4d1393897 100644
--- a/app/views/organizations/_show_org_document.html.erb
+++ b/app/views/organizations/_show_org_document.html.erb
@@ -8,24 +8,20 @@
<%= link_to User.find(document.creator_id), user_path(document.creator.id), :class => "newsBlue mr15" %>
TO <%= link_to document.organization.name, organization_path(document.organization), :class => "newsBlue" %>
|
- <% if document.organization.home_id == document.id %>
- 首页
- <% else %>
组织文章
- <% end %>
<%= link_to document.title, org_document_comment_path(:id => document.id, :organization_id => document.organization.id) %>
发布时间:<%= format_activity_day(document.created_at) %> <%= format_time(document.created_at, false) %>
<% unless document.content.blank? %>
-
+
<%= document.content.html_safe %>
<% end %>
- <% if User.current.admin? || User.current.admin_of_org?(Organization.find(document.organization_id) || User.current.id == document.creator_id) %>
+ <% if User.current.admin? || User.current.admin_of_org?(Organization.find(document.organization_id)) || User.current.id == document.creator_id %>
-
@@ -36,7 +32,7 @@
<% end %>
-
- <%= link_to "编辑文章", edit_org_document_comment_path(:id => document.id, :organization_id => document.organization_id, :flag => 0), :class => "postOptionLink" %>
+ <%= link_to "编辑文章", edit_org_document_comment_path(:id => document.id, :organization_id => document.organization_id, :flag => flag), :class => "postOptionLink" %>
-
<%= link_to "删除文章", org_document_comment_path(:id => document.id, :organization_id => document.organization_id), :method => 'delete',
diff --git a/app/views/organizations/cancel_homepage.js.erb b/app/views/organizations/cancel_homepage.js.erb
new file mode 100644
index 000000000..bf9eb798c
--- /dev/null
+++ b/app/views/organizations/cancel_homepage.js.erb
@@ -0,0 +1 @@
+window.location.href = "<%= organization_path(@org) %>";
\ No newline at end of file
diff --git a/app/views/organizations/show.html.erb b/app/views/organizations/show.html.erb
index e44e0778d..9e0fc365c 100644
--- a/app/views/organizations/show.html.erb
+++ b/app/views/organizations/show.html.erb
@@ -52,14 +52,14 @@
-<% if !@organization.home_id.nil? and OrgDocumentComment.where("id = ?", @organization.home_id).count > 0 %>
+<% if !@organization.home_id.nil? and OrgDocumentComment.where("id = ?", @organization.home_id).count > 0 %>
<% act = OrgActivity.where("org_act_type = 'OrgDocumentComment' and org_act_id =?", @organization.home_id).first %>
- <%= render :partial => 'show_org_document', :locals => {:document => OrgDocumentComment.find(@organization.home_id), :home_id => @organization.home_id, :act => act} %>
+ <%= render :partial => 'show_home_page', :locals => {:document => OrgDocumentComment.find(@organization.home_id), :home_id => @organization.home_id, :act => act} %>
<% end %>
<% if @org_activities %>
<%= render :partial => 'organizations/org_activities',
diff --git a/config/routes.rb b/config/routes.rb
index d12a38425..bb6d7b940 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -36,6 +36,7 @@ RedmineApp::Application.routes.draw do
get 'setting'#, :action => 'settings', :as => 'settings'
get 'clear_org_avatar_temp'
put 'set_homepage'
+ put 'cancel_homepage'
get 'members'
get 'more_org_projects'
get 'more_org_courses'
diff --git a/db/migrate/20151130032658_create_org_docume_editor.rb b/db/migrate/20151130032658_create_org_docume_editor.rb
new file mode 100644
index 000000000..0dc9857ba
--- /dev/null
+++ b/db/migrate/20151130032658_create_org_docume_editor.rb
@@ -0,0 +1,12 @@
+class CreateOrgDocumeEditor < ActiveRecord::Migration
+ def up
+ create_table :editor_of_documents do |t|
+ t.integer :editor_id
+ t.integer :org_document_comment_id
+ t.timestamp :created_at
+ end
+ end
+
+ def down
+ end
+end
diff --git a/db/migrate/20151130064556_copy_document_created_at_for_editor_of_document.rb b/db/migrate/20151130064556_copy_document_created_at_for_editor_of_document.rb
new file mode 100644
index 000000000..2361db3dd
--- /dev/null
+++ b/db/migrate/20151130064556_copy_document_created_at_for_editor_of_document.rb
@@ -0,0 +1,12 @@
+class CopyDocumentCreatedAtForEditorOfDocument < ActiveRecord::Migration
+ def up
+ OrgDocumentComment.all.each do |doc|
+ if doc.parent.nil?
+ EditorOfDocument.create(:editor_id => doc.creator_id, :org_document_comment_id => doc.id, :created_at => doc.updated_at)
+ end
+ end
+ end
+
+ def down
+ end
+end