Vote #81240
完了When editing an issue, the Log time and/or Add notes does not show or hide dynamically
0%
説明
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.
journals
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:
<pre><code class="diff">
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',
</code></pre>
--------------------------------------------------------------------------------
Nice catch! It probably needs some test coverage to ensure it won't break in the future.
--------------------------------------------------------------------------------
Let me look a little bit on this, I don't think that we need Javascript for this.
--------------------------------------------------------------------------------
Marius BALTEANU wrote:
> [...] I don't think that we need Javascript for this.
That would be even nicer then...
--------------------------------------------------------------------------------
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.
@Yuichi 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.
--------------------------------------------------------------------------------
For next minor release, we can deliver only the fix to hide the blocks if you find it useful.
--------------------------------------------------------------------------------
Marius BALTEANU wrote:
> @Yuichi 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.
<pre><code class="diff">
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 %>
</code></pre>
--------------------------------------------------------------------------------
Added system test to attachment:34641-v2.patch.
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
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.
<pre><code class="ruby">
app/views/issues/new.js.erb:1:replaceIssueFormWith('<%= escape_javascript(render :partial => 'form') %>');
</code></pre>
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
Yuichi, can you test the attached patch?
--------------------------------------------------------------------------------
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.
<pre><code class="diff">
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;' : '' %>">
</code></pre>
--------------------------------------------------------------------------------
Setting the target version to 5.0.0.
The patch that should be committed is attachment:0002-Update-log-time-and-add-notes-blocks-when-updating-t.patch with the update in #34641#note-16.
--------------------------------------------------------------------------------
Patch committed, thanks!
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------