puffer 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/.gitignore +3 -0
  2. data/.travis.yml +6 -0
  3. data/CHANGELOG.md +14 -0
  4. data/Gemfile.lock +98 -80
  5. data/README.md +6 -0
  6. data/Rakefile +1 -1
  7. data/app/assets/javascripts/puffer/puffer.js +15 -3
  8. data/app/assets/javascripts/puffer/right-sortable-src.js +28 -306
  9. data/app/assets/stylesheets/puffer/application.css +2 -0
  10. data/app/assets/stylesheets/puffer/file_input.css +59 -0
  11. data/app/assets/stylesheets/puffer/puffer.css +1 -0
  12. data/app/assets/stylesheets/puffer/puffer_grid.css +23 -0
  13. data/app/components/boolean/filter.html.erb +9 -0
  14. data/app/components/boolean_component.rb +4 -0
  15. data/app/components/carrierwave/form.html.erb +34 -0
  16. data/app/components/carrierwave/index.html.erb +6 -0
  17. data/app/components/carrierwave_component.rb +16 -0
  18. data/app/components/references_one/form.html.erb +2 -3
  19. data/app/controllers/admin/dashboard_controller.rb +0 -1
  20. data/app/controllers/admin/puffer_users_controller.rb +3 -7
  21. data/app/controllers/admin/sessions_controller.rb +1 -1
  22. data/app/models/puffer_user.rb +3 -18
  23. data/app/views/layouts/puffer.html.erb +2 -0
  24. data/app/views/puffer/base/_edit.html.erb +1 -1
  25. data/app/views/puffer/base/new.html.erb +1 -1
  26. data/app/views/puffer/grid_base/_grid.html.erb +9 -0
  27. data/app/views/puffer/grid_base/_index.html.erb +26 -0
  28. data/config/routes.rb +1 -1
  29. data/gemfiles/Gemfile-rails-3.1 +5 -0
  30. data/gemfiles/Gemfile-rails-3.1.lock +201 -0
  31. data/gemfiles/Gemfile-rails-3.2 +5 -0
  32. data/gemfiles/Gemfile-rails-3.2.lock +199 -0
  33. data/lib/puffer.rb +38 -12
  34. data/{app/controllers/puffer → lib/puffer/backends/controllers}/base.rb +1 -2
  35. data/{app/controllers/puffer → lib/puffer/backends/controllers}/dashboard_base.rb +0 -1
  36. data/lib/puffer/backends/controllers/grid_base.rb +12 -0
  37. data/{app/controllers/puffer → lib/puffer/backends/controllers}/puffer_users_base.rb +0 -0
  38. data/{app/controllers/puffer → lib/puffer/backends/controllers}/sessions/base.rb +0 -1
  39. data/{app/controllers/puffer → lib/puffer/backends/controllers}/sessions/clearance.rb +13 -5
  40. data/{app/controllers/puffer → lib/puffer/backends/controllers}/sessions/devise.rb +1 -1
  41. data/{app/controllers/puffer → lib/puffer/backends/controllers}/sessions/simple.rb +1 -1
  42. data/{app/controllers/puffer → lib/puffer/backends/controllers}/tree_base.rb +0 -1
  43. data/lib/puffer/backends/models/user/active_record.rb +9 -0
  44. data/lib/puffer/backends/models/user/base.rb +30 -0
  45. data/lib/puffer/backends/models/user/mongoid.rb +15 -0
  46. data/lib/puffer/component.rb +2 -2
  47. data/lib/puffer/controller/auth.rb +48 -47
  48. data/lib/puffer/controller/config.rb +4 -6
  49. data/lib/puffer/controller/dsl.rb +2 -4
  50. data/lib/puffer/controller/mutate.rb +23 -26
  51. data/lib/puffer/extensions/directive_processor.rb +11 -16
  52. data/lib/puffer/extensions/engine.rb +7 -9
  53. data/lib/puffer/extensions/{mapper.rb → mapper31.rb} +10 -12
  54. data/lib/puffer/extensions/mapper32.rb +108 -0
  55. data/lib/puffer/filters.rb +15 -3
  56. data/lib/puffer/orm_adapter/active_record.rb +15 -2
  57. data/lib/puffer/orm_adapter/base.rb +4 -0
  58. data/lib/puffer/orm_adapter/mongoid.rb +15 -2
  59. data/lib/puffer/resource.rb +1 -1
  60. data/lib/puffer/version.rb +1 -1
  61. data/puffer.gemspec +10 -4
  62. data/spec/{app/components → components}/base_component_spec.rb +0 -0
  63. data/spec/{app/components → components}/boolean_component_spec.rb +0 -0
  64. data/spec/{app/components → components}/date_time_component_spec.rb +0 -0
  65. data/spec/{app/components → components}/file_component_spec.rb +0 -0
  66. data/spec/{app/components → components}/hidden_component_spec.rb +0 -0
  67. data/spec/{app/components → components}/password_component_spec.rb +0 -0
  68. data/spec/{app/components → components}/references_many_component_spec.rb +0 -0
  69. data/spec/{app/components → components}/references_one_component_spec.rb +0 -0
  70. data/spec/{app/components → components}/select_component_spec.rb +0 -0
  71. data/spec/{app/components → components}/string_component_spec.rb +0 -0
  72. data/spec/{app/components → components}/text_component_spec.rb +0 -0
  73. data/spec/controllers/sessions/base_shared.rb +66 -0
  74. data/spec/controllers/sessions/clearance_spec.rb +21 -0
  75. data/spec/controllers/sessions/simple_spec.rb +14 -0
  76. data/spec/dummy/app/controllers/admin/news_controller.rb +1 -1
  77. data/spec/dummy/app/controllers/admin/profiles_controller.rb +3 -1
  78. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  79. data/spec/dummy/app/controllers/orms/mongoid_orm_primals_controller.rb +16 -0
  80. data/spec/dummy/app/helpers/news_helper.rb +1 -1
  81. data/spec/dummy/app/models/clearance_user.rb +3 -0
  82. data/spec/dummy/app/models/mongoid_orm/embeds_many_reference.rb +9 -0
  83. data/spec/dummy/app/models/mongoid_orm/embeds_one_reference.rb +9 -0
  84. data/spec/dummy/app/models/mongoid_orm/has_many_reference.rb +9 -0
  85. data/spec/dummy/app/models/mongoid_orm/has_one_reference.rb +9 -0
  86. data/spec/dummy/app/models/mongoid_orm/primal.rb +8 -0
  87. data/spec/dummy/app/models/profile.rb +2 -0
  88. data/spec/dummy/app/uploaders/avatar_uploader.rb +8 -0
  89. data/spec/dummy/config/application.rb +5 -3
  90. data/spec/dummy/config/initializers/clearance.rb +3 -0
  91. data/spec/dummy/config/initializers/devise.rb +34 -22
  92. data/spec/dummy/config/locales/devise.en.yml +6 -7
  93. data/spec/dummy/config/routes.rb +0 -1
  94. data/spec/dummy/db/migrate/{20100930133425_create_admin_profiles.rb → 20100930133425_create_profiles.rb} +2 -1
  95. data/spec/dummy/db/migrate/20111208222355_create_clearance_users.rb +13 -0
  96. data/spec/dummy/db/migrate/20120129091339_upgrade_clearance_to_diesel.rb +19 -0
  97. data/spec/dummy/db/schema.rb +12 -1
  98. data/spec/fabricators/clearance_user_fabricator.rb +4 -0
  99. data/spec/fabricators/puffer_user_fabricator.rb +5 -0
  100. data/spec/lib/filters_spec.rb +1 -1
  101. data/spec/lib/orm_adapter/active_record_spec.rb +0 -1
  102. data/spec/lib/orm_adapter/base_shared.rb +80 -76
  103. data/spec/lib/orm_adapter/mongoid_spec.rb +0 -2
  104. data/spec/lib/resource/tree_spec.rb +0 -1
  105. data/spec/spec_helper.rb +5 -3
  106. metadata +150 -75
  107. data/VERSION +0 -1
  108. data/app/models/puffer/puffer_user.rb +0 -25
