jsort 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +32 -16
- data/VERSION +1 -1
- data/jsort.gemspec +67 -0
- data/lib/jsort.rb +23 -5
- metadata +14 -13
data/README.md
CHANGED
@@ -13,33 +13,49 @@ Usage
|
|
13
13
|
|
14
14
|
**Controller**
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
|
17
|
+
def sort
|
18
|
+
params[:ordered_items].each_with_index do |id,idx|
|
19
|
+
m = MyModel.find(id)
|
20
|
+
m.position = idx
|
21
|
+
m.save
|
22
|
+
end
|
23
|
+
render :nothing => true
|
24
|
+
end
|
25
|
+
|
25
26
|
|
26
27
|
**View** (HAML; obviously, will work with html.erb too)
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
|
30
|
+
- jsort(@my_items,'ordered_items', sort_my_controller_path) do |item|
|
31
|
+
= item.name
|
32
|
+
= link_to "[Edit]", edit_my_item_path(item)
|
33
|
+
|
34
|
+
_Parameters_
|
35
|
+
|
36
|
+
`jsort ITEMS, NAME, PATH, [OPTIONS]`
|
37
|
+
|
38
|
+
* *ITEMS* - a collection of items to sort. If an item provides a method/field positon, the items will be sorted
|
39
|
+
* *NAME* - The div-id of the list. This will be the key of `params[:NAME]` passed to the controller.
|
40
|
+
* *PATH* - path or url to the controller/action where the script will post to.
|
41
|
+
* *OPTIONS* - Opional you may provide the following options:
|
42
|
+
|
43
|
+
`:text => 'MOVE` - Will use this text as a drag-n-drop-handle instead of the image
|
44
|
+
`:image => 'yourimage.jpg'` - use your own image (place it in assets/images path of your application
|
45
|
+
`:handle_only => true` - Only the handle (image or text) can be used to drag&move. Default is 'false' which allows you to pick up by clicking anywhere on the line.
|
46
|
+
|
47
|
+
|
33
48
|
|
34
49
|
This will display an ordered list which is sortable by drag and drop.
|
35
|
-
The block passed to jsort will be used to format each line. If no block is
|
36
|
-
given item.to_s will be used to display the items.
|
50
|
+
The block passed to jsort will be used to format each line/item. If no block is
|
51
|
+
given `item.to_s` will be used to display the items.
|
37
52
|
|
38
53
|
|
39
54
|
Installation
|
40
55
|
------------
|
41
56
|
|
42
57
|
* Rails 3.1:
|
58
|
+
* Add `gem "jsort", "~> 0.0.1"` to your Gemfile
|
43
59
|
* Add this line to your application.js-template: `//= require jsort_sortable`
|
44
60
|
* Rails < 3.1:
|
45
61
|
* A generator will be provided soon. At the moment you have to copy the jsort_sortable.js to your javascript-directory and you have to include it in your layout manually.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/jsort.gemspec
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{jsort}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Andi Altendorfer"]
|
12
|
+
s.date = %q{2011-08-12}
|
13
|
+
s.description = %q{Write a controller-method to do the sort and call jsort-helper in your view.}
|
14
|
+
s.email = %q{andi@iboard.cc}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"jsort.gemspec",
|
28
|
+
"lib/generators/jsort/install/install_generator.rb",
|
29
|
+
"lib/jsort.rb",
|
30
|
+
"lib/jsort/rails.rb",
|
31
|
+
"lib/jsort/rails/engine.rb",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_jsort.rb",
|
34
|
+
"vendor/assets/images/sortable_vertical.png",
|
35
|
+
"vendor/assets/javascripts/jsort_sortable.js"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/iboard/jsort}
|
38
|
+
s.licenses = ["MIT"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.6.2}
|
41
|
+
s.summary = %q{sort lists with drag & drop without coding a single line of Javascript by yourself}
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_runtime_dependency(%q<jquery-rails>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
50
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
51
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<jquery-rails>, [">= 0"])
|
54
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
55
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
56
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
57
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<jquery-rails>, [">= 0"])
|
61
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
62
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
63
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
64
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
data/lib/jsort.rb
CHANGED
@@ -3,15 +3,31 @@ require "jsort/rails"
|
|
3
3
|
module ActionView
|
4
4
|
module Helpers
|
5
5
|
module FormHelper
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
# Renders an ordered list of items and register the javascript-call for drag-n-sort
|
10
|
+
#
|
11
|
+
# @param [Enumerate] items - The collection of items to sort
|
12
|
+
# @param [String] name - The name of the div-tag and key of the params for the controller
|
13
|
+
# @param [String] path - The path or url to post against (The sort-method in your controller)
|
14
|
+
# @param [Hash] options - Options used to format the lines of items
|
15
|
+
#
|
16
|
+
# Options:
|
17
|
+
# * `:text => 'click here to sort'` - Will use this text as a drag-n-drop-handle instead of the image
|
18
|
+
# * `:image => 'yourimage.jpg'` - use your own image (place it in assets/images path of your application
|
19
|
+
# * `:handle_only => true` - Only the handle (image or text) can be used to drag&move. Default is 'false' which allows you to pick up by clicking anywhere on the line.
|
20
|
+
# * `:div_type => ['table','tr','td'] or ['ol',nil,'li'], ....
|
6
21
|
def jsort(items,name,path,options={},&block)
|
7
22
|
|
8
23
|
defaults = {
|
9
24
|
:handle_only => false,
|
10
25
|
:image => 'sortable_vertical.png',
|
11
|
-
:text => nil
|
26
|
+
:text => nil,
|
27
|
+
:div_type => ['ol',nil,'li']
|
12
28
|
}
|
13
29
|
defaults.merge!(options)
|
14
|
-
concat("
|
30
|
+
concat("<#{defaults[:div_type][0]} id='#{name.pluralize}' path='#{path}'>".html_safe)
|
15
31
|
|
16
32
|
begin
|
17
33
|
sorted_items = items.sort {|a,b| a.position <=> b.position}
|
@@ -20,7 +36,8 @@ module ActionView
|
|
20
36
|
end
|
21
37
|
|
22
38
|
for item in sorted_items
|
23
|
-
concat("
|
39
|
+
concat("<#{defaults[:div_type][1]}>") unless defaults[:div_type][1].nil?
|
40
|
+
concat("<#{defaults[:div_type][2]} class='#{name}_sort_entry' id='#{name}_#{item.to_param}'>".html_safe)
|
24
41
|
concat("<span class='handle'>".html_safe)
|
25
42
|
if options[:text]
|
26
43
|
concat(options[:text] + " ")
|
@@ -40,9 +57,10 @@ module ActionView
|
|
40
57
|
unless defaults[:handle_only] && options[:handle_only] == true
|
41
58
|
concat("</span>".html_safe)
|
42
59
|
end
|
43
|
-
concat("
|
60
|
+
concat("</#{defaults[:div_type][2]}>".html_safe)
|
61
|
+
concat("</#{defaults[:div_type][1]}>") unless defaults[:div_type][1].nil?
|
44
62
|
end
|
45
|
-
concat("
|
63
|
+
concat("</#{defaults[:div_type][0]}>".html_safe)
|
46
64
|
concat(javascript_tag( "registerSortableList($('##{name.pluralize}'));"))
|
47
65
|
end
|
48
66
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-12 00:00:00.000000000 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: jquery-rails
|
17
|
-
requirement: &
|
17
|
+
requirement: &70313271128080 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70313271128080
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: shoulda
|
28
|
-
requirement: &
|
28
|
+
requirement: &70313271127540 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70313271127540
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
requirement: &
|
39
|
+
requirement: &70313271126720 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.0.0
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70313271126720
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: jeweler
|
50
|
-
requirement: &
|
50
|
+
requirement: &70313271119120 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 1.6.4
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70313271119120
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: rcov
|
61
|
-
requirement: &
|
61
|
+
requirement: &70313271113660 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70313271113660
|
70
70
|
description: Write a controller-method to do the sort and call jsort-helper in your
|
71
71
|
view.
|
72
72
|
email: andi@iboard.cc
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- README.md
|
84
84
|
- Rakefile
|
85
85
|
- VERSION
|
86
|
+
- jsort.gemspec
|
86
87
|
- lib/generators/jsort/install/install_generator.rb
|
87
88
|
- lib/jsort.rb
|
88
89
|
- lib/jsort/rails.rb
|
@@ -107,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
108
|
version: '0'
|
108
109
|
segments:
|
109
110
|
- 0
|
110
|
-
hash:
|
111
|
+
hash: 3460106958135409389
|
111
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
113
|
none: false
|
113
114
|
requirements:
|