diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb index b5c174b0c..9d90cb9f2 100644 --- a/app/controllers/avatar_controller.rb +++ b/app/controllers/avatar_controller.rb @@ -12,11 +12,13 @@ class AvatarController < ApplicationController @source_id = params[:source_id] @temp_file = params[:avatar][:image] @image_file = @temp_file.original_filename + @is_direct = params[:is_direct] else unless request.raw_post.nil? @source_type = params[:source_type] @source_id = params[:source_id] @temp_file = request.raw_post + @is_direct = params[:is_direct] if @temp_file.size > 0 if @temp_file.respond_to?(:original_filename) @image_file = @temp_file.original_filename @@ -38,7 +40,7 @@ class AvatarController < ApplicationController @urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file)) # 用户头像上传时进行特别处理 - if @source_type == 'User' + if @is_direct == '1' && (@source_type == 'User' || @source_type == 'Course' || @source_type == 'Project') diskfile += "temp" @urlfile += "temp" end @@ -105,7 +107,7 @@ class AvatarController < ApplicationController path = File.dirname(diskfile) if File.directory?(path) && File.exist?(diskfile) # 用户头像进行特别处理 - if @source_type == 'User' + if @source_type == 'User' || @source_type == 'Course' || @source_type == 'Project' diskfile1 = diskfile + 'temp' File.open(diskfile1, "wb") do |f| buffer = "DELETE" diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 05b93d302..858c7e5c3 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -90,14 +90,34 @@ class MyController < ApplicationController end def clear_user_avatar_temp - @user = User.current - diskfile = disk_filename('User', @user.id) + if params[:course] + @course = Course.find params[:course] + diskfile = disk_filename('Course', @course.id) + elsif params[:project] + @project = Project.find params[:project] + diskfile = disk_filename('Project', @project.id) + else + @user = User.current + diskfile = disk_filename('User', @user.id) + end diskfile1 = diskfile + 'temp' File.delete(diskfile1) if File.exist?(diskfile1) end + def save_user_avatar - @user = User.current - diskfile = disk_filename('User', @user.id) + if params[:source_id] && params[:source_type] + case params[:source_type] + when 'User' + @user = User.current + diskfile = disk_filename('User', @user.id) + when 'Course' + @course = Course.find params[:source_id] + diskfile = disk_filename('Course', @course.id) + when 'Project' + @project = Project.find params[:source_id] + diskfile = disk_filename('Project', @project.id) + end + end diskfile1 = diskfile + 'temp' begin FileUtils.mv diskfile1, diskfile, force: true if File.exist? diskfile1 diff --git a/app/views/avatar/_new_avatar_form.html.erb b/app/views/avatar/_new_avatar_form.html.erb index 2593bf1f5..d13a2a4d5 100644 --- a/app/views/avatar/_new_avatar_form.html.erb +++ b/app/views/avatar/_new_avatar_form.html.erb @@ -17,7 +17,8 @@ :upload_path => upload_avatar_path(:format => 'js'), :description_placeholder => nil ,# l(:label_optional_description) :source_type => source.class.to_s, - :source_id => source.id.to_s + :source_id => source.id.to_s, + :is_direct => 0 } %> <% content_for :header_tags do %> diff --git a/app/views/avatar/upload.js.erb b/app/views/avatar/upload.js.erb index 41cf3ab77..c2fa23242 100644 --- a/app/views/avatar/upload.js.erb +++ b/app/views/avatar/upload.js.erb @@ -1,4 +1,4 @@ -<% if @source_type=='User' %> +<% if @is_direct == '1' && (@source_type=='User'|| @source_type == 'Course' || @source_type == 'Project') %> var imgSpan = $("img[nhname='avatar_image']"); imgSpan.attr({"src":'<%= "#{@urlfile.to_s}?#{Time.now.to_i}" %>'}); <% else %> diff --git a/app/views/courses/settings.html.erb b/app/views/courses/settings.html.erb index fabd687e0..0ac041921 100644 --- a/app/views/courses/settings.html.erb +++ b/app/views/courses/settings.html.erb @@ -27,9 +27,8 @@
邀 请 码
diff --git a/app/views/layouts/_upload_avatar.html.erb b/app/views/layouts/_upload_avatar.html.erb
new file mode 100644
index 000000000..ac6af739f
--- /dev/null
+++ b/app/views/layouts/_upload_avatar.html.erb
@@ -0,0 +1,44 @@
+
预览
+ <%= image_tag(url_to_avatar(source), :style=>"width:96px;height:96px;",:class=>"mb5 mt10",:nhname=>'avatar_image') %> +