@@ -0,0 +1,23 | |||||
|
1 | # redMine - project management software | |||
|
2 | # Copyright (C) 2008 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
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 | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
|
18 | class TimeEntryCustomField < CustomField | |||
|
19 | def type_name | |||
|
20 | :label_spent_time | |||
|
21 | end | |||
|
22 | end | |||
|
23 |
@@ -1,87 +1,89 | |||||
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 CustomFieldsController < ApplicationController |
|
18 | class CustomFieldsController < ApplicationController | |
19 | layout 'base' |
|
19 | layout 'base' | |
20 | before_filter :require_admin |
|
20 | before_filter :require_admin | |
21 |
|
21 | |||
22 | def index |
|
22 | def index | |
23 | list |
|
23 | list | |
24 | render :action => 'list' unless request.xhr? |
|
24 | render :action => 'list' unless request.xhr? | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | def list |
|
27 | def list | |
28 | @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name } |
|
28 | @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name } | |
29 | @tab = params[:tab] || 'IssueCustomField' |
|
29 | @tab = params[:tab] || 'IssueCustomField' | |
30 | render :action => "list", :layout => false if request.xhr? |
|
30 | render :action => "list", :layout => false if request.xhr? | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def new |
|
33 | def new | |
34 | case params[:type] |
|
34 | case params[:type] | |
35 | when "IssueCustomField" |
|
35 | when "IssueCustomField" | |
36 | @custom_field = IssueCustomField.new(params[:custom_field]) |
|
36 | @custom_field = IssueCustomField.new(params[:custom_field]) | |
37 | @custom_field.trackers = Tracker.find(params[:tracker_ids]) if params[:tracker_ids] |
|
37 | @custom_field.trackers = Tracker.find(params[:tracker_ids]) if params[:tracker_ids] | |
38 | when "UserCustomField" |
|
38 | when "UserCustomField" | |
39 | @custom_field = UserCustomField.new(params[:custom_field]) |
|
39 | @custom_field = UserCustomField.new(params[:custom_field]) | |
40 | when "ProjectCustomField" |
|
40 | when "ProjectCustomField" | |
41 | @custom_field = ProjectCustomField.new(params[:custom_field]) |
|
41 | @custom_field = ProjectCustomField.new(params[:custom_field]) | |
|
42 | when "TimeEntryCustomField" | |||
|
43 | @custom_field = TimeEntryCustomField.new(params[:custom_field]) | |||
42 | else |
|
44 | else | |
43 | redirect_to :action => 'list' |
|
45 | redirect_to :action => 'list' | |
44 | return |
|
46 | return | |
45 | end |
|
47 | end | |
46 | if request.post? and @custom_field.save |
|
48 | if request.post? and @custom_field.save | |
47 | flash[:notice] = l(:notice_successful_create) |
|
49 | flash[:notice] = l(:notice_successful_create) | |
48 | redirect_to :action => 'list', :tab => @custom_field.class.name |
|
50 | redirect_to :action => 'list', :tab => @custom_field.class.name | |
49 | end |
|
51 | end | |
50 | @trackers = Tracker.find(:all, :order => 'position') |
|
52 | @trackers = Tracker.find(:all, :order => 'position') | |
51 | end |
|
53 | end | |
52 |
|
54 | |||
53 | def edit |
|
55 | def edit | |
54 | @custom_field = CustomField.find(params[:id]) |
|
56 | @custom_field = CustomField.find(params[:id]) | |
55 | if request.post? and @custom_field.update_attributes(params[:custom_field]) |
|
57 | if request.post? and @custom_field.update_attributes(params[:custom_field]) | |
56 | if @custom_field.is_a? IssueCustomField |
|
58 | if @custom_field.is_a? IssueCustomField | |
57 | @custom_field.trackers = params[:tracker_ids] ? Tracker.find(params[:tracker_ids]) : [] |
|
59 | @custom_field.trackers = params[:tracker_ids] ? Tracker.find(params[:tracker_ids]) : [] | |
58 | end |
|
60 | end | |
59 | flash[:notice] = l(:notice_successful_update) |
|
61 | flash[:notice] = l(:notice_successful_update) | |
60 | redirect_to :action => 'list', :tab => @custom_field.class.name |
|
62 | redirect_to :action => 'list', :tab => @custom_field.class.name | |
61 | end |
|
63 | end | |
62 | @trackers = Tracker.find(:all, :order => 'position') |
|
64 | @trackers = Tracker.find(:all, :order => 'position') | |
63 | end |
|
65 | end | |
64 |
|
66 | |||
65 | def move |
|
67 | def move | |
66 | @custom_field = CustomField.find(params[:id]) |
|
68 | @custom_field = CustomField.find(params[:id]) | |
67 | case params[:position] |
|
69 | case params[:position] | |
68 | when 'highest' |
|
70 | when 'highest' | |
69 | @custom_field.move_to_top |
|
71 | @custom_field.move_to_top | |
70 | when 'higher' |
|
72 | when 'higher' | |
71 | @custom_field.move_higher |
|
73 | @custom_field.move_higher | |
72 | when 'lower' |
|
74 | when 'lower' | |
73 | @custom_field.move_lower |
|
75 | @custom_field.move_lower | |
74 | when 'lowest' |
|
76 | when 'lowest' | |
75 | @custom_field.move_to_bottom |
|
77 | @custom_field.move_to_bottom | |
76 | end if params[:position] |
|
78 | end if params[:position] | |
77 | redirect_to :action => 'list', :tab => @custom_field.class.name |
|
79 | redirect_to :action => 'list', :tab => @custom_field.class.name | |
78 | end |
|
80 | end | |
79 |
|
81 | |||
80 | def destroy |
|
82 | def destroy | |
81 | @custom_field = CustomField.find(params[:id]).destroy |
|
83 | @custom_field = CustomField.find(params[:id]).destroy | |
82 | redirect_to :action => 'list', :tab => @custom_field.class.name |
|
84 | redirect_to :action => 'list', :tab => @custom_field.class.name | |
83 | rescue |
|
85 | rescue | |
84 | flash[:error] = "Unable to delete custom field" |
|
86 | flash[:error] = "Unable to delete custom field" | |
85 | redirect_to :action => 'list' |
|
87 | redirect_to :action => 'list' | |
86 | end |
|
88 | end | |
87 | end |
|
89 | end |
@@ -1,429 +1,430 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 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 IssuesController < ApplicationController |
|
18 | class IssuesController < ApplicationController | |
19 | layout 'base' |
|
19 | layout 'base' | |
20 | menu_item :new_issue, :only => :new |
|
20 | menu_item :new_issue, :only => :new | |
21 |
|
21 | |||
22 | before_filter :find_issue, :only => [:show, :edit, :reply, :destroy_attachment] |
|
22 | before_filter :find_issue, :only => [:show, :edit, :reply, :destroy_attachment] | |
23 | before_filter :find_issues, :only => [:bulk_edit, :move, :destroy] |
|
23 | before_filter :find_issues, :only => [:bulk_edit, :move, :destroy] | |
24 | before_filter :find_project, :only => [:new, :update_form, :preview] |
|
24 | before_filter :find_project, :only => [:new, :update_form, :preview] | |
25 | before_filter :authorize, :except => [:index, :changes, :preview, :update_form, :context_menu] |
|
25 | before_filter :authorize, :except => [:index, :changes, :preview, :update_form, :context_menu] | |
26 | before_filter :find_optional_project, :only => [:index, :changes] |
|
26 | before_filter :find_optional_project, :only => [:index, :changes] | |
27 | accept_key_auth :index, :changes |
|
27 | accept_key_auth :index, :changes | |
28 |
|
28 | |||
29 | helper :journals |
|
29 | helper :journals | |
30 | helper :projects |
|
30 | helper :projects | |
31 | include ProjectsHelper |
|
31 | include ProjectsHelper | |
32 | helper :custom_fields |
|
32 | helper :custom_fields | |
33 | include CustomFieldsHelper |
|
33 | include CustomFieldsHelper | |
34 | helper :ifpdf |
|
34 | helper :ifpdf | |
35 | include IfpdfHelper |
|
35 | include IfpdfHelper | |
36 | helper :issue_relations |
|
36 | helper :issue_relations | |
37 | include IssueRelationsHelper |
|
37 | include IssueRelationsHelper | |
38 | helper :watchers |
|
38 | helper :watchers | |
39 | include WatchersHelper |
|
39 | include WatchersHelper | |
40 | helper :attachments |
|
40 | helper :attachments | |
41 | include AttachmentsHelper |
|
41 | include AttachmentsHelper | |
42 | helper :queries |
|
42 | helper :queries | |
43 | helper :sort |
|
43 | helper :sort | |
44 | include SortHelper |
|
44 | include SortHelper | |
45 | include IssuesHelper |
|
45 | include IssuesHelper | |
46 | helper :timelog |
|
46 | helper :timelog | |
47 |
|
47 | |||
48 | def index |
|
48 | def index | |
49 | sort_init "#{Issue.table_name}.id", "desc" |
|
49 | sort_init "#{Issue.table_name}.id", "desc" | |
50 | sort_update |
|
50 | sort_update | |
51 | retrieve_query |
|
51 | retrieve_query | |
52 | if @query.valid? |
|
52 | if @query.valid? | |
53 | limit = per_page_option |
|
53 | limit = per_page_option | |
54 | respond_to do |format| |
|
54 | respond_to do |format| | |
55 | format.html { } |
|
55 | format.html { } | |
56 | format.atom { } |
|
56 | format.atom { } | |
57 | format.csv { limit = Setting.issues_export_limit.to_i } |
|
57 | format.csv { limit = Setting.issues_export_limit.to_i } | |
58 | format.pdf { limit = Setting.issues_export_limit.to_i } |
|
58 | format.pdf { limit = Setting.issues_export_limit.to_i } | |
59 | end |
|
59 | end | |
60 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) |
|
60 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) | |
61 | @issue_pages = Paginator.new self, @issue_count, limit, params['page'] |
|
61 | @issue_pages = Paginator.new self, @issue_count, limit, params['page'] | |
62 | @issues = Issue.find :all, :order => sort_clause, |
|
62 | @issues = Issue.find :all, :order => sort_clause, | |
63 | :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ], |
|
63 | :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ], | |
64 | :conditions => @query.statement, |
|
64 | :conditions => @query.statement, | |
65 | :limit => limit, |
|
65 | :limit => limit, | |
66 | :offset => @issue_pages.current.offset |
|
66 | :offset => @issue_pages.current.offset | |
67 | respond_to do |format| |
|
67 | respond_to do |format| | |
68 | format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } |
|
68 | format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } | |
69 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } |
|
69 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } | |
70 | format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') } |
|
70 | format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') } | |
71 | format.pdf { send_data(render(:template => 'issues/index.rfpdf', :layout => false), :type => 'application/pdf', :filename => 'export.pdf') } |
|
71 | format.pdf { send_data(render(:template => 'issues/index.rfpdf', :layout => false), :type => 'application/pdf', :filename => 'export.pdf') } | |
72 | end |
|
72 | end | |
73 | else |
|
73 | else | |
74 | # Send html if the query is not valid |
|
74 | # Send html if the query is not valid | |
75 | render(:template => 'issues/index.rhtml', :layout => !request.xhr?) |
|
75 | render(:template => 'issues/index.rhtml', :layout => !request.xhr?) | |
76 | end |
|
76 | end | |
77 | rescue ActiveRecord::RecordNotFound |
|
77 | rescue ActiveRecord::RecordNotFound | |
78 | render_404 |
|
78 | render_404 | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | def changes |
|
81 | def changes | |
82 | sort_init "#{Issue.table_name}.id", "desc" |
|
82 | sort_init "#{Issue.table_name}.id", "desc" | |
83 | sort_update |
|
83 | sort_update | |
84 | retrieve_query |
|
84 | retrieve_query | |
85 | if @query.valid? |
|
85 | if @query.valid? | |
86 | @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ], |
|
86 | @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ], | |
87 | :conditions => @query.statement, |
|
87 | :conditions => @query.statement, | |
88 | :limit => 25, |
|
88 | :limit => 25, | |
89 | :order => "#{Journal.table_name}.created_on DESC" |
|
89 | :order => "#{Journal.table_name}.created_on DESC" | |
90 | end |
|
90 | end | |
91 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) |
|
91 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) | |
92 | render :layout => false, :content_type => 'application/atom+xml' |
|
92 | render :layout => false, :content_type => 'application/atom+xml' | |
93 | rescue ActiveRecord::RecordNotFound |
|
93 | rescue ActiveRecord::RecordNotFound | |
94 | render_404 |
|
94 | render_404 | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | def show |
|
97 | def show | |
98 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") |
|
98 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") | |
99 | @journals.each_with_index {|j,i| j.indice = i+1} |
|
99 | @journals.each_with_index {|j,i| j.indice = i+1} | |
100 | @journals.reverse! if User.current.wants_comments_in_reverse_order? |
|
100 | @journals.reverse! if User.current.wants_comments_in_reverse_order? | |
101 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
101 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
102 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
102 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | |
103 | @priorities = Enumeration::get_values('IPRI') |
|
103 | @priorities = Enumeration::get_values('IPRI') | |
104 | @time_entry = TimeEntry.new |
|
104 | @time_entry = TimeEntry.new | |
105 | respond_to do |format| |
|
105 | respond_to do |format| | |
106 | format.html { render :template => 'issues/show.rhtml' } |
|
106 | format.html { render :template => 'issues/show.rhtml' } | |
107 | format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' } |
|
107 | format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' } | |
108 | format.pdf { send_data(render(:template => 'issues/show.rfpdf', :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } |
|
108 | format.pdf { send_data(render(:template => 'issues/show.rfpdf', :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } | |
109 | end |
|
109 | end | |
110 | end |
|
110 | end | |
111 |
|
111 | |||
112 | # Add a new issue |
|
112 | # Add a new issue | |
113 | # The new issue will be created from an existing one if copy_from parameter is given |
|
113 | # The new issue will be created from an existing one if copy_from parameter is given | |
114 | def new |
|
114 | def new | |
115 | @issue = Issue.new |
|
115 | @issue = Issue.new | |
116 | @issue.copy_from(params[:copy_from]) if params[:copy_from] |
|
116 | @issue.copy_from(params[:copy_from]) if params[:copy_from] | |
117 | @issue.project = @project |
|
117 | @issue.project = @project | |
118 | # Tracker must be set before custom field values |
|
118 | # Tracker must be set before custom field values | |
119 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) |
|
119 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) | |
120 | if @issue.tracker.nil? |
|
120 | if @issue.tracker.nil? | |
121 | flash.now[:error] = 'No tracker is associated to this project. Please check the Project settings.' |
|
121 | flash.now[:error] = 'No tracker is associated to this project. Please check the Project settings.' | |
122 | render :nothing => true, :layout => true |
|
122 | render :nothing => true, :layout => true | |
123 | return |
|
123 | return | |
124 | end |
|
124 | end | |
125 | @issue.attributes = params[:issue] |
|
125 | @issue.attributes = params[:issue] | |
126 | @issue.author = User.current |
|
126 | @issue.author = User.current | |
127 |
|
127 | |||
128 | default_status = IssueStatus.default |
|
128 | default_status = IssueStatus.default | |
129 | unless default_status |
|
129 | unless default_status | |
130 | flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").' |
|
130 | flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").' | |
131 | render :nothing => true, :layout => true |
|
131 | render :nothing => true, :layout => true | |
132 | return |
|
132 | return | |
133 | end |
|
133 | end | |
134 | @issue.status = default_status |
|
134 | @issue.status = default_status | |
135 | @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)).uniq |
|
135 | @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)).uniq | |
136 |
|
136 | |||
137 | if request.get? || request.xhr? |
|
137 | if request.get? || request.xhr? | |
138 | @issue.start_date ||= Date.today |
|
138 | @issue.start_date ||= Date.today | |
139 | else |
|
139 | else | |
140 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) |
|
140 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) | |
141 | # Check that the user is allowed to apply the requested status |
|
141 | # Check that the user is allowed to apply the requested status | |
142 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status |
|
142 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status | |
143 | if @issue.save |
|
143 | if @issue.save | |
144 | attach_files(@issue, params[:attachments]) |
|
144 | attach_files(@issue, params[:attachments]) | |
145 | flash[:notice] = l(:notice_successful_create) |
|
145 | flash[:notice] = l(:notice_successful_create) | |
146 | Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added') |
|
146 | Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added') | |
147 | redirect_to :controller => 'issues', :action => 'show', :id => @issue |
|
147 | redirect_to :controller => 'issues', :action => 'show', :id => @issue | |
148 | return |
|
148 | return | |
149 | end |
|
149 | end | |
150 | end |
|
150 | end | |
151 | @priorities = Enumeration::get_values('IPRI') |
|
151 | @priorities = Enumeration::get_values('IPRI') | |
152 | render :layout => !request.xhr? |
|
152 | render :layout => !request.xhr? | |
153 | end |
|
153 | end | |
154 |
|
154 | |||
155 | # Attributes that can be updated on workflow transition (without :edit permission) |
|
155 | # Attributes that can be updated on workflow transition (without :edit permission) | |
156 | # TODO: make it configurable (at least per role) |
|
156 | # TODO: make it configurable (at least per role) | |
157 | UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION) |
|
157 | UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION) | |
158 |
|
158 | |||
159 | def edit |
|
159 | def edit | |
160 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
160 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
161 | @priorities = Enumeration::get_values('IPRI') |
|
161 | @priorities = Enumeration::get_values('IPRI') | |
162 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
162 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | |
|
163 | @time_entry = TimeEntry.new | |||
163 |
|
164 | |||
164 | @notes = params[:notes] |
|
165 | @notes = params[:notes] | |
165 | journal = @issue.init_journal(User.current, @notes) |
|
166 | journal = @issue.init_journal(User.current, @notes) | |
166 | # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed |
|
167 | # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed | |
167 | if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue] |
|
168 | if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue] | |
168 | attrs = params[:issue].dup |
|
169 | attrs = params[:issue].dup | |
169 | attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed |
|
170 | attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed | |
170 | attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s} |
|
171 | attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s} | |
171 | @issue.attributes = attrs |
|
172 | @issue.attributes = attrs | |
172 | end |
|
173 | end | |
173 |
|
174 | |||
174 | if request.post? |
|
175 | if request.post? | |
175 | @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) |
|
176 | @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) | |
176 | @time_entry.attributes = params[:time_entry] |
|
177 | @time_entry.attributes = params[:time_entry] | |
177 | attachments = attach_files(@issue, params[:attachments]) |
|
178 | attachments = attach_files(@issue, params[:attachments]) | |
178 | attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} |
|
179 | attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} | |
179 | if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.save |
|
180 | if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.save | |
180 | # Log spend time |
|
181 | # Log spend time | |
181 | if current_role.allowed_to?(:log_time) |
|
182 | if current_role.allowed_to?(:log_time) | |
182 | @time_entry.save |
|
183 | @time_entry.save | |
183 | end |
|
184 | end | |
184 | if !journal.new_record? |
|
185 | if !journal.new_record? | |
185 | # Only send notification if something was actually changed |
|
186 | # Only send notification if something was actually changed | |
186 | flash[:notice] = l(:notice_successful_update) |
|
187 | flash[:notice] = l(:notice_successful_update) | |
187 | Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') |
|
188 | Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') | |
188 | end |
|
189 | end | |
189 | redirect_to(params[:back_to] || {:action => 'show', :id => @issue}) |
|
190 | redirect_to(params[:back_to] || {:action => 'show', :id => @issue}) | |
190 | end |
|
191 | end | |
191 | end |
|
192 | end | |
192 | rescue ActiveRecord::StaleObjectError |
|
193 | rescue ActiveRecord::StaleObjectError | |
193 | # Optimistic locking exception |
|
194 | # Optimistic locking exception | |
194 | flash.now[:error] = l(:notice_locking_conflict) |
|
195 | flash.now[:error] = l(:notice_locking_conflict) | |
195 | end |
|
196 | end | |
196 |
|
197 | |||
197 | def reply |
|
198 | def reply | |
198 | journal = Journal.find(params[:journal_id]) if params[:journal_id] |
|
199 | journal = Journal.find(params[:journal_id]) if params[:journal_id] | |
199 | if journal |
|
200 | if journal | |
200 | user = journal.user |
|
201 | user = journal.user | |
201 | text = journal.notes |
|
202 | text = journal.notes | |
202 | else |
|
203 | else | |
203 | user = @issue.author |
|
204 | user = @issue.author | |
204 | text = @issue.description |
|
205 | text = @issue.description | |
205 | end |
|
206 | end | |
206 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> " |
|
207 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> " | |
207 | content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n" |
|
208 | content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n" | |
208 | render(:update) { |page| |
|
209 | render(:update) { |page| | |
209 | page.<< "$('notes').value = \"#{content}\";" |
|
210 | page.<< "$('notes').value = \"#{content}\";" | |
210 | page.show 'update' |
|
211 | page.show 'update' | |
211 | page << "Form.Element.focus('notes');" |
|
212 | page << "Form.Element.focus('notes');" | |
212 | page << "Element.scrollTo('update');" |
|
213 | page << "Element.scrollTo('update');" | |
213 | page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" |
|
214 | page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" | |
214 | } |
|
215 | } | |
215 | end |
|
216 | end | |
216 |
|
217 | |||
217 | # Bulk edit a set of issues |
|
218 | # Bulk edit a set of issues | |
218 | def bulk_edit |
|
219 | def bulk_edit | |
219 | if request.post? |
|
220 | if request.post? | |
220 | status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id]) |
|
221 | status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id]) | |
221 | priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id]) |
|
222 | priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id]) | |
222 | assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id]) |
|
223 | assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id]) | |
223 | category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id]) |
|
224 | category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id]) | |
224 | fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id]) |
|
225 | fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id]) | |
225 |
|
226 | |||
226 | unsaved_issue_ids = [] |
|
227 | unsaved_issue_ids = [] | |
227 | @issues.each do |issue| |
|
228 | @issues.each do |issue| | |
228 | journal = issue.init_journal(User.current, params[:notes]) |
|
229 | journal = issue.init_journal(User.current, params[:notes]) | |
229 | issue.priority = priority if priority |
|
230 | issue.priority = priority if priority | |
230 | issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none' |
|
231 | issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none' | |
231 | issue.category = category if category || params[:category_id] == 'none' |
|
232 | issue.category = category if category || params[:category_id] == 'none' | |
232 | issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none' |
|
233 | issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none' | |
233 | issue.start_date = params[:start_date] unless params[:start_date].blank? |
|
234 | issue.start_date = params[:start_date] unless params[:start_date].blank? | |
234 | issue.due_date = params[:due_date] unless params[:due_date].blank? |
|
235 | issue.due_date = params[:due_date] unless params[:due_date].blank? | |
235 | issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank? |
|
236 | issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank? | |
236 | # Don't save any change to the issue if the user is not authorized to apply the requested status |
|
237 | # Don't save any change to the issue if the user is not authorized to apply the requested status | |
237 | if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save |
|
238 | if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save | |
238 | # Send notification for each issue (if changed) |
|
239 | # Send notification for each issue (if changed) | |
239 | Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated') |
|
240 | Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated') | |
240 | else |
|
241 | else | |
241 | # Keep unsaved issue ids to display them in flash error |
|
242 | # Keep unsaved issue ids to display them in flash error | |
242 | unsaved_issue_ids << issue.id |
|
243 | unsaved_issue_ids << issue.id | |
243 | end |
|
244 | end | |
244 | end |
|
245 | end | |
245 | if unsaved_issue_ids.empty? |
|
246 | if unsaved_issue_ids.empty? | |
246 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? |
|
247 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? | |
247 | else |
|
248 | else | |
248 | flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #')) |
|
249 | flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #')) | |
249 | end |
|
250 | end | |
250 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
251 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project | |
251 | return |
|
252 | return | |
252 | end |
|
253 | end | |
253 | # Find potential statuses the user could be allowed to switch issues to |
|
254 | # Find potential statuses the user could be allowed to switch issues to | |
254 | @available_statuses = Workflow.find(:all, :include => :new_status, |
|
255 | @available_statuses = Workflow.find(:all, :include => :new_status, | |
255 | :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq |
|
256 | :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq | |
256 | end |
|
257 | end | |
257 |
|
258 | |||
258 | def move |
|
259 | def move | |
259 | @allowed_projects = [] |
|
260 | @allowed_projects = [] | |
260 | # find projects to which the user is allowed to move the issue |
|
261 | # find projects to which the user is allowed to move the issue | |
261 | if User.current.admin? |
|
262 | if User.current.admin? | |
262 | # admin is allowed to move issues to any active (visible) project |
|
263 | # admin is allowed to move issues to any active (visible) project | |
263 | @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name') |
|
264 | @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name') | |
264 | else |
|
265 | else | |
265 | User.current.memberships.each {|m| @allowed_projects << m.project if m.role.allowed_to?(:move_issues)} |
|
266 | User.current.memberships.each {|m| @allowed_projects << m.project if m.role.allowed_to?(:move_issues)} | |
266 | end |
|
267 | end | |
267 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] |
|
268 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] | |
268 | @target_project ||= @project |
|
269 | @target_project ||= @project | |
269 | @trackers = @target_project.trackers |
|
270 | @trackers = @target_project.trackers | |
270 | if request.post? |
|
271 | if request.post? | |
271 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) |
|
272 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) | |
272 | unsaved_issue_ids = [] |
|
273 | unsaved_issue_ids = [] | |
273 | @issues.each do |issue| |
|
274 | @issues.each do |issue| | |
274 | issue.init_journal(User.current) |
|
275 | issue.init_journal(User.current) | |
275 | unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker) |
|
276 | unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker) | |
276 | end |
|
277 | end | |
277 | if unsaved_issue_ids.empty? |
|
278 | if unsaved_issue_ids.empty? | |
278 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? |
|
279 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? | |
279 | else |
|
280 | else | |
280 | flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #')) |
|
281 | flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #')) | |
281 | end |
|
282 | end | |
282 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
283 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project | |
283 | return |
|
284 | return | |
284 | end |
|
285 | end | |
285 | render :layout => false if request.xhr? |
|
286 | render :layout => false if request.xhr? | |
286 | end |
|
287 | end | |
287 |
|
288 | |||
288 | def destroy |
|
289 | def destroy | |
289 | @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f |
|
290 | @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f | |
290 | if @hours > 0 |
|
291 | if @hours > 0 | |
291 | case params[:todo] |
|
292 | case params[:todo] | |
292 | when 'destroy' |
|
293 | when 'destroy' | |
293 | # nothing to do |
|
294 | # nothing to do | |
294 | when 'nullify' |
|
295 | when 'nullify' | |
295 | TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) |
|
296 | TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) | |
296 | when 'reassign' |
|
297 | when 'reassign' | |
297 | reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) |
|
298 | reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) | |
298 | if reassign_to.nil? |
|
299 | if reassign_to.nil? | |
299 | flash.now[:error] = l(:error_issue_not_found_in_project) |
|
300 | flash.now[:error] = l(:error_issue_not_found_in_project) | |
300 | return |
|
301 | return | |
301 | else |
|
302 | else | |
302 | TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) |
|
303 | TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) | |
303 | end |
|
304 | end | |
304 | else |
|
305 | else | |
305 | # display the destroy form |
|
306 | # display the destroy form | |
306 | return |
|
307 | return | |
307 | end |
|
308 | end | |
308 | end |
|
309 | end | |
309 | @issues.each(&:destroy) |
|
310 | @issues.each(&:destroy) | |
310 | redirect_to :action => 'index', :project_id => @project |
|
311 | redirect_to :action => 'index', :project_id => @project | |
311 | end |
|
312 | end | |
312 |
|
313 | |||
313 | def destroy_attachment |
|
314 | def destroy_attachment | |
314 | a = @issue.attachments.find(params[:attachment_id]) |
|
315 | a = @issue.attachments.find(params[:attachment_id]) | |
315 | a.destroy |
|
316 | a.destroy | |
316 | journal = @issue.init_journal(User.current) |
|
317 | journal = @issue.init_journal(User.current) | |
317 | journal.details << JournalDetail.new(:property => 'attachment', |
|
318 | journal.details << JournalDetail.new(:property => 'attachment', | |
318 | :prop_key => a.id, |
|
319 | :prop_key => a.id, | |
319 | :old_value => a.filename) |
|
320 | :old_value => a.filename) | |
320 | journal.save |
|
321 | journal.save | |
321 | redirect_to :action => 'show', :id => @issue |
|
322 | redirect_to :action => 'show', :id => @issue | |
322 | end |
|
323 | end | |
323 |
|
324 | |||
324 | def context_menu |
|
325 | def context_menu | |
325 | @issues = Issue.find_all_by_id(params[:ids], :include => :project) |
|
326 | @issues = Issue.find_all_by_id(params[:ids], :include => :project) | |
326 | if (@issues.size == 1) |
|
327 | if (@issues.size == 1) | |
327 | @issue = @issues.first |
|
328 | @issue = @issues.first | |
328 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
329 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
329 | @assignables = @issue.assignable_users |
|
330 | @assignables = @issue.assignable_users | |
330 | @assignables << @issue.assigned_to if @issue.assigned_to && !@assignables.include?(@issue.assigned_to) |
|
331 | @assignables << @issue.assigned_to if @issue.assigned_to && !@assignables.include?(@issue.assigned_to) | |
331 | end |
|
332 | end | |
332 | projects = @issues.collect(&:project).compact.uniq |
|
333 | projects = @issues.collect(&:project).compact.uniq | |
333 | @project = projects.first if projects.size == 1 |
|
334 | @project = projects.first if projects.size == 1 | |
334 |
|
335 | |||
335 | @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)), |
|
336 | @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)), | |
336 | :log_time => (@project && User.current.allowed_to?(:log_time, @project)), |
|
337 | :log_time => (@project && User.current.allowed_to?(:log_time, @project)), | |
337 | :update => (@issue && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && !@allowed_statuses.empty?))), |
|
338 | :update => (@issue && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && !@allowed_statuses.empty?))), | |
338 | :move => (@project && User.current.allowed_to?(:move_issues, @project)), |
|
339 | :move => (@project && User.current.allowed_to?(:move_issues, @project)), | |
339 | :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)), |
|
340 | :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)), | |
340 | :delete => (@project && User.current.allowed_to?(:delete_issues, @project)) |
|
341 | :delete => (@project && User.current.allowed_to?(:delete_issues, @project)) | |
341 | } |
|
342 | } | |
342 |
|
343 | |||
343 | @priorities = Enumeration.get_values('IPRI').reverse |
|
344 | @priorities = Enumeration.get_values('IPRI').reverse | |
344 | @statuses = IssueStatus.find(:all, :order => 'position') |
|
345 | @statuses = IssueStatus.find(:all, :order => 'position') | |
345 | @back = request.env['HTTP_REFERER'] |
|
346 | @back = request.env['HTTP_REFERER'] | |
346 |
|
347 | |||
347 | render :layout => false |
|
348 | render :layout => false | |
348 | end |
|
349 | end | |
349 |
|
350 | |||
350 | def update_form |
|
351 | def update_form | |
351 | @issue = Issue.new(params[:issue]) |
|
352 | @issue = Issue.new(params[:issue]) | |
352 | render :action => :new, :layout => false |
|
353 | render :action => :new, :layout => false | |
353 | end |
|
354 | end | |
354 |
|
355 | |||
355 | def preview |
|
356 | def preview | |
356 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? |
|
357 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? | |
357 | @attachements = @issue.attachments if @issue |
|
358 | @attachements = @issue.attachments if @issue | |
358 | @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil) |
|
359 | @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil) | |
359 | render :partial => 'common/preview' |
|
360 | render :partial => 'common/preview' | |
360 | end |
|
361 | end | |
361 |
|
362 | |||
362 | private |
|
363 | private | |
363 | def find_issue |
|
364 | def find_issue | |
364 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) |
|
365 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) | |
365 | @project = @issue.project |
|
366 | @project = @issue.project | |
366 | rescue ActiveRecord::RecordNotFound |
|
367 | rescue ActiveRecord::RecordNotFound | |
367 | render_404 |
|
368 | render_404 | |
368 | end |
|
369 | end | |
369 |
|
370 | |||
370 | # Filter for bulk operations |
|
371 | # Filter for bulk operations | |
371 | def find_issues |
|
372 | def find_issues | |
372 | @issues = Issue.find_all_by_id(params[:id] || params[:ids]) |
|
373 | @issues = Issue.find_all_by_id(params[:id] || params[:ids]) | |
373 | raise ActiveRecord::RecordNotFound if @issues.empty? |
|
374 | raise ActiveRecord::RecordNotFound if @issues.empty? | |
374 | projects = @issues.collect(&:project).compact.uniq |
|
375 | projects = @issues.collect(&:project).compact.uniq | |
375 | if projects.size == 1 |
|
376 | if projects.size == 1 | |
376 | @project = projects.first |
|
377 | @project = projects.first | |
377 | else |
|
378 | else | |
378 | # TODO: let users bulk edit/move/destroy issues from different projects |
|
379 | # TODO: let users bulk edit/move/destroy issues from different projects | |
379 | render_error 'Can not bulk edit/move/destroy issues from different projects' and return false |
|
380 | render_error 'Can not bulk edit/move/destroy issues from different projects' and return false | |
380 | end |
|
381 | end | |
381 | rescue ActiveRecord::RecordNotFound |
|
382 | rescue ActiveRecord::RecordNotFound | |
382 | render_404 |
|
383 | render_404 | |
383 | end |
|
384 | end | |
384 |
|
385 | |||
385 | def find_project |
|
386 | def find_project | |
386 | @project = Project.find(params[:project_id]) |
|
387 | @project = Project.find(params[:project_id]) | |
387 | rescue ActiveRecord::RecordNotFound |
|
388 | rescue ActiveRecord::RecordNotFound | |
388 | render_404 |
|
389 | render_404 | |
389 | end |
|
390 | end | |
390 |
|
391 | |||
391 | def find_optional_project |
|
392 | def find_optional_project | |
392 | return true unless params[:project_id] |
|
393 | return true unless params[:project_id] | |
393 | @project = Project.find(params[:project_id]) |
|
394 | @project = Project.find(params[:project_id]) | |
394 | authorize |
|
395 | authorize | |
395 | rescue ActiveRecord::RecordNotFound |
|
396 | rescue ActiveRecord::RecordNotFound | |
396 | render_404 |
|
397 | render_404 | |
397 | end |
|
398 | end | |
398 |
|
399 | |||
399 | # Retrieve query from session or build a new query |
|
400 | # Retrieve query from session or build a new query | |
400 | def retrieve_query |
|
401 | def retrieve_query | |
401 | if !params[:query_id].blank? |
|
402 | if !params[:query_id].blank? | |
402 | cond = "project_id IS NULL" |
|
403 | cond = "project_id IS NULL" | |
403 | cond << " OR project_id = #{@project.id}" if @project |
|
404 | cond << " OR project_id = #{@project.id}" if @project | |
404 | @query = Query.find(params[:query_id], :conditions => cond) |
|
405 | @query = Query.find(params[:query_id], :conditions => cond) | |
405 | @query.project = @project |
|
406 | @query.project = @project | |
406 | session[:query] = {:id => @query.id, :project_id => @query.project_id} |
|
407 | session[:query] = {:id => @query.id, :project_id => @query.project_id} | |
407 | else |
|
408 | else | |
408 | if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) |
|
409 | if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) | |
409 | # Give it a name, required to be valid |
|
410 | # Give it a name, required to be valid | |
410 | @query = Query.new(:name => "_") |
|
411 | @query = Query.new(:name => "_") | |
411 | @query.project = @project |
|
412 | @query.project = @project | |
412 | if params[:fields] and params[:fields].is_a? Array |
|
413 | if params[:fields] and params[:fields].is_a? Array | |
413 | params[:fields].each do |field| |
|
414 | params[:fields].each do |field| | |
414 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
415 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
415 | end |
|
416 | end | |
416 | else |
|
417 | else | |
417 | @query.available_filters.keys.each do |field| |
|
418 | @query.available_filters.keys.each do |field| | |
418 | @query.add_short_filter(field, params[field]) if params[field] |
|
419 | @query.add_short_filter(field, params[field]) if params[field] | |
419 | end |
|
420 | end | |
420 | end |
|
421 | end | |
421 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters} |
|
422 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters} | |
422 | else |
|
423 | else | |
423 | @query = Query.find_by_id(session[:query][:id]) if session[:query][:id] |
|
424 | @query = Query.find_by_id(session[:query][:id]) if session[:query][:id] | |
424 | @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters]) |
|
425 | @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters]) | |
425 | @query.project = @project |
|
426 | @query.project = @project | |
426 | end |
|
427 | end | |
427 | end |
|
428 | end | |
428 | end |
|
429 | end | |
429 | end |
|
430 | end |
@@ -1,87 +1,88 | |||||
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 | module CustomFieldsHelper |
|
18 | module CustomFieldsHelper | |
19 |
|
19 | |||
20 | def custom_fields_tabs |
|
20 | def custom_fields_tabs | |
21 | tabs = [{:name => 'IssueCustomField', :label => :label_issue_plural}, |
|
21 | tabs = [{:name => 'IssueCustomField', :label => :label_issue_plural}, | |
|
22 | {:name => 'TimeEntryCustomField', :label => :label_spent_time}, | |||
22 | {:name => 'ProjectCustomField', :label => :label_project_plural}, |
|
23 | {:name => 'ProjectCustomField', :label => :label_project_plural}, | |
23 | {:name => 'UserCustomField', :label => :label_user_plural} |
|
24 | {:name => 'UserCustomField', :label => :label_user_plural} | |
24 | ] |
|
25 | ] | |
25 | end |
|
26 | end | |
26 |
|
27 | |||
27 | # Return custom field html tag corresponding to its format |
|
28 | # Return custom field html tag corresponding to its format | |
28 | def custom_field_tag(name, custom_value) |
|
29 | def custom_field_tag(name, custom_value) | |
29 | custom_field = custom_value.custom_field |
|
30 | custom_field = custom_value.custom_field | |
30 | field_name = "#{name}[custom_field_values][#{custom_field.id}]" |
|
31 | field_name = "#{name}[custom_field_values][#{custom_field.id}]" | |
31 | field_id = "#{name}_custom_field_values_#{custom_field.id}" |
|
32 | field_id = "#{name}_custom_field_values_#{custom_field.id}" | |
32 |
|
33 | |||
33 | case custom_field.field_format |
|
34 | case custom_field.field_format | |
34 | when "date" |
|
35 | when "date" | |
35 | text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) + |
|
36 | text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) + | |
36 | calendar_for(field_id) |
|
37 | calendar_for(field_id) | |
37 | when "text" |
|
38 | when "text" | |
38 | text_area_tag(field_name, custom_value.value, :id => field_id, :rows => 3, :style => 'width:90%') |
|
39 | text_area_tag(field_name, custom_value.value, :id => field_id, :rows => 3, :style => 'width:90%') | |
39 | when "bool" |
|
40 | when "bool" | |
40 | check_box_tag(field_name, '1', custom_value.true?, :id => field_id) + hidden_field_tag(field_name, '0') |
|
41 | check_box_tag(field_name, '1', custom_value.true?, :id => field_id) + hidden_field_tag(field_name, '0') | |
41 | when "list" |
|
42 | when "list" | |
42 | blank_option = custom_field.is_required? ? |
|
43 | blank_option = custom_field.is_required? ? | |
43 | (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') : |
|
44 | (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') : | |
44 | '<option></option>' |
|
45 | '<option></option>' | |
45 | select_tag(field_name, blank_option + options_for_select(custom_field.possible_values, custom_value.value), :id => field_id) |
|
46 | select_tag(field_name, blank_option + options_for_select(custom_field.possible_values, custom_value.value), :id => field_id) | |
46 | else |
|
47 | else | |
47 | text_field_tag(field_name, custom_value.value, :id => field_id) |
|
48 | text_field_tag(field_name, custom_value.value, :id => field_id) | |
48 | end |
|
49 | end | |
49 | end |
|
50 | end | |
50 |
|
51 | |||
51 | # Return custom field label tag |
|
52 | # Return custom field label tag | |
52 | def custom_field_label_tag(name, custom_value) |
|
53 | def custom_field_label_tag(name, custom_value) | |
53 | content_tag "label", custom_value.custom_field.name + |
|
54 | content_tag "label", custom_value.custom_field.name + | |
54 | (custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>" : ""), |
|
55 | (custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>" : ""), | |
55 | :for => "#{name}_custom_field_values_#{custom_value.custom_field.id}", |
|
56 | :for => "#{name}_custom_field_values_#{custom_value.custom_field.id}", | |
56 | :class => (custom_value.errors.empty? ? nil : "error" ) |
|
57 | :class => (custom_value.errors.empty? ? nil : "error" ) | |
57 | end |
|
58 | end | |
58 |
|
59 | |||
59 | # Return custom field tag with its label tag |
|
60 | # Return custom field tag with its label tag | |
60 | def custom_field_tag_with_label(name, custom_value) |
|
61 | def custom_field_tag_with_label(name, custom_value) | |
61 | custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value) |
|
62 | custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value) | |
62 | end |
|
63 | end | |
63 |
|
64 | |||
64 | # Return a string used to display a custom value |
|
65 | # Return a string used to display a custom value | |
65 | def show_value(custom_value) |
|
66 | def show_value(custom_value) | |
66 | return "" unless custom_value |
|
67 | return "" unless custom_value | |
67 | format_value(custom_value.value, custom_value.custom_field.field_format) |
|
68 | format_value(custom_value.value, custom_value.custom_field.field_format) | |
68 | end |
|
69 | end | |
69 |
|
70 | |||
70 | # Return a string used to display a custom value |
|
71 | # Return a string used to display a custom value | |
71 | def format_value(value, field_format) |
|
72 | def format_value(value, field_format) | |
72 | return "" unless value && !value.empty? |
|
73 | return "" unless value && !value.empty? | |
73 | case field_format |
|
74 | case field_format | |
74 | when "date" |
|
75 | when "date" | |
75 | begin; format_date(value.to_date); rescue; value end |
|
76 | begin; format_date(value.to_date); rescue; value end | |
76 | when "bool" |
|
77 | when "bool" | |
77 | l_YesNo(value == "1") |
|
78 | l_YesNo(value == "1") | |
78 | else |
|
79 | else | |
79 | value |
|
80 | value | |
80 | end |
|
81 | end | |
81 | end |
|
82 | end | |
82 |
|
83 | |||
83 | # Return an array of custom field formats which can be used in select_tag |
|
84 | # Return an array of custom field formats which can be used in select_tag | |
84 | def custom_field_formats_for_select |
|
85 | def custom_field_formats_for_select | |
85 | CustomField::FIELD_FORMATS.sort {|a,b| a[1][:order]<=>b[1][:order]}.collect { |k| [ l(k[1][:name]), k[0] ] } |
|
86 | CustomField::FIELD_FORMATS.sort {|a,b| a[1][:order]<=>b[1][:order]}.collect { |k| [ l(k[1][:name]), k[0] ] } | |
86 | end |
|
87 | end | |
87 | end |
|
88 | end |
@@ -1,78 +1,79 | |||||
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 | class TimeEntry < ActiveRecord::Base |
|
18 | class TimeEntry < ActiveRecord::Base | |
19 | # could have used polymorphic association |
|
19 | # could have used polymorphic association | |
20 | # project association here allows easy loading of time entries at project level with one database trip |
|
20 | # project association here allows easy loading of time entries at project level with one database trip | |
21 | belongs_to :project |
|
21 | belongs_to :project | |
22 | belongs_to :issue |
|
22 | belongs_to :issue | |
23 | belongs_to :user |
|
23 | belongs_to :user | |
24 | belongs_to :activity, :class_name => 'Enumeration', :foreign_key => :activity_id |
|
24 | belongs_to :activity, :class_name => 'Enumeration', :foreign_key => :activity_id | |
25 |
|
25 | |||
26 | attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek |
|
26 | attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek | |
27 |
|
27 | |||
|
28 | acts_as_customizable | |||
28 | acts_as_event :title => Proc.new {|o| "#{o.user}: #{lwr(:label_f_hour, o.hours)} (#{(o.issue || o.project).event_title})"}, |
|
29 | acts_as_event :title => Proc.new {|o| "#{o.user}: #{lwr(:label_f_hour, o.hours)} (#{(o.issue || o.project).event_title})"}, | |
29 | :url => Proc.new {|o| {:controller => 'timelog', :action => 'details', :project_id => o.project}}, |
|
30 | :url => Proc.new {|o| {:controller => 'timelog', :action => 'details', :project_id => o.project}}, | |
30 | :author => :user, |
|
31 | :author => :user, | |
31 | :description => :comments |
|
32 | :description => :comments | |
32 |
|
33 | |||
33 | validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on |
|
34 | validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on | |
34 | validates_numericality_of :hours, :allow_nil => true |
|
35 | validates_numericality_of :hours, :allow_nil => true | |
35 | validates_length_of :comments, :maximum => 255, :allow_nil => true |
|
36 | validates_length_of :comments, :maximum => 255, :allow_nil => true | |
36 |
|
37 | |||
37 | def after_initialize |
|
38 | def after_initialize | |
38 | if new_record? && self.activity.nil? |
|
39 | if new_record? && self.activity.nil? | |
39 | if default_activity = Enumeration.default('ACTI') |
|
40 | if default_activity = Enumeration.default('ACTI') | |
40 | self.activity_id = default_activity.id |
|
41 | self.activity_id = default_activity.id | |
41 | end |
|
42 | end | |
42 | end |
|
43 | end | |
43 | end |
|
44 | end | |
44 |
|
45 | |||
45 | def before_validation |
|
46 | def before_validation | |
46 | self.project = issue.project if issue && project.nil? |
|
47 | self.project = issue.project if issue && project.nil? | |
47 | end |
|
48 | end | |
48 |
|
49 | |||
49 | def validate |
|
50 | def validate | |
50 | errors.add :hours, :activerecord_error_invalid if hours && (hours < 0 || hours >= 1000) |
|
51 | errors.add :hours, :activerecord_error_invalid if hours && (hours < 0 || hours >= 1000) | |
51 | errors.add :project_id, :activerecord_error_invalid if project.nil? |
|
52 | errors.add :project_id, :activerecord_error_invalid if project.nil? | |
52 | errors.add :issue_id, :activerecord_error_invalid if (issue_id && !issue) || (issue && project!=issue.project) |
|
53 | errors.add :issue_id, :activerecord_error_invalid if (issue_id && !issue) || (issue && project!=issue.project) | |
53 | end |
|
54 | end | |
54 |
|
55 | |||
55 | def hours=(h) |
|
56 | def hours=(h) | |
56 | write_attribute :hours, (h.is_a?(String) ? h.to_hours : h) |
|
57 | write_attribute :hours, (h.is_a?(String) ? h.to_hours : h) | |
57 | end |
|
58 | end | |
58 |
|
59 | |||
59 | # tyear, tmonth, tweek assigned where setting spent_on attributes |
|
60 | # tyear, tmonth, tweek assigned where setting spent_on attributes | |
60 | # these attributes make time aggregations easier |
|
61 | # these attributes make time aggregations easier | |
61 | def spent_on=(date) |
|
62 | def spent_on=(date) | |
62 | super |
|
63 | super | |
63 | self.tyear = spent_on ? spent_on.year : nil |
|
64 | self.tyear = spent_on ? spent_on.year : nil | |
64 | self.tmonth = spent_on ? spent_on.month : nil |
|
65 | self.tmonth = spent_on ? spent_on.month : nil | |
65 | self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil |
|
66 | self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil | |
66 | end |
|
67 | end | |
67 |
|
68 | |||
68 | # Returns true if the time entry can be edited by usr, otherwise false |
|
69 | # Returns true if the time entry can be edited by usr, otherwise false | |
69 | def editable_by?(usr) |
|
70 | def editable_by?(usr) | |
70 | (usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project) |
|
71 | (usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project) | |
71 | end |
|
72 | end | |
72 |
|
73 | |||
73 | def self.visible_by(usr) |
|
74 | def self.visible_by(usr) | |
74 | with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do |
|
75 | with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do | |
75 | yield |
|
76 | yield | |
76 | end |
|
77 | end | |
77 | end |
|
78 | end | |
78 | end |
|
79 | end |
@@ -1,110 +1,113 | |||||
1 | <%= error_messages_for 'custom_field' %> |
|
1 | <%= error_messages_for 'custom_field' %> | |
2 |
|
2 | |||
3 | <script type="text/javascript"> |
|
3 | <script type="text/javascript"> | |
4 | //<![CDATA[ |
|
4 | //<![CDATA[ | |
5 | function toggle_custom_field_format() { |
|
5 | function toggle_custom_field_format() { | |
6 | format = $("custom_field_field_format"); |
|
6 | format = $("custom_field_field_format"); | |
7 | p_length = $("custom_field_min_length"); |
|
7 | p_length = $("custom_field_min_length"); | |
8 | p_regexp = $("custom_field_regexp"); |
|
8 | p_regexp = $("custom_field_regexp"); | |
9 | p_values = $("custom_field_possible_values"); |
|
9 | p_values = $("custom_field_possible_values"); | |
10 | p_searchable = $("custom_field_searchable"); |
|
10 | p_searchable = $("custom_field_searchable"); | |
11 | p_default = $("custom_field_default_value"); |
|
11 | p_default = $("custom_field_default_value"); | |
12 |
|
12 | |||
13 | p_default.setAttribute('type','text'); |
|
13 | p_default.setAttribute('type','text'); | |
14 | Element.show(p_default.parentNode); |
|
14 | Element.show(p_default.parentNode); | |
15 |
|
15 | |||
16 | switch (format.value) { |
|
16 | switch (format.value) { | |
17 | case "list": |
|
17 | case "list": | |
18 | Element.hide(p_length.parentNode); |
|
18 | Element.hide(p_length.parentNode); | |
19 | Element.hide(p_regexp.parentNode); |
|
19 | Element.hide(p_regexp.parentNode); | |
20 | if (p_searchable) Element.show(p_searchable.parentNode); |
|
20 | if (p_searchable) Element.show(p_searchable.parentNode); | |
21 | Element.show(p_values); |
|
21 | Element.show(p_values); | |
22 | break; |
|
22 | break; | |
23 | case "bool": |
|
23 | case "bool": | |
24 | p_default.setAttribute('type','checkbox'); |
|
24 | p_default.setAttribute('type','checkbox'); | |
25 | Element.hide(p_length.parentNode); |
|
25 | Element.hide(p_length.parentNode); | |
26 | Element.hide(p_regexp.parentNode); |
|
26 | Element.hide(p_regexp.parentNode); | |
27 | if (p_searchable) Element.hide(p_searchable.parentNode); |
|
27 | if (p_searchable) Element.hide(p_searchable.parentNode); | |
28 | Element.hide(p_values); |
|
28 | Element.hide(p_values); | |
29 | break; |
|
29 | break; | |
30 | case "date": |
|
30 | case "date": | |
31 | Element.hide(p_length.parentNode); |
|
31 | Element.hide(p_length.parentNode); | |
32 | Element.hide(p_regexp.parentNode); |
|
32 | Element.hide(p_regexp.parentNode); | |
33 | if (p_searchable) Element.hide(p_searchable.parentNode); |
|
33 | if (p_searchable) Element.hide(p_searchable.parentNode); | |
34 | Element.hide(p_values); |
|
34 | Element.hide(p_values); | |
35 | break; |
|
35 | break; | |
36 | case "float": |
|
36 | case "float": | |
37 | case "int": |
|
37 | case "int": | |
38 | Element.show(p_length.parentNode); |
|
38 | Element.show(p_length.parentNode); | |
39 | Element.show(p_regexp.parentNode); |
|
39 | Element.show(p_regexp.parentNode); | |
40 | if (p_searchable) Element.hide(p_searchable.parentNode); |
|
40 | if (p_searchable) Element.hide(p_searchable.parentNode); | |
41 | Element.hide(p_values); |
|
41 | Element.hide(p_values); | |
42 | break; |
|
42 | break; | |
43 | default: |
|
43 | default: | |
44 | Element.show(p_length.parentNode); |
|
44 | Element.show(p_length.parentNode); | |
45 | Element.show(p_regexp.parentNode); |
|
45 | Element.show(p_regexp.parentNode); | |
46 | if (p_searchable) Element.show(p_searchable.parentNode); |
|
46 | if (p_searchable) Element.show(p_searchable.parentNode); | |
47 | Element.hide(p_values); |
|
47 | Element.hide(p_values); | |
48 | break; |
|
48 | break; | |
49 | } |
|
49 | } | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | function addValueField() { |
|
52 | function addValueField() { | |
53 | var f = $$('p#custom_field_possible_values span'); |
|
53 | var f = $$('p#custom_field_possible_values span'); | |
54 | p = document.getElementById("custom_field_possible_values"); |
|
54 | p = document.getElementById("custom_field_possible_values"); | |
55 | var v = f[0].cloneNode(true); |
|
55 | var v = f[0].cloneNode(true); | |
56 | v.childNodes[0].value = ""; |
|
56 | v.childNodes[0].value = ""; | |
57 | p.appendChild(v); |
|
57 | p.appendChild(v); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | function deleteValueField(e) { |
|
60 | function deleteValueField(e) { | |
61 | var f = $$('p#custom_field_possible_values span'); |
|
61 | var f = $$('p#custom_field_possible_values span'); | |
62 | if (f.length == 1) { |
|
62 | if (f.length == 1) { | |
63 | e.parentNode.childNodes[0].value = ""; |
|
63 | e.parentNode.childNodes[0].value = ""; | |
64 | } else { |
|
64 | } else { | |
65 | Element.remove(e.parentNode); |
|
65 | Element.remove(e.parentNode); | |
66 | } |
|
66 | } | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | //]]> |
|
69 | //]]> | |
70 | </script> |
|
70 | </script> | |
71 |
|
71 | |||
72 | <div class="box"> |
|
72 | <div class="box"> | |
73 | <p><%= f.text_field :name, :required => true %></p> |
|
73 | <p><%= f.text_field :name, :required => true %></p> | |
74 | <p><%= f.select :field_format, custom_field_formats_for_select, {}, :onchange => "toggle_custom_field_format();" %></p> |
|
74 | <p><%= f.select :field_format, custom_field_formats_for_select, {}, :onchange => "toggle_custom_field_format();" %></p> | |
75 | <p><label for="custom_field_min_length"><%=l(:label_min_max_length)%></label> |
|
75 | <p><label for="custom_field_min_length"><%=l(:label_min_max_length)%></label> | |
76 | <%= f.text_field :min_length, :size => 5, :no_label => true %> - |
|
76 | <%= f.text_field :min_length, :size => 5, :no_label => true %> - | |
77 | <%= f.text_field :max_length, :size => 5, :no_label => true %><br>(<%=l(:text_min_max_length_info)%>)</p> |
|
77 | <%= f.text_field :max_length, :size => 5, :no_label => true %><br>(<%=l(:text_min_max_length_info)%>)</p> | |
78 | <p><%= f.text_field :regexp, :size => 50 %><br>(<%=l(:text_regexp_info)%>)</p> |
|
78 | <p><%= f.text_field :regexp, :size => 50 %><br>(<%=l(:text_regexp_info)%>)</p> | |
79 | <p id="custom_field_possible_values"><label><%= l(:field_possible_values) %> <%= image_to_function "add.png", "addValueField();return false" %></label> |
|
79 | <p id="custom_field_possible_values"><label><%= l(:field_possible_values) %> <%= image_to_function "add.png", "addValueField();return false" %></label> | |
80 | <% (@custom_field.possible_values.to_a + [""]).each do |value| %> |
|
80 | <% (@custom_field.possible_values.to_a + [""]).each do |value| %> | |
81 | <span><%= text_field_tag 'custom_field[possible_values][]', value, :size => 30 %> <%= image_to_function "delete.png", "deleteValueField(this);return false" %><br /></span> |
|
81 | <span><%= text_field_tag 'custom_field[possible_values][]', value, :size => 30 %> <%= image_to_function "delete.png", "deleteValueField(this);return false" %><br /></span> | |
82 | <% end %> |
|
82 | <% end %> | |
83 | </p> |
|
83 | </p> | |
84 | <p><%= @custom_field.field_format == 'bool' ? f.check_box(:default_value) : f.text_field(:default_value) %></p> |
|
84 | <p><%= @custom_field.field_format == 'bool' ? f.check_box(:default_value) : f.text_field(:default_value) %></p> | |
85 | </div> |
|
85 | </div> | |
86 |
|
86 | |||
87 | <div class="box"> |
|
87 | <div class="box"> | |
88 | <% case @custom_field.type.to_s |
|
88 | <% case @custom_field.type.to_s | |
89 | when "IssueCustomField" %> |
|
89 | when "IssueCustomField" %> | |
90 |
|
90 | |||
91 | <fieldset><legend><%=l(:label_tracker_plural)%></legend> |
|
91 | <fieldset><legend><%=l(:label_tracker_plural)%></legend> | |
92 | <% for tracker in @trackers %> |
|
92 | <% for tracker in @trackers %> | |
93 | <%= check_box_tag "tracker_ids[]", tracker.id, (@custom_field.trackers.include? tracker) %> <%= tracker.name %> |
|
93 | <%= check_box_tag "tracker_ids[]", tracker.id, (@custom_field.trackers.include? tracker) %> <%= tracker.name %> | |
94 | <% end %> |
|
94 | <% end %> | |
95 | </fieldset> |
|
95 | </fieldset> | |
96 | |
|
96 | | |
97 | <p><%= f.check_box :is_required %></p> |
|
97 | <p><%= f.check_box :is_required %></p> | |
98 | <p><%= f.check_box :is_for_all %></p> |
|
98 | <p><%= f.check_box :is_for_all %></p> | |
99 | <p><%= f.check_box :is_filter %></p> |
|
99 | <p><%= f.check_box :is_filter %></p> | |
100 | <p><%= f.check_box :searchable %></p> |
|
100 | <p><%= f.check_box :searchable %></p> | |
101 |
|
101 | |||
102 | <% when "UserCustomField" %> |
|
102 | <% when "UserCustomField" %> | |
103 | <p><%= f.check_box :is_required %></p> |
|
103 | <p><%= f.check_box :is_required %></p> | |
104 |
|
104 | |||
105 | <% when "ProjectCustomField" %> |
|
105 | <% when "ProjectCustomField" %> | |
106 | <p><%= f.check_box :is_required %></p> |
|
106 | <p><%= f.check_box :is_required %></p> | |
107 |
|
107 | |||
|
108 | <% when "TimeEntryCustomField" %> | |||
|
109 | <p><%= f.check_box :is_required %></p> | |||
|
110 | ||||
108 | <% end %> |
|
111 | <% end %> | |
109 | </div> |
|
112 | </div> | |
110 | <%= javascript_tag "toggle_custom_field_format();" %> |
|
113 | <%= javascript_tag "toggle_custom_field_format();" %> |
@@ -1,51 +1,54 | |||||
1 | <% labelled_tabular_form_for :issue, @issue, |
|
1 | <% labelled_tabular_form_for :issue, @issue, | |
2 | :url => {:action => 'edit', :id => @issue}, |
|
2 | :url => {:action => 'edit', :id => @issue}, | |
3 | :html => {:id => 'issue-form', |
|
3 | :html => {:id => 'issue-form', | |
4 | :class => nil, |
|
4 | :class => nil, | |
5 | :multipart => true} do |f| %> |
|
5 | :multipart => true} do |f| %> | |
6 | <%= error_messages_for 'issue' %> |
|
6 | <%= error_messages_for 'issue' %> | |
7 | <%= error_messages_for 'time_entry' %> |
|
7 | <%= error_messages_for 'time_entry' %> | |
8 | <div class="box"> |
|
8 | <div class="box"> | |
9 | <% if @edit_allowed || !@allowed_statuses.empty? %> |
|
9 | <% if @edit_allowed || !@allowed_statuses.empty? %> | |
10 | <fieldset class="tabular"><legend><%= l(:label_change_properties) %> |
|
10 | <fieldset class="tabular"><legend><%= l(:label_change_properties) %> | |
11 | <% if !@issue.new_record? && !@issue.errors.any? && @edit_allowed %> |
|
11 | <% if !@issue.new_record? && !@issue.errors.any? && @edit_allowed %> | |
12 | <small>(<%= link_to l(:label_more), {}, :onclick => 'Effect.toggle("issue_descr_fields", "appear", {duration:0.3}); return false;' %>)</small> |
|
12 | <small>(<%= link_to l(:label_more), {}, :onclick => 'Effect.toggle("issue_descr_fields", "appear", {duration:0.3}); return false;' %>)</small> | |
13 | <% end %> |
|
13 | <% end %> | |
14 | </legend> |
|
14 | </legend> | |
15 | <%= render :partial => (@edit_allowed ? 'form' : 'form_update'), :locals => {:f => f} %> |
|
15 | <%= render :partial => (@edit_allowed ? 'form' : 'form_update'), :locals => {:f => f} %> | |
16 | </fieldset> |
|
16 | </fieldset> | |
17 | <% end %> |
|
17 | <% end %> | |
18 | <% if authorize_for('timelog', 'edit') %> |
|
18 | <% if authorize_for('timelog', 'edit') %> | |
19 | <fieldset class="tabular"><legend><%= l(:button_log_time) %></legend> |
|
19 | <fieldset class="tabular"><legend><%= l(:button_log_time) %></legend> | |
20 | <% fields_for :time_entry, @time_entry, { :builder => TabularFormBuilder, :lang => current_language} do |time_entry| %> |
|
20 | <% fields_for :time_entry, @time_entry, { :builder => TabularFormBuilder, :lang => current_language} do |time_entry| %> | |
21 | <div class="splitcontentleft"> |
|
21 | <div class="splitcontentleft"> | |
22 | <p><%= time_entry.text_field :hours, :size => 6, :label => :label_spent_time %> <%= l(:field_hours) %></p> |
|
22 | <p><%= time_entry.text_field :hours, :size => 6, :label => :label_spent_time %> <%= l(:field_hours) %></p> | |
23 | </div> |
|
23 | </div> | |
24 | <div class="splitcontentright"> |
|
24 | <div class="splitcontentright"> | |
25 | <p><%= time_entry.select :activity_id, activity_collection_for_select_options %></p> |
|
25 | <p><%= time_entry.select :activity_id, activity_collection_for_select_options %></p> | |
26 | </div> |
|
26 | </div> | |
27 | <p><%= time_entry.text_field :comments, :size => 60 %></p> |
|
27 | <p><%= time_entry.text_field :comments, :size => 60 %></p> | |
|
28 | <% @time_entry.custom_field_values.each do |value| %> | |||
|
29 | <p><%= custom_field_tag_with_label :time_entry, value %></p> | |||
|
30 | <% end %> | |||
28 | <% end %> |
|
31 | <% end %> | |
29 | </fieldset> |
|
32 | </fieldset> | |
30 | <% end %> |
|
33 | <% end %> | |
31 |
|
34 | |||
32 | <fieldset><legend><%= l(:field_notes) %></legend> |
|
35 | <fieldset><legend><%= l(:field_notes) %></legend> | |
33 | <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %> |
|
36 | <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %> | |
34 | <%= wikitoolbar_for 'notes' %> |
|
37 | <%= wikitoolbar_for 'notes' %> | |
35 |
|
38 | |||
36 | <p><%=l(:label_attachment_plural)%><br /><%= render :partial => 'attachments/form' %></p> |
|
39 | <p><%=l(:label_attachment_plural)%><br /><%= render :partial => 'attachments/form' %></p> | |
37 | </fieldset> |
|
40 | </fieldset> | |
38 | </div> |
|
41 | </div> | |
39 |
|
42 | |||
40 | <%= f.hidden_field :lock_version %> |
|
43 | <%= f.hidden_field :lock_version %> | |
41 | <%= submit_tag l(:button_submit) %> |
|
44 | <%= submit_tag l(:button_submit) %> | |
42 | <%= link_to_remote l(:label_preview), |
|
45 | <%= link_to_remote l(:label_preview), | |
43 | { :url => { :controller => 'issues', :action => 'preview', :project_id => @project, :id => @issue }, |
|
46 | { :url => { :controller => 'issues', :action => 'preview', :project_id => @project, :id => @issue }, | |
44 | :method => 'post', |
|
47 | :method => 'post', | |
45 | :update => 'preview', |
|
48 | :update => 'preview', | |
46 | :with => 'Form.serialize("issue-form")', |
|
49 | :with => 'Form.serialize("issue-form")', | |
47 | :complete => "Element.scrollTo('preview')" |
|
50 | :complete => "Element.scrollTo('preview')" | |
48 | }, :accesskey => accesskey(:preview) %> |
|
51 | }, :accesskey => accesskey(:preview) %> | |
49 | <% end %> |
|
52 | <% end %> | |
50 |
|
53 | |||
51 | <div id="preview" class="wiki"></div> |
|
54 | <div id="preview" class="wiki"></div> |
@@ -1,17 +1,20 | |||||
1 | <h2><%= l(:label_spent_time) %></h2> |
|
1 | <h2><%= l(:label_spent_time) %></h2> | |
2 |
|
2 | |||
3 | <% labelled_tabular_form_for :time_entry, @time_entry, :url => {:action => 'edit', :project_id => @time_entry.project} do |f| %> |
|
3 | <% labelled_tabular_form_for :time_entry, @time_entry, :url => {:action => 'edit', :project_id => @time_entry.project} do |f| %> | |
4 | <%= error_messages_for 'time_entry' %> |
|
4 | <%= error_messages_for 'time_entry' %> | |
5 | <%= back_url_hidden_field_tag %> |
|
5 | <%= back_url_hidden_field_tag %> | |
6 |
|
6 | |||
7 | <div class="box"> |
|
7 | <div class="box"> | |
8 | <p><%= f.text_field :issue_id, :size => 6 %> <em><%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %></em></p> |
|
8 | <p><%= f.text_field :issue_id, :size => 6 %> <em><%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %></em></p> | |
9 | <p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p> |
|
9 | <p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p> | |
10 | <p><%= f.text_field :hours, :size => 6, :required => true %></p> |
|
10 | <p><%= f.text_field :hours, :size => 6, :required => true %></p> | |
11 | <p><%= f.text_field :comments, :size => 100 %></p> |
|
11 | <p><%= f.text_field :comments, :size => 100 %></p> | |
12 | <p><%= f.select :activity_id, activity_collection_for_select_options, :required => true %></p> |
|
12 | <p><%= f.select :activity_id, activity_collection_for_select_options, :required => true %></p> | |
|
13 | <% @time_entry.custom_field_values.each do |value| %> | |||
|
14 | <p><%= custom_field_tag_with_label :time_entry, value %></p> | |||
|
15 | <% end %> | |||
13 | </div> |
|
16 | </div> | |
14 |
|
17 | |||
15 | <%= submit_tag l(:button_save) %> |
|
18 | <%= submit_tag l(:button_save) %> | |
16 |
|
19 | |||
17 | <% end %> |
|
20 | <% end %> |
General Comments 0
You need to be logged in to leave comments.
Login now