Resourcified custom fields.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8144 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang committed 2011-12-09 22:58:30 +00:00
1 parent 877fbc15da
commit b127f9157d
10 files changed
+108 -28

No files matched your search

+26 -12
View File
@@ -19,6 +19,8 @@ class CustomFieldsController < ApplicationController
layout 'admin'
before_filter :require_admin
before_filter :build_new_custom_field, :only => [:new, :create]
before_filter :find_custom_field, :only => [:edit, :update, :destroy]
def index
@custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name }
@@ -26,39 +28,51 @@ class CustomFieldsController < ApplicationController
end
def new
@custom_field = begin
if params[:type].to_s.match(/.+CustomField$/)
params[:type].to_s.constantize.new(params[:custom_field])
end
rescue
end
(redirect_to(:action => 'index'); return) unless @custom_field.is_a?(CustomField)
end
def create
if request.post? and @custom_field.save
flash[:notice] = l(:notice_successful_create)
call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
redirect_to :action => 'index', :tab => @custom_field.class.name
else
@trackers = Tracker.find(:all, :order => 'position')
render :action => 'new'
end
end
def edit
@custom_field = CustomField.find(params[:id])
if request.post? and @custom_field.update_attributes(params[:custom_field])
end
def update
if request.put? and @custom_field.update_attributes(params[:custom_field])
flash[:notice] = l(:notice_successful_update)
call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
redirect_to :action => 'index', :tab => @custom_field.class.name
else
@trackers = Tracker.find(:all, :order => 'position')
render :action => 'edit'
end
end
def destroy
@custom_field = CustomField.find(params[:id]).destroy
@custom_field.destroy
redirect_to :action => 'index', :tab => @custom_field.class.name
rescue
flash[:error] = l(:error_can_not_delete_custom_field)
redirect_to :action => 'index'
end
private
def build_new_custom_field
@custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field])
if @custom_field.nil?
render_404
end
end
def find_custom_field
@custom_field = CustomField.find(params[:id])
rescue ActiveRecord::RecordNotFound
render_404
end
end
+16
View File
@@ -155,6 +155,22 @@ class CustomField < ActiveRecord::Base
find(:all, :conditions => ["is_for_all=?", true], :order => 'position')
end
# Returns an instance of the given subclass name
def self.new_subclass_instance(class_name, *args)
klass = nil
begin
klass = class_name.to_s.classify.constantize
rescue
# invalid class name
end
unless subclasses.include? klass
klass = nil
end
if klass
klass.new(*args)
end
end
def type_name
nil
end
+1 -1
View File
@@ -81,7 +81,7 @@ function toggle_custom_field_format() {
when "IssueCustomField" %>
<fieldset><legend><%=l(:label_tracker_plural)%></legend>
<% for tracker in @trackers %>
<% Tracker.all.each do |tracker| %>
<%= check_box_tag "custom_field[tracker_ids][]",
tracker.id,
(@custom_field.trackers.include? tracker),
+4 -4
View File
@@ -13,7 +13,7 @@
<tbody>
<% (@custom_fields_by_type[tab[:name]] || []).sort.each do |custom_field| -%>
<tr class="<%= cycle("odd", "even") %>">
<td><%= link_to h(custom_field.name), :action => 'edit', :id => custom_field %></td>
<td><%= link_to h(custom_field.name), edit_custom_field_path(custom_field) %></td>
<td align="center"><%= l(Redmine::CustomFieldFormat.label_for(custom_field.field_format)) %></td>
<td align="center"><%= checked_image custom_field.is_required? %></td>
<% if tab[:name] == 'IssueCustomField' %>
@@ -22,8 +22,8 @@
<% end %>
<td align="center" style="width:15%;"><%= reorder_links('custom_field', {:action => 'edit', :id => custom_field}) %></td>
<td class="buttons">
<%= link_to(l(:button_delete), { :action => 'destroy', :id => custom_field },
:method => :post,
<%= link_to(l(:button_delete), custom_field_path(custom_field),
:method => :delete,
:confirm => l(:text_are_you_sure),
:class => 'icon icon-del') %>
</td>
@@ -32,4 +32,4 @@
</tbody>
</table>
<p><%= link_to l(:label_custom_field_new), {:action => 'new', :type => tab[:name]}, :class => 'icon icon-add' %></p>
<p><%= link_to l(:label_custom_field_new), new_custom_field_path(:type => tab[:name]), :class => 'icon icon-add' %></p>
+1 -1
View File
@@ -2,7 +2,7 @@
&#187; <%= link_to l(@custom_field.type_name), :controller => 'custom_fields', :action => 'index', :tab => @custom_field.class.name %>
&#187; <%=h @custom_field.name %></h2>
<% labelled_form_for :custom_field, @custom_field, :url => { :action => "edit", :id => @custom_field } do |f| %>
<% labelled_form_for :custom_field, @custom_field, :url => custom_field_path(@custom_field), :html => {:method => :put} do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
<% end %>
+1 -1
View File
@@ -2,7 +2,7 @@
&#187; <%= link_to l(@custom_field.type_name), :controller => 'custom_fields', :action => 'index', :tab => @custom_field.class.name %>
&#187; <%= l(:label_custom_field_new) %></h2>
<% labelled_form_for :custom_field, @custom_field, :url => { :action => "new" } do |f| %>
<% labelled_form_for :custom_field, @custom_field, :url => custom_fields_path do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= hidden_field_tag 'type', @custom_field.type %>
<%= submit_tag l(:button_save) %>