summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/custom_fields_controller.rb3
-rw-r--r--app/models/custom_field.rb20
-rw-r--r--app/views/custom_fields/_index.html.erb1
-rw-r--r--app/views/custom_fields/new.html.erb1
4 files changed, 25 insertions, 0 deletions
diff --git a/app/controllers/custom_fields_controller.rb b/app/controllers/custom_fields_controller.rb
index 893bc4819..41a41ebe9 100644
--- a/app/controllers/custom_fields_controller.rb
+++ b/app/controllers/custom_fields_controller.rb
@@ -98,6 +98,9 @@ class CustomFieldsController < ApplicationController
if @custom_field.nil?
render :action => 'select_type'
else
+ if params[:copy].present? && (@copy_from = CustomField.find_by(id: params[:copy]))
+ @custom_field.copy_from(@copy_from)
+ end
@custom_field.safe_attributes = params[:custom_field]
end
end
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index e0ea10cc8..816a52fb8 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -102,6 +102,26 @@ class CustomField < ActiveRecord::Base
'extensions_allowed',
'full_width_layout')
+ def copy_from(arg, options={})
+ return if arg.blank?
+
+ custom_field = arg.is_a?(CustomField) ? arg : CustomField.find_by(id: arg.to_s)
+ self.attributes = custom_field.attributes.dup.except('id', 'name', 'position')
+ custom_field.enumerations.each do |e|
+ new_enumeration = self.enumerations.build
+ new_enumeration.attributes = e.attributes.except('id')
+ end
+ self.default_value = nil if custom_field.enumerations.any?
+ if %w(IssueCustomField TimeEntryCustomField ProjectCustomField VersionCustomField).include?(self.class.name)
+ self.role_ids = custom_field.role_ids.dup
+ end
+ if self.is_a?(IssueCustomField)
+ self.tracker_ids = custom_field.tracker_ids.dup
+ self.project_ids = custom_field.project_ids.dup
+ end
+ self
+ end
+
def format
@format ||= Redmine::FieldFormat.find(field_format)
end
diff --git a/app/views/custom_fields/_index.html.erb b/app/views/custom_fields/_index.html.erb
index 04d4aa21d..81fe21404 100644
--- a/app/views/custom_fields/_index.html.erb
+++ b/app/views/custom_fields/_index.html.erb
@@ -22,6 +22,7 @@
<% end %>
<td class="buttons">
<%= reorder_handle(custom_field, :url => custom_field_path(custom_field), :param => 'custom_field') %>
+ <%= link_to_function l(:button_copy), "location.href = '#{new_custom_field_path(:copy => custom_field)}&type=' + encodeURIComponent(($('.tabs a.selected').attr('id')||'').split('tab-').pop())", :class => 'icon icon-copy' %>
<%= delete_link custom_field_path(custom_field) %>
</td>
</tr>
diff --git a/app/views/custom_fields/new.html.erb b/app/views/custom_fields/new.html.erb
index db422296b..45b5cc0cf 100644
--- a/app/views/custom_fields/new.html.erb
+++ b/app/views/custom_fields/new.html.erb
@@ -3,6 +3,7 @@
<%= labelled_form_for :custom_field, @custom_field, :url => custom_fields_path, :html => {:id => 'custom_field_form'} do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= hidden_field_tag 'type', @custom_field.type %>
+<%= hidden_field_tag 'copy', @copy_from.id if @copy_from %>
<% end %>
<%= javascript_tag do %>