activeadmin_draggable 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
-
3
2
  # Specify your gem's dependencies in activeadmin_draggable.gemspec
4
3
  gemspec
4
+
@@ -20,5 +20,4 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
- spec.add_runtime_dependency "acts_as_list"
24
23
  end
@@ -3,28 +3,20 @@
3
3
  //= require activeadmin_draggable/jquery.tablednd_0_5
4
4
 
5
5
  $(document).ready(function(){
6
- //sortable tables
6
+ //enabling and disaabling reorder mode of resources table
7
7
  $('a.reorder').click(function(event) {
8
8
  event.preventDefault();
9
+ var link = $(this)
9
10
  var url = this.href
10
11
  TableTree.toggle($('table.list'), url);
12
+ if (link.text() == link.data('on_text')){
13
+ link.text(link.data('off_text'));
14
+ } else {
15
+ link.text(link.data('on_text'));
16
+ }
17
+
11
18
  return false;
12
19
  });
13
20
 
14
- $('#add_product_button').click(function(event) {
15
- event.preventDefault();
16
- $('div.modal').omniWindow() // create modal
17
- .trigger('show'); // and show it
18
- return false;
19
- });
20
-
21
- $('#search-attributes .layout-slider input').each(function(index, value) {
22
- var sb = new SliderBar();
23
- sb.initialize(value);
24
- });
25
-
26
-
27
- // calculate next matching value from given set of options
28
-
29
21
  });
30
22
 