data/.gitignore CHANGED
@@ -3,5 +3,8 @@ log/*.log
3
3
  pkg/
4
4
  spec/dummy/db/*.sqlite3
5
5
  spec/dummy/log/*.log
6
+ spec/dummy/public/uploads/
6
7
  spec/dummy/tmp/
7
8
  *.orig
9
+ *.sublime-project
10
+ *.sublime-workspace
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - ruby-head
5
+ #- rbx
6
+ #- rbx-2.0
@@ -0,0 +1,14 @@
1
+ ## 0.1.1 \[ In Development \] \[ Branch: master \]
2
+
3
+ ### New Behavior
4
+
5
+ * Unified behavior for all built-in app classes (controller and models).
6
+ Now there are one or more versions inside modules and default version is inherited.
7
+ See more - [default behaviors](https://github.com/puffer/puffer/wiki/Default-behaviors)
8
+ No more autoconfig attempts.
9
+
10
+ ### New features
11
+
12
+ * `per_page` config option.
13
+ * Grid index controller.
14
+ * Carrierwave component implemented.
@@ -1,51 +1,51 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- puffer (0.1.0)
4
+ puffer (0.1.1)
5
5
  kaminari
6
6
  orm_adapter
7
- rails (~> 3.1.0)
7
+ rails (~> 3.1)
8
8
 
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
- actionmailer (3.1.3)
13
- actionpack (= 3.1.3)
14
- mail (~> 2.3.0)
15
- actionpack (3.1.3)
16
- activemodel (= 3.1.3)
17
- activesupport (= 3.1.3)
12
+ actionmailer (3.2.1)
13
+ actionpack (= 3.2.1)
14
+ mail (~> 2.4.0)
15
+ actionpack (3.2.1)
16
+ activemodel (= 3.2.1)
17
+ activesupport (= 3.2.1)
18
18
  builder (~> 3.0.0)
19
19
  erubis (~> 2.7.0)
20
- i18n (~> 0.6)
21
- rack (~> 1.3.5)
20
+ journey (~> 1.0.1)
21
+ rack (~> 1.4.0)
22
22
  rack-cache (~> 1.1)
23
- rack-mount (~> 0.8.2)
24
23
  rack-test (~> 0.6.1)
25
- sprockets (~> 2.0.3)
26
- activemodel (3.1.3)
27
- activesupport (= 3.1.3)
24
+ sprockets (~> 2.1.2)
25
+ activemodel (3.2.1)
26
+ activesupport (= 3.2.1)
28
27
  builder (~> 3.0.0)
29
- i18n (~> 0.6)
30
- activerecord (3.1.3)
31
- activemodel (= 3.1.3)
32
- activesupport (= 3.1.3)
33
- arel (~> 2.2.1)
28
+ activerecord (3.2.1)
29
+ activemodel (= 3.2.1)
30
+ activesupport (= 3.2.1)
31
+ arel (~> 3.0.0)
34
32
  tzinfo (~> 0.3.29)
35
- activeresource (3.1.3)
36
- activemodel (= 3.1.3)
37
- activesupport (= 3.1.3)
38
- activesupport (3.1.3)
33
+ activeresource (3.2.1)
34
+ activemodel (= 3.2.1)
35
+ activesupport (= 3.2.1)
36
+ activesupport (3.2.1)
37
+ i18n (~> 0.6)
39
38
  multi_json (~> 1.0)
40
- ammeter (0.2.1)
41
- activesupport (~> 3.0)
42
- railties (~> 3.0)
43
- rspec (~> 2.2)
44
- rspec-rails (~> 2.2)
45
- arel (2.2.1)
39
+ ammeter (0.2.2)
40
+ activesupport (>= 3.0)
41
+ railties (>= 3.0)
42
+ rspec (>= 2.2)
43
+ rspec-rails (>= 2.2)
44
+ arel (3.0.0)
46
45
  bcrypt-ruby (3.0.1)
47
- bson (1.4.1)
48
- bson_ext (1.4.0)
46
+ bson (1.5.2)
47
+ bson_ext (1.5.2)
48
+ bson (= 1.5.2)
49
49
  builder (3.0.0)
50
50
  capybara (1.1.2)
51
51
  mime-types (>= 1.16)
@@ -54,98 +54,112 @@ GEM
54
54
  rack-test (>= 0.5.4)
55
55
  selenium-webdriver (~> 2.0)
56
56
  xpath (~> 0.1.4)
57
- childprocess (0.2.2)
57
+ carrierwave (0.5.8)
58
+ activesupport (~> 3.0)
59
+ childprocess (0.3.0)
58
60
  ffi (~> 1.0.6)
59
- database_cleaner (0.7.0)
60
- devise (1.5.1)
61
+ clearance (0.14.0)
62
+ diesel (~> 0.1.5)
63
+ rails (>= 3.0)
64
+ database_cleaner (0.7.1)
65
+ devise (2.0.0)
61
66
  bcrypt-ruby (~> 3.0)
62
67
  orm_adapter (~> 0.0.3)
68
+ railties (~> 3.1)
63
69
  warden (~> 1.1)
70
+ diesel (0.1.5)
71
+ railties
64
72
  diff-lcs (1.1.3)
65
73
  erubis (2.7.0)
66
74
  fabrication (1.2.0)
67
75
  ffi (1.0.11)
68
76
  forgery (0.5.0)
69
- guard (0.8.8)
77
+ guard (1.0.0)
78
+ ffi (>= 0.5.0)
70
79
  thor (~> 0.14.6)
71
- guard-rspec (0.5.5)
72
- guard (>= 0.8.4)
80
+ guard-rspec (0.6.0)
81
+ guard (>= 0.10.0)
73
82
  hike (1.2.1)
74
83
  i18n (0.6.0)
75
- json (1.6.1)
76
- json_pure (1.6.1)
77
- kaminari (0.12.4)
78
- rails (>= 3.0.0)
79
- libnotify (0.5.9)
80
- mail (2.3.0)
84
+ journey (1.0.1)
85
+ json (1.6.5)
86
+ kaminari (0.13.0)
87
+ actionpack (>= 3.0.0)
88
+ activesupport (>= 3.0.0)
89
+ railties (>= 3.0.0)
90
+ libnotify (0.7.2)
91
+ mail (2.4.1)
81
92
  i18n (>= 0.4.0)
82
93
  mime-types (~> 1.16)
83
94
  treetop (~> 1.4.8)
84
95
  mime-types (1.17.2)
85
- mongo (1.4.1)
86
- bson (= 1.4.1)
87
- mongoid (2.3.3)
96
+ mini_magick (3.4)
97
+ subexec (~> 0.2.1)
98
+ mongo (1.5.2)
99
+ bson (= 1.5.2)
100
+ mongoid (2.4.3)
88
101
  activemodel (~> 3.1)
89
102
  mongo (~> 1.3)
90
103
  tzinfo (~> 0.3.22)
91
- multi_json (1.0.3)
104
+ multi_json (1.0.4)
92
105
  nested_set (1.6.8)
93
106
  activerecord (>= 3.0.0)
94
107
  railties (>= 3.0.0)
95
108
  nokogiri (1.5.0)
96
- orm_adapter (0.0.5)
109
+ orm_adapter (0.0.6)
97
110
  polyglot (0.3.3)
98
- rack (1.3.5)
111
+ rack (1.4.1)
99
112
  rack-cache (1.1)
100
113
  rack (>= 0.4)
101
- rack-mount (0.8.3)
102
- rack (>= 1.0.0)
103
114
  rack-ssl (1.3.2)
104
115
  rack
105
116
  rack-test (0.6.1)
106
117
  rack (>= 1.0)
107
- rails (3.1.3)
108
- actionmailer (= 3.1.3)
109
- actionpack (= 3.1.3)
110
- activerecord (= 3.1.3)
111
- activeresource (= 3.1.3)
112
- activesupport (= 3.1.3)
118
+ rails (3.2.1)
119
+ actionmailer (= 3.2.1)
120
+ actionpack (= 3.2.1)
121
+ activerecord (= 3.2.1)
122
+ activeresource (= 3.2.1)
123
+ activesupport (= 3.2.1)
113
124
  bundler (~> 1.0)
114
- railties (= 3.1.3)
115
- railties (3.1.3)
116
- actionpack (= 3.1.3)
117
- activesupport (= 3.1.3)
125
+ railties (= 3.2.1)
126
+ railties (3.2.1)
127
+ actionpack (= 3.2.1)
128
+ activesupport (= 3.2.1)
118
129
  rack-ssl (~> 1.3.2)
119
130
  rake (>= 0.8.7)
120
131
  rdoc (~> 3.4)
121
132
  thor (~> 0.14.6)
122
133
  rake (0.9.2.2)
123
- rdoc (3.11)
134
+ rb-inotify (0.8.8)
135
+ ffi (>= 0.5.0)
136
+ rdoc (3.12)
124
137
  json (~> 1.4)
125
- rspec (2.7.0)
126
- rspec-core (~> 2.7.0)
127
- rspec-expectations (~> 2.7.0)
128
- rspec-mocks (~> 2.7.0)
129
- rspec-core (2.7.1)
130
- rspec-expectations (2.7.0)
138
+ rspec (2.8.0)
139
+ rspec-core (~> 2.8.0)
140
+ rspec-expectations (~> 2.8.0)
141
+ rspec-mocks (~> 2.8.0)
142
+ rspec-core (2.8.0)
143
+ rspec-expectations (2.8.0)
131
144
  diff-lcs (~> 1.1.2)
132
- rspec-mocks (2.7.0)
133
- rspec-rails (2.7.0)
134
- actionpack (~> 3.0)
135
- activesupport (~> 3.0)
136
- railties (~> 3.0)
137
- rspec (~> 2.7.0)
138
- rubyzip (0.9.4)
139
- selenium-webdriver (2.13.0)
140
- childprocess (>= 0.2.1)
145
+ rspec-mocks (2.8.0)
146
+ rspec-rails (2.8.1)
147
+ actionpack (>= 3.0)
148
+ activesupport (>= 3.0)
149
+ railties (>= 3.0)
150
+ rspec (~> 2.8.0)
151
+ rubyzip (0.9.5)
152
+ selenium-webdriver (2.18.0)
153
+ childprocess (>= 0.2.5)
141
154
  ffi (~> 1.0.9)
142
- json_pure
155
+ multi_json (~> 1.0.4)
143
156
  rubyzip
144
- sprockets (2.0.3)
157
+ sprockets (2.1.2)
145
158
  hike (~> 1.2)
146
159
  rack (~> 1.0)
147
160
  tilt (~> 1.1, != 1.3.0)
148
- sqlite3 (1.3.4)
161
+ sqlite3 (1.3.5)
162
+ subexec (0.2.1)
149
163
  thor (0.14.6)
150
164
  tilt (1.3.3)
151
165
  timecop (0.3.5)
@@ -165,6 +179,8 @@ DEPENDENCIES
165
179
  ammeter
166
180
  bson_ext
167
181
  capybara
182
+ carrierwave
183
+ clearance
168
184
  database_cleaner
169
185
  devise
170
186
  fabrication
@@ -172,9 +188,11 @@ DEPENDENCIES
172
188
  guard
173
189
  guard-rspec
174
190
  libnotify
191
+ mini_magick
175
192
  mongoid
176
193
  nested_set
177
194
  puffer!
195
+ rb-inotify
178
196
  rspec-rails
179
197
  sqlite3
180
198
  timecop
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://secure.travis-ci.org/puffer/puffer.png)](http://travis-ci.org/puffer/puffer)
2
+
1
3
  # Puffer — YARAI (Yet Another Rails Admin Interface)
2
4
 
3
5
  Puffer was created to help a project owner or moderators view and
@@ -167,3 +169,7 @@ end
167
169
  ```
168
170
 
169
171
  Have a nice day and let Puffer rock for you.
172
+
173
+ ***
174
+
175
+ Thanks to [Dmitry Ustalov](http://eveel.ru) for the name of Puffer along with the Clearance integration.
data/Rakefile CHANGED
@@ -24,4 +24,4 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
24
24
  rdoc.rdoc_files.include('lib/**/*.rb')
