Added position on Enumeration model.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@800 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
479b9b5433
commit
c216ab325b
|
@ -59,6 +59,21 @@ class EnumerationsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def move
|
||||||
|
@enumeration = Enumeration.find(params[:id])
|
||||||
|
case params[:position]
|
||||||
|
when 'highest'
|
||||||
|
@enumeration.move_to_top
|
||||||
|
when 'higher'
|
||||||
|
@enumeration.move_higher
|
||||||
|
when 'lower'
|
||||||
|
@enumeration.move_lower
|
||||||
|
when 'lowest'
|
||||||
|
@enumeration.move_to_bottom
|
||||||
|
end if params[:position]
|
||||||
|
redirect_to :action => 'index'
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
Enumeration.find(params[:id]).destroy
|
Enumeration.find(params[:id]).destroy
|
||||||
flash[:notice] = l(:notice_successful_delete)
|
flash[:notice] = l(:notice_successful_delete)
|
||||||
|
|
|
@ -16,27 +16,33 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class Enumeration < ActiveRecord::Base
|
class Enumeration < ActiveRecord::Base
|
||||||
|
acts_as_list :scope => 'opt = \'#{opt}\''
|
||||||
|
|
||||||
before_destroy :check_integrity
|
before_destroy :check_integrity
|
||||||
|
|
||||||
validates_presence_of :opt, :name
|
validates_presence_of :opt, :name
|
||||||
validates_uniqueness_of :name, :scope => [:opt]
|
validates_uniqueness_of :name, :scope => [:opt]
|
||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
validates_format_of :name, :with => /^[\w\s\'\-]*$/i
|
validates_format_of :name, :with => /^[\w\s\'\-]*$/i
|
||||||
|
|
||||||
OPTIONS = {
|
OPTIONS = {
|
||||||
"IPRI" => :enumeration_issue_priorities,
|
"IPRI" => :enumeration_issue_priorities,
|
||||||
"DCAT" => :enumeration_doc_categories,
|
"DCAT" => :enumeration_doc_categories,
|
||||||
"ACTI" => :enumeration_activities
|
"ACTI" => :enumeration_activities
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
def self.get_values(option)
|
def self.get_values(option)
|
||||||
find(:all, :conditions => ['opt=?', option])
|
find(:all, :conditions => {:opt => option}, :order => 'position')
|
||||||
end
|
end
|
||||||
|
|
||||||
def option_name
|
def option_name
|
||||||
OPTIONS[self.opt]
|
OPTIONS[self.opt]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#def <=>(enumeration)
|
||||||
|
# position <=> enumeration.position
|
||||||
|
#end
|
||||||
|
|
||||||
def to_s; name end
|
def to_s; name end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -1,19 +1,25 @@
|
||||||
<h2><%=l(:label_enumerations)%></h2>
|
<h2><%=l(:label_enumerations)%></h2>
|
||||||
|
|
||||||
<% Enumeration::OPTIONS.each do |option, name| %>
|
|
||||||
|
|
||||||
<% if params[:opt]==option %>
|
<% Enumeration::OPTIONS.each do |option, name| %>
|
||||||
|
<h3><%= l(name) %></h3>
|
||||||
<h3><%= l(name) %></h3>
|
|
||||||
<ul>
|
<% enumerations = Enumeration.get_values(option) %>
|
||||||
<% for value in Enumeration.find(:all, :conditions => ["opt = ?", option]) %>
|
<% if enumerations.any? %>
|
||||||
<li><%= link_to value.name, :action => 'edit', :id => value %></li>
|
<table class="list">
|
||||||
<% end %>
|
<% enumerations.each do |enumeration| %>
|
||||||
</ul>
|
<tr class="<%= cycle('odd', 'even') %>">
|
||||||
<p><%= link_to l(:label_enumeration_new), { :action => 'new', :opt => option }, :class => "icon icon-add" %></p>
|
<td><%= link_to enumeration.name, :action => 'edit', :id => enumeration %></td>
|
||||||
|
<td style="width:15%;">
|
||||||
<% else %>
|
<%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:action => 'move', :id => enumeration, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %>
|
||||||
<h3><%= link_to l(name), :opt => option %></h3>
|
<%= link_to image_tag('1uparrow.png', :alt => l(:label_sort_higher)), {:action => 'move', :id => enumeration, :position => 'higher'}, :method => :post, :title => l(:label_sort_higher) %> -
|
||||||
<% end %>
|
<%= link_to image_tag('1downarrow.png', :alt => l(:label_sort_lower)), {:action => 'move', :id => enumeration, :position => 'lower'}, :method => :post, :title => l(:label_sort_lower) %>
|
||||||
|
<%= link_to image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), {:action => 'move', :id => enumeration, :position => 'lowest'}, :method => :post, :title => l(:label_sort_lowest) %>
|
||||||
<% end %>
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
<% reset_cycle %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<p><%= link_to l(:label_enumeration_new), { :action => 'new', :opt => option } %></p>
|
||||||
|
<% end %>
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
class AddEnumerationsPosition < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
add_column :enumerations, :position, :integer, :default => 1, :null => false
|
||||||
|
Enumeration.find(:all).group_by(&:opt).each_value do |enums|
|
||||||
|
enums.each_with_index {|enum, i| enum.update_attribute(:position, i+1)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
remove_column :enumerations, :position
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue