Resourcified enumerations.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8189 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -19,28 +19,19 @@ class EnumerationsController < ApplicationController
|
||||
layout 'admin'
|
||||
|
||||
before_filter :require_admin
|
||||
before_filter :build_new_enumeration, :only => [:new, :create]
|
||||
before_filter :find_enumeration, :only => [:edit, :update, :destroy]
|
||||
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
verify :method => :post, :only => [ :destroy, :create, :update ],
|
||||
:redirect_to => { :action => :index }
|
||||
|
||||
def new
|
||||
begin
|
||||
@enumeration = params[:type].constantize.new
|
||||
rescue NameError
|
||||
@enumeration = Enumeration.new
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@enumeration = Enumeration.new(params[:enumeration])
|
||||
@enumeration.type = params[:enumeration][:type]
|
||||
if @enumeration.save
|
||||
if request.post? && @enumeration.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to :action => 'index', :type => @enumeration.type
|
||||
else
|
||||
@@ -49,13 +40,10 @@ class EnumerationsController < ApplicationController
|
||||
end
|
||||
|
||||
def edit
|
||||
@enumeration = Enumeration.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@enumeration = Enumeration.find(params[:id])
|
||||
@enumeration.type = params[:enumeration][:type] if params[:enumeration][:type]
|
||||
if @enumeration.update_attributes(params[:enumeration])
|
||||
if request.put? && @enumeration.update_attributes(params[:enumeration])
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to :action => 'index', :type => @enumeration.type
|
||||
else
|
||||
@@ -63,8 +51,8 @@ class EnumerationsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
verify :method => :delete, :only => :destroy, :render => { :nothing => true, :status => :method_not_allowed }
|
||||
def destroy
|
||||
@enumeration = Enumeration.find(params[:id])
|
||||
if !@enumeration.in_use?
|
||||
# No associated objects
|
||||
@enumeration.destroy
|
||||
@@ -77,9 +65,22 @@ class EnumerationsController < ApplicationController
|
||||
return
|
||||
end
|
||||
end
|
||||
@enumerations = @enumeration.class.find(:all) - [@enumeration]
|
||||
#rescue
|
||||
# flash[:error] = 'Unable to delete enumeration'
|
||||
# redirect_to :action => 'index'
|
||||
@enumerations = @enumeration.class.all - [@enumeration]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_new_enumeration
|
||||
class_name = params[:enumeration] && params[:enumeration][:type] || params[:type]
|
||||
@enumeration = Enumeration.new_subclass_instance(class_name, params[:enumeration])
|
||||
if @enumeration.nil?
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
def find_enumeration
|
||||
@enumeration = Enumeration.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class Enumeration < ActiveRecord::Base
|
||||
include Redmine::SubclassFactory
|
||||
|
||||
default_scope :order => "#{Enumeration.table_name}.position ASC"
|
||||
|
||||
belongs_to :project
|
||||
@@ -27,6 +29,8 @@ class Enumeration < ActiveRecord::Base
|
||||
before_destroy :check_integrity
|
||||
before_save :check_default
|
||||
|
||||
attr_protected :type
|
||||
|
||||
validates_presence_of :name
|
||||
validates_uniqueness_of :name, :scope => [:type, :project_id]
|
||||
validates_length_of :name, :maximum => 30
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
<%= error_messages_for 'enumeration' %>
|
||||
<div class="box">
|
||||
<!--[form:optvalue]-->
|
||||
<%= hidden_field 'enumeration', 'type' %>
|
||||
|
||||
<p><label for="enumeration_name"><%=l(:field_name)%></label>
|
||||
<%= text_field 'enumeration', 'name' %></p>
|
||||
<div class="box tabular">
|
||||
<p><%= f.text_field :name %></p>
|
||||
<p><%= f.check_box :active %></p>
|
||||
<p><%= f.check_box :is_default %></p>
|
||||
|
||||
<p><label for="enumeration_active"><%=l(:field_active)%></label>
|
||||
<%= check_box 'enumeration', 'active' %></p>
|
||||
|
||||
<p><label for="enumeration_is_default"><%=l(:field_is_default)%></label>
|
||||
<%= check_box 'enumeration', 'is_default' %></p>
|
||||
<!--[eoform:optvalue]-->
|
||||
|
||||
<% @enumeration.custom_field_values.each do |value| %>
|
||||
<p><%= custom_field_tag_with_label :enumeration, value %></p>
|
||||
<% end %>
|
||||
<% @enumeration.custom_field_values.each do |value| %>
|
||||
<p><%= custom_field_tag_with_label :enumeration, value %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<h2><%= l(@enumeration.option_name) %>: <%=h @enumeration %></h2>
|
||||
|
||||
<% form_tag({}) do %>
|
||||
<% form_tag({}, :method => :delete) do %>
|
||||
<div class="box">
|
||||
<p><strong><%= l(:text_enumeration_destroy_question, @enumeration.objects_count) %></strong></p>
|
||||
<p><label for='reassign_to_id'><%= l(:text_enumeration_category_reassign_to) %></label>
|
||||
@@ -8,5 +8,5 @@
|
||||
</div>
|
||||
|
||||
<%= submit_tag l(:button_apply) %>
|
||||
<%= link_to l(:button_cancel), :controller => 'enumerations', :action => 'index' %>
|
||||
<%= link_to l(:button_cancel), enumerations_path %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<h2><%= link_to l(@enumeration.option_name), :controller => 'enumerations', :action => 'index' %> » <%=h @enumeration %></h2>
|
||||
<h2><%= link_to l(@enumeration.option_name), enumerations_path %> » <%=h @enumeration %></h2>
|
||||
|
||||
<% form_tag({:action => 'update', :id => @enumeration}, :class => "tabular") do %>
|
||||
<%= render :partial => 'form' %>
|
||||
<% labelled_form_for :enumeration, @enumeration, :url => enumeration_path(@enumeration), :html => {:method => :put} do |f| %>
|
||||
<%= render :partial => 'form', :locals => {:f => f} %>
|
||||
<%= submit_tag l(:button_save) %>
|
||||
<% end %>
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
</tr></thead>
|
||||
<% enumerations.each do |enumeration| %>
|
||||
<tr class="<%= cycle('odd', 'even') %>">
|
||||
<td><%= link_to h(enumeration), :action => 'edit', :id => enumeration %></td>
|
||||
<td><%= link_to h(enumeration), edit_enumeration_path(enumeration) %></td>
|
||||
<td class="center" style="width:15%;"><%= checked_image enumeration.is_default? %></td>
|
||||
<td class="center" style="width:15%;"><%= checked_image enumeration.active? %></td>
|
||||
<td style="width:15%;"><%= reorder_links('enumeration', {:action => 'update', :id => enumeration}) %></td>
|
||||
<td style="width:15%;"><%= reorder_links('enumeration', {:action => 'update', :id => enumeration}, :put) %></td>
|
||||
<td class="buttons">
|
||||
<%= link_to l(:button_delete), { :action => 'destroy', :id => enumeration },
|
||||
:method => :post,
|
||||
<%= link_to l(:button_delete), enumeration_path(enumeration),
|
||||
:method => :delete,
|
||||
:confirm => l(:text_are_you_sure),
|
||||
:class => 'icon icon-del' %>
|
||||
</td>
|
||||
@@ -31,7 +31,7 @@
|
||||
<% reset_cycle %>
|
||||
<% end %>
|
||||
|
||||
<p><%= link_to l(:label_enumeration_new), { :action => 'new', :type => klass.name } %></p>
|
||||
<p><%= link_to l(:label_enumeration_new), new_enumeration_path(:type => klass.name) %></p>
|
||||
<% end %>
|
||||
|
||||
<% html_title(l(:label_enumerations)) -%>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<h2><%= link_to l(@enumeration.option_name), :controller => 'enumerations', :action => 'index' %> » <%=l(:label_enumeration_new)%></h2>
|
||||
<h2><%= link_to l(@enumeration.option_name), enumerations_path %> » <%=l(:label_enumeration_new)%></h2>
|
||||
|
||||
<% form_tag({:action => 'create'}, :class => "tabular") do %>
|
||||
<%= render :partial => 'form' %>
|
||||
<% labelled_form_for :enumeration, @enumeration, :url => enumerations_path do |f| %>
|
||||
<%= f.hidden_field :type %>
|
||||
<%= render :partial => 'form', :locals => {:f => f} %>
|
||||
<%= submit_tag l(:button_create) %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user