完成training_task 编辑功能
This commit is contained in:
parent
04edefac8b
commit
9a3793ffa9
|
@ -108,7 +108,7 @@ class TrainingTasksController < ApplicationController
|
|||
@training_task.subject = params[:training_task][:subject]
|
||||
@training_task.description = params[:training_task][:description]
|
||||
@training_task.tracker_id = params[:training_task][:tracker_id]
|
||||
@training_task.position = params[:training_sequence].to_i
|
||||
@training_task.position = params[:training_task][:position].to_i
|
||||
if @training_task.save
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
|
@ -129,87 +129,23 @@ class TrainingTasksController < ApplicationController
|
|||
end
|
||||
|
||||
def edit
|
||||
@project_menu_type = 11
|
||||
# 修改实例变量的值
|
||||
return unless update_issue_from_params
|
||||
# issue 关联的commit
|
||||
commit_issues = CommitIssues.where(:issue_id => @issue.id, :project_id => @issue.project_id)
|
||||
@issue_commit_ids = commit_issues.map{|commit_issue| commit_issue.commit_id}
|
||||
|
||||
return unless build_new_task_from_params
|
||||
respond_to do |format|
|
||||
format.html {render :layout => 'base_projects' }#added by young
|
||||
format.html {render :layout => 'base_projects' }
|
||||
format.xml { }
|
||||
end
|
||||
end
|
||||
|
||||
# 用户编辑更改issue
|
||||
def update
|
||||
# params[:assigned_to_id] = nil if params[:assigned_to_id].to_i == 0
|
||||
# params[:fixed_version_id] = nil if params[:fixed_version_id].to_i == 0
|
||||
if params[:issue_detail]
|
||||
issue = Issue.find(params[:id])
|
||||
issue = update_user_issue_detail(issue, params)
|
||||
@saved = update_user_issue_detail(issue, params)
|
||||
return
|
||||
else
|
||||
# 修改实例变量的值
|
||||
return unless update_issue_from_params
|
||||
@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
|
||||
@issue.assigned_to_id = nil if @issue.assigned_to_id == 0
|
||||
@issue.fixed_version_id = nil if @issue.fixed_version_id == 0
|
||||
saved = false
|
||||
begin
|
||||
@saved = @issue.save_issue_with_child_records(params, @time_entry)
|
||||
rescue ActiveRecord::StaleObjectError
|
||||
@conflict = true
|
||||
if params[:last_journal_id]
|
||||
@conflict_journals = @issue.journals_after(params[:last_journal_id]).all
|
||||
@conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
|
||||
end
|
||||
end
|
||||
end
|
||||
if @saved
|
||||
# 更新commit关联情况
|
||||
update_issue_commit params[:commit_ids]
|
||||
#修改界面增加跟踪者
|
||||
watcherlist = @issue.watcher_users
|
||||
select_users = []
|
||||
if params[:issue]
|
||||
if params[:issue][:watcher_user_ids]
|
||||
params[:issue][:watcher_user_ids].each do |user_id|
|
||||
select_users << User.find(user_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
select_users.each do |user|
|
||||
if watcherlist.include? user
|
||||
else
|
||||
@issue.add_watcher user
|
||||
end
|
||||
end
|
||||
watcherlist.each do |user|
|
||||
if select_users.include? user
|
||||
else
|
||||
@issue.remove_watcher user
|
||||
end
|
||||
end
|
||||
|
||||
render_attachment_warning_if_needed(@issue)
|
||||
reply_id = params[:reference_user_id].to_i
|
||||
if reply_id > 0
|
||||
JournalReply.add_reply(@issue.current_journal.id, reply_id, User.current.id)
|
||||
end
|
||||
#flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? 去掉这个notice,因为现在更新都是ajax操作
|
||||
return unless build_new_task_from_params
|
||||
@training_task.save_attachments(params[:attachments] || (params[:training_task] && params[:training_task][:uploads]))
|
||||
if @training_task.update_attributes(params[:training_task])
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html { redirect_to issue_url(@issue.id) }
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
|
||||
format.js
|
||||
format.html { render :action => 'edit' }
|
||||
format.api { render_validation_errors(@issue) }
|
||||
format.html{redirect_to training_task_url(@training_task)}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -723,65 +659,16 @@ class TrainingTasksController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# Used by #edit and #update to set some common instance variables
|
||||
# from the params
|
||||
# TODO: Refactor, not everything in here is needed by #edit
|
||||
def update_issue_from_params
|
||||
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
||||
@time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
|
||||
@time_entry.attributes = params[:time_entry]
|
||||
|
||||
# 更新issue状态时,journal表产生记录,返回@current_journal
|
||||
@issue.init_journal(User.current)
|
||||
issue_attributes = params[:issue]
|
||||
if issue_attributes && params[:conflict_resolution]
|
||||
case params[:conflict_resolution]
|
||||
when 'overwrite'
|
||||
issue_attributes = issue_attributes.dup
|
||||
issue_attributes.delete(:lock_version)
|
||||
when 'add_notes'
|
||||
issue_attributes = issue_attributes.slice(:notes)
|
||||
when 'cancel'
|
||||
redirect_to issue_url(@issue)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
if params[:action] == "update"
|
||||
senduser = User.find(params[:issue][:assigned_to_id])
|
||||
if senduser.id != User.current.id && @issue.assigned_to_id != params[:issue][:assigned_to_id].to_i
|
||||
issue_id = @issue.id
|
||||
issue_title = params[:issue][:subject]
|
||||
priority_id = params[:issue][:priority_id]
|
||||
ps = ProjectsService.new
|
||||
ps.send_wechat_project_issue_notice senduser,@issue.project,issue_id,issue_title,priority_id
|
||||
end
|
||||
end
|
||||
|
||||
@issue.safe_attributes = issue_attributes
|
||||
@priorities = IssuePriority.active
|
||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||
true
|
||||
end
|
||||
|
||||
# TODO: Refactor, lots of extra code in here
|
||||
# TODO: Changing tracker on an existing issue should not trigger this
|
||||
def build_new_task_from_params
|
||||
if params[:id].blank?
|
||||
@training_task = TrainingTask.new
|
||||
@training_task.project = @project
|
||||
else
|
||||
@training_task = @project.training_tasks.visible.find(params[:id])
|
||||
@training_task = @project.training_tasks.find(params[:id])
|
||||
end
|
||||
|
||||
@training_task.project = @project
|
||||
@training_task.author ||= User.current
|
||||
# Tracker must be set before custom field values
|
||||
@training_task.tracker ||= @project.trackers.find((params[:training_task] && params[:training_task][:tracker_id]) || params[:tracker_id] || :first)
|
||||
if @training_task.tracker.nil?
|
||||
render_error l(:error_no_tracker_in_project)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def check_for_default_issue_status
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
<li class="homepagePostSettingIcon">
|
||||
<ul class="homepagePostSettiongText">
|
||||
<li>
|
||||
<%#= link_to l(:button_edit), edit_issue_path(activity.id), :class => 'postOptionLink', :accesskey => accesskey(:edit) if activity.editable? && User.current.allowed_to?(:edit_issues, activity.project) %>
|
||||
<%= link_to l(:button_edit), edit_training_task_path(activity.id), :class => 'postOptionLink', :accesskey => accesskey(:edit) %>
|
||||
</li>
|
||||
<li>
|
||||
<%#= link_to l(:button_delete), issue_path(activity.id), :data => {:confirm => issues_destroy_confirmation_message(activity)}, :method => :delete, :class => 'postOptionLink' if User.current.allowed_to?(:delete_issues, activity.project) %>
|
||||
<%= link_to l(:button_delete), training_task_path(activity.id), :data => {:confirm => l(:text_trainig_task_destroy_confirmation)}, :method => :delete, :class => 'postOptionLink' %>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
<ul>
|
||||
<li class="clear">
|
||||
<label class="label"><span class="c_red f12">*</span> 序号 : </label>
|
||||
<input type="text" name="training_sequence" placeholder="请输入序号(整数)" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" />
|
||||
<span ></span>
|
||||
<%= f.text_field :position, :no_label => true, :placeholder => "请输入序号(整数)", :onkeyup => "this.value=this.value.replace(/\D/g,'')", :onafterpaste => "this.value=this.value.replace(/\D/g,'')" %>
|
||||
</li>
|
||||
<li class="clear">
|
||||
<label class="label"><span class="c_red f12">*</span> 标题 : </label>
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<div id="training_task_edit">
|
||||
<%= content_for(:header_tags) do %>
|
||||
<%= import_ke(enable_at: true, prettify: false, init_activity: false) %>
|
||||
<% end %>
|
||||
|
||||
<div class="pro_new_con mb10">
|
||||
<div class="pro-task-new-con clear">
|
||||
<%= labelled_form_for @training_task, :html => {:id => 'project_training_form', :multipart => true} do |f| %>
|
||||
<div id="all_attributes" >
|
||||
<%= render :partial => 'training_tasks/form', :locals => {:f => f} %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -1003,6 +1003,7 @@ zh:
|
|||
text_status_changed_by_changeset: "已应用到变更列表 %{value}."
|
||||
text_time_logged_by_changeset: "已应用到修订版本 %{value}."
|
||||
text_issues_destroy_confirmation: '您确定要删除选中的问题吗?'
|
||||
text_trainig_task_destroy_confirmation: '您确定要删除选中的任务吗?'
|
||||
text_default_administrator_account_changed: 默认的管理员帐号已改变
|
||||
text_file_repository_writable: 附件路径可写
|
||||
text_plugin_assets_writable: 插件的附件路径可写
|
||||
|
|
Loading…
Reference in New Issue