diff --git a/Gemfile b/Gemfile index 29b2716a9..fb0312d5b 100644 --- a/Gemfile +++ b/Gemfile @@ -23,7 +23,7 @@ gem 'ruby-ole' #gem 'email_verifier', path: 'lib/email_verifier' gem 'rufus-scheduler' #gem 'dalli', path: 'lib/dalli-2.7.2' -gem 'rails_kindeditor' +gem 'rails_kindeditor',path:'lib/rails_kindeditor' group :development do gem 'grape-swagger' #gem 'grape-swagger-ui', git: 'https://github.com/guange2015/grape-swagger-ui.git' diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 64157ea42..c347ba6b8 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -1,7 +1,7 @@ # added by fq class ForumsController < ApplicationController layout "users_base" - + include ApplicationHelper # GET /forums # GET /forums.json before_filter :find_forum_if_available @@ -63,6 +63,9 @@ class ForumsController < ApplicationController respond_to do |format| if @memo.save + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids ,@memo.id,1 + #end format.html { redirect_to (forum_memo_url(@forum, (@memo.parent_id.nil? ? @memo : @memo.parent_id))), notice: "#{l :label_memo_create_succ}" } format.json { render json: @memo, status: :created, location: @memo } else @@ -163,6 +166,13 @@ class ForumsController < ApplicationController @forum = Forum.new(params[:forum]) @forum.creator_id = User.current.id if @forum.save + # Time 2015-03-24 17:07:05 + # Author lizanle + # Description after save后需要进行资源记录的更新 + # owner_type = 2 对应的是 forum + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids ,@forum.id,2 + #end respond_to do |format| format.html { redirect_to @forum, notice: l(:label_forum_create_succ) } diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index aaa99e417..54bcc0496 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -59,6 +59,20 @@ class MemosController < ApplicationController @memo.content = @quote + @memo.content respond_to do |format| if @memo.save + # Time 2015-03-24 14:47:05 + # Author lizanle + # Description after save后需要进行资源记录的更新 + # owner_type = 1 对应的是 memo + if !params[:asset_id].nil? + ids = params[:asset_id].split(',') + ids.each do |id| + asset = Kindeditor::Asset.find(id.to_i) + asset.owner_id = @memo.id + asset.owner_type = 1 + asset.save + end + end + #end format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" } format.json { render json: @memo, status: :created, location: @memo } else diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b4f54f075..a5cfc2b16 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -33,6 +33,35 @@ module ApplicationHelper extend Forwardable def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter + # Time 2015-03-24 15:27:29 + # Author lizanle + # Description 从硬盘上删除对应的资源文件 + def delete_kindeditor_assets_from_disk owner_id,owner_type + assets = Kindeditor::Asset.where(["owner_id = ? and owner_type = ?",owner_id,owner_type]) + if !assets.nil? && !assets.blank? + assets.all.each do |asset| + next if asset.nil? + filepath = File.join(Rails.root,"public","files","uploads", + asset[:created_at].to_s.gsub("+0800","").to_datetime.strftime("%Y%m").to_s, + asset[:asset].to_s) + File.delete(filepath) if File.exist?filepath + end + end + end + + # Time 2015-03-24 16:38:05 + # Author lizanle + # Description after save后需要进行资源记录的更新 + # owner_type = 1 对应的是 memo + def update_kindeditor_assets_owner ids,owner_id,owner_type + ids.each do |id| + asset = Kindeditor::Asset.find(id.to_i) + asset.owner_id = owner_id + asset.owner_type = owner_type + asset.save + end + end + # Added by young # Define the course menu's link class # 不是数组的转化成数组,然后判断当前menu_item是否在给定的列表 diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 9eff409ff..884ebc2eb 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -87,7 +87,10 @@ module FilesHelper def visable_attachemnts attachments result = [] attachments.each do |attachment| - if attachment.is_public? || (attachment.container_type == "Course" && User.current.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id + if attachment.is_public? || + (attachment.container_type == "Project" && User.current.member_of?(attachment.project)) || + (attachment.container_type == "Course" && User.current.member_of_course?(Course.find(attachment.container_id)))|| + attachment.author_id == User.current.id result << attachment end end diff --git a/app/models/forum.rb b/app/models/forum.rb index 878937ea7..6843ab678 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -1,5 +1,7 @@ class Forum < ActiveRecord::Base include Redmine::SafeAttributes + include ApplicationHelper + has_many_kindeditor_assets :assets, :dependent => :destroy has_many :topics, :class_name => 'Memo', :conditions => "#{Memo.table_name}.parent_id IS NULL", :order => "#{Memo.table_name}.created_at DESC", :dependent => :destroy has_many :memos, :dependent => :destroy, conditions: "parent_id IS NULL" belongs_to :creator, :class_name => "User", :foreign_key => 'creator_id' @@ -15,7 +17,7 @@ class Forum < ActiveRecord::Base validates_length_of :name, maximum: 50 #validates_length_of :description, maximum: 255 validates :name, :uniqueness => true - + after_destroy :delete_kindeditor_assets acts_as_taggable scope :by_join_date, order("created_at DESC") #after_create :send_email @@ -47,5 +49,11 @@ class Forum < ActiveRecord::Base ["id = ?", forum_id]) end + # Time 2015-03-26 15:50:54 + # Author lizanle + # Description 删除论坛后删除对应的资源 + def delete_kindeditor_assets + delete_kindeditor_assets_from_disk self.id,2 + end end diff --git a/app/models/memo.rb b/app/models/memo.rb index b4e30dabe..eb0c86855 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -1,7 +1,9 @@ class Memo < ActiveRecord::Base include Redmine::SafeAttributes include UserScoreHelper + include ApplicationHelper belongs_to :forum + has_many_kindeditor_assets :assets, :dependent => :destroy belongs_to :author, :class_name => "User", :foreign_key => 'author_id' validates_presence_of :author_id, :forum_id, :subject,:content # 若是主题帖,则内容可以是空 @@ -44,7 +46,7 @@ class Memo < ActiveRecord::Base after_create :add_author_as_watcher, :reset_counters!, :sendmail # after_update :update_memos_forum - after_destroy :reset_counters!#,:down_user_score -- 公共区发帖暂不计入得分 + after_destroy :reset_counters!,:delete_kindeditor_assets#,:down_user_score -- 公共区发帖暂不计入得分 # after_create :send_notification # after_save :plusParentAndForum # after_destroy :minusParentAndForum @@ -170,4 +172,10 @@ class Memo < ActiveRecord::Base update_replay_for_memo(User.current,1) end + # Time 2015-03-26 15:20:24 + # Author lizanle + # Description 从硬盘上删除资源 + def delete_kindeditor_assets + delete_kindeditor_assets_from_disk self.id,1 + end end diff --git a/app/views/forums/_form.html.erb b/app/views/forums/_form_create_mode.html.erb similarity index 81% rename from app/views/forums/_form.html.erb rename to app/views/forums/_form_create_mode.html.erb index ac9c298ff..63162c7a0 100644 --- a/app/views/forums/_form.html.erb +++ b/app/views/forums/_form_create_mode.html.erb @@ -1,49 +1,51 @@ - - -
- <%= labelled_form_for(@forum) do |f| %> - <% if @forum.errors.any? %> - - <% end %> -
-
- <%= f.text_field :name, :required => true, :style => 'width: 100%;', :class => 'create-share', :maxlength => 50%> -
-
- <% if User.current.logged? && User.current.admin? %> - <% if @forum.safe_attribute? 'sticky' %> - <%= f.check_box :sticky %> - <%= label_tag 'message_sticky', l(:label_board_sticky) %> - <% end %> - <% if @forum.safe_attribute? 'locked' %> - <%= f.check_box :locked %> - <%= label_tag 'message_locked', l(:label_board_locked) %> - <% end %> - <% end %> -
-
- -

