Mercurial > hg > soundsoftware-site
comparison .svn/pristine/e2/e2ef5bc95f9f13036764408192b2e2ad22d7c3aa.svn-base @ 1296:038ba2d95de8 redmine-2.2
Fix redmine-2.2 branch update (add missing svn files)
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:05:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1294:3e4c3460b6ca | 1296:038ba2d95de8 |
---|---|
1 module CollectiveIdea #:nodoc: | |
2 module Acts #:nodoc: | |
3 module NestedSet #:nodoc: | |
4 # This module provides some helpers for the model classes using acts_as_nested_set. | |
5 # It is included by default in all views. | |
6 # | |
7 module Helper | |
8 # Returns options for select. | |
9 # You can exclude some items from the tree. | |
10 # You can pass a block receiving an item and returning the string displayed in the select. | |
11 # | |
12 # == Params | |
13 # * +class_or_item+ - Class name or top level times | |
14 # * +mover+ - The item that is being move, used to exlude impossible moves | |
15 # * +&block+ - a block that will be used to display: { |item| ... item.name } | |
16 # | |
17 # == Usage | |
18 # | |
19 # <%= f.select :parent_id, nested_set_options(Category, @category) {|i| | |
20 # "#{'–' * i.level} #{i.name}" | |
21 # }) %> | |
22 # | |
23 def nested_set_options(class_or_item, mover = nil) | |
24 if class_or_item.is_a? Array | |
25 items = class_or_item.reject { |e| !e.root? } | |
26 else | |
27 class_or_item = class_or_item.roots if class_or_item.is_a?(Class) | |
28 items = Array(class_or_item) | |
29 end | |
30 result = [] | |
31 items.each do |root| | |
32 result += root.self_and_descendants.map do |i| | |
33 if mover.nil? || mover.new_record? || mover.move_possible?(i) | |
34 [yield(i), i.id] | |
35 end | |
36 end.compact | |
37 end | |
38 result | |
39 end | |
40 | |
41 end | |
42 end | |
43 end | |
44 end |