25
25
  end
26
26
 
27
- require "bundler/gem_tasks"
27
+ require "bundler/gem_tasks"
@@ -1,6 +1,6 @@
1
1
  var association_done = function(event) {
2
2
  current = this.first('li.current');
3
- this.input.next('input[type=hidden]').value(current.get('data-id'));
3
+ this.input.next('input[type=hidden]').value(current.data('id'));
4
4
  this.input.value(current.find('.title').first().html().stripTags()).disable();
5
5
  }
6
6
 
@@ -18,7 +18,7 @@ var association_done = function(event) {
18
18
  dialog = new Dialog({expandable: true});
19
19
  }
20
20
 
21
- dialog.load(this.get('data-dialog-uri'));
21
+ dialog.load(this.data('dialog-uri'));
22
22
  });
23
23
 
24
24
  'a[data-new-dialog-uri]'.on('click', function(event) {
@@ -26,4 +26,16 @@ var association_done = function(event) {
26
26
  event.stop();
27
27
 
28
28
  new Dialog({expandable: true}).load(this.get('data-new-dialog-uri'));
29
- });
29
+ });
30
+
31
+ 'a[data-sortable]'.on('mousedown', function(event) {
32
+ if (event.which != 1) return;
33
+
34
+ new Sortable(this, this.data('sortable'));
35
+ });
36
+
37
+ $(document).on('ready', function(event) {
38
+ $$('[data-sortable]').each(function(element) {
39
+ new Sortable(element);
40
+ });
41
+ });
@@ -1,10 +1,5 @@
1
- /**
2
- * RightJS-UI Sortable v2.2.0
3
- * http://rightjs.org/ui/sortable
4
- *
5
- * Copyright (C) 2009-2011 Nikolay Nemshilov
6
- */
7
- var Sortable = RightJS.Sortable = (function(document, RightJS) {
1
+ var Sortable = RightJS.Sortable = (function(document, Math, RightJS) {
2
+
8
3
  /**
9
4
  * This module defines the basic widgets constructor
10
5
  * it creates an abstract proxy with the common functionality
@@ -105,326 +100,53 @@ function Widget(tag_name, methods) {
105
100
 
106
101
 
107
102
  /**
108
- * Sortable initialization script
103
+ * The filenames to include
109
104
  *
110
105
  * Copyright (C) 2010 Nikolay Nemshilov
111
106
  */
112
- var R = RightJS,
113
- $ = RightJS.$,
114
- $w = RightJS.$w,
115
- isString = RightJS.isString,
116
- isArray = RightJS.isArray,
117
- Object = RightJS.Object;
118
-
119
-
107
+ var R = RightJS,
108
+ $ = RightJS.$,
109
+ $$ = RightJS.$$,
110
+ $w = RightJS.$w,
111
+ $E = RightJS.$E,
112
+ $A = RightJS.$A,
113
+ isHash = RightJS.isHash,
114
+ Element = RightJS.Element;
120
115
 
121
116
 
122
- /**
123
- * The Sortable unit
124
- *
125
- * Copyright (C) 2009-2011 Nikolay Nemshilov
126
- */
127
- var Sortable = new Widget('UL', {
117
+ var Sortable = new Widget({
128
118
  extend: {
129
- version: '2.2.0',
130
-
131
- EVENTS: $w('start change finish'),
119
+ version: '2.2.3',
132
120
 
133
121
  Options: {
134
- url: null, // the Xhr requests url address, might contain the '%{id}' placeholder
135
- method: 'put', // the Xhr requests method
136
-
137
- Xhr: {}, // additional Xhr options
138
-
139
- idParam: 'id', // the id value name
140
- posParam: 'position', // the position value name
141
- parseId: true, // if the id attribute should be converted into an integer before sending
142
-
143
- dragClass: 'dragging', // the in-process class name
144
- accept: null, // a reference or a list of references to the other sortables between which you can drag the items
145
- minLength: 1, // minimum number of items on the list when the feature works
146
-
147
- itemCss: 'li', // the draggable item's css rule
148
- handleCss: 'li', // the draggables handle element css rule
149
-
150
- cssRule: '*[data-sortable]' // css-rule for automatically initializable sortables
151
- },
152
-
153
- current: false, // a reference to the currently active sortable
154
-
155
- /**
156
- * Typecasting the list element for Sortable
157
- *
158
- * @param Element list
159
- * @return Sortable list
160
- */
161
- cast: function(element) {
162
- element = $(element._);
163
- if (!(element instanceof Sortable)) {
164
- element = new Sortable(element);
165
- }
166
- return element;
122
+ itemCss: 'li'
167
123
  }
168
124
  },
169
125
 
170
- /**
171
- * basic constructor
172
- *
173
- * @param mixed element reference
174
- * @param Object options
175
- * @return void
176
- */
177
- initialize: function(element, options) {
178
- this.$super('sortable', element)
179
- .setOptions(options)
180
- .addClass('rui-sortable')
181
- .on('finish', this._tryXhr)
182
- .on('selectstart', 'stopEvent'); // disable select under IE
183
- },
184
-
185
- /**
186
- * some additional options processing
187
- *
188
- * @param Object options
189
- * @param Element optional context
190
- * @return Sortable this
191
- */
192
- setOptions: function(options, context) {
193
- this.$super(options, context);
194
-
195
- options = this.options;
196
-
197
- // Preprocessing the acceptance list
198
- var list = options.accept || [];
199
- if (!isArray(list)) { list = [list]; }
200
-
201
- options.accept = R([this].concat(list)).map($).uniq();
202
-
203
- return this;
204
- },
205
-
206
- // returns a list of draggable items
207
- items: function() {
208
- return this.children(this.options.itemCss);
209
- },
210
-
211
- // protected
212
-
213
- // starts the drag
214
- startDrag: function(event) {
215
- // don't let to drag out the last item
216
- if (this.items().length <= this.options.minLength) { return; }
217
-
218
- // trying to find the list-item upon which the user pressed the mouse
219
- var item = event.find(this.options.itemCss),
220
- handle = event.find(this.options.handleCss);
221
-
222
- if (item && handle) {
223
- this._initDrag(item, event.position());
224
- Sortable.current = this;
225
- this.fire('start', this._evOpts(event));
226
- }
227
- },
228
-
229
- // moves the item
230
- moveItem: function(event) {
231
- var event_pos = event.position(),
232
- item = this.itemClone._.style,
233
- top = event_pos.y - this.yRDiff,
234
- left = event_pos.x - this.xRDiff,
235
- right = left + this.cloneWidth,
236
- bottom = top + this.cloneHeight;
237
-
238
- // moving the clone
239
- item.top = (event_pos.y - this.yDiff) + 'px';
240
- item.left = (event_pos.x - this.xDiff) + 'px';
241
-
242
- // checking for an overlaping item
243
- var over_item = this.suspects.first(function(suspect) {
244
- return (
245
- (top > suspect.top && top < suspect.topHalf) ||
246
- (bottom < suspect.bottom && bottom > suspect.topHalf)
247
- ) && (
248
- (left > suspect.left && left < suspect.leftHalf) ||
249
- (right < suspect.right && right > suspect.leftHalf)
250
- );
251
- });
252
-
253
- if (over_item) {
254
- item = over_item.item;
255
- item.insert(this.item, item.prevSiblings().include(this.item) ? 'after' : 'before');
256
- this._findSuspects();
257
-
258
- this.fire('change', this._evOpts(event, item));
259
- }
260
- },
126
+ initialize: function() {
127
+ var args = $A(arguments).compact(), options = args.pop(), element = args.pop();
261
128
 
262
- // finalizes the drag
263
- finishDrag: function(event) {
264
- if (this.itemClone) {
265
- this.itemClone.remove();
266
- this.item.setStyle('visibility:visible');
129
+ if (!isHash(options) || options instanceof Element) {
130
+ element = $(element || options);
131
+ options = {};
267
132
  }
268
- Sortable.current = false;
269
- this.fire('finish', this._evOpts(event));
270
- },
271
-
272
- // returns the event options
273
- _evOpts: function(event, item) {
274
- item = item || this.item;
275
- var list = Sortable.cast(item.parent());
276
-
277
- return {
278
- list: list,
279
- item: item,
280
- event: event,
281
- index: list.items().indexOf(item)
282
- };
283
- },
284
-
285
- _initDrag: function(item, event_pos) {
286
- var dims = this.dimensions(), item_dims = item.dimensions();
287
-
288
- // creating the draggable clone
289
- var clone = item.clone().setStyle({
290
- margin: 0,
291
- zIndex: 9999,
292
- position: 'absolute',
293
- top: '0px',
294
- left: '0px'
295
- })
296
- .addClass(this.options.dragClass).insertTo(this)
297
- .setHeight(this.cloneHeight = item_dims.height)
298
- .setWidth(this.cloneWidth = item_dims.width);
299
-
300
- // adjusting the clone position to compensate relative fields and margins
301
- var clone_pos = clone.position(),
302
- real_x = item_dims.left - clone_pos.x,
303
- real_y = item_dims.top - clone_pos.y;
304
-
305
- clone.moveTo(real_x, real_y);
306
133
 
307
- this.item = item.setStyle('visibility:hidden');
308
- this.itemClone = clone;
309
-
310
- // mouse event-position diffs
311
- this.xDiff = event_pos.x - real_x;
312
- this.yDiff = event_pos.y - real_y;
313
- this.xRDiff = event_pos.x - clone.position().x;
314
- this.yRDiff = event_pos.y - clone.position().y;
315
-
316
- // collecting the list of interchangable items with their positions
317
- this._findSuspects();
318
- },
319
-
320
- // collects the precached list of suspects
321
- _findSuspects: function() {
322
- var suspects = this.suspects = R([]), item = this.item, clone = this.itemClone;
323
- this.options.accept.each(function(list) {
324
- Sortable.cast(list).items().each(function(element) {
325
- if (element !== item && element !== clone) {
326
- var dims = element.dimensions();
327
-
328
- // caching the sizes
329
- suspects.push({
330
- item: element,
331
- top: dims.top,
332
- left: dims.left,
333
- right: dims.left + dims.width,
334
- bottom: dims.top + dims.height,
335
- topHalf: dims.top + dims.height/2,
336
- leftHalf: dims.left + dims.width/2
337
- });
338
- }
339
- });
340
- });
341
- },
342
-
343
- // tries to send an Xhr request about the element relocation
344
- _tryXhr: function(event) {
345
- if (this.options.url) {
346
- var url = R(this.options.url), params = {}, item = event.item, position = event.index + 1;
347
-
348
- // building the Xhr request options
349
- var options = Object.merge({
350
- method: this.options.method,
351
- params: {}
352
- }, this.options.Xhr);
353
-
354
- // grabbing the id
355
- var id = item.get('id') || '';
356
- if (this.options.parseId && id) {
357
- id = (id.match(/\d+/) || [''])[0];
358
- }
134
+ this.$super('sortable', element).setOptions(options);
359
135
 
360
- // assigning the parameters
361
- if (url.include('%{id}')) {
362
- url = url.replace('%{id}', id);
363
- } else {
364
- params[this.options.idParam] = id;
136
+ this.find(this.options.itemCss).each('makeDraggable', {
137
+ 'revert': true,
138
+ 'onDrag': function(draggable, event) {
139
+ console.log(event.find(this.options.itemCss).index())
365
140
  }
366
- params[this.options.posParam] = position;
367
-
368
- // merging the params with possible Xhr params
369
- if (isString(options.params)) {
370
- options.params += '&'+Object.toQueryString(params);
371
- } else {
372
- options.params = Object.merge(options.params, params);
373
- }
374
-
375
- // calling the server
376
- RightJS.Xhr.load(url, options);
377
- }
141
+ });
378
142
  }
379
143
  });
380
144
 
381
-
382
- /**
383
- * Document level hooks for sortables
384
- *
385
- * Copyright (C) 2009-2010 Nikolay Nemshilov
386
- */
387
145
  $(document).on({
388
- mousedown: function(event) {
389
- var element = event.find(Sortable.Options.cssRule+",*.rui-sortable");
390
-
391
- if (element) {
392
- Sortable.cast(element).startDrag(event);
393
- }
394
- },
395
-
396
- mousemove: function(event) {
397
- if (Sortable.current) {
398
- Sortable.current.moveItem(event);
399
- }
400
- },
401
-
402
- mouseup: function(event) {
403
- if (Sortable.current) {
404
- Sortable.current.finishDrag(event);
405
- }
146
+ ready: function() {
147
+
406
148
  }
407
149
  });
408
150
 
409
- $(window).onBlur(function() {
410
- if (Sortable.current) {
411
- Sortable.current.finishDrag();
412
- }
413
- });
414
-
415
-
416
- var embed_style = document.createElement('style'),
417
- embed_rules = document.createTextNode(".rui-sortable{user-select:none;-moz-user-select:none;-webkit-user-select:none}");
418
-
419
- embed_style.type = 'text/css';
420
- document.getElementsByTagName('head')[0].appendChild(embed_style);
421
-
422
- if(embed_style.styleSheet) {
423
- embed_style.styleSheet.cssText = embed_rules.nodeValue;
424
- } else {
425
- embed_style.appendChild(embed_rules);
426
- }
427
-
428
-
429
151
  return Sortable;
430
- })(document, RightJS);
152
+ })(document, Math, RightJS);