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
|
class DetailsIssueHooks < Redmine::Hook::ViewListener
|
||||||
|
|
||||||
def protect_against_forgery?
|
def protect_against_forgery?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
@ -10,18 +9,18 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
|
|||||||
end
|
end
|
||||||
|
|
||||||
def view_layouts_base_html_head(context)
|
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)
|
stylesheet_link_tag('issue_dynamic_edit.css', :plugin => :redmine_issue_dynamic_edit)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def view_layouts_base_body_bottom(context)
|
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)
|
javascript_include_tag('issue_dynamic_edit_configuration_file.js', 'issue_dynamic_edit.js', :plugin => :redmine_issue_dynamic_edit)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def view_issues_show_details_bottom(context = { })
|
def view_issues_show_details_bottom(context = {})
|
||||||
project = context[:project]
|
project = context[:project]
|
||||||
request = context[:request]
|
request = context[:request]
|
||||||
issue_id = request.path_parameters[:id]
|
issue_id = request.path_parameters[:id]
|
||||||
@ -29,7 +28,7 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
|
|||||||
|
|
||||||
o = ''
|
o = ''
|
||||||
|
|
||||||
if (issue_id)
|
if issue_id
|
||||||
issue = Issue.find(issue_id)
|
issue = Issue.find(issue_id)
|
||||||
readOnlyAttributes = issue.read_only_attribute_names(User.current)
|
readOnlyAttributes = issue.read_only_attribute_names(User.current)
|
||||||
requiredAttributes = issue.required_attribute_names(User.current)
|
requiredAttributes = issue.required_attribute_names(User.current)
|
||||||
@ -38,20 +37,23 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
|
|||||||
|
|
||||||
allRequiredFieldsFilled = true
|
allRequiredFieldsFilled = true
|
||||||
requiredAttributes.each do |attr|
|
requiredAttributes.each do |attr|
|
||||||
if(issue.read_attribute(attr).to_s.empty?)
|
if issue.read_attribute(attr).to_s.empty?
|
||||||
allRequiredFieldsFilled = false
|
allRequiredFieldsFilled = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if (issue)
|
if issue
|
||||||
if (User.current.allowed_to?(:edit_issues, project))
|
if User.current.allowed_to?(:edit_issues, project)
|
||||||
|
|
||||||
# if there's a JS error, we hide the generated values
|
# if there's a JS error, we hide the generated values
|
||||||
o << '<div style="display:none">'
|
o << '<div style="display:none">'
|
||||||
|
|
||||||
# Status dropdown
|
# Status dropdown
|
||||||
statuses = issue.new_statuses_allowed_to(User.current)
|
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 << "<span class='dynamicEdit' id='statusListDropdown'>"
|
||||||
o << "<select data-issue='#{issue_id}'><option disabled='disabled' selected> </option>"
|
o << "<select data-issue='#{issue_id}'><option disabled='disabled' selected> </option>"
|
||||||
statuses.each do |s|
|
statuses.each do |s|
|
||||||
@ -61,14 +63,19 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
|
|||||||
o << "<option value='#{s.id}' selected>#{s.name}</option>"
|
o << "<option value='#{s.id}' selected>#{s.name}</option>"
|
||||||
end
|
end
|
||||||
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>"
|
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
|
end
|
||||||
|
|
||||||
# Users dropdown
|
# Users dropdown
|
||||||
assignables = project.assignable_users
|
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 << "<span class='dynamicEdit' id='usersListDropdown'>"
|
||||||
o << "<select data-issue='#{issue_id}'><option disabled='disabled' selected> </option>"
|
o << "<select data-issue='#{issue_id}'><option disabled='disabled' selected> </option>"
|
||||||
|
|
||||||
assignables.each do |u|
|
assignables.each do |u|
|
||||||
if (u != issue.assigned_to)
|
if (u != issue.assigned_to)
|
||||||
o << "<option value='#{u.id}'>#{u.name}</option>"
|
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>"
|
o << "<option value='#{u.id}' selected>#{u.name}</option>"
|
||||||
end
|
end
|
||||||
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>"
|
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
|
end
|
||||||
|
|
||||||
# Priorities dropdown
|
# Priorities dropdown
|
||||||
priorities = IssuePriority.all
|
priorities = IssuePriority.all
|
||||||
if(!priorities.empty? && !(readOnlyAttributes.include? 'priority_id'))
|
|
||||||
|
if !priorities.empty? && !(readOnlyAttributes.include? 'priority_id')
|
||||||
o << "<span class='dynamicEdit' id='prioritiesListDropdown'>"
|
o << "<span class='dynamicEdit' id='prioritiesListDropdown'>"
|
||||||
o << "<select data-issue='#{issue_id}'><option disabled='disabled' selected> </option>"
|
o << "<select data-issue='#{issue_id}'><option disabled='disabled' selected> </option>"
|
||||||
|
|
||||||
priorities.each do |p|
|
priorities.each do |p|
|
||||||
if (p != issue.priority)
|
if (p != issue.priority)
|
||||||
o << "<option value='#{p.id}'>#{p.name}</option>"
|
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>"
|
o << "<option value='#{p.id}' selected>#{p.name}</option>"
|
||||||
end
|
end
|
||||||
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>"
|
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
|
end
|
||||||
|
|
||||||
# %done dropdown
|
# %done dropdown
|
||||||
if(!(readOnlyAttributes.include? 'done_ratio'))
|
if ! readOnlyAttributes.include?('done_ratio')
|
||||||
percent = 0
|
percent = 0
|
||||||
o << "<span class='dynamicEdit' id='doneRatioListDropdown'>"
|
o << "<span class='dynamicEdit' id='doneRatioListDropdown'>"
|
||||||
o << "<select data-issue='#{issue_id}'><option disabled='disabled' selected> </option>"
|
o << "<select data-issue='#{issue_id}'><option disabled='disabled' selected> </option>"
|
||||||
loop do
|
loop do
|
||||||
if (percent == issue.done_ratio)
|
if percent == issue.done_ratio
|
||||||
o << "<option value='#{percent}' selected>#{percent}%</option>"
|
o << "<option value='#{percent}' selected>#{percent}%</option>"
|
||||||
else
|
else
|
||||||
o << "<option value='#{percent}'>#{percent}%</option>"
|
o << "<option value='#{percent}'>#{percent}%</option>"
|
||||||
end
|
end
|
||||||
percent += 10
|
percent += 10
|
||||||
if percent == 110
|
|
||||||
break
|
break if percent == 110
|
||||||
end
|
|
||||||
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>"
|
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
|
end
|
||||||
|
|
||||||
# Estimated_time dropdown
|
# Estimated_time dropdown
|
||||||
if(!(readOnlyAttributes.include? 'estimated_hours'))
|
if ! readOnlyAttributes.include?('estimated_hours')
|
||||||
o << "<span class='dynamicEdit' id='EstimatedTimeInput'>"
|
o << "<span class='dynamicEdit' id='EstimatedTimeInput'>"
|
||||||
o << " <input type='text' value='#{issue.estimated_hours}' size='6'/>"
|
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>"
|
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
|
end
|
||||||
|
|
||||||
# Start date
|
# Start date
|
||||||
if(!(readOnlyAttributes.include? 'start_date'))
|
if ! readOnlyAttributes.include?('start_date')
|
||||||
o << "<span class='dynamicEdit' id='StartDateInput'>"
|
o << "<span class='dynamicEdit' id='StartDateInput'>"
|
||||||
o << " <input size=\"10\" value=\"#{issue.start_date}\" type=\"date\" max=\"#{issue.due_date}\">"
|
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>"
|
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
|
end
|
||||||
|
|
||||||
# Due date
|
# Due date
|
||||||
if(!(readOnlyAttributes.include? 'due_date'))
|
if ! readOnlyAttributes.include?('due_date')
|
||||||
o << "<span class='dynamicEdit' id='DueDateInput'>"
|
o << "<span class='dynamicEdit' id='DueDateInput'>"
|
||||||
o << " <input size=\"10\" value=\"#{issue.due_date}\" type=\"date\" min=\"#{issue.start_date}\">"
|
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>"
|
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 << " <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 << " <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>"
|
o << "</span>"
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -189,15 +199,12 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
|
|||||||
o << " var _TXT_REQUIRED_FIELD = \"" + l(:ide_txt_required_field) + "\";\n"
|
o << " var _TXT_REQUIRED_FIELD = \"" + l(:ide_txt_required_field) + "\";\n"
|
||||||
o << "</script>\n"
|
o << "</script>\n"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
o << "<div style='display:none' id='required_field_array'>#{requiredAttributes.to_json}</div>\n"
|
o << "<div style='display:none' id='required_field_array'>#{requiredAttributes.to_json}</div>\n"
|
||||||
|
|
||||||
|
|
||||||
# closing the display none div parent
|
# closing the display none div parent
|
||||||
o << "</div>"
|
o << "</div>"
|
||||||
|
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user