@@ -1,49 +1,42 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | module JournalsHelper |
|
18 | module JournalsHelper | |
19 | def render_notes(issue, journal, options={}) |
|
19 | def render_notes(issue, journal, options={}) | |
20 | content = '' |
|
20 | content = '' | |
21 | editable = User.current.logged? && (User.current.allowed_to?(:edit_issue_notes, issue.project) || (journal.user == User.current && User.current.allowed_to?(:edit_own_issue_notes, issue.project))) |
|
21 | editable = User.current.logged? && (User.current.allowed_to?(:edit_issue_notes, issue.project) || (journal.user == User.current && User.current.allowed_to?(:edit_own_issue_notes, issue.project))) | |
22 | links = [] |
|
22 | links = [] | |
23 | if !journal.notes.blank? |
|
23 | if !journal.notes.blank? | |
24 | links << link_to_remote(image_tag('comment.png'), |
|
24 | links << link_to_remote(image_tag('comment.png'), | |
25 | { :url => {:controller => 'journals', :action => 'new', :id => issue, :journal_id => journal} }, |
|
25 | { :url => {:controller => 'journals', :action => 'new', :id => issue, :journal_id => journal} }, | |
26 | :title => l(:button_quote)) if options[:reply_links] |
|
26 | :title => l(:button_quote)) if options[:reply_links] | |
27 | links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes", |
|
27 | links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes", | |
28 | { :controller => 'journals', :action => 'edit', :id => journal }, |
|
28 | { :controller => 'journals', :action => 'edit', :id => journal }, | |
29 | :title => l(:button_edit)) if editable |
|
29 | :title => l(:button_edit)) if editable | |
30 | end |
|
30 | end | |
31 | content << content_tag('div', links.join(' '), :class => 'contextual') unless links.empty? |
|
31 | content << content_tag('div', links.join(' '), :class => 'contextual') unless links.empty? | |
32 | content << textilizable(journal, :notes) |
|
32 | content << textilizable(journal, :notes) | |
33 | css_classes = "wiki" |
|
33 | css_classes = "wiki" | |
34 | css_classes << " editable" if editable |
|
34 | css_classes << " editable" if editable | |
35 | content_tag('div', content, :id => "journal-#{journal.id}-notes", :class => css_classes) |
|
35 | content_tag('div', content, :id => "journal-#{journal.id}-notes", :class => css_classes) | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | def link_to_in_place_notes_editor(text, field_id, url, options={}) |
|
38 | def link_to_in_place_notes_editor(text, field_id, url, options={}) | |
39 | onclick = "new Ajax.Request('#{url_for(url)}', {asynchronous:true, evalScripts:true, method:'get'}); return false;" |
|
39 | onclick = "new Ajax.Request('#{url_for(url)}', {asynchronous:true, evalScripts:true, method:'get'}); return false;" | |
40 | link_to text, '#', options.merge(:onclick => onclick) |
|
40 | link_to text, '#', options.merge(:onclick => onclick) | |
41 | end |
|
41 | end | |
42 |
|
||||
43 | def css_journal_classes(journal) |
|
|||
44 | s = 'journal' |
|
|||
45 | s << ' has-notes' unless journal.notes.blank? |
|
|||
46 | s << ' has-details' unless journal.details.blank? |
|
|||
47 | s |
|
|||
48 | end |
|
|||
49 | end |
|
42 | end |
@@ -1,68 +1,76 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class Journal < ActiveRecord::Base |
|
18 | class Journal < ActiveRecord::Base | |
19 | belongs_to :journalized, :polymorphic => true |
|
19 | belongs_to :journalized, :polymorphic => true | |
20 | # added as a quick fix to allow eager loading of the polymorphic association |
|
20 | # added as a quick fix to allow eager loading of the polymorphic association | |
21 | # since always associated to an issue, for now |
|
21 | # since always associated to an issue, for now | |
22 | belongs_to :issue, :foreign_key => :journalized_id |
|
22 | belongs_to :issue, :foreign_key => :journalized_id | |
23 |
|
23 | |||
24 | belongs_to :user |
|
24 | belongs_to :user | |
25 | has_many :details, :class_name => "JournalDetail", :dependent => :delete_all |
|
25 | has_many :details, :class_name => "JournalDetail", :dependent => :delete_all | |
26 | attr_accessor :indice |
|
26 | attr_accessor :indice | |
27 |
|
27 | |||
28 | acts_as_event :title => Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" }, |
|
28 | acts_as_event :title => Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" }, | |
29 | :description => :notes, |
|
29 | :description => :notes, | |
30 | :author => :user, |
|
30 | :author => :user, | |
31 | :type => Proc.new {|o| (s = o.new_status) ? (s.is_closed? ? 'issue-closed' : 'issue-edit') : 'issue-note' }, |
|
31 | :type => Proc.new {|o| (s = o.new_status) ? (s.is_closed? ? 'issue-closed' : 'issue-edit') : 'issue-note' }, | |
32 | :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}} |
|
32 | :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}} | |
33 |
|
33 | |||
34 | acts_as_activity_provider :type => 'issues', |
|
34 | acts_as_activity_provider :type => 'issues', | |
35 | :permission => :view_issues, |
|
35 | :permission => :view_issues, | |
36 | :author_key => :user_id, |
|
36 | :author_key => :user_id, | |
37 | :find_options => {:include => [{:issue => :project}, :details, :user], |
|
37 | :find_options => {:include => [{:issue => :project}, :details, :user], | |
38 | :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" + |
|
38 | :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" + | |
39 | " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"} |
|
39 | " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"} | |
40 |
|
40 | |||
41 | def save(*args) |
|
41 | def save(*args) | |
42 | # Do not save an empty journal |
|
42 | # Do not save an empty journal | |
43 | (details.empty? && notes.blank?) ? false : super |
|
43 | (details.empty? && notes.blank?) ? false : super | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | # Returns the new status if the journal contains a status change, otherwise nil |
|
46 | # Returns the new status if the journal contains a status change, otherwise nil | |
47 | def new_status |
|
47 | def new_status | |
48 | c = details.detect {|detail| detail.prop_key == 'status_id'} |
|
48 | c = details.detect {|detail| detail.prop_key == 'status_id'} | |
49 | (c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil |
|
49 | (c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def new_value_for(prop) |
|
52 | def new_value_for(prop) | |
53 | c = details.detect {|detail| detail.prop_key == prop} |
|
53 | c = details.detect {|detail| detail.prop_key == prop} | |
54 | c ? c.value : nil |
|
54 | c ? c.value : nil | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | def editable_by?(usr) |
|
57 | def editable_by?(usr) | |
58 | usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project))) |
|
58 | usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project))) | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def project |
|
61 | def project | |
62 | journalized.respond_to?(:project) ? journalized.project : nil |
|
62 | journalized.respond_to?(:project) ? journalized.project : nil | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | def attachments |
|
65 | def attachments | |
66 | journalized.respond_to?(:attachments) ? journalized.attachments : nil |
|
66 | journalized.respond_to?(:attachments) ? journalized.attachments : nil | |
67 | end |
|
67 | end | |
|
68 | ||||
|
69 | # Returns a string of css classes | |||
|
70 | def css_classes | |||
|
71 | s = 'journal' | |||
|
72 | s << ' has-notes' unless notes.blank? | |||
|
73 | s << ' has-details' unless details.blank? | |||
|
74 | s | |||
|
75 | end | |||
68 | end |
|
76 | end |
@@ -1,19 +1,19 | |||||
1 | <% reply_links = authorize_for('issues', 'edit') -%> |
|
1 | <% reply_links = authorize_for('issues', 'edit') -%> | |
2 | <% for journal in journals %> |
|
2 | <% for journal in journals %> | |
3 |
<div id="change-<%= journal.id %>" class="<%= |
|
3 | <div id="change-<%= journal.id %>" class="<%= journal.css_classes %>"> | |
4 | <h4><div class="journal-link"><%= link_to "##{journal.indice}", :anchor => "note-#{journal.indice}" %></div> |
|
4 | <h4><div class="journal-link"><%= link_to "##{journal.indice}", :anchor => "note-#{journal.indice}" %></div> | |
5 | <%= avatar(journal.user, :size => "24") %> |
|
5 | <%= avatar(journal.user, :size => "24") %> | |
6 | <%= content_tag('a', '', :name => "note-#{journal.indice}")%> |
|
6 | <%= content_tag('a', '', :name => "note-#{journal.indice}")%> | |
7 | <%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %></h4> |
|
7 | <%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %></h4> | |
8 |
|
8 | |||
9 | <% if journal.details.any? %> |
|
9 | <% if journal.details.any? %> | |
10 | <ul class="details"> |
|
10 | <ul class="details"> | |
11 | <% for detail in journal.details %> |
|
11 | <% for detail in journal.details %> | |
12 | <li><%= show_detail(detail) %></li> |
|
12 | <li><%= show_detail(detail) %></li> | |
13 | <% end %> |
|
13 | <% end %> | |
14 | </ul> |
|
14 | </ul> | |
15 | <% end %> |
|
15 | <% end %> | |
16 | <%= render_notes(issue, journal, :reply_links => reply_links) unless journal.notes.blank? %> |
|
16 | <%= render_notes(issue, journal, :reply_links => reply_links) unless journal.notes.blank? %> | |
17 | </div> |
|
17 | </div> | |
18 | <%= call_hook(:view_issues_history_journal_bottom, { :journal => journal }) %> |
|
18 | <%= call_hook(:view_issues_history_journal_bottom, { :journal => journal }) %> | |
19 | <% end %> |
|
19 | <% end %> |
General Comments 0
You need to be logged in to leave comments.
Login now