This commit is contained in:
z9hang 2014-08-29 16:52:27 +08:00
commit 54ed41e483
4 changed files with 62 additions and 6 deletions

View File

@ -28,6 +28,13 @@ class AvatarController < ApplicationController
if @temp_file && (@temp_file.size > 0)
diskfile=disk_filename(@source_type,@source_id)
@urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file))
# 用户头像上传时进行特别处理
if @source_type == 'User'
diskfile += "temp"
@urlfile += "temp"
end
logger.info("Saving avatar '#{diskfile}' (#{@temp_file.size} bytes)")
path = File.dirname(diskfile)
unless File.directory?(path)
@ -96,7 +103,16 @@ class AvatarController < ApplicationController
unless diskfile.nil? || diskfile == ""
path = File.dirname(diskfile)
if File.directory?(path) && File.exist?(diskfile)
File.delete(diskfile)
# 用户头像进行特别处理
if @source_type == 'User'
diskfile1 = diskfile + 'temp'
File.open(diskfile1, "wb") do |f|
buffer = "DELETE"
f.write(buffer)
end
else
File.delete(diskfile)
end
end
end
rescue e do

View File

@ -76,6 +76,8 @@ class MyController < ApplicationController
def account
@user = User.current
@pref = @user.pref
diskfile = disk_filename('User', @user.id)
diskfile1 = diskfile + 'temp'
if request.post?
@user.safe_attributes = params[:user]
@user.pref.attributes = params[:pref]
@ -97,6 +99,33 @@ class MyController < ApplicationController
@se.student_id = params[:no] if params[:no]
if @user.save && @se.save
# 头像保存
if File.exist?(diskfile1)
if File.exist?(diskfile)
File.delete(diskfile)
end
File.open(diskfile1, "rb") do |f|
buffer = f.read(10)
if buffer != "DELETE"
File.open(diskfile1, "rb") do |f1|
File.open(diskfile, "wb") do |f|
buffer = ""
while (buffer = f1.read(8192))
f.write(buffer)
end
end
end
# File.rename(diskfile + 'temp',diskfile);
end
end
end
# 确保文件被删除
if File.exist?(diskfile1)
File.delete(diskfile1)
end
@user.pref.save
@user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
set_language_if_valid @user.language
@ -104,8 +133,17 @@ class MyController < ApplicationController
redirect_to user_path(@user)
return
else
# 确保文件被删除
if File.exist?(diskfile1)
File.delete(diskfile1)
end
@user
end
else
# 确保文件被删除
if File.exist?(diskfile1)
File.delete(diskfile1)
end
end
end

View File

@ -27,14 +27,15 @@
<p><label><%= l(:label_board) %></label><br />
<%# modify by nwb%>
<% if @message.project %>
<%= f.select :board_id, boards_options_for_select(@message.project.boards) %></p>
<%= f.select :board_id, boards_options_for_select(@message.project.boards) %>
<% elsif @message.course %>
<%= f.select :board_id, boards_options_for_select(@message.course.boards) %></p>
<%= f.select :board_id, boards_options_for_select(@message.course.boards) %>
<% end %>
</p>
<% end %>
<div id="message_quote" class="wiki" style="width: 100%;word-break: break-all;word-wrap: break-word;"></div>
<%= text_area :quote,:quote,:style => 'display:none' %>
<p><label for="message_subject"><%= l(:field_description) %><span class="required"> *&nbsp;&nbsp;</span></label>
<%= text_area :quote,:quote,:style => 'display:none' %>
</p>
<p>
<%= label_tag "message_content", l(:description_message_content), :class => "hidden-for-sighted" %>
<%= f.text_area :content, :cols => 80, :rows => 13, :class => 'wiki-edit', :id => 'message_content' %></p>

View File

@ -276,6 +276,7 @@ zh:
field_is_default: 默认值
field_tracker: 跟踪
field_subject: 主题
field_quote: 描述
field_due_date: 计划完成日期
field_assigned_to: 指派给
field_priority: 优先级