active_scaffold_config_list 3.2.9 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,4 +1,5 @@
1
- This works with Rails 3.2 and ActiveScaffold >= 3.3
1
+ This works with Rails 3.2 and ActiveScaffold >= 3.4.4
2
+ Version 3.2.x worked with Rails 3.2 and ActiveScaffold >= 3.3.0
2
3
 
3
4
  Usage:
4
5
  active_scaffold :model do |conf|
@@ -23,4 +24,4 @@ class User < ActiveRecord::Base
23
24
  end
24
25
  end
25
26
 
26
- The model storing list configuration must have a config_list attribute storing the config list.
27
+ The model storing list configuration must have a config_list text column storing the config list, and config_list_sort serialized text column.
@@ -7,11 +7,10 @@ options = {:id => element_form_id(:action => :config_list),
7
7
  'data-loading' => true}
8
8
  form_tag url_options, options %>
9
9
  <h4><%= active_scaffold_config.config_list.label -%></h4>
10
- <%= render :partial => 'show_config_list_form_body', :locals => { :columns => active_scaffold_config.config_list } %>
10
+ <%= render :partial => 'show_config_list_form_body' %>
11
11
  <p class="form-footer">
12
12
  <%= submit_tag as_(:config_list), :class => "submit" %>
13
13
  <%= link_to as_(:reset), url_for(url_options.merge(:config_list => '')), :class => 'as_cancel', :remote => true, :data => {:refresh => true} %>
14
14
  <%= loading_indicator_tag(:action => :config_list) %>
15
15
  </p>
16
16
  </form>
17
- <%= javascript_tag("ActiveScaffold.focus_first_element_of_form('#{element_form_id(:action => :config_list)}');") %>
@@ -1,14 +1,33 @@
1
- <ol id="<%= config_list_ol_id %>" class="form sortable-container">
2
- <% hidden_columns = if !config_list_params.nil? && config_list_params.is_a?(Array)
3
- config_list = config_list_params
4
- active_scaffold_config.list.columns.collect_visible.select{|column| config_list.exclude? column.name}
5
- else
6
- []
7
- end %>
8
- <% list_columns.concat(hidden_columns).each do |c| %>
9
- <li class="form-element sortable">
10
- <%= check_box_tag 'config_list[]', c.name.to_s, (config_list_params.nil? ? true : config_list_params.include?(c.name)), {:id => nil}%>
11
- <label for="update_table_from"><%= c.label%></label>
1
+ <ol class="form">
2
+ <li class="form-element">
3
+ <dl><dt><label>Columns</label></dt>
4
+ <dd><ul class="<%= active_scaffold_config.config_list.draggable ? 'draggable-lists' : 'sortable-container' %>" id="<%= element_form_id(:action => :config_list) %>-columns">
5
+ <%
6
+ if !config_list_params.nil? && config_list_params.is_a?(Array)
7
+ config_list = config_list_params
8
+ list_columns.concat active_scaffold_config.list.columns.collect_visible.select{|column| config_list.exclude? column.name}
9
+ end
10
+ %>
11
+ <% list_columns.each do |c| %>
12
+ <li class="sortable">
13
+ <%= check_box_tag 'config_list[]', c.name.to_s, (config_list_params.nil? ? true : config_list_params.include?(c.name)), {:id => nil}%>
14
+ <label><%= c.label%></label>
15
+ </li>
16
+ <% end %>
17
+ </ul></dd></dl>
12
18
  </li>
19
+ <li class="form-element">
20
+ <dl><dt><label>Default Sorting</label></dt>
21
+ <dd><ol>
22
+ <%
23
+ columns_options = list_columns.select{|c| c.sortable?}.map{|c| [c.label, c.name]}
24
+ order_options = ['asc', 'desc']
25
+ selected = config_list_sorting || []
26
+ 3.times do |i|
27
+ %>
28
+ <li><%= select_tag "config_list_sorting[#{i}][]", options_for_select(columns_options, :selected => selected[i].try(:first)), :include_blank => as_(:_select_), :class => 'column' %>
29
+ <%= select_tag "config_list_sorting[#{i}][]", options_for_select(order_options, :selected => selected[i].try(:last)), :include_blank => as_(:_select_), :class => 'order' %></li>
13
30
  <% end %>
