inline_forms 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/controllers/inline_forms_controller.rb +34 -8
- data/app/helpers/form_elements/check_list.rb +6 -2
- data/app/helpers/form_elements/dropdown.rb +5 -1
- data/app/helpers/inline_forms_helper.rb +14 -1
- data/app/views/inline_forms/_list.html.erb +1 -7
- data/inline_forms.gemspec +2 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.7
|
@@ -22,6 +22,27 @@
|
|
22
22
|
#
|
23
23
|
class InlineFormsController < ApplicationController
|
24
24
|
before_filter :getKlass
|
25
|
+
|
26
|
+
def self.cancan_enabled?
|
27
|
+
begin
|
28
|
+
::Ability && true
|
29
|
+
rescue NameError
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def cancan_enabled?
|
35
|
+
self.class.cancan_enabled?
|
36
|
+
end
|
37
|
+
|
38
|
+
def cancan_disabled?
|
39
|
+
! self.class.cancan_enabled?
|
40
|
+
end
|
41
|
+
|
42
|
+
helper_method :cancan_disabled?, :cancan_enabled?
|
43
|
+
|
44
|
+
load_and_authorize_resource if cancan_enabled?
|
45
|
+
|
25
46
|
include InlineFormsHelper
|
26
47
|
|
27
48
|
# shows a list of all objects from class @Klass, using will_paginate
|
@@ -31,11 +52,12 @@ class InlineFormsController < ApplicationController
|
|
31
52
|
def index
|
32
53
|
update_span = params[:update]
|
33
54
|
@parent_class = params[:parent_class]
|
34
|
-
|
35
|
-
|
55
|
+
@parent_id = params[:parent_id]
|
56
|
+
@parent_class.nil? ? conditions = [] : conditions = [ "#{@parent_class.foreign_key} = ?", @parent_id ]
|
57
|
+
if cancan_enabled?
|
58
|
+
@objects = @Klass.accessible_by(current_ability).paginate :page => params[:page], :order => 'created_at DESC', :conditions => conditions
|
36
59
|
else
|
37
|
-
@
|
38
|
-
@objects = @Klass.paginate :page => params[:page], :order => 'created_at DESC', :conditions => [ "#{@parent_class.foreign_key} = ?", @parent_id ]
|
60
|
+
@objects = @Klass.paginate :page => params[:page], :order => 'created_at DESC', :conditions => conditions
|
39
61
|
end
|
40
62
|
|
41
63
|
respond_to do |format|
|
@@ -99,12 +121,14 @@ class InlineFormsController < ApplicationController
|
|
99
121
|
flash.now[:error] = "Failed to create #{object.class.to_s.underscore}."
|
100
122
|
end
|
101
123
|
@parent_class = params[:parent_class]
|
102
|
-
|
103
|
-
|
124
|
+
@parent_id = params[:parent_id]
|
125
|
+
@parent_class.nil? ? conditions = [] : conditions = [ "#{@parent_class.foreign_key} = ?", @parent_id ]
|
126
|
+
if cancan_enabled?
|
127
|
+
@objects = @Klass.accessible_by(current_ability).paginate :page => params[:page], :order => 'created_at DESC', :conditions => conditions
|
104
128
|
else
|
105
|
-
@
|
106
|
-
@objects = @Klass.paginate :page => params[:page], :order => 'created_at DESC', :conditions => [ "#{@parent_class.foreign_key} = ?", @parent_id ]
|
129
|
+
@objects = @Klass.paginate :page => params[:page], :order => 'created_at DESC', :conditions => conditions
|
107
130
|
end
|
131
|
+
|
108
132
|
respond_to do |format|
|
109
133
|
# found this here: http://www.ruby-forum.com/topic/211467
|
110
134
|
format.js { render(:update) {|page| page.replace_html @update_span, :partial => 'inline_forms/list'}
|
@@ -190,9 +214,11 @@ class InlineFormsController < ApplicationController
|
|
190
214
|
# redirect_to(@Klass.constantizes_url)
|
191
215
|
# end
|
192
216
|
|
217
|
+
|
193
218
|
private
|
194
219
|
# Get the class from the controller name.
|
195
220
|
def getKlass #:doc:
|
196
221
|
@Klass = self.controller_name.classify.constantize
|
197
222
|
end
|
223
|
+
|
198
224
|
end
|
@@ -15,7 +15,11 @@ end
|
|
15
15
|
|
16
16
|
def check_list_edit(object, attribute)
|
17
17
|
object.send(attribute).build if object.send(attribute).empty?
|
18
|
-
|
18
|
+
if cancan_enabled?
|
19
|
+
values = object.send(attribute).first.class.name.constantize.accessible_by(current_ability) # TODO bring order!
|
20
|
+
else
|
21
|
+
values = object.send(attribute).first.class.name.constantize.all # TODO bring order!
|
22
|
+
end
|
19
23
|
out = '<div class="edit_form_checklist">'
|
20
24
|
out << '<ul>'
|
21
25
|
values.each do | item |
|
@@ -34,6 +38,6 @@ end
|
|
34
38
|
|
35
39
|
def check_list_update(object, attribute)
|
36
40
|
params[attribute] ||= {}
|
37
|
-
object.send(attribute.singularize + '_ids=', params[attribute].keys)
|
41
|
+
object.send(attribute.to_s.singularize + '_ids=', params[attribute].keys)
|
38
42
|
end
|
39
43
|
|
@@ -8,7 +8,11 @@ end
|
|
8
8
|
|
9
9
|
def dropdown_edit(object, attribute)
|
10
10
|
object.send('build_' + attribute.to_s) unless object.send(attribute)
|
11
|
-
|
11
|
+
if cancan_enabled?
|
12
|
+
values = object.send(attribute).class.name.constantize.accessible_by(current_ability) # TODO bring order!
|
13
|
+
else
|
14
|
+
values = object.send(attribute).class.name.constantize.all # TODO bring order!
|
15
|
+
end
|
12
16
|
# the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form!
|
13
17
|
collection_select( ('_' + object.class.to_s.underscore).to_sym, attribute.to_s.foreign_key.to_sym, values, 'id', '_presentation', :selected => object.send(attribute).id)
|
14
18
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
module InlineFormsHelper
|
2
|
-
|
3
2
|
# load form elements. Each element goes into a separate file
|
4
3
|
# and defines a _show, _edit and _update method.
|
5
4
|
#
|
@@ -27,6 +26,7 @@ module InlineFormsHelper
|
|
27
26
|
spaces = attribute_value.length > 40 ? 0 : 40 - attribute_value.length
|
28
27
|
attribute_value << " ".html_safe * spaces
|
29
28
|
css_class_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}"
|
29
|
+
if cancan_disabled? || ( can? :update, object )
|
30
30
|
link_to attribute_value,
|
31
31
|
send( 'edit_' + object.class.to_s.underscore + '_path',
|
32
32
|
object,
|
@@ -34,6 +34,9 @@ module InlineFormsHelper
|
|
34
34
|
:form_element => calling_method.sub(/_[a-z]+$/,''),
|
35
35
|
:update => css_class_id ),
|
36
36
|
:remote => true
|
37
|
+
else
|
38
|
+
attribute_value
|
39
|
+
end
|
37
40
|
end
|
38
41
|
|
39
42
|
# link to inline image edit
|
@@ -48,6 +51,16 @@ module InlineFormsHelper
|
|
48
51
|
:remote => true
|
49
52
|
end
|
50
53
|
|
54
|
+
def link_to_new_record(text, model, path_to_new, update_span, parent_class, parent_id)
|
55
|
+
out = ""
|
56
|
+
out << "<li class='new_record_link'>"
|
57
|
+
out << (link_to text, send(path_to_new, :update => update_span, :parent_class => parent_class, :parent_id => parent_id ), :remote => true)
|
58
|
+
out << "</li>"
|
59
|
+
""
|
60
|
+
raw out if cancan_disabled? || ( can? :create, model.constantize )
|
61
|
+
end
|
62
|
+
|
63
|
+
|
51
64
|
# get the values for an attribute
|
52
65
|
#
|
53
66
|
# values should be a Hash { integer => string, ... }
|
@@ -43,13 +43,7 @@ they are @object. We need this magic here to rewrite all the @variables to varia
|
|
43
43
|
<ul id="<%= update_span -%>" class="inline_forms_list">
|
44
44
|
<% end %>
|
45
45
|
<!-- # link to new -->
|
46
|
-
|
47
|
-
<%= link_to "Add a new #{human_readable_class}",
|
48
|
-
send(path_to_new, :update => update_span,
|
49
|
-
:parent_class => parent_class,
|
50
|
-
:parent_id => parent_id ),
|
51
|
-
:remote => true -%>
|
52
|
-
</li>
|
46
|
+
<%= link_to_new_record("Add a new #{human_readable_class}", objects.first.class.name, path_to_new, update_span, parent_class, parent_id) -%>
|
53
47
|
<!-- # list of objects -->
|
54
48
|
<% for object in objects %>
|
55
49
|
<% if parent_class.nil? %>
|
data/inline_forms.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{inline_forms}
|
8
|
-
s.version = "0.9.
|
8
|
+
s.version = "0.9.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ace Suares"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-05-25}
|
13
13
|
s.description = %q{Inline Forms aims to ease the setup of forms that provide inline editing. The field list can be specified in the model.}
|
14
14
|
s.email = %q{ace@suares.an}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inline_forms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 53
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 7
|
10
|
+
version: 0.9.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ace Suares
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-05-25 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|