Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

some updates to SortedHierarchy

  • Loading branch information...
commit 0484a5c5ceebf7e2689a72a514c6cd572fb15779 1 parent 5872bbc
@khustochka authored
View
2  app/controllers/taxonomy/taxa_controller.rb
@@ -126,7 +126,7 @@ def rescue_invalid_record
respond_to do |format|
find_all_siblings_and_parents
# TODO: maybe move nil or illegal sort transformation to valid last one into Sorted Hierarchy callback like before_validation ?
- @taxon.sort = (@siblings.size + 1) if !@taxon[model_class.parent_key].nil? && (@taxon.sort.nil? || @taxon.changed.include?(model_class.parent_key.to_s))
+# @taxon.sort = (@siblings.size + 1) if !@taxon[model_class.parent_key].nil? && (@taxon.sort.nil? || @taxon.changed.include?(model_class.parent_key.to_s))
format.html { render 'taxa/add_edit' }
#format.xml { render :xml => @taxon.errors, :status => :unprocessable_entity }
end
View
2  lib/rails_ext/action_view/helpers.rb
@@ -3,7 +3,7 @@ module ActionView::Helpers
class FormBuilder
def set_sorting_combo(bunch, one, &block)
- select( :sort, [["At the beginning", 1]] + (bunch - [one]).map {|tx| [block_given? ? (yield tx) : "sort number: #{tx[:sort]}", tx[:sort] + (tx[:sort] < one[:sort] ? 1 : 0)]} )
+ select( :sort, [["At the beginning", 1]] + (bunch - [one]).map {|tx| [block_given? ? (yield tx) : "sort number: #{tx[:sort]}", tx[:sort] + (one.new_record? || tx[:sort] < one[:sort] ? 1 : 0)]} )
end
alias :original_method_missing :method_missing
View
2  lib/sorted_hierarchy/active_record.rb
@@ -112,7 +112,7 @@ def correctness_of_sort_value
def give_way_to_create
latest = siblings_count + 1
- self[get_sort_column] = latest if self[get_sort_column].nil? || self.changed.include?(parent_key.to_s)
+ self[get_sort_column] = latest if self[get_sort_column].nil? #|| self.changed.include?(parent_key.to_s)
if self[get_sort_column] < latest
siblings_scope.update_all("#{get_sort_column} = #{get_sort_column} + 1", "#{get_sort_column} >= #{self[get_sort_column]}")
end
Please sign in to comment.
Something went wrong with that request. Please try again.