| 
									
										
										
										
											2009-01-17 08:46:23 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							| 
									
										
										
										
											2016-03-13 10:30:10 +00:00
										 |  |  | # Copyright (C) 2006-2016  Jean-Philippe Lang | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | # modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | # as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | # of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2011-08-31 12:11:19 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | # GNU General Public License for more details. | 
					
						
							| 
									
										
										
										
											2011-08-31 12:11:19 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | # along with this program; if not, write to the Free Software | 
					
						
							|  |  |  | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class CustomFieldsController < ApplicationController | 
					
						
							| 
									
										
										
										
											2009-12-17 18:21:02 +00:00
										 |  |  |   layout 'admin' | 
					
						
							| 
									
										
										
										
											2016-11-19 10:30:02 +00:00
										 |  |  |   self.main_menu = false | 
					
						
							| 
									
										
										
										
											2011-08-31 12:11:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-14 07:27:31 +00:00
										 |  |  |   before_action :require_admin | 
					
						
							|  |  |  |   before_action :build_new_custom_field, :only => [:new, :create] | 
					
						
							|  |  |  |   before_action :find_custom_field, :only => [:edit, :update, :destroy] | 
					
						
							| 
									
										
										
										
											2013-09-29 10:08:30 +00:00
										 |  |  |   accept_api_auth :index | 
					
						
							| 
									
										
										
										
											2006-07-29 09:32:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |   def index | 
					
						
							| 
									
										
										
										
											2013-09-29 10:08:30 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							|  |  |  |       format.html { | 
					
						
							|  |  |  |         @custom_fields_by_type = CustomField.all.group_by {|f| f.class.name } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       format.api { | 
					
						
							|  |  |  |         @custom_fields = CustomField.all | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:11:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |   def new | 
					
						
							| 
									
										
										
										
											2013-12-14 08:22:43 +00:00
										 |  |  |     @custom_field.field_format = 'string' if @custom_field.field_format.blank? | 
					
						
							|  |  |  |     @custom_field.default_value = nil | 
					
						
							| 
									
										
										
										
											2011-12-09 22:58:30 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:11:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-09 22:58:30 +00:00
										 |  |  |   def create | 
					
						
							| 
									
										
										
										
											2012-12-11 19:42:12 +00:00
										 |  |  |     if @custom_field.save | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |       flash[:notice] = l(:notice_successful_create) | 
					
						
							| 
									
										
										
										
											2009-03-21 00:22:59 +00:00
										 |  |  |       call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field) | 
					
						
							| 
									
										
										
										
											2015-10-25 08:37:54 +00:00
										 |  |  |       redirect_to edit_custom_field_path(@custom_field) | 
					
						
							| 
									
										
										
										
											2011-05-01 23:15:03 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2011-12-09 22:58:30 +00:00
										 |  |  |       render :action => 'new' | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def edit | 
					
						
							| 
									
										
										
										
											2011-12-09 22:58:30 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def update | 
					
						
							| 
									
										
										
										
											2016-07-17 07:15:25 +00:00
										 |  |  |     @custom_field.safe_attributes = params[:custom_field] | 
					
						
							|  |  |  |     if @custom_field.save | 
					
						
							| 
									
										
										
										
											2009-03-21 00:22:59 +00:00
										 |  |  |       call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field) | 
					
						
							| 
									
										
										
										
											2016-04-17 07:40:39 +00:00
										 |  |  |       respond_to do |format| | 
					
						
							|  |  |  |         format.html { | 
					
						
							|  |  |  |           flash[:notice] = l(:notice_successful_update) | 
					
						
							|  |  |  |           redirect_back_or_default edit_custom_field_path(@custom_field) | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-07-17 06:35:28 +00:00
										 |  |  |         format.js { head 200 } | 
					
						
							| 
									
										
										
										
											2016-04-17 07:40:39 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2011-05-01 23:15:03 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2016-04-17 07:40:39 +00:00
										 |  |  |       respond_to do |format| | 
					
						
							|  |  |  |         format.html { render :action => 'edit' } | 
					
						
							| 
									
										
										
										
											2016-07-17 06:35:28 +00:00
										 |  |  |         format.js { head 422 } | 
					
						
							| 
									
										
										
										
											2016-04-17 07:40:39 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:11:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |   def destroy | 
					
						
							| 
									
										
										
										
											2012-12-11 19:42:12 +00:00
										 |  |  |     begin | 
					
						
							|  |  |  |       @custom_field.destroy | 
					
						
							|  |  |  |     rescue | 
					
						
							|  |  |  |       flash[:error] = l(:error_can_not_delete_custom_field) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-12-11 17:51:30 +00:00
										 |  |  |     redirect_to custom_fields_path(:tab => @custom_field.class.name) | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-12-09 22:58:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def build_new_custom_field | 
					
						
							| 
									
										
										
										
											2016-07-17 07:15:25 +00:00
										 |  |  |     @custom_field = CustomField.new_subclass_instance(params[:type]) | 
					
						
							| 
									
										
										
										
											2011-12-09 22:58:30 +00:00
										 |  |  |     if @custom_field.nil? | 
					
						
							| 
									
										
										
										
											2014-02-07 07:57:59 +00:00
										 |  |  |       render :action => 'select_type' | 
					
						
							| 
									
										
										
										
											2016-07-17 07:15:25 +00:00
										 |  |  |     else | 
					
						
							|  |  |  |       @custom_field.safe_attributes = params[:custom_field] | 
					
						
							| 
									
										
										
										
											2011-12-09 22:58:30 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def find_custom_field | 
					
						
							|  |  |  |     @custom_field = CustomField.find(params[:id]) | 
					
						
							|  |  |  |   rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |     render_404 | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  | end |