rs-active_admin-sortable_tree 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 186e690db8e7c024d32af6eb103aec23a61995b7843aa82380506d0ba9e14a91
4
+ data.tar.gz: d12dcb444862b75f86e03a00e8acd8ea084865e9537d3e648992d5374875a1ab
5
+ SHA512:
6
+ metadata.gz: d3add2cb7ab0ea838175ee39ff88378932e8337742c0a3898ae3083554bba57f00bd119d8d02dc86dc76d51f812fc851020deccefa136c6d92dbeff38f885bfd
7
+ data.tar.gz: c8949af1bb754a93d463356bce5b999f9aedd8c797c33d80b1dde3745dc863fb451d872a9114e4b1b2a6292bcbb9c22a5e49dfc3b73b893bf355956276dcc8de
@@ -0,0 +1,75 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [2.0.0] - 2018-01-22
6
+
7
+ ### Changed
8
+
9
+ - Depend on same version of `jquery-ui-rails` as ActiveAdmin
10
+ - Update dependencies to only support ActiveAdmin `< 1.1.0` because `v1.1.0`
11
+ [dropped its dependency on `jquery-ui-rails`](https://github.com/activeadmin/activeadmin/blob/master/CHANGELOG.md).
12
+ - Remove usage of bourbon mixin; instead rely on ActiveAdmin's utilities mixin
13
+ (fixes #73)
14
+
15
+ ### Removed
16
+
17
+ - Remove support for Rails 3.2
18
+ - Remove support for ActiveAdmin 0.6.6
19
+
20
+ ### Upgrading from 1.0.0
21
+
22
+ It is suggested (but not required) to manually include the JavaScript and
23
+ stylesheet to your manifest files in preparation for ActiveAdmin v2.0. See the
24
+ Installation section of the [README.md](README.md#installation) for instructions.
25
+
26
+ ## [1.0.0] - 2017-06-01
27
+
28
+ ### Added
29
+
30
+ - Support for Rails 5.0 and 5.1 by conditionally invoking `parameterize` with its
31
+ expected parameters.
32
+
33
+ ### Changed
34
+
35
+ - Relax dependency on `jquery-ui-rails` to be `>= 5.0` (previously `~> 5.0`).
36
+
37
+ ### Removed
38
+
39
+ - Ruby 1.9.3, 2.1, and 2.2 are no longer explicitly supported.
40
+
41
+ ## [0.3.0] - 2016-09-08
42
+
43
+ - Rename sortable.css.sass to sortable.sass to fix deprecation warnings
44
+ - Update usage of box-sizing to fix Bourbon deprecation warning
45
+
46
+ ## [0.2.1] - 2015-04-15
47
+
48
+ - Suppress list styles on sortable indexes when batch actions are disabled.
49
+ ([#48](https://github.com/zorab47/activeadmin-sortable-tree/issues/48)).
50
+ - Do not render the extra cell for batch actions when they are disabled, which
51
+ removes extra whitespace to the left of items.
52
+
53
+ ## [0.2.0] - 2014-12-23
54
+
55
+ - Shrink gem file size by excluding spec files and dummy application.
56
+
57
+ ## [0.1.0] - 2014-11-19
58
+
59
+ - Add option to disable sorting: `sortable: false`, which causes the index view
60
+ to be a static tree view.
61
+ - Ensure the default actions honor authorization checks
62
+ ([#43](https://github.com/nebirhos/activeadmin-sortable-tree/pull/43)).
63
+
64
+ ## 0.0.1 - 2014-08-07
65
+
66
+ - Published to Rubygems.
67
+
68
+
69
+ [unreleased]: https://github.com/zorab47/active_admin-sortable_tree/compare/v1.0.0...HEAD
70
+ [0.1.0]: https://github.com/zorab47/active_admin-sortable_tree/compare/v0.0.1...v0.1.0
71
+ [0.2.0]: https://github.com/zorab47/active_admin-sortable_tree/compare/v0.1.0...v0.2.0
72
+ [0.2.1]: https://github.com/zorab47/active_admin-sortable_tree/compare/v0.2.0...v0.2.1
73
+ [0.3.0]: https://github.com/zorab47/active_admin-sortable_tree/compare/v0.2.1...v0.3.0
74
+ [1.0.0]: https://github.com/zorab47/active_admin-sortable_tree/compare/v0.3.0...v1.0.0
75
+ [1.1.0]: https://github.com/zorab47/active_admin-sortable_tree/compare/v1.0.0...v1.1.0
@@ -0,0 +1,20 @@
1
+ Copyright 2012 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.
@@ -0,0 +1,254 @@
1
+ # ActiveAdmin::SortableTree
2
+
3
+ This fork allows to work with awesome nested set & adds custom HTML in label
4
+
5
+ [![Build Status](https://travis-ci.org/rs-pro/active_admin-sortable_tree.svg?branch=master)](https://travis-ci.org/rs-pro/active_admin-sortable_tree)
6
+
7
+ This gem adds a tree and a list view to your ActiveAdmin resource index, both
8
+ sortable via drag'n'drop.
9
+
10
+ ![ActiveAdmin::SortableTree Example](docs/example.gif)
11
+
12
+ ## Installation
13
+
14
+ ```ruby
15
+ # Gemfile
16
+ gem "activeadmin"
17
+ gem "rs-active_admin-sortable_tree"
18
+ ```
19
+
20
+ ```ruby
21
+ # app/assets/javascripts/active_admin.js
22
+ //= require active_admin/sortable
23
+
24
+ # app/assets/stylesheets/active_admin.scss
25
+ @import "active_admin/sortable";
26
+ ```
27
+
28
+ ## Usage (Tree)
29
+
30
+ **Admin**:
31
+
32
+ ```ruby
33
+ # app/admin/page.rb
34
+ ActiveAdmin.register Page do
35
+ sortable tree: true
36
+
37
+ index :as => :sortable do
38
+ label :title # item content
39
+ actions
40
+ end
41
+ end
42
+ ```
43
+
44
+ ### Custom HTML in label
45
+
46
+ ```ruby
47
+ # app/admin/home_item.rb
48
+ ActiveAdmin.register HomeItem do
49
+ member_action :toggle, method: :get do
50
+ resource.update_attribute :enabled, !resource.enabled
51
+
52
+ render js: "$('#home_item_#{resource.id} .status_tag').removeClass('yes').removeClass('no').addClass('#{resource.enabled ? :yes : :no}').text('#{resource.enabled ? "Вкл" : "Выкл"}')"
53
+ end
54
+
55
+ index as: :sortable do
56
+ label do |r|
57
+ span(r.id) +
58
+ span(r.name) + span(" ") +
59
+ a("data-href": toggle_admin_home_item_path(r), class: "status_tag #{r.enabled ? :yes : :no}") do
60
+ r.enabled ? "Вкл" : "Выкл"
61
+ end
62
+ end
63
+ end
64
+ end
65
+ ```
66
+
67
+ ```js
68
+ // app/assets/javascripts/active_admin.js
69
+
70
+ $(document).on("click", ".status_tag", function(e) {
71
+ e.preventDefault()
72
+ e.stopPropagation();
73
+ var $t = $(this)
74
+ $.ajax({
75
+ url: $t.data("href"),
76
+ success: function (r) {
77
+ eval(r)
78
+ },
79
+ error: function(e) {
80
+ console.error(e)
81
+ }
82
+ })
83
+ })
84
+
85
+ ```
86
+
87
+ **Model**: ActiveAdmin::SortableTree is agnostic to the tree implementation. All
88
+ you have to do is expose a sorting attribute and a few tree methods (`:parent`,
89
+ `:children` and `:roots`). Let's say you use
90
+ [Ancestry](https://github.com/stefankroes/ancestry):
91
+
92
+ ```ruby
93
+ class Page < ActiveRecord::Base
94
+ attr_accessible :title, :body, :position
95
+ has_ancestry :orphan_strategy => :rootify
96
+ end
97
+ ```
98
+
99
+ You can configure these methods if you need:
100
+
101
+ ```ruby
102
+ ActiveAdmin.register Page do
103
+ sortable tree: true,
104
+ sorting_attribute: :position,
105
+ parent_method: :parent,
106
+ children_method: :children,
107
+ roots_method: :roots,
108
+ roots_collection: proc { current_user.pages.roots }
109
+ # …
110
+ end
111
+ ```
112
+
113
+ The option `roots_collection` provides full control on how to find the root
114
+ nodes of your sortable tree and is evaluated within the context of the
115
+ controller. Please note that `roots_collection` will override what is specified
116
+ in `roots_method`.
117
+
118
+ ## Usage (List)
119
+
120
+ **Admin**:
121
+
122
+ ```ruby
123
+ # app/admin/page.rb
124
+ ActiveAdmin.register Page do
125
+ sortable
126
+
127
+ index :as => :sortable do
128
+ label :title # item content
129
+ actions
130
+ end
131
+ end
132
+ ```
133
+
134
+ **Model**: Sortable list assumes you have a `:position` field in your resource.
135
+ Of course it's configurable:
136
+
137
+ ```ruby
138
+ ActiveAdmin.register Page do
139
+ sortable tree: false, # default
140
+ sorting_attribute: :my_position_field
141
+ # …
142
+ end
143
+ ```
144
+
145
+ **Note**: If you are using the [acts_as_list](https://github.com/swanandp/acts_as_list) gem to manage a `:position` field (not required, but allows for other nice programmatic manipulation of ordered model lists), you must ensure a zero-based index for your list using the `top_of_list` option:
146
+
147
+ ```ruby
148
+ class Page < ActiveRecord::Base
149
+ # Make this list act like a zero-indexed array to avoid off-by-one errors in your sorting
150
+ acts_as_list top_of_list: 0
151
+ end
152
+ ```
153
+
154
+
155
+ ## Usage (generic ActiveAdmin index)
156
+
157
+ Currently supports only IndexAsBlock, more to come!
158
+
159
+ **Admin**:
160
+ ```ruby
161
+ # app/admin/page.rb
162
+ ActiveAdmin.register Page do
163
+ sortable
164
+
165
+ index :as => :block do |page|
166
+ # item content
167
+ end
168
+ end
169
+ ```
170
+
171
+ **Model**: Same as list view (see above)
172
+
173
+ ## Customization
174
+
175
+ ### Full options list with defaults
176
+
177
+ ```ruby
178
+ ActiveAdmin.register Page do
179
+ sortable tree: true,
180
+ max_levels: 0, # infinite indent levels
181
+ protect_root: false, # allow root items to be dragged
182
+ sorting_attribute: :position,
183
+ parent_method: :parent,
184
+ children_method: :children,
185
+ roots_method: :roots,
186
+ roots_collection: nil, # proc to specifiy retrieval of roots
187
+ sortable: true, # Disable sorting (use only 'tree' functionality)
188
+ collapsible: false, # show +/- buttons to collapse children
189
+ start_collapsed: false, # when collapsible, start with all roots collapsed
190
+ end
191
+ ```
192
+
193
+
194
+ ### Actions
195
+
196
+ In `IndexAsSortable` you can add custom actions (with or without the defaults):
197
+
198
+ ```ruby
199
+ index :as => :sortable do
200
+ actions defaults: false do |page|
201
+ link_to "Custom action", my_custom_path(page)
202
+ end
203
+ end
204
+ ```
205
+
206
+ ### Ajax Callback Config
207
+
208
+ It exposes three Ajax Events: ajaxDone, ajaxFail and ajaxAlways, which
209
+ correspond to jQuery ajax callbacks: done, fail and always.
210
+
211
+ To subscribe Ajax callback:
212
+
213
+ ```javascript
214
+ ActiveAdminSortableEvent.add('ajaxDone', function (){
215
+ // do what you want
216
+ })
217
+ ```
218
+
219
+ ### Upgrading to SortableTree 2.0 from 1.0
220
+
221
+ Upgrading from SortableTree 1.x requires manually specifying assets in your
222
+ `app/assets/javascripts/active_admin.js` and `app/assets/stylesheets/active_admin.scss`
223
+ files.
224
+
225
+
226
+ ### Dependencies
227
+
228
+ ActiveAdmin::SortableTree 2.0 supports ActiveAdmin 1.0.0+. For previous versions
229
+ of ActiveAdmin use older SortableTree versions from the 1.x branch.
230
+
231
+ Note: If you experience issues with drag and drop capability, you may need to
232
+ specify the version for your ActiveAdmin installation. It is reported working
233
+ using v0.6.6, or if you are using v1.0.0.pre, it is reported working on this
234
+ commit [b3a9f4b](https://github.com/activeadmin/activeadmin/commit/b3a9f4b3e4051447d011c59649a73f876989a199)
235
+ or later.
236
+
237
+ ```ruby
238
+ # Gemfile
239
+ gem 'activeadmin', github: 'activeadmin', ref: 'b3a9f4b'
240
+ ```
241
+
242
+ ## Semantic Versioning
243
+
244
+ ActiveAdmin::SortableTree follows [semantic versioning](http://semver.org).
245
+
246
+ ## Alternatives
247
+
248
+ - [Active Admin Sortable](https://github.com/neo/activeadmin-sortable)
249
+
250
+ ## Copyright
251
+
252
+ Copyright © 2013 Francesco Disperati, Cantiere Creativo. See the file
253
+ MIT-LICENSE for details. See the full list list of
254
+ [contributors](http://github.com/zorab47/active_admin-sortable_tree/graphs/contributors).
@@ -0,0 +1,2 @@
1
+ //= require jquery-ui/widgets/sortable
2
+ //= require active_admin/sortable_core
@@ -0,0 +1,109 @@
1
+ //= require jquery.mjs.nestedSortable
2
+
3
+ window.ActiveAdminSortableEvent = (function() {
4
+ var eventToListeners;
5
+ eventToListeners = {};
6
+ return {
7
+ add: function(event, callback) {
8
+ if (!eventToListeners.hasOwnProperty(event)) {
9
+ eventToListeners[event] = [];
10
+ }
11
+ eventToListeners[event].push(callback);
12
+ },
13
+ trigger: function(event, args) {
14
+ var callback, e, i, len, ref, results;
15
+ if (eventToListeners.hasOwnProperty(event)) {
16
+ ref = eventToListeners[event];
17
+ results = [];
18
+ for (i = 0, len = ref.length; i < len; i++) {
19
+ callback = ref[i];
20
+ try {
21
+ results.push(callback.call(null, args));
22
+ } catch (_error) {
23
+ e = _error;
24
+ if (console && console.error) {
25
+ results.push(console.error(e));
26
+ } else {
27
+ results.push(void 0);
28
+ }
29
+ }
30
+ }
31
+ return results;
32
+ }
33
+ }
34
+ };
35
+ })();
36
+
37
+ $(function() {
38
+ $('.disclose').bind('click', function(event) {
39
+ $(this).closest('li').toggleClass('mjs-nestedSortable-collapsed').toggleClass('mjs-nestedSortable-expanded');
40
+ });
41
+ $(".index_as_sortable [data-sortable-type]").each(function() {
42
+ var $this, max_levels, tab_hack, getData;
43
+ $this = $(this);
44
+
45
+
46
+ if ($this.data('sortable-type') === "tree") {
47
+ max_levels = $this.data('max-levels');
48
+ tab_hack = 20;
49
+ getData = function(item) {
50
+ return {
51
+ id: item.data("id"),
52
+ parent_id: item.parent().parent().data("id"),
53
+ prev_id: item.prev().data("id"),
54
+ next_id: item.next().data("id")
55
+ }
56
+ }
57
+ } else {
58
+ max_levels = 1;
59
+ tab_hack = 99999;
60
+
61
+ getData = function(item) {
62
+ return $this.nestedSortable("serialize")
63
+ }
64
+ }
65
+
66
+ $this.nestedSortable({
67
+ forcePlaceholderSize: true,
68
+ forceHelperSizeType: true,
69
+ errorClass: 'cantdoit',
70
+ disableNesting: 'cantdoit',
71
+ handle: '> .item',
72
+ listType: 'ol',
73
+ items: 'li',
74
+ opacity: .6,
75
+ placeholder: 'placeholder',
76
+ revert: 250,
77
+ maxLevels: max_levels,
78
+ tabSize: tab_hack,
79
+ protectRoot: $this.data('protect-root'),
80
+ tolerance: 'pointer',
81
+ toleranceElement: '> div',
82
+ isTree: true,
83
+ startCollapsed: $this.data("start-collapsed"),
84
+ update: function(event, ui) {
85
+ $this.nestedSortable("disable");
86
+ $.ajax({
87
+ url: $this.data("sortable-url"),
88
+ type: "post",
89
+ data: getData(ui.item)
90
+ }).always(function() {
91
+ $this.find('.item').each(function(index) {
92
+ if (index % 2) {
93
+ $(this).removeClass('odd').addClass('even');
94
+ } else {
95
+ $(this).removeClass('even').addClass('odd');
96
+ }
97
+ });
98
+ $this.nestedSortable("enable");
99
+ ActiveAdminSortableEvent.trigger('ajaxAlways');
100
+ }).done(function() {
101
+ ActiveAdminSortableEvent.trigger('ajaxDone');
102
+ }).fail(function() {
103
+ ActiveAdminSortableEvent.trigger('ajaxFail');
104
+ });
105
+ }
106
+ });
107
+ });
108
+ });
109
+