lol_sortable 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +27 -0
- data/app/assets/javascripts/lol_sortable/sortable.js +69 -0
- data/app/controllers/sortable_controller.rb +23 -0
- data/config/routes.rb +3 -0
- data/lib/generators/lol_sortable/install_generator.rb +16 -0
- data/lib/lol_sortable/engine.rb +4 -0
- data/lib/lol_sortable/version.rb +3 -0
- data/lib/lol_sortable.rb +5 -0
- data/lib/mongoid/lol_sortable.rb +20 -0
- data/lib/tasks/lol_sortable_tasks.rake +4 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7b506a3caaea28859234e2e440d734861fb672d0
|
4
|
+
data.tar.gz: 412f757cb830224e97f7467384d2a1a59995f996
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cf0f42be4d260739aaf1ca264eedf7afd6f67ec4371735254f91d90eec5729723841a2607d1233ee43e1a481f07319110a11e70d1b68186eff345abbe7e4a56a
|
7
|
+
data.tar.gz: 1cd52ca9e429db297d6133b8e549c91b97c04326a753ff2f5f51de9a91833316892c2d2758c5d6dec81104f636f6ffec794a863d03b75df67b730b123c164221
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
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.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'LolSortable'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
(function($)
|
2
|
+
{
|
3
|
+
$.fn.LOLSortable = function(params)
|
4
|
+
{
|
5
|
+
params = $.extend( {
|
6
|
+
id_obj_attr: 'data-id',
|
7
|
+
url: '/sortable'
|
8
|
+
}, params);
|
9
|
+
|
10
|
+
this.each(function() {
|
11
|
+
new Plugin(this, params);
|
12
|
+
});
|
13
|
+
|
14
|
+
return this;
|
15
|
+
};
|
16
|
+
})(jQuery);
|
17
|
+
|
18
|
+
function Plugin(element, options) {
|
19
|
+
var that = this;
|
20
|
+
this.el = element;
|
21
|
+
this.$el = $(element);
|
22
|
+
this.options = options;
|
23
|
+
|
24
|
+
// Initialize the plugin instance
|
25
|
+
this.init();
|
26
|
+
}
|
27
|
+
|
28
|
+
//
|
29
|
+
// Plugin prototype
|
30
|
+
//
|
31
|
+
Plugin.prototype = {
|
32
|
+
|
33
|
+
init: function() {
|
34
|
+
var self = this;
|
35
|
+
|
36
|
+
this.$el.sortable();
|
37
|
+
|
38
|
+
this.$el.on( "sortupdate", function(){
|
39
|
+
self._update_priority();
|
40
|
+
} );
|
41
|
+
|
42
|
+
},
|
43
|
+
|
44
|
+
destroy: function() {
|
45
|
+
},
|
46
|
+
|
47
|
+
_update_priority: function(event, ui){
|
48
|
+
var self = this;
|
49
|
+
|
50
|
+
var ids = this.$el.sortable('toArray', {'attribute': this.options.id_obj_attr});
|
51
|
+
|
52
|
+
$.ajax({
|
53
|
+
url: self.options.url,
|
54
|
+
type: 'POST',
|
55
|
+
dataType: 'json',
|
56
|
+
data: {ids: ids, resource: self.$el.attr('data-resource')},
|
57
|
+
success: function(data, textStatus, xhr) {
|
58
|
+
|
59
|
+
}
|
60
|
+
});
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
jQuery(document).ready(function($) {
|
65
|
+
var $isSortable = $('.is-sortable');
|
66
|
+
if($isSortable[0]){
|
67
|
+
$isSortable.LOLSortable();
|
68
|
+
}
|
69
|
+
});
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class SortableController < ApplicationController
|
2
|
+
respond_to :json
|
3
|
+
|
4
|
+
before_filter :validate_params, only: :prioritize
|
5
|
+
|
6
|
+
def prioritize
|
7
|
+
params[:resource].classify.constantize.prioritize params[:ids]
|
8
|
+
|
9
|
+
render nothing: true
|
10
|
+
|
11
|
+
rescue Exception => e
|
12
|
+
render_error(e.message)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def validate_params
|
17
|
+
render_error("must send ids params with resources listed") unless params[:ids].present?
|
18
|
+
end
|
19
|
+
|
20
|
+
def render_error(message)
|
21
|
+
render text: {error_message: message}.to_json, status: :error
|
22
|
+
end
|
23
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#endoding: utf-8
|
2
|
+
module LolSortable
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
def add_routes
|
7
|
+
route "mount LolSortable::Engine => '/'"
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_js_config
|
11
|
+
inject_into_file 'app/assets/javascripts/application.js', after: "//= require jquery_ujs\n" do
|
12
|
+
"//= require jquery.ui.sortable\n//= require lol_sortable/sortable"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/lol_sortable.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module LolSortable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
field :priority, type: Integer, default: 30000
|
7
|
+
|
8
|
+
scope :prioritized, order_by(:priority.asc)
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def prioritize(list_ids)
|
13
|
+
list_ids.each_with_index do |id, index|
|
14
|
+
resource = self.find id
|
15
|
+
resource.update_attribute(:priority, index)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lol_sortable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eduardo Zaghi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jquery-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jquery-ui-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mongoid
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.1.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.1.2
|
69
|
+
description: Sort yours models with mongoid, jquery.ui.sortable
|
70
|
+
email:
|
71
|
+
- eduardo@loldesign.com.br
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- app/assets/javascripts/lol_sortable/sortable.js
|
77
|
+
- app/controllers/sortable_controller.rb
|
78
|
+
- config/routes.rb
|
79
|
+
- lib/generators/lol_sortable/install_generator.rb
|
80
|
+
- lib/lol_sortable/engine.rb
|
81
|
+
- lib/lol_sortable/version.rb
|
82
|
+
- lib/lol_sortable.rb
|
83
|
+
- lib/mongoid/lol_sortable.rb
|
84
|
+
- lib/tasks/lol_sortable_tasks.rake
|
85
|
+
- MIT-LICENSE
|
86
|
+
- Rakefile
|
87
|
+
- README.rdoc
|
88
|
+
homepage: http://www.loldesign.com.br
|
89
|
+
licenses: []
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.0.3
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Sort your models with jquery sortable
|
111
|
+
test_files: []
|