31
+ </ol></dd></dl>
32
+ </li>
14
33
  </ol>
@@ -2,8 +2,8 @@ module ActiveScaffold::Actions
2
2
  module ConfigList
3
3
 
4
4
  def self.included(base)
5
- base.before_filter :store_config_list_params, :only => [:index]
6
- base.helper_method :config_list_params
5
+ base.before_filter :store_config_list_params, :set_default_sorting, :only => [:index]
6
+ base.helper_method :config_list_params, :config_list_sorting
7
7
  base.extend ClassMethods
8
8
  end
9
9
 
@@ -29,6 +29,12 @@ module ActiveScaffold::Actions
29
29
  end
30
30
 
31
31
  protected
32
+
33
+ def set_default_sorting
34
+ unless active_scaffold_config.list.user['sort'] || (params['sort'] and params['sort_direction'])
35
+ active_scaffold_config.list.user.sorting.set *config_list_sorting if config_list_sorting
36
+ end
37
+ end
32
38
 
33
39
  def store_config_list_params
34
40
  if params[:config_list]
@@ -37,10 +43,18 @@ module ActiveScaffold::Actions
37
43
  when String
38
44
  delete_config_list_params
39
45
  when Array
40
- save_config_list_params(config_list)
46
+ save_config_list_params(config_list, config_list_sorting_params)
41
47
  end
42
48
  end
43
49
  end
50
+
51
+ def config_list_sorting_params
52
+ sorting_params = params.delete(:config_list_sorting)
53
+ if sorting_params
54
+ sorting_params = sorting_params.values.select{ |c,d| c.present? && d.present? }
55
+ sorting_params if sorting_params.present?
56
+ end
57
+ end
44
58
 
45
59
  def config_list_session_storage_method
46
60
  respond_to?(:custom_config_list_session_storage) ? :custom_config_list_session_storage : :active_scaffold_session_storage
@@ -55,18 +69,27 @@ module ActiveScaffold::Actions
55
69
  if active_scaffold_config.config_list.save_to_user && current_user = send(active_scaffold_config.class.security.current_user_method)
56
70
  current_user.send(active_scaffold_config.config_list.save_to_user, active_scaffold_session_storage_key, controller_name).destroy
57
71
  else
58
- config_list_session_storage[:config_list] = nil
72
+ config_list_session_storage['config_list'] = nil
73
+ config_list_session_storage['config_list_sorting'] = nil
59
74
  end
75
+ active_scaffold_config.list.user['sort'] = nil
76
+ logger.debug "list #{active_scaffold_config.list.sorting.object_id}"
60
77
  @config_list_params = nil
78
+ @config_list_sorting = nil
61
79
  end
62
80
 
63
- def save_config_list_params(config_list)
81
+ def save_config_list_params(config_list, config_list_sorting)
64
82
  if active_scaffold_config.config_list.save_to_user && current_user = send(active_scaffold_config.class.security.current_user_method)
65
- current_user.send(active_scaffold_config.config_list.save_to_user, active_scaffold_session_storage_key, controller_name).update_attribute :config_list, config_list.join(',')
83
+ record = current_user.send(active_scaffold_config.config_list.save_to_user, active_scaffold_session_storage_key, controller_name)
84
+ record.config_list = config_list.join(',')
85
+ record.config_list_sorting = config_list_sorting if record.respond_to? :config_list_sorting
86
+ record.save
66
87
  else
67
- config_list_session_storage[:config_list] = config_list.map(&:to_sym)
88
+ config_list_session_storage['config_list'] = config_list.map(&:to_sym)
89
+ config_list_session_storage['config_list_sorting'] = config_list_sorting
68
90
  end
