@@ -1,100 +1,102 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2016 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 'admin' |
|
19 | layout 'admin' | |
20 | self.main_menu = false |
|
20 | self.main_menu = false | |
21 |
|
21 | |||
22 | before_action :require_admin |
|
22 | before_action :require_admin | |
23 | before_action :build_new_custom_field, :only => [:new, :create] |
|
23 | before_action :build_new_custom_field, :only => [:new, :create] | |
24 | before_action :find_custom_field, :only => [:edit, :update, :destroy] |
|
24 | before_action :find_custom_field, :only => [:edit, :update, :destroy] | |
25 | accept_api_auth :index |
|
25 | accept_api_auth :index | |
26 |
|
26 | |||
27 | def index |
|
27 | def index | |
28 | respond_to do |format| |
|
28 | respond_to do |format| | |
29 | format.html { |
|
29 | format.html { | |
30 | @custom_fields_by_type = CustomField.all.group_by {|f| f.class.name } |
|
30 | @custom_fields_by_type = CustomField.all.group_by {|f| f.class.name } | |
|
31 | @custom_fields_projects_count = | |||
|
32 | IssueCustomField.where(is_for_all: false).joins(:projects).group(:custom_field_id).count | |||
31 | } |
|
33 | } | |
32 | format.api { |
|
34 | format.api { | |
33 | @custom_fields = CustomField.all |
|
35 | @custom_fields = CustomField.all | |
34 | } |
|
36 | } | |
35 | end |
|
37 | end | |
36 | end |
|
38 | end | |
37 |
|
39 | |||
38 | def new |
|
40 | def new | |
39 | @custom_field.field_format = 'string' if @custom_field.field_format.blank? |
|
41 | @custom_field.field_format = 'string' if @custom_field.field_format.blank? | |
40 | @custom_field.default_value = nil |
|
42 | @custom_field.default_value = nil | |
41 | end |
|
43 | end | |
42 |
|
44 | |||
43 | def create |
|
45 | def create | |
44 | if @custom_field.save |
|
46 | if @custom_field.save | |
45 | flash[:notice] = l(:notice_successful_create) |
|
47 | flash[:notice] = l(:notice_successful_create) | |
46 | call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field) |
|
48 | call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field) | |
47 | redirect_to edit_custom_field_path(@custom_field) |
|
49 | redirect_to edit_custom_field_path(@custom_field) | |
48 | else |
|
50 | else | |
49 | render :action => 'new' |
|
51 | render :action => 'new' | |
50 | end |
|
52 | end | |
51 | end |
|
53 | end | |
52 |
|
54 | |||
53 | def edit |
|
55 | def edit | |
54 | end |
|
56 | end | |
55 |
|
57 | |||
56 | def update |
|
58 | def update | |
57 | @custom_field.safe_attributes = params[:custom_field] |
|
59 | @custom_field.safe_attributes = params[:custom_field] | |
58 | if @custom_field.save |
|
60 | if @custom_field.save | |
59 | call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field) |
|
61 | call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field) | |
60 | respond_to do |format| |
|
62 | respond_to do |format| | |
61 | format.html { |
|
63 | format.html { | |
62 | flash[:notice] = l(:notice_successful_update) |
|
64 | flash[:notice] = l(:notice_successful_update) | |
63 | redirect_back_or_default edit_custom_field_path(@custom_field) |
|
65 | redirect_back_or_default edit_custom_field_path(@custom_field) | |
64 | } |
|
66 | } | |
65 | format.js { head 200 } |
|
67 | format.js { head 200 } | |
66 | end |
|
68 | end | |
67 | else |
|
69 | else | |
68 | respond_to do |format| |
|
70 | respond_to do |format| | |
69 | format.html { render :action => 'edit' } |
|
71 | format.html { render :action => 'edit' } | |
70 | format.js { head 422 } |
|
72 | format.js { head 422 } | |
71 | end |
|
73 | end | |
72 | end |
|
74 | end | |
73 | end |
|
75 | end | |
74 |
|
76 | |||
75 | def destroy |
|
77 | def destroy | |
76 | begin |
|
78 | begin | |
77 | @custom_field.destroy |
|
79 | @custom_field.destroy | |
78 | rescue |
|
80 | rescue | |
79 | flash[:error] = l(:error_can_not_delete_custom_field) |
|
81 | flash[:error] = l(:error_can_not_delete_custom_field) | |
80 | end |
|
82 | end | |
81 | redirect_to custom_fields_path(:tab => @custom_field.class.name) |
|
83 | redirect_to custom_fields_path(:tab => @custom_field.class.name) | |
82 | end |
|
84 | end | |
83 |
|
85 | |||
84 | private |
|
86 | private | |
85 |
|
87 | |||
86 | def build_new_custom_field |
|
88 | def build_new_custom_field | |
87 | @custom_field = CustomField.new_subclass_instance(params[:type]) |
|
89 | @custom_field = CustomField.new_subclass_instance(params[:type]) | |
88 | if @custom_field.nil? |
|
90 | if @custom_field.nil? | |
89 | render :action => 'select_type' |
|
91 | render :action => 'select_type' | |
90 | else |
|
92 | else | |
91 | @custom_field.safe_attributes = params[:custom_field] |
|
93 | @custom_field.safe_attributes = params[:custom_field] | |
92 | end |
|
94 | end | |
93 | end |
|
95 | end | |
94 |
|
96 | |||
95 | def find_custom_field |
|
97 | def find_custom_field | |
96 | @custom_field = CustomField.find(params[:id]) |
|
98 | @custom_field = CustomField.find(params[:id]) | |
97 | rescue ActiveRecord::RecordNotFound |
|
99 | rescue ActiveRecord::RecordNotFound | |
98 | render_404 |
|
100 | render_404 | |
99 | end |
|
101 | end | |
100 | end |
|
102 | end |
@@ -1,30 +1,30 | |||||
1 | <table class="list custom_fields"> |
|
1 | <table class="list custom_fields"> | |
2 | <thead><tr> |
|
2 | <thead><tr> | |
3 | <th><%=l(:field_name)%></th> |
|
3 | <th><%=l(:field_name)%></th> | |
4 | <th><%=l(:field_field_format)%></th> |
|
4 | <th><%=l(:field_field_format)%></th> | |
5 | <th><%=l(:field_is_required)%></th> |
|
5 | <th><%=l(:field_is_required)%></th> | |
6 | <% if tab[:name] == 'IssueCustomField' %> |
|
6 | <% if tab[:name] == 'IssueCustomField' %> | |
7 | <th><%=l(:field_is_for_all)%></th> |
|
7 | <th><%=l(:field_is_for_all)%></th> | |
8 | <th><%=l(:label_used_by)%></th> |
|
8 | <th><%=l(:label_used_by)%></th> | |
9 | <% end %> |
|
9 | <% end %> | |
10 | <th></th> |
|
10 | <th></th> | |
11 | </tr></thead> |
|
11 | </tr></thead> | |
12 | <tbody> |
|
12 | <tbody> | |
13 | <% (@custom_fields_by_type[tab[:name]] || []).sort.each do |custom_field| -%> |
|
13 | <% (@custom_fields_by_type[tab[:name]] || []).sort.each do |custom_field| -%> | |
14 | <% back_url = custom_fields_path(:tab => tab[:name]) %> |
|
14 | <% back_url = custom_fields_path(:tab => tab[:name]) %> | |
15 | <tr class="<%= cycle("odd", "even") %>"> |
|
15 | <tr class="<%= cycle("odd", "even") %>"> | |
16 | <td class="name"><%= link_to custom_field.name, edit_custom_field_path(custom_field) %></td> |
|
16 | <td class="name"><%= link_to custom_field.name, edit_custom_field_path(custom_field) %></td> | |
17 | <td><%= l(custom_field.format.label) %></td> |
|
17 | <td><%= l(custom_field.format.label) %></td> | |
18 | <td><%= checked_image custom_field.is_required? %></td> |
|
18 | <td><%= checked_image custom_field.is_required? %></td> | |
19 | <% if tab[:name] == 'IssueCustomField' %> |
|
19 | <% if tab[:name] == 'IssueCustomField' %> | |
20 | <td><%= checked_image custom_field.is_for_all? %></td> |
|
20 | <td><%= checked_image custom_field.is_for_all? %></td> | |
21 |
<td><%= l(:label_x_projects, :count => custom_field |
|
21 | <td><%= l(:label_x_projects, :count => @custom_fields_projects_count[custom_field.id]) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %></td> | |
22 | <% end %> |
|
22 | <% end %> | |
23 | <td class="buttons"> |
|
23 | <td class="buttons"> | |
24 | <%= reorder_handle(custom_field, :url => custom_field_path(custom_field), :param => 'custom_field') %> |
|
24 | <%= reorder_handle(custom_field, :url => custom_field_path(custom_field), :param => 'custom_field') %> | |
25 | <%= delete_link custom_field_path(custom_field) %> |
|
25 | <%= delete_link custom_field_path(custom_field) %> | |
26 | </td> |
|
26 | </td> | |
27 | </tr> |
|
27 | </tr> | |
28 | <% end; reset_cycle %> |
|
28 | <% end; reset_cycle %> | |
29 | </tbody> |
|
29 | </tbody> | |
30 | </table> |
|
30 | </table> |
General Comments 0
You need to be logged in to leave comments.
Login now