- <%= f.text_area :description, :required => true, :id => 'editor01' %> -

- - -

- (<%= l(:label_forums_max_length) %>) -

-
-
- <%= submit_tag l(:button_submit) %> - <%= link_to l(:button_back), forums_path ,:style => 'font-size: 14px; padding: 0px 3px;' %> -
-
- <% end %> -
+ + + +
+ <%= labelled_form_for(@forum) do |f| %> + <% if @forum.errors.any? %> + + <% end %> +
+
+ <%= f.text_field :name, :required => true, :style => 'width: 100%;', :class => 'create-share', :maxlength => 50%> +
+
+ <% if User.current.logged? && User.current.admin? %> + <% if @forum.safe_attribute? 'sticky' %> + <%= f.check_box :sticky %> + <%= label_tag 'message_sticky', l(:label_board_sticky) %> + <% end %> + <% if @forum.safe_attribute? 'locked' %> + <%= f.check_box :locked %> + <%= label_tag 'message_locked', l(:label_board_locked) %> + <% end %> + <% end %> +
+
+ + <%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %> +

+ <%= f.kindeditor :description, :required => true %> +

+ + +

+ (<%= l(:label_forums_max_length) %>) +

+
+
+ <%= submit_tag l(:button_submit) %> + <%= link_to l(:button_back), forums_path ,:style => 'font-size: 14px; padding: 0px 3px;' %> +
+
+ <% end %> +
diff --git a/app/views/forums/_form_edit_mode.html.erb b/app/views/forums/_form_edit_mode.html.erb new file mode 100644 index 000000000..a9bb05f79 --- /dev/null +++ b/app/views/forums/_form_edit_mode.html.erb @@ -0,0 +1,49 @@ + + + +
+ <%= labelled_form_for(@forum) do |f| %> + <% if @forum.errors.any? %> + + <% end %> +
+
+ <%= f.text_field :name, :required => true, :style => 'width: 100%;', :class => 'create-share', :maxlength => 50%> +
+
+ <% if User.current.logged? && User.current.admin? %> + <% if @forum.safe_attribute? 'sticky' %> + <%= f.check_box :sticky %> + <%= label_tag 'message_sticky', l(:label_board_sticky) %> + <% end %> + <% if @forum.safe_attribute? 'locked' %> + <%= f.check_box :locked %> + <%= label_tag 'message_locked', l(:label_board_locked) %> + <% end %> + <% end %> +
+
+