69
91
  @config_list_params = config_list.map(&:to_sym)
92
+ @config_list_sorting = config_list_sorting
70
93
  end
71
94
 
72
95
  def objects_for_etag
@@ -99,11 +122,20 @@ module ActiveScaffold::Actions
99
122
  params = config_list_record.config_list
100
123
  params.split(',').map(&:to_sym) if params
101
124
  else
102
- config_list_session_storage[:config_list]
125
+ config_list_session_storage['config_list']
103
126
  end unless defined? @config_list_params
104
127
  @config_list_params || active_scaffold_config.config_list.default_columns
105
128
  end
106
129
 
130
+ def config_list_sorting
131
+ @config_list_sorting = if config_list_record
132
+ config_list_record.config_list_sorting if config_list_record.respond_to? :config_list_sorting
133
+ else
134
+ config_list_session_storage['config_list_sorting']
135
+ end unless defined? @config_list_sorting
136
+ @config_list_sorting
137
+ end
138
+
107
139
  def list_columns
108
140
  @list_columns ||= begin
109
141
  columns = super
@@ -5,6 +5,7 @@ module ActiveScaffold::Config
5
5
  super
6
6
  @link = self.class.link.clone unless self.class.link.nil?
7
7
  @save_to_user = self.class.save_to_user
8
+ @draggable = self.class.draggable
8
9
  end
9
10
 
10
11
  # global level configuration
@@ -20,11 +21,15 @@ module ActiveScaffold::Config
20
21
 
21
22
  # configures where the plugin itself is located. there is no instance version of this.
22
23
  cattr_accessor :plugin_directory
23
- @@plugin_directory = File.expand_path(__FILE__).match(%{(^.*)/lib/active_scaffold/config/config_list.rb})[1]
24
+ self.plugin_directory = File.expand_path(__FILE__).match(%{(^.*)/lib/active_scaffold/config/config_list.rb})[1]
24
25
 
25
26
  # configures the method in user model to save list configuration for every controller
26
27
  cattr_accessor :save_to_user
27
28
 
29
+ # enable draggable lists to select displayed columns (enabled by default)
30
+ cattr_accessor :draggable
31
+ self.draggable = true
32
+
28
33
  # instance-level configuration
29
34
  # ----------------------------
30
35
  # the label= method already exists in the Form base class
@@ -39,6 +44,9 @@ module ActiveScaffold::Config
39
44
  # configures the method in user model to save list configuration for every controller
40
45
  attr_accessor :save_to_user
41
46
 
47
+ # enable draggable lists to select displayed columns
48
+ attr_accessor :draggable
49
+
42
50
  # provides access to the list of columns specifically meant for the config_list to use
43
51
  def columns
44
52
  unless @columns # lazy evaluation
@@ -12,8 +12,4 @@ module ActiveScaffold
12
12
  module Config
13
13
  ActiveScaffold.autoload_subdir('config', self, File.dirname(__FILE__))
14
14
  end
15
-
16
- module Helpers
17
- ActiveScaffold.autoload_subdir('helpers', self, File.dirname(__FILE__))
18
- end
19
15
  end
@@ -4,10 +4,6 @@ module ActiveScaffoldConfigList
4
4
  ActiveSupport.on_load(:action_controller) do
5
5
  require "active_scaffold_config_list/config/core.rb"
6
6
  end
7
-
8
- ActiveSupport.on_load(:action_view) do
9
- include ActiveScaffold::Helpers::ConfigListHelpers
10
- end
11
7
  end
12
8
  end
13
9
  end
@@ -1,8 +1,8 @@
1
1
  module ActiveScaffoldConfigList
2
2
  module Version
3
3
  MAJOR = 3
