inline_forms 0.2.4 → 0.2.6
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 +65 -50
- data/app/helpers/inline_forms_helper.rb +23 -29
- data/app/views/inline_forms/_index.html.erb +4 -0
- data/app/views/inline_forms/_new.html.erb +10 -0
- data/app/views/inline_forms/new.html.erb +7 -6
- data/app/views/layouts/inline_forms.rhtml +16 -5
- data/inline_forms.gemspec +4 -2
- metadata +6 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|
@@ -16,7 +16,7 @@ class InlineFormsController < ApplicationController
|
|
16
16
|
# if the request is an XhttpRequest. There is not much use permitting the actions outside of
|
17
17
|
# the XhttpRequest context (except action => :index). Of course, this is not a security measure.
|
18
18
|
before_filter :getKlass
|
19
|
-
before_filter :must_be_xhr_request, :except => :index
|
19
|
+
#before_filter :must_be_xhr_request, :except => :index
|
20
20
|
include InlineFormsHelper # this might also be included in you application_controller with helper :all but it's not needed
|
21
21
|
layout false
|
22
22
|
# :index shows a list of all objects from class Klass, with all attribute values linked to the 'edit' action.
|
@@ -26,10 +26,15 @@ class InlineFormsController < ApplicationController
|
|
26
26
|
# GET /examples
|
27
27
|
#
|
28
28
|
def index
|
29
|
-
# nolayout = params[:layout] == 'false' || false
|
30
29
|
@objects = @Klass.all
|
31
|
-
|
32
|
-
|
30
|
+
update_span = params[:update]
|
31
|
+
respond_to do |format|
|
32
|
+
# found this here: http://www.ruby-forum.com/topic/211467
|
33
|
+
format.html { render 'inline_forms/index', :layout => 'inline_forms' }
|
34
|
+
format.js { render(:update) {|page| page.replace_html update_span, :partial => 'inline_forms/index' }
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
33
38
|
end
|
34
39
|
|
35
40
|
# :show shows one field (attribute) from a record (object). It inludes the link to 'edit'
|
@@ -55,7 +60,13 @@ render 'inline_forms/inline_forms'
|
|
55
60
|
#
|
56
61
|
# GET /examples/new
|
57
62
|
def new
|
58
|
-
@object = @Klass.
|
63
|
+
@object = @Klass.new
|
64
|
+
@update_span = params[:update]
|
65
|
+
respond_to do |format|
|
66
|
+
# found this here: http://www.ruby-forum.com/topic/211467
|
67
|
+
format.js { render(:update) {|page| page.replace_html @update_span, :partial => 'inline_forms/new'}
|
68
|
+
}
|
69
|
+
end
|
59
70
|
end
|
60
71
|
|
61
72
|
# :edit presents a form to edit one specific field from an object
|
@@ -75,58 +86,62 @@ render 'inline_forms/inline_forms'
|
|
75
86
|
# POST /examples
|
76
87
|
#
|
77
88
|
def create
|
78
|
-
object = @Klass.
|
79
|
-
|
89
|
+
object = @Klass.new
|
90
|
+
@update_span = params[:update]
|
91
|
+
attributes = object.respond_to?(:inline_forms_field_list) ? object.inline_forms_field_list : [ '', :name, :text ] # sensible default
|
80
92
|
attributes = [ attributes ] if not attributes[0].is_a?(Array) # make sure we have an array of arrays
|
81
93
|
attributes.each do | name, attribute, form_element, values |
|
82
94
|
send("#{form_element.to_s}_update", object, attribute, values)
|
83
95
|
end
|
84
96
|
object.save
|
85
|
-
@objects = @Klass.
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
# PUT /examples/1
|
92
|
-
#
|
93
|
-
def update
|
94
|
-
@object = @Klass.constantize.find(params[:id])
|
95
|
-
@field = params[:field]
|
96
|
-
@form_element = params[:form_element]
|
97
|
-
@values = params[:values]
|
98
|
-
@sub_id = params[:sub_id]
|
99
|
-
send("#{@form_element.to_s}_update", @object, @field, @values)
|
100
|
-
@object.save
|
101
|
-
render :inline => '<%= send("#{@form_element.to_s}_show", @object, @field, @values) %>'
|
97
|
+
@objects = @Klass.all
|
98
|
+
respond_to do |format|
|
99
|
+
# found this here: http://www.ruby-forum.com/topic/211467
|
100
|
+
format.js { render(:update) {|page| page.replace_html @update_span, :partial => 'inline_forms/index'}
|
101
|
+
}
|
102
|
+
end
|
102
103
|
end
|
104
|
+
# :update updates a specific field from an object.
|
105
|
+
#
|
106
|
+
# PUT /examples/1
|
107
|
+
#
|
108
|
+
def update
|
109
|
+
@object = @Klass.constantize.find(params[:id])
|
110
|
+
@field = params[:field]
|
111
|
+
@form_element = params[:form_element]
|
112
|
+
@values = params[:values]
|
113
|
+
@sub_id = params[:sub_id]
|
114
|
+
send("#{@form_element.to_s}_update", @object, @field, @values)
|
115
|
+
@object.save
|
116
|
+
render :inline => '<%= send("#{@form_element.to_s}_show", @object, @field, @values) %>'
|
117
|
+
end
|
103
118
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
119
|
+
# :destroy is not implemented
|
120
|
+
# TODO implement a destroy method
|
121
|
+
#
|
122
|
+
# DELETE /examples/1
|
123
|
+
#
|
124
|
+
def destroy
|
125
|
+
# @@Klass.constantize = @Klass.constantize.find(params[:id])
|
126
|
+
# @@Klass.constantize.destroy
|
127
|
+
redirect_to(@Klass.constantizes_url)
|
128
|
+
end
|
114
129
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
130
|
+
private
|
131
|
+
# If it's not an XhttpRequest, redirect to the index page for this controller.
|
132
|
+
#
|
133
|
+
# Used in before_filter as a way to limit access to all actions (except :index)
|
134
|
+
def must_be_xhr_request #:doc:
|
135
|
+
redirect_to "/#{@Klass_pluralized}" if not request.xhr?
|
136
|
+
end
|
122
137
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
138
|
+
# Get the class
|
139
|
+
# Used in before_filter
|
140
|
+
def getKlass #:doc:
|
141
|
+
@Klass = self.controller_name.classify.constantize
|
142
|
+
#request.request_uri.split(/[\/?]/)[1].classify
|
143
|
+
#@Klass_constantized = @Klass.constantize
|
144
|
+
#@Klass_underscored = @Klass.underscore
|
145
|
+
#@Klass_pluralized = @Klass_underscored.pluralize
|
146
|
+
end
|
131
147
|
end
|
132
|
-
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
puts 'inline forms helper loaded'
|
2
1
|
module InlineFormsHelper
|
3
2
|
# display the forms from an array of attributes
|
4
3
|
def inline_form_display(object, attributes, action=:show)
|
@@ -22,8 +21,9 @@ module InlineFormsHelper
|
|
22
21
|
end
|
23
22
|
end
|
24
23
|
out += content_tag :tr, name_cell + value_cell
|
24
|
+
out += "\n"
|
25
25
|
end
|
26
|
-
return content_tag :table, out, :cellspacing => 0, :cellpadding => 0
|
26
|
+
return content_tag :table, raw(out), :cellspacing => 0, :cellpadding => 0
|
27
27
|
when :new
|
28
28
|
attributes.each do | name, attribute, form_element, values |
|
29
29
|
#css_class_id = form_element == :associated ? "subform_#{attribute.to_s}_#{object.id}" : "field_#{attribute.to_s}_#{object.id}"
|
@@ -46,7 +46,7 @@ module InlineFormsHelper
|
|
46
46
|
end
|
47
47
|
out += content_tag :tr, name_cell + value_cell
|
48
48
|
end
|
49
|
-
return content_tag :table, out, :cellspacing => 0, :cellpadding => 0
|
49
|
+
return content_tag :table, raw(out), :cellspacing => 0, :cellpadding => 0
|
50
50
|
end
|
51
51
|
end
|
52
52
|
# display a list of objects
|
@@ -54,22 +54,14 @@ module InlineFormsHelper
|
|
54
54
|
t = ''
|
55
55
|
objects.each do |object|
|
56
56
|
t += content_tag tag do
|
57
|
-
inline_form_display object, object.respond_to?(:
|
57
|
+
inline_form_display object, object.respond_to?(:inline_forms_field_list) ? object.inline_forms_field_list : [ '', :name, :text ]
|
58
58
|
end
|
59
59
|
end
|
60
|
-
return t
|
60
|
+
return raw(t)
|
61
61
|
end
|
62
62
|
# link for new item
|
63
|
-
def inline_form_new_record(attribute, form_element, text='
|
64
|
-
|
65
|
-
:url => {
|
66
|
-
:action => :new,
|
67
|
-
:controller => @Klass_pluralized,
|
68
|
-
:field => attribute,
|
69
|
-
:form_element => form_element,
|
70
|
-
:update_span => update_span },
|
71
|
-
:method => :get,
|
72
|
-
:update => update_span )
|
63
|
+
def inline_form_new_record(attribute, form_element, text='neeeeew', update_span='inline_form_list')
|
64
|
+
link_to text, new_valid_table_path(:update => update_span), :remote => true
|
73
65
|
end
|
74
66
|
|
75
67
|
# dropdown
|
@@ -195,7 +187,7 @@ module InlineFormsHelper
|
|
195
187
|
if @sub_id && @sub_id.to_i > 0
|
196
188
|
# if it's not a new record (sub_id > 0) then just update the list-element
|
197
189
|
out << '<li>'
|
198
|
-
out <<
|
190
|
+
out << link_to( @associated_record.title,
|
199
191
|
:url => { :action => 'edit',
|
200
192
|
:id => object.id,
|
201
193
|
:field => attribute,
|
@@ -203,7 +195,8 @@ module InlineFormsHelper
|
|
203
195
|
:form_element => this_method.reverse.sub(/.*_/,'').reverse,
|
204
196
|
:values => values },
|
205
197
|
:method => :get,
|
206
|
-
:update => "field_#{attribute.singularize}_#{@sub_id.to_s}"
|
198
|
+
:update => "field_#{attribute.singularize}_#{@sub_id.to_s}",
|
199
|
+
:remote => true )
|
207
200
|
out << '</li>'
|
208
201
|
else
|
209
202
|
# if it's a new record (sub_id == 0) then update the whole <ul> and redraw all list-elements
|
@@ -213,7 +206,7 @@ module InlineFormsHelper
|
|
213
206
|
object.send(attribute.pluralize).each do |m|
|
214
207
|
out << "<span id='field_#{attribute.singularize}_#{m.id.to_s}'>"
|
215
208
|
out << '<li>'
|
216
|
-
out <<
|
209
|
+
out << link_to( m.title,
|
217
210
|
:url => { :action => 'edit',
|
218
211
|
:id => object.id,
|
219
212
|
:field => attribute,
|
@@ -221,14 +214,15 @@ module InlineFormsHelper
|
|
221
214
|
:form_element => this_method.sub(/_[a-z]+$/,''),
|
222
215
|
:values => values },
|
223
216
|
:method => :get,
|
224
|
-
:update => "field_#{attribute.singularize}_#{m.id.to_s}"
|
217
|
+
:update => "field_#{attribute.singularize}_#{m.id.to_s}",
|
218
|
+
:remote => true )
|
225
219
|
out << '</li>'
|
226
220
|
out << '</span>'
|
227
221
|
end
|
228
222
|
end
|
229
223
|
# add a 'new' link for creating a new record
|
230
224
|
out << '<li>'
|
231
|
-
out <<
|
225
|
+
out << link_to( 'new',
|
232
226
|
:url => { :action => 'edit',
|
233
227
|
:id => object.id,
|
234
228
|
:field => attribute,
|
@@ -236,7 +230,8 @@ module InlineFormsHelper
|
|
236
230
|
:form_element => this_method.sub(/_[a-z]+$/,''),
|
237
231
|
:values => values },
|
238
232
|
:method => :get,
|
239
|
-
:update => "list_#{attribute}_#{object.id.to_s}"
|
233
|
+
:update => "list_#{attribute}_#{object.id.to_s}",
|
234
|
+
:remote => true )
|
240
235
|
out << '</li>'
|
241
236
|
out << '</ul>' if @sub_id.nil?
|
242
237
|
end
|
@@ -294,23 +289,22 @@ module InlineFormsHelper
|
|
294
289
|
private
|
295
290
|
|
296
291
|
# link_to_inline_edit
|
297
|
-
# Directly call Erb::Util.h because we sometimes call this from the controller!
|
298
|
-
# same with link_to_remote. We are using the @template stuff.
|
299
292
|
def link_to_inline_edit(object, attribute, attribute_value, values)
|
300
|
-
#needed for h() and link_to_remote()
|
301
293
|
attribute_value = h(attribute_value)
|
302
294
|
spaces = attribute_value.length > 40 ? 0 : 40 - attribute_value.length
|
303
|
-
attribute_value << " " * spaces
|
295
|
+
attribute_value << " ".html_safe * spaces
|
304
296
|
if @Klass == 'Index'
|
305
|
-
|
297
|
+
link_to raw(attribute_value),
|
306
298
|
:url => "/#{@Klass_pluralized}/edit/#{object.id}?field=#{attribute.to_s}&form_element=#{calling_method.sub(/_[a-z]+$/,'')}&values=#{values}",
|
307
299
|
:update => 'field_' + attribute.to_s + '_' + object.id.to_s,
|
308
|
-
:method => :get
|
300
|
+
:method => :get,
|
301
|
+
:remote => true
|
309
302
|
else
|
310
|
-
|
303
|
+
link_to raw(attribute_value),
|
311
304
|
:url => "/#{@Klass_pluralized}/#{object.id}/edit?field=#{attribute.to_s}&form_element=#{calling_method.sub(/_[a-z]+$/,'')}&values=#{values}",
|
312
305
|
:update => 'field_' + attribute.to_s + '_' + object.id.to_s,
|
313
|
-
:method => :get
|
306
|
+
:method => :get,
|
307
|
+
:remote => true
|
314
308
|
|
315
309
|
end
|
316
310
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<% form_tag valid_tables_path( :update => @update_span || 'inline_form_list' ),
|
2
|
+
:multipart => true, :remote => true, :class => "edit_form" do -%>
|
3
|
+
<div class="edit_form_field">
|
4
|
+
<%= inline_form_display(@object, @object.respond_to?(:inline_forms_field_list) ? @object.inline_forms_field_list : [ '', :name, :text ], :new) %>
|
5
|
+
</div>
|
6
|
+
<%= link_to "nee", valid_tables_path(:update => @update_span), :remote => true,
|
7
|
+
:class => "edit_form_cancel" %>
|
8
|
+
<%= submit_tag "ok", :class => "edit_form_submit"-%>
|
9
|
+
<div style="clear: both;"></div>
|
10
|
+
<% end -%>
|
@@ -1,16 +1,17 @@
|
|
1
|
-
<%
|
2
|
-
:url => "/#{@
|
1
|
+
<% form_tag :multipart => true,
|
2
|
+
:url => "/#{@Klass.to_s.pluralize}?field=#{@attribute.to_s}&form_element=#{@form_element}&values=#{@values}&sub_id=#{@sub_id}",
|
3
3
|
:update => @update_span || 'inline_form_list',
|
4
4
|
:html => { :class => "edit_form" } do -%>
|
5
5
|
<div class="edit_form_field">
|
6
|
-
<%= inline_form_display(@object, @object.respond_to?(:
|
6
|
+
<%= inline_form_display(@object, @object.respond_to?(:inline_forms_field_list) ? @object.inline_forms_field_list : [ '', :name, :text ], :new) %>
|
7
7
|
</div>
|
8
|
-
<%=
|
9
|
-
# :url => "/#{@Klass_pluralized}/index?field=#{@attribute.to_s}&form_element=#{@form_element}&values=#{@values}&sub_id=#{@sub_id}",
|
8
|
+
<%= link_to "nee",
|
9
|
+
# :url => "/#{@Klass_pluralized}/index?field=#{@attribute.to_s}&form_element=#{@form_element}&values=#{@values}&sub_id=#{@sub_id}",
|
10
10
|
:url => "/#{@Klass_pluralized}?layout=false",
|
11
11
|
:html => { :class => "edit_form_cancel" },
|
12
12
|
:update => 'inline_form_list',
|
13
|
-
:method => :get
|
13
|
+
:method => :get,
|
14
|
+
:remote => true -%>
|
14
15
|
<%= submit_tag "ok", :class => "edit_form_submit"-%>
|
15
16
|
<div style="clear: both;"></div>
|
16
17
|
<% end -%>
|
@@ -1,7 +1,18 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<title><%= h(yield(:title) || "xyxyxyx") %></title>
|
6
|
+
<%= csrf_meta_tag %>
|
1
7
|
<%= stylesheet_link_tag 'inline_form_elements' %>
|
2
8
|
<%= javascript_include_tag :defaults %>
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
9
|
+
<%= yield(:head) %>
|
10
|
+
</head>
|
11
|
+
<%#= calendar_date_select_includes "red" %>
|
12
|
+
<body>
|
13
|
+
<h1><%= @Klass.to_s %></h1>
|
14
|
+
<ul id="inline_form_list">
|
15
|
+
<%= yield %>
|
16
|
+
</ul>
|
17
|
+
</body>
|
18
|
+
</html>
|
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.2.
|
8
|
+
s.version = "0.2.6"
|
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-01-
|
12
|
+
s.date = %q{2011-01-30}
|
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 = [
|
@@ -28,6 +28,8 @@ Gem::Specification.new do |s|
|
|
28
28
|
"app/helpers/inline_forms_helper.rb",
|
29
29
|
"app/models/geo_code_curacao.rb",
|
30
30
|
"app/models/inline_form.rb",
|
31
|
+
"app/views/inline_forms/_index.html.erb",
|
32
|
+
"app/views/inline_forms/_new.html.erb",
|
31
33
|
"app/views/inline_forms/_subform.html.erb",
|
32
34
|
"app/views/inline_forms/edit.html.erb",
|
33
35
|
"app/views/inline_forms/index.html.erb",
|
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: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 6
|
10
|
+
version: 0.2.6
|
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-01-
|
18
|
+
date: 2011-01-30 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -99,6 +99,8 @@ files:
|
|
99
99
|
- app/helpers/inline_forms_helper.rb
|
100
100
|
- app/models/geo_code_curacao.rb
|
101
101
|
- app/models/inline_form.rb
|
102
|
+
- app/views/inline_forms/_index.html.erb
|
103
|
+
- app/views/inline_forms/_new.html.erb
|
102
104
|
- app/views/inline_forms/_subform.html.erb
|
103
105
|
- app/views/inline_forms/edit.html.erb
|
104
106
|
- app/views/inline_forms/index.html.erb
|