jsort 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +20 -0
- data/README.md +64 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/generators/jsort/install/install_generator.rb +43 -0
- data/lib/jsort.rb +50 -0
- data/lib/jsort/rails.rb +9 -0
- data/lib/jsort/rails/engine.rb +9 -0
- data/test/helper.rb +18 -0
- data/test/test_jsort.rb +7 -0
- data/vendor/assets/images/sortable_vertical.png +0 -0
- data/vendor/assets/javascripts/jsort_sortable.js +32 -0
- metadata +124 -0
data/.document
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionpack (3.0.9)
|
6
|
+
activemodel (= 3.0.9)
|
7
|
+
activesupport (= 3.0.9)
|
8
|
+
builder (~> 2.1.2)
|
9
|
+
erubis (~> 2.6.6)
|
10
|
+
i18n (~> 0.5.0)
|
11
|
+
rack (~> 1.2.1)
|
12
|
+
rack-mount (~> 0.6.14)
|
13
|
+
rack-test (~> 0.5.7)
|
14
|
+
tzinfo (~> 0.3.23)
|
15
|
+
activemodel (3.0.9)
|
16
|
+
activesupport (= 3.0.9)
|
17
|
+
builder (~> 2.1.2)
|
18
|
+
i18n (~> 0.5.0)
|
19
|
+
activesupport (3.0.9)
|
20
|
+
builder (2.1.2)
|
21
|
+
erubis (2.6.6)
|
22
|
+
abstract (>= 1.0.0)
|
23
|
+
git (1.2.5)
|
24
|
+
i18n (0.5.0)
|
25
|
+
jeweler (1.6.4)
|
26
|
+
bundler (~> 1.0)
|
27
|
+
git (>= 1.2.5)
|
28
|
+
rake
|
29
|
+
jquery-rails (1.0.12)
|
30
|
+
railties (~> 3.0)
|
31
|
+
thor (~> 0.14)
|
32
|
+
rack (1.2.3)
|
33
|
+
rack-mount (0.6.14)
|
34
|
+
rack (>= 1.0.0)
|
35
|
+
rack-test (0.5.7)
|
36
|
+
rack (>= 1.0)
|
37
|
+
railties (3.0.9)
|
38
|
+
actionpack (= 3.0.9)
|
39
|
+
activesupport (= 3.0.9)
|
40
|
+
rake (>= 0.8.7)
|
41
|
+
rdoc (~> 3.4)
|
42
|
+
thor (~> 0.14.4)
|
43
|
+
rake (0.9.2)
|
44
|
+
rcov (0.9.10)
|
45
|
+
rdoc (3.9.1)
|
46
|
+
shoulda (2.11.3)
|
47
|
+
thor (0.14.6)
|
48
|
+
tzinfo (0.3.29)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
bundler (~> 1.0.0)
|
55
|
+
jeweler (~> 1.6.4)
|
56
|
+
jquery-rails
|
57
|
+
rcov
|
58
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Andi Altendorfer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
jsort
|
2
|
+
=====
|
3
|
+
|
4
|
+
_jsort_ does the javascript/jquery stuff for drag&drop sortable lists in your rails applications.
|
5
|
+
|
6
|
+
|
7
|
+
Usage
|
8
|
+
-----
|
9
|
+
|
10
|
+
**Model**
|
11
|
+
|
12
|
+
Your model should have a 'position'-column of type integer.
|
13
|
+
|
14
|
+
**Controller**
|
15
|
+
|
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
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
**View** (HAML; obviously, will work with html.erb too)
|
27
|
+
|
28
|
+
```
|
29
|
+
- jsort(@my_items,'ordered_items', sort_my_controller_path) do |item|
|
30
|
+
= item.name
|
31
|
+
= link_to "[Edit]", edit_my_item_path(item)
|
32
|
+
```
|
33
|
+
|
34
|
+
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.
|
37
|
+
|
38
|
+
|
39
|
+
Installation
|
40
|
+
------------
|
41
|
+
|
42
|
+
* Rails 3.1:
|
43
|
+
* Add this line to your application.js-template: `//= require jsort_sortable`
|
44
|
+
* Rails < 3.1:
|
45
|
+
* 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.
|
46
|
+
|
47
|
+
|
48
|
+
Contributing to jsort
|
49
|
+
=====================
|
50
|
+
|
51
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
52
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
53
|
+
* Fork the project
|
54
|
+
* Start a feature/bugfix branch
|
55
|
+
* Commit and push until you are happy with your contribution
|
56
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
57
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
58
|
+
|
59
|
+
Copyright
|
60
|
+
=========
|
61
|
+
|
62
|
+
Copyright (c) 2011 Andi Altendorfer. See LICENSE.txt for
|
63
|
+
further details.
|
64
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "jsort"
|
18
|
+
gem.homepage = "http://github.com/iboard/jsort"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{sort lists with drag & drop without coding a single line of Javascript by yourself}
|
21
|
+
gem.description = %Q{Write a controller-method to do the sort and call jsort-helper in your view.}
|
22
|
+
gem.email = "andi@iboard.cc"
|
23
|
+
gem.authors = ["Andi Altendorfer"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "jsort #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module Jsort
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
|
7
|
+
desc "This generator installs jSort for rails < 3.1"
|
8
|
+
def copy_files
|
9
|
+
say_status("copying", "NOT IMPLEMENTED YET. Please copy assets manually")
|
10
|
+
end
|
11
|
+
|
12
|
+
#class_option :ui, :type => :boolean, :default => false, :desc => "Include jQueryUI"
|
13
|
+
#source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
|
14
|
+
#
|
15
|
+
#def remove_prototype
|
16
|
+
# Rails::PROTOTYPE_JS.each do |name|
|
17
|
+
# remove_file "public/javascripts/#{name}.js"
|
18
|
+
# end
|
19
|
+
#end
|
20
|
+
#
|
21
|
+
#def copy_jquery
|
22
|
+
# say_status("copying", "jQuery (#{Jquery::Rails::JQUERY_VERSION})", :green)
|
23
|
+
# copy_file "jquery.js", "public/javascripts/jquery.js"
|
24
|
+
# copy_file "jquery.min.js", "public/javascripts/jquery.min.js"
|
25
|
+
#end
|
26
|
+
#
|
27
|
+
#def copy_jquery_ui
|
28
|
+
# if options.ui?
|
29
|
+
# say_status("copying", "jQuery UI (#{Jquery::Rails::JQUERY_UI_VERSION})", :green)
|
30
|
+
# copy_file "jquery-ui.js", "public/javascripts/jquery-ui.js"
|
31
|
+
# copy_file "jquery-ui.min.js", "public/javascripts/jquery-ui.min.js"
|
32
|
+
# end
|
33
|
+
#end
|
34
|
+
#
|
35
|
+
#def copy_ujs_driver
|
36
|
+
# say_status("copying", "jQuery UJS adapter (#{Jquery::Rails::JQUERY_UJS_VERSION[0..5]})", :green)
|
37
|
+
# remove_file "public/javascripts/rails.js"
|
38
|
+
# copy_file "jquery_ujs.js", "public/javascripts/jquery_ujs.js"
|
39
|
+
#end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end if ::Rails.version < "3.1"
|
data/lib/jsort.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "jsort/rails"
|
2
|
+
|
3
|
+
module ActionView
|
4
|
+
module Helpers
|
5
|
+
module FormHelper
|
6
|
+
def jsort(items,name,path,options={},&block)
|
7
|
+
|
8
|
+
defaults = {
|
9
|
+
:handle_only => false,
|
10
|
+
:image => 'sortable_vertical.png',
|
11
|
+
:text => nil
|
12
|
+
}
|
13
|
+
defaults.merge!(options)
|
14
|
+
concat("<ol id='#{name.pluralize}' path='#{path}'>".html_safe)
|
15
|
+
|
16
|
+
begin
|
17
|
+
sorted_items = items.sort {|a,b| a.position <=> b.position}
|
18
|
+
rescue
|
19
|
+
sorted_items = items
|
20
|
+
end
|
21
|
+
|
22
|
+
for item in sorted_items
|
23
|
+
concat("<li class='#{name}_sort_entry' id='#{name}_#{item.to_param}'>".html_safe)
|
24
|
+
concat("<span class='handle'>".html_safe)
|
25
|
+
if options[:text]
|
26
|
+
concat(options[:text] + " ")
|
27
|
+
else
|
28
|
+
concat(image_tag(defaults[:image], :style => 'box-shadow: none; border-radius: 0;') + " ")
|
29
|
+
end
|
30
|
+
if defaults[:handle_only] && options[:handle_only] == true
|
31
|
+
concat("</span>".html_safe)
|
32
|
+
end
|
33
|
+
|
34
|
+
if block_given?
|
35
|
+
yield(item)
|
36
|
+
else
|
37
|
+
concat item.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
unless defaults[:handle_only] && options[:handle_only] == true
|
41
|
+
concat("</span>".html_safe)
|
42
|
+
end
|
43
|
+
concat("</li>".html_safe)
|
44
|
+
end
|
45
|
+
concat("</ol>".html_safe)
|
46
|
+
concat(javascript_tag( "registerSortableList($('##{name.pluralize}'));"))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/jsort/rails.rb
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'jsort'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
data/test/test_jsort.rb
ADDED
Binary file
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/*
|
2
|
+
usage registerSortableList($('#sort_syllabus_components'));
|
3
|
+
<ul id='sort_syllabus_components'>
|
4
|
+
<li>....
|
5
|
+
</ul>
|
6
|
+
*/
|
7
|
+
function registerSortableList(list) {
|
8
|
+
list.sortable(
|
9
|
+
{
|
10
|
+
connectWith: '.list',
|
11
|
+
axis: 'y',
|
12
|
+
dropOnEmpty:false,
|
13
|
+
handle: '.handle',
|
14
|
+
cursor: 'crosshair',
|
15
|
+
items: 'li',
|
16
|
+
opacity: 0.4,
|
17
|
+
scroll: true,
|
18
|
+
update: function(){
|
19
|
+
var path = list.attr('path');
|
20
|
+
$.ajax({
|
21
|
+
type: 'post',
|
22
|
+
data: list.sortable('serialize'),
|
23
|
+
dataType: 'script',
|
24
|
+
complete: function(request){
|
25
|
+
list.effect('highlight');
|
26
|
+
},
|
27
|
+
url: path})
|
28
|
+
}
|
29
|
+
}
|
30
|
+
);
|
31
|
+
/* list.hide(); */
|
32
|
+
};
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jsort
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andi Altendorfer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-11 00:00:00.000000000 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: jquery-rails
|
17
|
+
requirement: &70183613714720 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70183613714720
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: shoulda
|
28
|
+
requirement: &70183613714220 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70183613714220
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
requirement: &70183613713720 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.0.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70183613713720
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: jeweler
|
50
|
+
requirement: &70183613713220 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.6.4
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70183613713220
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rcov
|
61
|
+
requirement: &70183613712720 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *70183613712720
|
70
|
+
description: Write a controller-method to do the sort and call jsort-helper in your
|
71
|
+
view.
|
72
|
+
email: andi@iboard.cc
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files:
|
76
|
+
- LICENSE.txt
|
77
|
+
- README.md
|
78
|
+
files:
|
79
|
+
- .document
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- VERSION
|
86
|
+
- lib/generators/jsort/install/install_generator.rb
|
87
|
+
- lib/jsort.rb
|
88
|
+
- lib/jsort/rails.rb
|
89
|
+
- lib/jsort/rails/engine.rb
|
90
|
+
- test/helper.rb
|
91
|
+
- test/test_jsort.rb
|
92
|
+
- vendor/assets/images/sortable_vertical.png
|
93
|
+
- vendor/assets/javascripts/jsort_sortable.js
|
94
|
+
has_rdoc: true
|
95
|
+
homepage: http://github.com/iboard/jsort
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
hash: -4219561250019622986
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.6.2
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: sort lists with drag & drop without coding a single line of Javascript by
|
123
|
+
yourself
|
124
|
+
test_files: []
|