+ <%= f.kindeditor :description, :required => true,:owner_id => @forum.id,:owner_type => 2 %> +

+ + +

+ (<%= l(:label_forums_max_length) %>) +

+
+
+ <%= submit_tag l(:button_submit) %> + <%= link_to l(:button_back), forums_path ,:style => 'font-size: 14px; padding: 0px 3px;' %> +
+
+ <% end %> +
diff --git a/app/views/forums/edit.html.erb b/app/views/forums/edit.html.erb index 4aafbac7f..9fe72fdb7 100644 --- a/app/views/forums/edit.html.erb +++ b/app/views/forums/edit.html.erb @@ -1,4 +1,4 @@

编辑讨论区

- -<%= render 'form' %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= render 'form_edit_mode' %> diff --git a/app/views/forums/new.html.erb b/app/views/forums/new.html.erb index 0d51db57a..35814d843 100644 --- a/app/views/forums/new.html.erb +++ b/app/views/forums/new.html.erb @@ -5,7 +5,7 @@ <% @nav_dispaly_forum_label = 1%>

<%= l :label_forum_new %>

- -<%= render 'form' %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= render 'form_create_mode' %> <%#= link_to l(:button_back), forums_path %> diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb index 85fa8093a..2f4ec56a0 100644 --- a/app/views/forums/show.html.erb +++ b/app/views/forums/show.html.erb @@ -6,13 +6,14 @@ <% if User.current.logged? %> <%= labelled_form_for(@memo, :url => create_memo_forum_path(@forum), :html => {:multipart => true} ) do |f| %>
+ <%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %>

<%= f.text_field :subject, :required => true, :maxlength => 50%>

- <%= f.text_area :content, :required => true, :id => 'editor02' %> + <%= f.kindeditor :content, :required => true %>

- +

(<%= l(:label_memos_max_length) %>)

diff --git a/app/views/layouts/_base_feedback.html.erb b/app/views/layouts/_base_feedback.html.erb index 719021526..0ddb5913f 100644 --- a/app/views/layouts/_base_feedback.html.erb +++ b/app/views/layouts/_base_feedback.html.erb @@ -167,7 +167,7 @@ function cookieget(n) <% get_memo %> <%= form_for(@new_memo, :url => create_feedback_forum_path(@public_forum)) do |f| %> <%= f.text_area :subject, :class => "opnionText", :placeholder => l(:label_feedback_tips) %> - <%= f.hidden_field :content, :required => true , :value => l(:label_feedback_value) %> + <%= f.hidden_field :content,:id => 'hidden', :required => true , :value => l(:label_feedback_value) %> <%#= f.submit :value => l(:label_memo_create), :class => "opnionButton", :id => "button1" %> <%= l(:label_submit)%> <% end %> diff --git a/app/views/layouts/base_forums.html.erb b/app/views/layouts/base_forums.html.erb index cc9cdd071..a7e2ef08a 100644 --- a/app/views/layouts/base_forums.html.erb +++ b/app/views/layouts/base_forums.html.erb @@ -12,11 +12,12 @@ <%= csrf_meta_tag %> <%= favicon %> + <%= javascript_include_tag "/assets/kindeditor/kindeditor" %> <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'application', 'nyan', :media => 'all' %> <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> <%= javascript_heads %> <%= heads_for_theme %> - <%= javascript_include_tag "ckeditor/ckeditor.js" %> + <%= call_hook :view_layouts_base_html_head %> <%= yield :header_tags -%> @@ -52,7 +53,7 @@