small syntax refactorings
modifié : lib/details_issue_hooks.rb
This commit is contained in:
parent
0b2ba88f71
commit
693f60ce1b
@ -1,5 +1,4 @@
|
||||
class DetailsIssueHooks < Redmine::Hook::ViewListener
|
||||
|
||||
def protect_against_forgery?
|
||||
false
|
||||
end
|
||||
@ -10,16 +9,16 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
|
||||
end
|
||||
|
||||
def view_layouts_base_html_head(context)
|
||||
if current_is_detail_page(context)
|
||||
return unless current_is_detail_page(context)
|
||||
|
||||
stylesheet_link_tag('issue_dynamic_edit.css', :plugin => :redmine_issue_dynamic_edit)
|
||||
end
|
||||
end
|
||||
|
||||
def view_layouts_base_body_bottom(context)
|
||||
if current_is_detail_page(context)
|
||||
return unless current_is_detail_page(context)
|
||||
|
||||
javascript_include_tag('issue_dynamic_edit_configuration_file.js', 'issue_dynamic_edit.js', :plugin => :redmine_issue_dynamic_edit)
|
||||
end
|
||||
end
|
||||
|
||||
def view_issues_show_details_bottom(context = {})
|
||||
project = context[:project]
|
||||
@ -29,7 +28,7 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
|
||||
|
||||
o = ''
|
||||
|
||||
if (issue_id)
|
||||
if issue_id
|
||||
issue = Issue.find(issue_id)
|
||||
readOnlyAttributes = issue.read_only_attribute_names(User.current)
|
||||
requiredAttributes = issue.required_attribute_names(User.current)
|
||||
@ -38,20 +37,23 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
|
||||
|
||||
allRequiredFieldsFilled = true
|
||||
requiredAttributes.each do |attr|
|
||||
if(issue.read_attribute(attr).to_s.empty?)
|
||||
if issue.read_attribute(attr).to_s.empty?
|
||||
allRequiredFieldsFilled = false
|
||||
end
|
||||
end
|
||||
|
||||
if (issue)
|
||||
if (User.current.allowed_to?(:edit_issues, project))
|
||||
|
||||
if issue
|
||||
if User.current.allowed_to?(:edit_issues, project)
|
||||
# if there's a JS error, we hide the generated values
|
||||
o << '<div style="display:none">'
|
||||
|
||||
# Status dropdown
|
||||
statuses = issue.new_statuses_allowed_to(User.current)
|
||||
if (!statuses.empty? && !(readOnlyAttributes.include? 'status_id') && allRequiredFieldsFilled)
|
||||
if (
|
||||
!statuses.empty? &&
|
||||
!readOnlyAttributes.include?('status_id') &&
|
||||
allRequiredFieldsFilled
|
||||
)
|
||||
o << "<span class='dynamicEdit' id='statusListDropdown'>"
|
||||
o << "<select data-issue='#{issue_id}'><option disabled='disabled' selected> </option>"
|
||||
statuses.each do |s|
|
||||
@ -61,14 +63,19 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
|
||||
o << "<option value='#{s.id}' selected>#{s.name}</option>"
|
||||
end
|
||||
end
|
||||
|
||||
o << "</select> <a href='#' class='btn btn-primary close' aria-label='" + l(:ide_txt_cancel_btn) + "'><i class='fa fa-times fa-fw' aria-hidden='true'></i></a></span>"
|
||||
end
|
||||
|
||||
# Users dropdown
|
||||
assignables = project.assignable_users
|
||||
if (!assignables.empty? && !(readOnlyAttributes.include? 'assigned_to_id'))
|
||||
if (
|
||||
!assignables.empty? &&
|
||||
!readOnlyAttributes.include?('assigned_to_id')
|
||||
)
|
||||
o << "<span class='dynamicEdit' id='usersListDropdown'>"
|
||||
o << "<select data-issue='#{issue_id}'><option disabled='disabled' selected> </option>"
|
||||
|
||||
assignables.each do |u|
|
||||
if (u != issue.assigned_to)
|
||||
o << "<option value='#{u.id}'>#{u.name}</option>"
|
||||
@ -76,14 +83,17 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
|
||||
o << "<option value='#{u.id}' selected>#{u.name}</option>"
|
||||
end
|
||||
end
|
||||
|
||||
o << "</select> <a href='#' class='btn btn-primary close' aria-label='" + l(:ide_txt_cancel_btn) + "'><i class='fa fa-times fa-fw' aria-hidden='true'></i></a></span>"
|
||||
end
|
||||
|
||||
# Priorities dropdown
|
||||
priorities = IssuePriority.all
|
||||
if(!priorities.empty? && !(readOnlyAttributes.include? 'priority_id'))
|
||||
|
||||
if !priorities.empty? && !(readOnlyAttributes.include? 'priority_id')
|
||||
o << "<span class='dynamicEdit' id='prioritiesListDropdown'>"
|
||||
o << "<select data-issue='#{issue_id}'><option disabled='disabled' selected> </option>"
|
||||
|
||||
priorities.each do |p|
|
||||
if (p != issue.priority)
|
||||
o << "<option value='#{p.id}'>#{p.name}</option>"
|
||||
@ -91,30 +101,31 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
|
||||
o << "<option value='#{p.id}' selected>#{p.name}</option>"
|
||||
end
|
||||
end
|
||||
|
||||
o << "</select> <a href='#' class='btn btn-primary close' aria-label='" + l(:ide_txt_cancel_btn) + "'><i class='fa fa-times fa-fw' aria-hidden='true'></i></a></span>"
|
||||
end
|
||||
|
||||
# %done dropdown
|
||||
if(!(readOnlyAttributes.include? 'done_ratio'))
|
||||
if ! readOnlyAttributes.include?('done_ratio')
|
||||
percent = 0
|
||||
o << "<span class='dynamicEdit' id='doneRatioListDropdown'>"
|
||||
o << "<select data-issue='#{issue_id}'><option disabled='disabled' selected> </option>"
|
||||
loop do
|
||||
if (percent == issue.done_ratio)
|
||||
if percent == issue.done_ratio
|
||||
o << "<option value='#{percent}' selected>#{percent}%</option>"
|
||||
else
|
||||
o << "<option value='#{percent}'>#{percent}%</option>"
|
||||
end
|
||||
percent += 10
|
||||
if percent == 110
|
||||
break
|
||||
end
|
||||
|
||||
break if percent == 110
|
||||
end
|
||||
|
||||
o << "</select> <a href='#' class='btn btn-primary close' aria-label='" + l(:ide_txt_cancel_btn) + "'><i class='fa fa-times fa-fw' aria-hidden='true'></i></a></span>"
|
||||
end
|
||||
|
||||
# Estimated_time dropdown
|
||||
if(!(readOnlyAttributes.include? 'estimated_hours'))
|
||||
if ! readOnlyAttributes.include?('estimated_hours')
|
||||
o << "<span class='dynamicEdit' id='EstimatedTimeInput'>"
|
||||
o << " <input type='text' value='#{issue.estimated_hours}' size='6'/>"
|
||||
o << "<a href='#' class='btn btn-primary validate' aria-label='" + l(:ide_txt_validation_btn) + "'><i class='fa fa-check fa-fw' aria-hidden='true'></i></a>"
|
||||
@ -123,7 +134,7 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
|
||||
end
|
||||
|
||||
# Start date
|
||||
if(!(readOnlyAttributes.include? 'start_date'))
|
||||
if ! readOnlyAttributes.include?('start_date')
|
||||
o << "<span class='dynamicEdit' id='StartDateInput'>"
|
||||
o << " <input size=\"10\" value=\"#{issue.start_date}\" type=\"date\" max=\"#{issue.due_date}\">"
|
||||
o << " <a href='#' class='btn btn-primary validate' aria-label='" + l(:ide_txt_validation_btn) + "'><i class='fa fa-check fa-fw' aria-hidden='true'></i></a>"
|
||||
@ -139,7 +150,7 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
|
||||
end
|
||||
|
||||
# Due date
|
||||
if(!(readOnlyAttributes.include? 'due_date'))
|
||||
if ! readOnlyAttributes.include?('due_date')
|
||||
o << "<span class='dynamicEdit' id='DueDateInput'>"
|
||||
o << " <input size=\"10\" value=\"#{issue.due_date}\" type=\"date\" min=\"#{issue.start_date}\">"
|
||||
o << " <a href='#' class='btn btn-primary validate' aria-label='" + l(:ide_txt_validation_btn) + "'><i class='fa fa-check fa-fw' aria-hidden='true'></i></a>"
|
||||
@ -167,7 +178,6 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
|
||||
o << " <div style='display:block; text-align:right; margin-top:10px;'><a href='#' class='btn btn-primary validate' aria-label='" + l(:ide_txt_validation_btn) + "'><i class='fa fa-check fa-fw' aria-hidden='true'></i></a>"
|
||||
o << " <a href='#' class='btn btn-primary close' aria-label='" + l(:ide_txt_cancel_btn) + "'><i class='fa fa-times fa-fw' aria-hidden='true'></i></a></div>"
|
||||
o << "</span>"
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@ -189,15 +199,12 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
|
||||
o << " var _TXT_REQUIRED_FIELD = \"" + l(:ide_txt_required_field) + "\";\n"
|
||||
o << "</script>\n"
|
||||
|
||||
|
||||
|
||||
o << "<div style='display:none' id='required_field_array'>#{requiredAttributes.to_json}</div>\n"
|
||||
|
||||
|
||||
# closing the display none div parent
|
||||
o << "</div>"
|
||||
|
||||
return o
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user