@@ -183,7 +183,7 @@ TableTree.Table.prototype = jQuery.extend(new TableTree.Base(), {
183
183
  },
184
184
  show_spinner: function(row) {
185
185
  img = document.createElement('img');
186
- img.src = '/assets/active_admin/indicator.gif';
186
+ img.src = '/assets/activeadmin_draggable/indicator.gif';
187
187
  img.className = 'spinner';
188
188
  $('td', row)[0].appendChild(img);
189
189
  },
@@ -119,12 +119,23 @@ jQuery.tableDnD = {
119
119
  return this;
120
120
  },
121
121
 
122
+
123
+ //unbind all event from table
124
+ teardown: function(table){
125
+ var rows = table.find("tr");
126
+ var link = $('a.reorder');
127
+ $.each(rows, function(){
128
+ $(this).unbind();
129
+ $(this).css('cursor', 'default');
130
+ });
131
+ },
132
+
122
133
  /** This function makes all the rows on the table draggable apart from those marked as "NoDrag" */
123
134
  makeDraggable: function(table) {
124
135
  var config = table.tableDnDConfig;
125
136
  if (table.tableDnDConfig.dragHandle) {
126
137
  // We only need to add the event to the specified cells
127
- var cells = $("td."+table.tableDnDConfig.dragHandle, table);
138
+ jQuery.tableDnD.teardown(table);
128
139
  cells.each(function() {
129
140
  // The cell is bound to "this"
130
141
  jQuery(this).mousedown(function(ev) {
@@ -1,5 +1,7 @@
1
1
  require "activeadmin_draggable/version"
2
2
  require 'activeadmin_draggable/engine'
3
+ require 'activeadmin_draggable/draggable_list_item'
4
+ require 'activeadmin_draggable/sortable_tree'
3
5
 
4
6
  module ActiveadminDraggable
5
7
  end
@@ -0,0 +1,46 @@
1
+ module ActiveadminDraggable
2
+ class DraggableListItem
3
+
4
+ #method that given any resource class changes possition
5
+ #of an item according to params passed by javascript sorting action
6
+
7
+ def self.move(klass, id, left_id)
8
+ left_id = left_id.to_i
9
+ dropped_item = klass.find(id)
10
+
11
+ if left_id != 0
12
+ item_to_insert_at = klass.find(left_id)
13
+ else
14
+ item_to_insert_at = nil
15
+ end
16
+
17
+ item = DraggableListItem.new(dropped_item)
18
+ item.move_to(item_to_insert_at)
19
+
20
+ end
21
+
22
+ def initialize(dropped_item)
23
+ @dropped_item = dropped_item
24
+ end
25
+
26
+ def move_to(item_to_insert_at)
27
+ if item_to_insert_at
28
+ @item_to_insert_at = item_to_insert_at
29
+ if moving_up?
30
+ @dropped_item.insert_at(@item_to_insert_at.position)
31
+ @dropped_item.increment_position
32
+ else
33
+ @dropped_item.insert_at(@item_to_insert_at.position)
34
+ end
35
+ else
36
+ @dropped_item.move_to_top
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def moving_up?
43
+ @item_to_insert_at.position < @dropped_item.position
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,70 @@
1
+ module ActiveAdmin
2
+ module Views
3
+ # An index page component, which allows both list and tree reordering
4
+ # It has full interface-wise compatibility with IndexAsTable component
5
+ # Example usage:
6
+ # index :as => :sortable_table, :tree => true
7
+
8
+ class IndexAsSortableTable < IndexAsTable
9
+ def build(page_presenter, collection)
10
+ table_options = {
11
+
12
+ :id => active_admin_config.resource_name.plural,
13
+ :sortable => false,
14
+ :class => "index_table list",
15
+ :i18n => active_admin_config.resource_class,
16
+ :paginator => false
17
+ }
18
+
19
+ if is_tree = page_presenter.options[:tree]
20
+ table_options[:class] += " tree"
21
+ end
22
+
23
+ table_for collection, table_options do |t|
24
+ table_config_block = page_presenter.block || default_table
25
+ instance_exec(t, &table_config_block)
26
+ end
27
+ end
28
+
29
+ def table_for(*args, &block)
30
+ insert_tag IndexSortableTableFor, *args, &block
31
+ end
32
+
33
+ class IndexSortableTableFor < IndexTableFor
34
+ def sortable?
35
+ false
36
+ end
37
+
38
+ protected
39
+
40
+ def build_table_body
41
+ @tbody = tbody do
42
+ # Build enough rows for our collection
43
+ @collection.each{|_| tr(:class => "level_#{_.level rescue 0}", :id => dom_id(_)) }
44
+ end
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+
51
+ # This form helper allows us to create form for nested belongs_to association.
52
+
53
+ class FormBuilder
54
+ def has_one_nested(association, options = {}, &block)
55
+ options = { :for => association }.merge(options)
56
+ options[:class] ||= ""
57
+ options[:class] << "inputs has_one_field"
58
+
59
+ #looks dirty...but works (still better than active admin's way)
60
+ if object.new_record?
61
+ content = inputs_for_nested_attributes :for => [association, object.class.reflect_on_association(association).klass.new],
62
+ &block
63
+ form_buffers.last << content.html_safe
64
+ else
65
+ content = inputs options, &block
66
+ end
67
+ end
68
+ end
69
+
70
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveadminDraggable
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_draggable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Krzysztof Bia\xC5\x82ek"
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2013-04-29 00:00:00 Z
19
+ date: 2013-04-30 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: bundler
@@ -47,20 +47,6 @@ dependencies:
47
47
  version: "0"
48
48
  type: :development
49
49
  version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: acts_as_list
52
- prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
62
- type: :runtime
63
- version_requirements: *id003
64
50
  description: Active admin sortable add on
65
51
  email:
66
52
  - krzysztofbialek@gmail.com
@@ -77,11 +63,14 @@ files:
77
63
  - README.md
78
64
  - Rakefile
79
65
  - activeadmin_draggable.gemspec
66
+ - app/assets/images/activeadmin_draggable/indicator.gif
80
67
  - app/assets/javascripts/activeadmin_draggable/activeadmin_draggable.js
81
68
  - app/assets/javascripts/activeadmin_draggable/jquery.table_tree.js
82
69
  - app/assets/javascripts/activeadmin_draggable/jquery.tablednd_0_5.js
83
70
  - lib/activeadmin_draggable.rb
71
+ - lib/activeadmin_draggable/draggable_list_item.rb
84
72
  - lib/activeadmin_draggable/engine.rb
73
+ - lib/activeadmin_draggable/sortable_tree.rb
85
74
  - lib/activeadmin_draggable/version.rb
86
75
  homepage: ""
87
76
  licenses: