active_admin-sortable_tree 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/.gitignore +11 -0
- data/.travis.yml +8 -0
- data/Gemfile +10 -0
- data/MIT-LICENSE +20 -0
- data/README.md +163 -0
- data/Rakefile +57 -0
- data/active_admin-sortable_tree.gemspec +30 -0
- data/app/assets/javascripts/active_admin/sortable.js.coffee +91 -0
- data/app/assets/stylesheets/active_admin/sortable.css.sass +79 -0
- data/bin/rails +11 -0
- data/gemfiles/3.2.gemfile +7 -0
- data/gemfiles/4.0.gemfile +10 -0
- data/lib/active_admin/sortable_tree.rb +4 -0
- data/lib/active_admin/sortable_tree/controller_actions.rb +52 -0
- data/lib/active_admin/sortable_tree/engine.rb +19 -0
- data/lib/active_admin/sortable_tree/version.rb +5 -0
- data/lib/active_admin/views/index_as_block_decorator.rb +30 -0
- data/lib/active_admin/views/index_as_sortable.rb +154 -0
- data/lib/activeadmin-sortable-tree.rb +1 -0
- data/script/rails +11 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/admin/category.rb +15 -0
- data/spec/dummy/app/admin/category_tree.rb +9 -0
- data/spec/dummy/app/admin/dashboard.rb +5 -0
- data/spec/dummy/app/assets/javascripts/active_admin.js +2 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/javascripts/jquery.simulate.js +314 -0
- data/spec/dummy/app/assets/stylesheets/active_admin.css.scss +17 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/admin_user.rb +6 -0
- data/spec/dummy/app/models/category.rb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +56 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +28 -0
- data/spec/dummy/config/environments/production.rb +64 -0
- data/spec/dummy/config/environments/test.rb +32 -0
- data/spec/dummy/config/initializers/active_admin.rb +231 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/devise.rb +256 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +8 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/devise.en.yml +59 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +61 -0
- data/spec/dummy/db/migrate/20140806024135_devise_create_admin_users.rb +48 -0
- data/spec/dummy/db/migrate/20140806024139_create_active_admin_comments.rb +19 -0
- data/spec/dummy/db/migrate/20140806032156_create_categories.rb +12 -0
- data/spec/dummy/db/schema.rb +58 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/features/sortable_spec.rb +58 -0
- data/spec/rails_helper.rb +65 -0
- data/spec/spec_helper.rb +58 -0
- data/spec/support/wait_for_ajax.rb +19 -0
- data/vendor/assets/javascripts/jquery.mjs.nestedSortable.js +613 -0
- metadata +231 -0
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,15 @@
|
|
1
|
+
ActiveAdmin.register Category do
|
2
|
+
sortable
|
3
|
+
|
4
|
+
permit_params :name, :ancestry, :description, :position if ENV['RAILS_VERSION'] == '4'
|
5
|
+
|
6
|
+
index as: :sortable do
|
7
|
+
label :name
|
8
|
+
actions
|
9
|
+
end
|
10
|
+
|
11
|
+
form do |f|
|
12
|
+
f.inputs :name, :description
|
13
|
+
f.actions
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,314 @@
|
|
1
|
+
/*!
|
2
|
+
* jQuery Simulate v@VERSION - simulate browser mouse and keyboard events
|
3
|
+
* https://github.com/jquery/jquery-simulate
|
4
|
+
*
|
5
|
+
* Copyright 2012 jQuery Foundation and other contributors
|
6
|
+
* Released under the MIT license.
|
7
|
+
* http://jquery.org/license
|
8
|
+
*
|
9
|
+
* Date: @DATE
|
10
|
+
*/
|
11
|
+
|
12
|
+
;(function( $, undefined ) {
|
13
|
+
|
14
|
+
var rkeyEvent = /^key/,
|
15
|
+
rmouseEvent = /^(?:mouse|contextmenu)|click/;
|
16
|
+
|
17
|
+
$.fn.simulate = function( type, options ) {
|
18
|
+
return this.each(function() {
|
19
|
+
new $.simulate( this, type, options );
|
20
|
+
});
|
21
|
+
};
|
22
|
+
|
23
|
+
$.simulate = function( elem, type, options ) {
|
24
|
+
var method = $.camelCase( "simulate-" + type );
|
25
|
+
|
26
|
+
this.target = elem;
|
27
|
+
this.options = options;
|
28
|
+
|
29
|
+
if ( this[ method ] ) {
|
30
|
+
this[ method ]();
|
31
|
+
} else {
|
32
|
+
this.simulateEvent( elem, type, options );
|
33
|
+
}
|
34
|
+
};
|
35
|
+
|
36
|
+
$.extend( $.simulate, {
|
37
|
+
|
38
|
+
keyCode: {
|
39
|
+
BACKSPACE: 8,
|
40
|
+
COMMA: 188,
|
41
|
+
DELETE: 46,
|
42
|
+
DOWN: 40,
|
43
|
+
END: 35,
|
44
|
+
ENTER: 13,
|
45
|
+
ESCAPE: 27,
|
46
|
+
HOME: 36,
|
47
|
+
LEFT: 37,
|
48
|
+
NUMPAD_ADD: 107,
|
49
|
+
NUMPAD_DECIMAL: 110,
|
50
|
+
NUMPAD_DIVIDE: 111,
|
51
|
+
NUMPAD_ENTER: 108,
|
52
|
+
NUMPAD_MULTIPLY: 106,
|
53
|
+
NUMPAD_SUBTRACT: 109,
|
54
|
+
PAGE_DOWN: 34,
|
55
|
+
PAGE_UP: 33,
|
56
|
+
PERIOD: 190,
|
57
|
+
RIGHT: 39,
|
58
|
+
SPACE: 32,
|
59
|
+
TAB: 9,
|
60
|
+
UP: 38
|
61
|
+
},
|
62
|
+
|
63
|
+
buttonCode: {
|
64
|
+
LEFT: 0,
|
65
|
+
MIDDLE: 1,
|
66
|
+
RIGHT: 2
|
67
|
+
}
|
68
|
+
});
|
69
|
+
|
70
|
+
$.extend( $.simulate.prototype, {
|
71
|
+
|
72
|
+
simulateEvent: function( elem, type, options ) {
|
73
|
+
var event = this.createEvent( type, options );
|
74
|
+
this.dispatchEvent( elem, type, event, options );
|
75
|
+
},
|
76
|
+
|
77
|
+
createEvent: function( type, options ) {
|
78
|
+
if ( rkeyEvent.test( type ) ) {
|
79
|
+
return this.keyEvent( type, options );
|
80
|
+
}
|
81
|
+
|
82
|
+
if ( rmouseEvent.test( type ) ) {
|
83
|
+
return this.mouseEvent( type, options );
|
84
|
+
}
|
85
|
+
},
|
86
|
+
|
87
|
+
mouseEvent: function( type, options ) {
|
88
|
+
var event, eventDoc, doc, body;
|
89
|
+
options = $.extend({
|
90
|
+
bubbles: true,
|
91
|
+
cancelable: (type !== "mousemove"),
|
92
|
+
view: window,
|
93
|
+
detail: 0,
|
94
|
+
screenX: 0,
|
95
|
+
screenY: 0,
|
96
|
+
clientX: 1,
|
97
|
+
clientY: 1,
|
98
|
+
ctrlKey: false,
|
99
|
+
altKey: false,
|
100
|
+
shiftKey: false,
|
101
|
+
metaKey: false,
|
102
|
+
button: 0,
|
103
|
+
relatedTarget: undefined
|
104
|
+
}, options );
|
105
|
+
|
106
|
+
if ( document.createEvent ) {
|
107
|
+
event = document.createEvent( "MouseEvents" );
|
108
|
+
event.initMouseEvent( type, options.bubbles, options.cancelable,
|
109
|
+
options.view, options.detail,
|
110
|
+
options.screenX, options.screenY, options.clientX, options.clientY,
|
111
|
+
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey,
|
112
|
+
options.button, options.relatedTarget || document.body.parentNode );
|
113
|
+
|
114
|
+
// IE 9+ creates events with pageX and pageY set to 0.
|
115
|
+
// Trying to modify the properties throws an error,
|
116
|
+
// so we define getters to return the correct values.
|
117
|
+
if ( event.pageX === 0 && event.pageY === 0 && Object.defineProperty ) {
|
118
|
+
eventDoc = event.relatedTarget.ownerDocument || document;
|
119
|
+
doc = eventDoc.documentElement;
|
120
|
+
body = eventDoc.body;
|
121
|
+
|
122
|
+
Object.defineProperty( event, "pageX", {
|
123
|
+
get: function() {
|
124
|
+
return options.clientX +
|
125
|
+
( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) -
|
126
|
+
( doc && doc.clientLeft || body && body.clientLeft || 0 );
|
127
|
+
}
|
128
|
+
});
|
129
|
+
Object.defineProperty( event, "pageY", {
|
130
|
+
get: function() {
|
131
|
+
return options.clientY +
|
132
|
+
( doc && doc.scrollTop || body && body.scrollTop || 0 ) -
|
133
|
+
( doc && doc.clientTop || body && body.clientTop || 0 );
|
134
|
+
}
|
135
|
+
});
|
136
|
+
}
|
137
|
+
} else if ( document.createEventObject ) {
|
138
|
+
event = document.createEventObject();
|
139
|
+
$.extend( event, options );
|
140
|
+
// standards event.button uses constants defined here: http://msdn.microsoft.com/en-us/library/ie/ff974877(v=vs.85).aspx
|
141
|
+
// old IE event.button uses constants defined here: http://msdn.microsoft.com/en-us/library/ie/ms533544(v=vs.85).aspx
|
142
|
+
// so we actually need to map the standard back to oldIE
|
143
|
+
event.button = {
|
144
|
+
0: 1,
|
145
|
+
1: 4,
|
146
|
+
2: 2
|
147
|
+
}[ event.button ] || event.button;
|
148
|
+
}
|
149
|
+
|
150
|
+
return event;
|
151
|
+
},
|
152
|
+
|
153
|
+
keyEvent: function( type, options ) {
|
154
|
+
var event;
|
155
|
+
options = $.extend({
|
156
|
+
bubbles: true,
|
157
|
+
cancelable: true,
|
158
|
+
view: window,
|
159
|
+
ctrlKey: false,
|
160
|
+
altKey: false,
|
161
|
+
shiftKey: false,
|
162
|
+
metaKey: false,
|
163
|
+
keyCode: 0,
|
164
|
+
charCode: undefined
|
165
|
+
}, options );
|
166
|
+
|
167
|
+
if ( document.createEvent ) {
|
168
|
+
try {
|
169
|
+
event = document.createEvent( "KeyEvents" );
|
170
|
+
event.initKeyEvent( type, options.bubbles, options.cancelable, options.view,
|
171
|
+
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey,
|
172
|
+
options.keyCode, options.charCode );
|
173
|
+
// initKeyEvent throws an exception in WebKit
|
174
|
+
// see: http://stackoverflow.com/questions/6406784/initkeyevent-keypress-only-works-in-firefox-need-a-cross-browser-solution
|
175
|
+
// and also https://bugs.webkit.org/show_bug.cgi?id=13368
|
176
|
+
// fall back to a generic event until we decide to implement initKeyboardEvent
|
177
|
+
} catch( err ) {
|
178
|
+
event = document.createEvent( "Events" );
|
179
|
+
event.initEvent( type, options.bubbles, options.cancelable );
|
180
|
+
$.extend( event, {
|
181
|
+
view: options.view,
|
182
|
+
ctrlKey: options.ctrlKey,
|
183
|
+
altKey: options.altKey,
|
184
|
+
shiftKey: options.shiftKey,
|
185
|
+
metaKey: options.metaKey,
|
186
|
+
keyCode: options.keyCode,
|
187
|
+
charCode: options.charCode
|
188
|
+
});
|
189
|
+
}
|
190
|
+
} else if ( document.createEventObject ) {
|
191
|
+
event = document.createEventObject();
|
192
|
+
$.extend( event, options );
|
193
|
+
}
|
194
|
+
|
195
|
+
if ( !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() ) || (({}).toString.call( window.opera ) === "[object Opera]") ) {
|
196
|
+
event.keyCode = (options.charCode > 0) ? options.charCode : options.keyCode;
|
197
|
+
event.charCode = undefined;
|
198
|
+
}
|
199
|
+
|
200
|
+
return event;
|
201
|
+
},
|
202
|
+
|
203
|
+
dispatchEvent: function( elem, type, event ) {
|
204
|
+
if ( elem[ type ] ) {
|
205
|
+
elem[ type ]();
|
206
|
+
} else if ( elem.dispatchEvent ) {
|
207
|
+
elem.dispatchEvent( event );
|
208
|
+
} else if ( elem.fireEvent ) {
|
209
|
+
elem.fireEvent( "on" + type, event );
|
210
|
+
}
|
211
|
+
},
|
212
|
+
|
213
|
+
simulateFocus: function() {
|
214
|
+
var focusinEvent,
|
215
|
+
triggered = false,
|
216
|
+
element = $( this.target );
|
217
|
+
|
218
|
+
function trigger() {
|
219
|
+
triggered = true;
|
220
|
+
}
|
221
|
+
|
222
|
+
element.bind( "focus", trigger );
|
223
|
+
element[ 0 ].focus();
|
224
|
+
|
225
|
+
if ( !triggered ) {
|
226
|
+
focusinEvent = $.Event( "focusin" );
|
227
|
+
focusinEvent.preventDefault();
|
228
|
+
element.trigger( focusinEvent );
|
229
|
+
element.triggerHandler( "focus" );
|
230
|
+
}
|
231
|
+
element.unbind( "focus", trigger );
|
232
|
+
},
|
233
|
+
|
234
|
+
simulateBlur: function() {
|
235
|
+
var focusoutEvent,
|
236
|
+
triggered = false,
|
237
|
+
element = $( this.target );
|
238
|
+
|
239
|
+
function trigger() {
|
240
|
+
triggered = true;
|
241
|
+
}
|
242
|
+
|
243
|
+
element.bind( "blur", trigger );
|
244
|
+
element[ 0 ].blur();
|
245
|
+
|
246
|
+
// blur events are async in IE
|
247
|
+
setTimeout(function() {
|
248
|
+
// IE won't let the blur occur if the window is inactive
|
249
|
+
if ( element[ 0 ].ownerDocument.activeElement === element[ 0 ] ) {
|
250
|
+
element[ 0 ].ownerDocument.body.focus();
|
251
|
+
}
|
252
|
+
|
253
|
+
// Firefox won't trigger events if the window is inactive
|
254
|
+
// IE doesn't trigger events if we had to manually focus the body
|
255
|
+
if ( !triggered ) {
|
256
|
+
focusoutEvent = $.Event( "focusout" );
|
257
|
+
focusoutEvent.preventDefault();
|
258
|
+
element.trigger( focusoutEvent );
|
259
|
+
element.triggerHandler( "blur" );
|
260
|
+
}
|
261
|
+
element.unbind( "blur", trigger );
|
262
|
+
}, 1 );
|
263
|
+
}
|
264
|
+
});
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
/** complex events **/
|
269
|
+
|
270
|
+
function findCenter( elem ) {
|
271
|
+
var offset,
|
272
|
+
document = $( elem.ownerDocument );
|
273
|
+
elem = $( elem );
|
274
|
+
offset = elem.offset();
|
275
|
+
|
276
|
+
return {
|
277
|
+
x: offset.left + elem.outerWidth() / 2 - document.scrollLeft(),
|
278
|
+
y: offset.top + elem.outerHeight() / 2 - document.scrollTop()
|
279
|
+
};
|
280
|
+
}
|
281
|
+
|
282
|
+
$.extend( $.simulate.prototype, {
|
283
|
+
simulateDrag: function() {
|
284
|
+
var i = 0,
|
285
|
+
target = this.target,
|
286
|
+
options = this.options,
|
287
|
+
center = findCenter( target ),
|
288
|
+
x = Math.floor( center.x ),
|
289
|
+
y = Math.floor( center.y ),
|
290
|
+
dx = options.dx || 0,
|
291
|
+
dy = options.dy || 0,
|
292
|
+
moves = options.moves || 3,
|
293
|
+
coord = { clientX: x, clientY: y };
|
294
|
+
|
295
|
+
this.simulateEvent( target, "mousedown", coord );
|
296
|
+
|
297
|
+
for ( ; i < moves ; i++ ) {
|
298
|
+
x += dx / moves;
|
299
|
+
y += dy / moves;
|
300
|
+
|
301
|
+
coord = {
|
302
|
+
clientX: Math.round( x ),
|
303
|
+
clientY: Math.round( y )
|
304
|
+
};
|
305
|
+
|
306
|
+
this.simulateEvent( document, "mousemove", coord );
|
307
|
+
}
|
308
|
+
|
309
|
+
this.simulateEvent( target, "mouseup", coord );
|
310
|
+
this.simulateEvent( target, "click", coord );
|
311
|
+
}
|
312
|
+
});
|
313
|
+
|
314
|
+
})( jQuery );
|
@@ -0,0 +1,17 @@
|
|
1
|
+
// SASS variable overrides must be declared before loading up Active Admin's styles.
|
2
|
+
//
|
3
|
+
// To view the variables that Active Admin provides, take a look at
|
4
|
+
// `app/assets/stylesheets/active_admin/mixins/_variables.css.scss` in the
|
5
|
+
// Active Admin source.
|
6
|
+
//
|
7
|
+
// For example, to change the sidebar width:
|
8
|
+
// $sidebar-width: 242px;
|
9
|
+
|
10
|
+
// Active Admin's got SASS!
|
11
|
+
@import "active_admin/mixins";
|
12
|
+
@import "active_admin/base";
|
13
|
+
|
14
|
+
// Overriding any non-variable SASS must be done after the fact.
|
15
|
+
// For example, to change the default status-tag color:
|
16
|
+
//
|
17
|
+
// .status_tag { background: #6090DB; }
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
File without changes
|
File without changes
|