Defect #34641
closedWhen editing an issue, the Log time and/or Add notes does not show or hide dynamically
0%
Description
I changed the project when editing an issue, but the Log time does not show or hide dynamically. There is a mixture of projects with the Time tracking module enabled or disabled.
Files
Related issues
Updated by Yuichi HARADA almost 4 years ago
- File 34641.patch 34641.patch added
When you change the project, source:trunk/app/views/issues/edit.js.erb will be executed, so you should be able to show/hide the Log time. However, the function does not work because $('#log_time')
does not exist on the issue edit form.
I created a patch like this:
diff --git a/app/views/issues/_edit.html.erb b/app/views/issues/_edit.html.erb
index 33f8352f57..766e9c78aa 100644
--- a/app/views/issues/_edit.html.erb
+++ b/app/views/issues/_edit.html.erb
@@ -9,8 +9,7 @@
</div>
</fieldset>
<% end %>
- <% if User.current.allowed_to?(:log_time, @project) %>
- <fieldset class="tabular"><legend><%= l(:button_log_time) %></legend>
+ <fieldset id="log_time" class="tabular"><legend><%= l(:button_log_time) %></legend>
<%= labelled_fields_for :time_entry, @time_entry do |time_entry| %>
<div class="splitcontent">
<div class="splitcontentleft">
@@ -25,8 +24,8 @@
<p><%= custom_field_tag_with_label :time_entry, value %></p>
<% end %>
<% end %>
- </fieldset>
- <% end %>
+ </fieldset>
+ <%= javascript_tag("$('#log_time').hide();") unless User.current.allowed_to?(:log_time, @project) %>
<% if @issue.notes_addable? %>
<fieldset><legend><%= l(:field_notes) %></legend>
<%= f.text_area :notes, :cols => 60, :rows => 10, :class => 'wiki-edit',
Updated by Mischa The Evil almost 4 years ago
- Target version set to Candidate for next minor release
Nice catch! It probably needs some test coverage to ensure it won't break in the future.
Updated by Marius BĂLTEANU almost 4 years ago
- Assignee set to Marius BĂLTEANU
Let me look a little bit on this, I don't think that we need Javascript for this.
Updated by Mischa The Evil almost 4 years ago
Marius BALTEANU wrote:
[...] I don't think that we need Javascript for this.
That would be even nicer then...
Updated by Marius BĂLTEANU almost 4 years ago
- Subject changed from When editing an issue, the Log time does not show or hide dynamically to When editing an issue, the Log time and/or Add notes does not show or hide dynamically
- Target version changed from Candidate for next minor release to Candidate for next major release
I've updated the subject because the same problem reproduces also for add notes block.
Looking in the code, the log time block was supposed to hide automatically (see source:trunk/app/views/issues/edit.js.erb#L3), but it doesn't work because the fieldset is missing the "log_time" id (most probably, because of r8142).
The fix to hide both blocks is quite small, just adding some ids and extra few lines of code for add notes, but it doesn't work in all cases, for example, if you edit an issue with the log time not available for the user and you change the project to one with log time available, it won't appear because the element was not rendered initially in the page.
優一 内田 HARADA, indeed, rendering the block all the time and hiding using javascript it is an option, but I still prefer to find a non javascript solution for this.
Updated by Marius BĂLTEANU almost 4 years ago
For next minor release, we can deliver only the fix to hide the blocks if you find it useful.
Updated by Yuichi HARADA almost 4 years ago
- File 34641-v2.patch 34641-v2.patch added
Marius BALTEANU wrote:
優一 内田 HARADA, indeed, rendering the block all the time and hiding using javascript it is an option, but I still prefer to find a non javascript solution for this.
I tried using hidden
class (source:trunk/public/stylesheets/application.css#L136) like a source:trunk/app/views/issues/_attributes.html.erb#L27 . I fixed only the Log time block.
diff --git a/app/views/issues/_edit.html.erb b/app/views/issues/_edit.html.erb
index 33f8352f57..fe7dad04a8 100644
--- a/app/views/issues/_edit.html.erb
+++ b/app/views/issues/_edit.html.erb
@@ -9,8 +9,7 @@
</div>
</fieldset>
<% end %>
- <% if User.current.allowed_to?(:log_time, @project) %>
- <fieldset class="tabular"><legend><%= l(:button_log_time) %></legend>
+ <fieldset id="log_time" class="tabular<%= ' hidden' unless User.current.allowed_to?(:log_time, @project) %>"><legend><%= l(:button_log_time) %></legend>
<%= labelled_fields_for :time_entry, @time_entry do |time_entry| %>
<div class="splitcontent">
<div class="splitcontentleft">
@@ -25,8 +24,7 @@
<p><%= custom_field_tag_with_label :time_entry, value %></p>
<% end %>
<% end %>
- </fieldset>
- <% end %>
+ </fieldset>
<% if @issue.notes_addable? %>
<fieldset><legend><%= l(:field_notes) %></legend>
<%= f.text_area :notes, :cols => 60, :rows => 10, :class => 'wiki-edit',
diff --git a/app/views/issues/edit.js.erb b/app/views/issues/edit.js.erb
index 8c94aecebd..ef04553e0c 100644
--- a/app/views/issues/edit.js.erb
+++ b/app/views/issues/edit.js.erb
@@ -1,7 +1,7 @@
replaceIssueFormWith('<%= escape_javascript(render :partial => 'form') %>');
<% if User.current.allowed_to?(:log_time, @issue.project) %>
- $('#log_time').show();
+ $('#log_time').removeClass('hidden');
<% else %>
- $('#log_time').hide();
+ $('#log_time').addClass('hidden');
<% end %>
Updated by Yuichi HARADA almost 4 years ago
- File 34641-v3.patch 34641-v3.patch added
Added system test to 34641-v2.patch.
Updated by Marius BĂLTEANU almost 4 years ago
- File 0001-Update-log-time-and-add-notes-blocks-when-updating-t.patch added
Yuichi, thanks for updating your patch.
What do you think if we update the entire "edit" form instead of only "form"? In this way, we fix this issue for all three affected blocks: log time, add notes and add attachments and we simplify the code, as well.
Beside this, the attached patch fixes another issue:if User.current.allowed_to?(:log_time, @project)
checks if the user has the log time permission on the project and not on the issue's project and because of this, you can have the case when you open an issue on a project where you have rights to log time and when you select another project where you don't have rights, the block is still displayed because @project
is the same.
Updated by Marius BĂLTEANU almost 4 years ago
- File deleted (
0001-Update-log-time-and-add-notes-blocks-when-updating-t.patch)
Updated by Yuichi HARADA over 3 years ago
Marius BALTEANU wrote:
What do you think if we update the entire "edit" form instead of only "form"? In this way, we fix this issue for all three affected blocks: log time, add notes and add attachments and we simplify the code, as well.
Marius, I thought it was good. However, replaceIssueFormWith
was also used in the issue creation form, and this patch broke this issue creation form.
app/views/issues/new.js.erb:1:replaceIssueFormWith('<%= escape_javascript(render :partial => 'form') %>');
Updated by Marius BĂLTEANU over 3 years ago
Yuichi HARADA wrote:
Marius BALTEANU wrote:
What do you think if we update the entire "edit" form instead of only "form"? In this way, we fix this issue for all three affected blocks: log time, add notes and add attachments and we simplify the code, as well.
Marius, I thought it was good. However,
replaceIssueFormWith
was also used in the issue creation form, and this patch broke this issue creation form.[...]
Oh, such a bad patch, sorry for it. I'll post soon an updated one.
Updated by Marius BĂLTEANU over 3 years ago
- File 0002-Update-log-time-and-add-notes-blocks-when-updating-t.patch 0002-Update-log-time-and-add-notes-blocks-when-updating-t.patch added
Yuichi, can you test the attached patch?
Updated by Yuichi HARADA over 3 years ago
Marius BALTEANU wrote:
Yuichi, can you test the attached patch?
Marius, I tested your patch. I confirmed that the show or hide is dynamically switched. I think it's good.
However, I found a typo. I think it's better to fix it.
diff --git a/app/views/issues/_edit.html.erb b/app/views/issues/_edit.html.erb
index aca1ae8f4..bc881db4b 100644
--- a/app/views/issues/_edit.html.erb
+++ b/app/views/issues/_edit.html.erb
@@ -43,7 +43,7 @@
<%= call_hook(:view_issues_edit_notes_bottom, { :issue => @issue, :notes => @notes, :form => f }) %>
</fieldset>
- <fieldset id="add_attachments"'><legend><%= l(:label_attachment_plural) %></legend>
+ <fieldset id="add_attachments"><legend><%= l(:label_attachment_plural) %></legend>
<% if @issue.attachments.any? && @issue.safe_attribute?('deleted_attachment_ids') %>
<div class="contextual"><%= link_to l(:label_edit_attachments), '#', :onclick => "$('#existing-attachments').toggle(); return false;" %></div>
<div id="existing-attachments" style="<%= @issue.deleted_attachment_ids.blank? ? 'display:none;' : '' %>">
Updated by Go MAEDA almost 3 years ago
- Target version changed from Candidate for next major release to 5.0.0
Setting the target version to 5.0.0.
The patch that should be committed is 0002-Update-log-time-and-add-notes-blocks-when-updating-t.patch with the update in #34641#note-16.
Updated by Marius BĂLTEANU over 2 years ago
- Status changed from New to Resolved
- Resolution set to Fixed
Patch committed, thanks!
Updated by Marius BĂLTEANU over 2 years ago
- Status changed from Resolved to Closed
Updated by Marius BĂLTEANU over 2 years ago
- Related to Defect #37053: Attachments are lost when the status of the ticket is changed added