Skip to content

Commit 03c7479

Browse files
committed
Merge pull request #56 from WiteFox/master
made js\ruby refactoring + fix for all items\group items check\uncheck, remov...
2 parents 1746953 + 03fffa7 commit 03c7479

File tree

7 files changed

+74
-120
lines changed

7 files changed

+74
-120
lines changed

app/helpers/timesheet_helper.rb

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,45 +39,31 @@ def link_to_csv_export(timesheet)
3939
:class => 'icon icon-timesheet')
4040
end
4141

42-
def toggle_issue_arrows(issue_id)
43-
js = "toggleTimeEntries('#{issue_id}'); return false;"
42+
def toggle_arrows(element, js_function)
43+
js = "#{js_function}('#{element}');"
4444

45-
return toggle_issue_arrow(issue_id, 'toggle-arrow-closed.gif', js, false) +
46-
toggle_issue_arrow(issue_id, 'toggle-arrow-open.gif', js, true)
45+
return toggle_arrow(element, 'toggle-arrow-closed.gif', js, false) +
46+
toggle_arrow(element, 'toggle-arrow-open.gif', js, true)
4747
end
4848

49-
def toggle_issue_arrow(issue_id, image, js, hide=false)
50-
style = "display:none;" if hide
49+
def toggle_arrow(element, image, js, hide=false)
50+
style = 'display:none;' if hide
5151
style ||= ''
5252

5353
content_tag(:span,
54-
link_to_function(image_tag(image, :plugin => "redmine_timesheet_plugin"), js),
55-
:class => "toggle-" + issue_id.to_s,
56-
:style => style
54+
link_to_function(image_tag(image, :plugin => "redmine_timesheet_plugin"), js),
55+
:class => "toggle-" + element.to_s,
56+
:style => style
5757
)
58-
5958
end
60-
61-
def toggle_issue_arrows_date(spent_on)
62-
js = "toggleTimeEntriesdate('#{spent_on}'); return false;"
63-
64-
return toggle_issue_arrow_date(spent_on, 'toggle-arrow-closed.gif', js, false) +
65-
toggle_issue_arrow(spent_on, 'toggle-arrow-open.gif', js, true)
66-
end
67-
68-
def toggle_issue_arrow_date(spent_on, image, js, hide=false)
69-
style = "display:none;" if hide
70-
style ||= ''
71-
72-
content_tag(:span,
73-
link_to_function(image_tag(image, :plugin => "redmine_timesheet_plugin"), js),
74-
:class => "toggle-" + spent_on.to_s,
75-
:style => style
76-
)
7759

60+
def toggle_issue_arrows(issue_id)
61+
return toggle_arrows(issue_id, 'toggleTimeEntriesIssue')
7862
end
7963

80-
64+
def toggle_issue_arrows_date(spent_on)
65+
return toggle_arrows(spent_on, 'toggleTimeEntriesDate')
66+
end
8167

8268
def displayed_time_entries_for_issue(time_entries)
8369
time_entries.collect(&:hours).sum

app/views/timesheet/#_by_issue.html.erb#

Lines changed: 0 additions & 36 deletions
This file was deleted.

app/views/timesheet/_by_issue.html.erb

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<thead>
33
<th width="2%">
44
<%= link_to image_tag('toggle_check.png'), "javascript:;",
5-
:onclick => 'toggleIssuesSelection(".toggle-all"); return false;',
5+
:onclick => 'toggleIssuesSelection(this); return false;',
66
:title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}", :class => 'toggle-all' %>
77
</th>
88
<th width="2%">&nbsp;</th>
@@ -18,19 +18,4 @@
1818
</tbody>
1919
</table>
2020
<br />
21-
<script type="text/javascript">
22-
function toggleTimeEntries(id) {
23-
$('.issue-time-entry-' + id).each(function() { $(this).toggle();} )
24-
$('.toggle-' + id).each(function() { $(this).toggle();} )
25-
}
2621

27-
/*
28-
* Checks all the Time Entries under issue_id
29-
*/
30-
function toggleTimeEntriesSelection(issue_id) {
31-
$$('.issue-time-entry-' + issue_id).each(function(ele) {
32-
toggleIssuesSelection(ele);
33-
});
34-
}
35-
36-
</script>

app/views/timesheet/_issue_time_entries.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<% unless issue.nil? %>
55
<tr class="<%= cycle("odd", "even") %>">
66
<td align="center">
7-
<%= link_to image_tag('toggle_check.png'), {}, :onclick => "toggleTimeEntriesSelection('#{issue.id}'); return false;",
7+
<%= link_to image_tag('toggle_check.png'), {}, :onclick => "toggleTimeEntriesSelectionIssue('#{issue.id}'); return false;",
88
:title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}", :class => 'toggle-all' %>
99
</td>
1010
<td align="center">