4
- MINOR = 2
5
- PATCH = 9
4
+ MINOR = 3
5
+ PATCH = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold_config_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.9
4
+ hash: 11
5
+ prerelease:
6
+ segments:
7
+ - 3
8
+ - 3
9
+ - 0
10
+ version: 3.3.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Sergio Cambra
@@ -9,28 +15,40 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2014-07-17 00:00:00 Z
18
+ date: 2014-09-02 00:00:00 Z
13
19
  dependencies:
14
20
  - !ruby/object:Gem::Dependency
21
+ type: :runtime
15
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
16
24
  requirements:
17
25
  - - ">="
18
26
  - !ruby/object:Gem::Version
19
- version: 3.3.0
27
+ hash: 31
28
+ segments:
29
+ - 3
30
+ - 4
31
+ - 4
32
+ version: 3.4.4
20
33
  version_requirements: *id001
21
- prerelease: false
22
- type: :runtime
23
34
  name: active_scaffold
35
+ prerelease: false
24
36
  - !ruby/object:Gem::Dependency
37
+ type: :runtime
25
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
26
40
  requirements:
27
41
  - - ">="
28
42
  - !ruby/object:Gem::Version
43
+ hash: 11
44
+ segments:
45
+ - 3
46
+ - 2
47
+ - 2
29
48
  version: 3.2.2
30
49
  version_requirements: *id002
31
- prerelease: false
32
- type: :runtime
33
50
  name: active_scaffold_sortable
51
+ prerelease: false
34
52
  description: User may reorder and hide/show list columns
35
53
  email: activescaffold@googlegroups.com
36
54
  executables: []
@@ -45,7 +63,6 @@ files:
45
63
  - app/views/active_scaffold_overrides/show_config_list_form.html.erb
46
64
  - lib/active_scaffold/actions/config_list.rb
47
65
  - lib/active_scaffold/config/config_list.rb
48
- - lib/active_scaffold/helpers/config_list_helpers.rb
49
66
  - lib/active_scaffold_config_list.rb
50
67
  - lib/active_scaffold_config_list/config/core.rb
51
68
  - lib/active_scaffold_config_list/engine.rb
@@ -55,28 +72,35 @@ files:
55
72
  homepage: http://activescaffold.com
56
73
  licenses:
57
74
  - MIT
58
- metadata: {}
59
-
60
75
  post_install_message:
61
76
  rdoc_options: []
62
77
 
63
78
  require_paths:
64
79
  - lib
65
80
  required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
66
82
  requirements:
67
- - &id003
68
- - ">="
83
+ - - ">="
69
84
  - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
70
88
  version: "0"
71
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
72
91
  requirements:
73
- - *id003
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
74
98
  requirements: []
75
99
 
76
100
  rubyforge_project:
77
- rubygems_version: 2.0.7
101
+ rubygems_version: 1.8.29
78
102
  signing_key:
79
- specification_version: 4
103
+ specification_version: 3
80
104
  summary: User specific column configuration for ActiveScaffold
81
105
  test_files: []
82
106
 
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: c7f59d06507175af8cd27a5d855a9b2929d1e8b4
4
- data.tar.gz: 2fd63bc9bba6663590cfa9d4213b0f11cd6a076f
5
- SHA512:
6
- metadata.gz: a58336285acf4982720e927732a971342197f3e4c6898ce59fc699ad7620484c11ddc4fcddbb84c579f4c50cb7b33f51b885831c14bb80068a7626e88f5a6863
7
- data.tar.gz: 4600ee0d71fc192a0935a85806fdda8518df4f81c2167fc17935cce45694c3cb8838393ed00cb0027144b5613f38ba4ff7738eb1675d8e52e651f2d0806ff17a
@@ -1,10 +0,0 @@
1
- module ActiveScaffold
2
- module Helpers
3
- # Helpers that assist with the rendering of a Form Column
4
- module ConfigListHelpers
5
- def config_list_ol_id
6
- "ol_#{element_form_id(:action => :config_list)}"
7
- end
8
- end
9
- end
10
- end