Permalink
Browse files

renamed

  • Loading branch information...
1 parent edcdfb1 commit 5e326a258b7025ba65625bd4b283e2b5a9ff7a3e @dalpo committed Sep 19, 2012
View
@@ -1,3 +1,3 @@
-= RailsAdminAncestry
+= RailsAdminNestable
-This project rocks and uses MIT-LICENSE.
+This project rocks and uses MIT-LICENSE.
View
@@ -14,7 +14,7 @@ end
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'RailsAdminAncestry'
+ rdoc.title = 'RailsAdminNestable'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
@@ -1,4 +0,0 @@
-//= require jquery.nestable.js
-//= require_self
-
-$('#tree_nodes').nestable()
@@ -0,0 +1,26 @@
+//= require jquery.nestable.js
+//= require_self
+
+$(document).ready ->
+ $tree_nodes = $('#tree_nodes')
+ $tree_nodes_options = {}
+ $tree_nodes_max_depth = $tree_nodes.data('max-depth')
+
+ if $tree_nodes_max_depth && $tree_nodes_max_depth != 'false'
+ $tree_nodes_options['maxDepth'] = $tree_nodes_max_depth
+
+ $tree_nodes
+ .nestable( $tree_nodes_options )
+ .on
+ change: (event) ->
+ $this = $(this)
+ serialized_tree = $this.nestable('serialize')
+
+ $.ajax
+ url: $this.data('update-path'),
+ type: 'POST',
+ data: tree_nodes: serialized_tree,
+ complete: (event, XMLHttpRequest, ajaxOptions) ->
+ console.dir event
+ console.dir XMLHttpRequest
+ console.dir ajaxOptions
@@ -1,5 +1,5 @@
module RailsAdmin
- module AncestryHelper
+ module NestableHelper
def nested_tree_nodes(tree_nodes)
tree_nodes.map do |tree_node, sub_tree_nodes|
@@ -25,5 +25,9 @@ def action_links(model)
end
end
+ def tree_max_depth
+ ::RailsAdmin::Config.model(@abstract_model.model).nestable_max_depth || 'false'
+ end
+
end
end
@@ -1,9 +0,0 @@
-
-.row-fluid
- .span12
- #tree_nodes.dd
- = nested_tree_nodes @tree_nodes
-
-
-= stylesheet_link_tag 'rails_admin/rails_admin_ancestry'
-= javascript_include_tag 'rails_admin/rails_admin_ancestry'
@@ -0,0 +1,9 @@
+
+.row-fluid
+ .span12
+ #tree_nodes.dd{:'data-update-path' => nestable_path(model_name: @abstract_model), :'data-max-depth' => tree_max_depth}
+ = nested_tree_nodes @tree_nodes
+
+
+= stylesheet_link_tag 'rails_admin/rails_admin_nestable'
+= javascript_include_tag 'rails_admin/rails_admin_nestable'
@@ -1,11 +0,0 @@
-
-en:
- admin:
- actions:
- ancestry:
- title: "Ancestry"
- menu: "Ancestry for %{model_label} '%{object_label}'"
- breadcrumb: "Ancestry"
- link: "Ancestry"
- bulk_link: "Ancestry selected %{model_label_plural}"
- done: "Ancestryed"
@@ -0,0 +1,10 @@
+en:
+ admin:
+ actions:
+ nestable:
+ title: "Sorting"
+ menu: "Sorting for %{model_label}"
+ breadcrumb: "Sorting"
+ link: "Sorting"
+ bulk_link: "Sort selected %{model_label_plural}"
+ done: "Sorted"
@@ -1,7 +1,7 @@
it:
admin:
actions:
- ancestry:
+ nestable:
title: "Ordinamento"
menu: "Ordinamento %{model_label}"
breadcrumb: "Ordinamento"
@@ -1,42 +0,0 @@
-require "rails_admin_ancestry/engine"
-
-module RailsAdminAncestry
-end
-
-require 'rails_admin/config/actions'
-
-module RailsAdmin
- module Config
- module Actions
- class Ancestry < Base
- RailsAdmin::Config::Actions.register(self)
-
- # Is the action acting on the root level (Example: /admin/contact)
- register_instance_option :root? do
- false
- end
-
- register_instance_option :collection? do
- true
- end
-
- # Is the action on an object scope (Example: /admin/team/1/edit)
- register_instance_option :member? do
- false
- end
-
- register_instance_option :controller do
- Proc.new do
- @tree_nodes = @abstract_model.all.arrange
- render :action => @action.template_name
- end
- end
-
- register_instance_option :link_icon do
- 'icon-align-left'
- end
- end
- end
- end
-end
-
@@ -1,3 +0,0 @@
-module RailsAdminAncestry
- VERSION = "0.0.1"
-end
@@ -0,0 +1,84 @@
+require "rails_admin_Nestable/engine"
+
+module RailsAdminNestable
+end
+
+require 'rails_admin/config/actions'
+require 'rails_admin/config/model'
+
+module RailsAdmin
+ module Config
+ module Actions
+ class Nestable < Base
+ RailsAdmin::Config::Actions.register(self)
+
+ # Is the action acting on the root level (Example: /admin/contact)
+ register_instance_option :root? do
+ false
+ end
+
+ register_instance_option :collection? do
+ true
+ end
+
+ # Is the action on an object scope (Example: /admin/team/1/edit)
+ register_instance_option :member? do
+ false
+ end
+
+ register_instance_option :controller do
+ Proc.new do
+ def update_recoursively(tree_nodes, parent_node = nil)
+ tree_nodes.each do |key, value|
+ model = @abstract_model.model.find(value['id'])
+ model.parent = parent_node if parent_node.present?
+
+ if ::RailsAdmin::Config.model(@abstract_model.model).nestable_position_field
+ model.send("#{::RailsAdmin::Config.model(@abstract_model.model).nestable_position_field}=", (key.to_i + 1))
+ end
+
+ model.save!(validate: false)
+
+ if value.has_key?('children')
+ update_recoursively(value['children'], model)
+ end
+ end
+ end
+
+ if params['tree_nodes'].present?
+ update_recoursively params[:tree_nodes]
+ render text: 'done'
+ else
+ @tree_nodes = @abstract_model.model.arrange(order: ::RailsAdmin::Config.model(@abstract_model.model).nestable_position_field)
+ render action: @action.template_name
+ end
+ end
+ end
+
+ register_instance_option :link_icon do
+ 'icon-align-left'
+ end
+
+ register_instance_option :http_methods do
+ [:get, :post]
+ end
+ end
+ end
+ end
+end
+
+module RailsAdmin
+ module Config
+ class Model
+
+ register_instance_option :nestable_position_field do
+ nil
+ end
+
+ register_instance_option :nestable_max_depth do
+ nil
+ end
+
+ end
+ end
+end
@@ -1,4 +1,4 @@
-module RailsAdminAncestry
+module RailsAdminNestable
class Engine < ::Rails::Engine
end
end
@@ -0,0 +1,3 @@
+module RailsAdminNestable
+ VERSION = "0.0.1"
+end
@@ -1,17 +1,17 @@
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
-require "rails_admin_ancestry/version"
+require "rails_admin_nestable/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
- s.name = "rails_admin_ancestry"
- s.version = RailsAdminAncestry::VERSION
+ s.name = "rails_admin_nestable"
+ s.version = RailsAdminNestable::VERSION
s.authors = ["TODO: Your name"]
s.email = ["TODO: Your email"]
s.homepage = "TODO"
- s.summary = "TODO: Summary of RailsAdminAncestry."
- s.description = "TODO: Description of RailsAdminAncestry."
+ s.summary = "TODO: Summary of RailsAdminNestable."
+ s.description = "TODO: Description of RailsAdminNestable."
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]

0 comments on commit 5e326a2

Please sign in to comment.