app/views/timesheet/_timesheet_group.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<thead>
33
<th width="2%">
44
<%= link_to image_tag('toggle_check.png'), "javascript:;",
5-
:onclick => 'toggleIssuesSelection(".toggle-all"); return false;',
5+
:onclick => 'toggleTimeEntriesSelectionProject(this); return false;',
66
:title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}", :class => 'toggle-all' %>
77
</th>
88
<th width="8%"><%= l(:label_date) %></th>

app/views/timesheet/report.html.erb

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,12 @@
3131

3232
<span class="<%= cycle("odd", "even") %> issue-time-entry-<%= entryname -%>" style="display:none;">
3333
<%= render :partial => 'timesheet_group', :locals => {:entry => entry, :name => entryname, :total => @total[entryname] } %>
34-
</span>
35-
34+
</span>
3635
<%#*end%>
37-
<script type="text/javascript">
38-
function toggleTimeEntriesdate(entryname) {
39-
40-
$('.issue-time-entry-' + entryname).each(function() {
41-
$(this).toggle();
42-
})
43-
$('.toggle-' + entryname).each(function() {
44-
$(this).toggle();
45-
})
46-
}
47-
48-
/*
49-
* Checks all the Time Entries under issue_id
50-
*/
51-
function toggleTimeEntriesSelection(entryname) {
52-
$$('.issue-time-entry-' + entryname).each(function(ele) {
53-
toggleIssuesSelection(ele);
54-
});
55-
}
56-
57-
</script>
5836
<% else %>
5937
<%# Default to :project %>
6038
<h3><%= h entryname -%> (<%= h number_with_precision(@total[entryname], :precision => @precision) %> <%= h(l(:field_hours)) -%>) <%= showing_users(entry[:users]) %></h3>
6139
<%= render :partial => 'timesheet_group', :locals => {:entry => entry, :name => entryname, :total => @total[entryname] } %>
62-
6340
<% end
6441
end # each
6542
end # length

assets/javascripts/timesheet.js

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,58 @@
11
$(function() {
2-
$('#select_timesheet_period_type_2').click(function() {
3-
$('#timesheet_period_type_2').attr('checked','checked')
4-
})
5-
6-
$('#select_timesheet_period_type_1').focus(function() {
7-
$('#timesheet_period_type_1').attr('checked','checked')
8-
})
9-
10-
$("label.select-all").click(function () {
11-
var select = $(this).siblings("select")
12-
var options = select.children()
13-
var selected = options.length != select.find(":selected").length
14-
options.each(function (index, ele) { ele.selected = selected });
15-
})
2+
$('#select_timesheet_period_type_2').click(function() {
3+
$('#timesheet_period_type_2').attr('checked','checked')
4+
})
5+
6+
$('#select_timesheet_period_type_1').focus(function() {
7+
$('#timesheet_period_type_1').attr('checked','checked')
8+
})
9+
10+
$("label.select-all").click(function () {
11+
var select = $(this).siblings("select")
12+
var options = select.children()
13+
var selected = options.length != select.find(":selected").length
14+
options.each(function (index, ele) { ele.selected = selected });
15+
})
1616
})
17+
18+
function toggleTimeEntries(element) {
19+
$('.issue-time-entry-' + element).each(function() { $(this).toggle();} )
20+
$('.toggle-' + element).each(function() { $(this).toggle();} )
21+
}
22+
23+
function toggleTimeEntriesIssue(id) {
24+
toggleTimeEntries(id);
25+
}
26+
27+
function toggleTimeEntriesDate(entryname) {
28+
toggleTimeEntries(entryname);
29+
}
30+
31+
/*
32+
* Checks all the Time Entries under issue_id
33+
*/
34+
function toggleTimeEntriesSelectionIssue(issue_id) {
35+
var issues = $('.issue-time-entry-' + issue_id);
36+
toggleTimeEntriesSelection(issues);
37+
}
38+
39+
function toggleTimeEntriesSelectionProject(element){
40+
var table = $(element).parents('table.list.issues');
41+
toggleTimeEntriesSelection(table);
42+
}
43+
44+
function toggleTimeEntriesSelection(element){
45+
var boxes = $(element).find('input[type=checkbox]');
46+
var all_checked = true;
47+
boxes.each(function(){ if (!$(this).prop('checked')) { all_checked = false; } });
48+
boxes.each(function(){
49+
if (all_checked) {
50+
$(this).removeAttr('checked');
51+
$(this).parents('tr').removeClass('context-menu-selection');
52+
} else if (!$(this).prop('checked')) {
53+
$(this).prop('checked', true);
54+
$(this).parents('tr').addClass('context-menu-selection');
55+
}
56+
});
57+
}
58+

0 commit comments

Comments
 (0)