Anonymous avatar Anonymous committed fca2493

Clean up custom field format definition.

Comments (0)

Files changed (2)

 Redmine::Scm::Base.add "Filesystem"
 
 Redmine::CustomFieldFormat.map do |fields|
-  fields.register Redmine::CustomFieldFormat.new('string', :label => :label_string, :order => 1)
-  fields.register Redmine::CustomFieldFormat.new('text', :label => :label_text, :order => 2)
-  fields.register Redmine::CustomFieldFormat.new('int', :label => :label_integer, :order => 3)
-  fields.register Redmine::CustomFieldFormat.new('float', :label => :label_float, :order => 4)
-  fields.register Redmine::CustomFieldFormat.new('list', :label => :label_list, :order => 5)
-  fields.register Redmine::CustomFieldFormat.new('date', :label => :label_date, :order => 6)
-  fields.register Redmine::CustomFieldFormat.new('bool', :label => :label_boolean, :order => 7)
-  fields.register Redmine::CustomFieldFormat.new('user', :label => :label_user, :only => %w(Issue TimeEntry Version Project), :edit_as => 'list', :order => 8)
-  fields.register Redmine::CustomFieldFormat.new('version', :label => :label_version, :only => %w(Issue TimeEntry Version Project), :edit_as => 'list', :order => 9)
+  fields.register 'string'
+  fields.register 'text'
+  fields.register 'int', :label => :label_integer
+  fields.register 'float'
+  fields.register 'list'
+  fields.register 'date'
+  fields.register 'bool', :label => :label_boolean
+  fields.register 'user', :only => %w(Issue TimeEntry Version Project), :edit_as => 'list'
+  fields.register 'version', :only => %w(Issue TimeEntry Version Project), :edit_as => 'list'
 end
 
 # Permissions

lib/redmine/custom_field_format.rb

 
     def initialize(name, options={})
       self.name = name
-      self.label = options[:label]
-      self.order = options[:order]
+      self.label = options[:label] || "label_#{name}".to_sym
+      self.order = options[:order] || self.class.available_formats.size
       self.edit_as = options[:edit_as] || name
       self.class_names = options[:only]
     end
       end
 
       # Registers a custom field format
-      def register(custom_field_format, options={})
+      def register(*args)
+        custom_field_format = args.first
+        unless custom_field_format.is_a?(Redmine::CustomFieldFormat)
+          custom_field_format = Redmine::CustomFieldFormat.new(*args)
+        end
         @@available[custom_field_format.name] = custom_field_format unless @@available.keys.include?(custom_field_format.name)
       end
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.