sortable_nested_set 0.1.23

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,3 @@
1
+ To copy support files (images, stylesheets, javascript, etc.), run:
2
+
3
+ rake sortable_nested_set:sync
@@ -0,0 +1,34 @@
1
+ require "awesome_nested_set/helper"
2
+ include CollectiveIdea::Acts::NestedSet::Helper
3
+
4
+ module SortableNestedSetHelper
5
+ def sortable_nested_set_tree(class_or_category)
6
+ if class_or_category.is_a?(Class)
7
+ @category_class = class_or_category
8
+ @categories = class_or_category.all(:include => class_or_category.sns_items_type)
9
+ else
10
+ @category_class = class_or_category.class
11
+ @categories = class_or_category.self_and_descendants_with_items
12
+ @root = class_or_category
13
+ end
14
+
15
+ @sortable_ids = @categories.collect(&:id)
16
+
17
+ render('sortable_nested_set/tree',
18
+ :category_class => @category_class,
19
+ :categories => @categories,
20
+ :sortable_ids => @sortable_ids,
21
+ :root => @root)
22
+ end
23
+
24
+ def sns_lineage(category, options=Hash.new)
25
+ content_tag(:p, category.lineage(options).collect { |a| link_to(a.name, a) }
26
+ .join(image_tag('folder_closed.png', :class => :descent)).html_safe)
27
+ end
28
+
29
+ def sns_options(class_or_category, mover=nil)
30
+ nested_set_options(class_or_category, mover) { |category| "#{'.' * category.level} #{category.name}" }
31
+ end
32
+ end
33
+
34
+ ActionView::Base.send(:include, SortableNestedSetHelper)
@@ -0,0 +1,27 @@
1
+ <% cpath = category.class.name.underscore + '_path' %>
2
+
3
+ <%= render 'sortable_nested_set/toggle',
4
+ :category_type => category.class.name.underscore,
5
+ :id => category.id,
6
+ :state => 'open' %>
7
+
8
+ <%= content_tag :span, category, :class => :handle %>
9
+
10
+ <%= content_tag :span, link_to('-', category), :id => "toggle_actions_category_#{category.id}", :class => :mega %>
11
+
12
+ <%= content_tag :div, :id => "actions_category_#{category.id}", :class => :links do %>
13
+ <%= link_to_unless_current 'show', category %> |
14
+ <%= link_to 'edit', send("edit_#{cpath}", category) %> |
15
+ <%= link_to 'remove',
16
+ send("sns_destroy_category_#{cpath}", category),
17
+ :confirm => 'Are you sure?',
18
+ :method => :delete,
19
+ :remote => true %> |
20
+ <%= link_to 'add subcategory', send("sns_add_subcategory_#{cpath}", category) %> |
21
+ <%= link_to 'add item', send("sns_add_item_#{cpath}", category) %>
22
+ <% end %>
23
+
24
+ <%= content_tag :div, :id => "items_#{category.id}", :class => :items do %>
25
+ <%= render :partial => 'sortable_nested_set/item',
26
+ :collection => category.sns_items %>
27
+ <% end %>
@@ -0,0 +1,12 @@
1
+ <%= content_tag :div, :id => "item_#{item.id}", :class => :item do %>
2
+ <%= content_tag :span, item, :class => :handle %>
3
+
4
+ <%= content_tag :span, link_to('-', item), :id => "toggle_actions_item_#{item.id}", :class => :mega %>
5
+
6
+ <%= content_tag :div, :id => "actions_item_#{item.id}", :class => :links do %>
7
+ <%= link_to 'show', item %> |
8
+ <%= link_to 'edit', send("edit_#{item.class.name.underscore}_path", item) %> |
9
+ <%= link_to 'remove', send("sns_destroy_item_#{item.class.name.underscore}_path", item), :confirm => 'Are you sure?', :method => :delete, :remote => true %>
10
+ <% end %>
11
+ <% end %>
12
+
@@ -0,0 +1,5 @@
1
+ <%= content_tag :span, :id => "toggle_#{id}", :class => :toggle do %>
2
+ <%= link_to image_tag("folder_#{state}.png"),
3
+ send("sns_toggle_#{category_type}_path", id, :category_type => category_type, :state => state),
4
+ :remote => true %>
5
+ <% end %>
@@ -0,0 +1,44 @@
1
+ <%= content_tag :ul, :id => :menu, :class => :menu_links do %>
2
+ <%= content_tag :li, nil, :class => :placeholder unless local_assigns[:root] %>
3
+
4
+ <% prev_level = -1 %>
5
+
6
+ <% category_class.each_with_level(categories) do |category, level| %>
7
+ <%=raw '</ul></li>' if level <= prev_level %>
8
+ <%=raw '</ul>' * (prev_level - level) if level < prev_level %>
9
+
10
+ <li id="category_<%= category.id %>" class="category">
11
+ <%= render :partial => 'sortable_nested_set/category', :object => category %>
12
+
13
+ <ul id="subcategories_<%= category.id %>" class="sub_menu_links">
14
+ <%= content_tag :li, :class => :placeholder do %>
15
+ <%= content_tag :span, nil, :class => :handle %>
16
+ <% end %>
17
+
18
+ <% prev_level = level %>
19
+ <% end %>
20
+
21
+ <%=raw '</ul></li>' if prev_level != -1 %>
22
+ <% end %>
23
+
24
+ <% unless categories.empty? %>
25
+ <% for category_id in sortable_ids %>
26
+ <%= sortable_element_reporting_target "items_#{category_id}",
27
+ :moved,
28
+ :containment => sortable_ids.collect { |cid| "items_#{cid}" },
29
+ :dropOnEmpty => true,
30
+ :method => :put,
31
+ :tag => :div,
32
+ :url => sns_sort_items_categories_path %>
33
+ <% end %>
34
+
35
+ <%= sortable_element_reporting_target :menu,
36
+ :moved,
37
+ :ghosting => true,
38
+ :handle => :handle,
39
+ :hoverclass => "'hovered'",
40
+ :method => :put,
41
+ :only => [ :category, :placeholder ],
42
+ :tree => true,
43
+ :url => sns_sort_categories_categories_path(:root => root) %>
44
+ <% end %>
Binary file
Binary file
Binary file