inline_forms 0.2.6 → 0.3.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.3.0
@@ -12,13 +12,8 @@ class InlineFormsController < ApplicationController
12
12
  # === How it works
13
13
  # The getKlass before_filter extracts the class and puts it in @Klass
14
14
  # === Limited Access
15
- # the must_be_xhr_request before_filter is supposed to only perform the specific actions
16
- # if the request is an XhttpRequest. There is not much use permitting the actions outside of
17
- # the XhttpRequest context (except action => :index). Of course, this is not a security measure.
18
15
  before_filter :getKlass
19
- #before_filter :must_be_xhr_request, :except => :index
20
16
  include InlineFormsHelper # this might also be included in you application_controller with helper :all but it's not needed
21
- layout false
22
17
  # :index shows a list of all objects from class Klass, with all attribute values linked to the 'edit' action.
23
18
  # Each field (attribute) is edited seperately (so you don't edit an entire object!)
24
19
  # The link to 'new' allows you to create a new record.
@@ -34,26 +29,25 @@ class InlineFormsController < ApplicationController
34
29
  format.js { render(:update) {|page| page.replace_html update_span, :partial => 'inline_forms/index' }
35
30
  }
36
31
  end
37
-
38
32
  end
39
33
 
40
34
  # :show shows one field (attribute) from a record (object). It inludes the link to 'edit'
41
35
  #
42
36
  # GET /examples/1?field=name&form_element=text
43
37
  #
44
- def show
45
- @object = @Klass.constantize.find(params[:id])
46
- @field = params[:field]
47
- @form_element = params[:form_element]
48
- if @form_element == "associated"
49
- @sub_id = params[:sub_id]
50
- if @sub_id.to_i > 0
51
- @associated_record_id = @object.send(@field.singularize + "_ids").index(@sub_id.to_i)
52
- @associated_record = @object.send(@field)[@associated_record_id]
53
- end
54
- end
55
- render :inline => '<%= send("#{@form_element}_show", @object, @field, @values) %>'
56
- end
38
+ # def show
39
+ # @object = @Klass.constantize.find(params[:id])
40
+ # @field = params[:field]
41
+ # @form_element = params[:form_element]
42
+ # if @form_element == "associated"
43
+ # @sub_id = params[:sub_id]
44
+ # if @sub_id.to_i > 0
45
+ # @associated_record_id = @object.send(@field.singularize + "_ids").index(@sub_id.to_i)
46
+ # @associated_record = @object.send(@field)[@associated_record_id]
47
+ # end
48
+ # end
49
+ # render :inline => '<%= send("#{@form_element}_show", @object, @field, @values) %>'
50
+ # end
57
51
 
58
52
  # :new prepares a new object, updates the entire list of objects and replaces it with a new
59
53
  # empty form. After pressing OK or Cancel, the list of objects is retrieved in the same way as :index
@@ -74,11 +68,17 @@ class InlineFormsController < ApplicationController
74
68
  # GET /examples/1/edit
75
69
  #
76
70
  def edit
77
- @object = @Klass.constantize.find(params[:id])
71
+ @object = @Klass.find(params[:id])
78
72
  @field = params[:field]
79
73
  @form_element = params[:form_element]
80
74
  @values = params[:values]
81
75
  @sub_id = params[:sub_id]
76
+ @update_span = params[:update]
77
+ respond_to do |format|
78
+ # found this here: http://www.ruby-forum.com/topic/211467
79
+ format.js { render(:update) {|page| page.replace_html @update_span, :partial => 'inline_forms/edit'}
80
+ }
81
+ end
82
82
  end
83
83
 
84
84
  # :create creates the object made with :new. It then presents the list of objects.
@@ -101,47 +101,53 @@ class InlineFormsController < ApplicationController
101
101
  }
102
102
  end
103
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) %>'
104
+ # :update updates a specific field from an object.
105
+ #
106
+ # PUT /examples/1
107
+ #
108
+ def update
109
+ @object = @Klass.find(params[:id])
110
+ @field = params[:field]
111
+ @form_element = params[:form_element]
112
+ @values = params[:values]
113
+ @sub_id = params[:sub_id]
114
+ @update_span = params[:update]
115
+ send("#{@form_element.to_s}_update", @object, @field, @values)
116
+ @object.save
117
+ respond_to do |format|
118
+ # found this here: http://www.ruby-forum.com/topic/211467
119
+ format.js { render(:update) {|page| page.replace_html @update_span, :inline => '<%= send("#{@form_element.to_s}_show", @object, @field, @values) %>' }
120
+ }
117
121
  end
122
+
123
+ end
118
124
 
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
125
+ # :destroy is not implemented
126
+ # TODO implement a destroy method
127
+ #
128
+ # DELETE /examples/1
129
+ #
130
+ # def destroy
131
+ # # @@Klass.constantize = @Klass.constantize.find(params[:id])
132
+ # # @@Klass.constantize.destroy
133
+ # redirect_to(@Klass.constantizes_url)
134
+ # end
129
135
 
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
136
+ private
137
+ # If it's not an XhttpRequest, redirect to the index page for this controller.
138
+ #
139
+ # Used in before_filter as a way to limit access to all actions (except :index)
140
+ # def must_be_xhr_request #:doc:
141
+ # redirect_to "/#{@Klass_pluralized}" if not request.xhr?
142
+ # end
137
143
 
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
144
+ # Get the class
145
+ # Used in before_filter
146
+ def getKlass #:doc:
147
+ @Klass = self.controller_name.classify.constantize
148
+ #request.request_uri.split(/[\/?]/)[1].classify
149
+ #@Klass_constantized = @Klass.constantize
150
+ #@Klass_underscored = @Klass.underscore
151
+ #@Klass_pluralized = @Klass_underscored.pluralize
147
152
  end
153
+ end
@@ -61,7 +61,7 @@ module InlineFormsHelper
61
61
  end
62
62
  # link for new item
63
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
64
+ link_to text, send('new_' + @Klass.to_s.underscore + '_path', :update => update_span), :remote => true
65
65
  end
66
66
 
67
67
  # dropdown
@@ -215,7 +215,7 @@ module InlineFormsHelper
215
215
  :values => values },
216
216
  :method => :get,
217
217
  :update => "field_#{attribute.singularize}_#{m.id.to_s}",
218
- :remote => true )
218
+ :remote => true )
219
219
  out << '</li>'
220
220
  out << '</span>'
221
221
  end
@@ -231,7 +231,7 @@ module InlineFormsHelper
231
231
  :values => values },
232
232
  :method => :get,
233
233
  :update => "list_#{attribute}_#{object.id.to_s}",
234
- :remote => true )
234
+ :remote => true )
235
235
  out << '</li>'
236
236
  out << '</ul>' if @sub_id.nil?
237
237
  end
@@ -239,7 +239,7 @@ module InlineFormsHelper
239
239
  end
240
240
  def associated_edit(object, attribute, values)
241
241
  # @sub_id is the id of the assoicated record
242
- if @sub_id.to_i > 0
242
+ if @sub_id.to_i > 0
243
243
  # only if @sub_id > 0, means we have a associated record
244
244
  @associated_record_id = object.send(attribute.singularize + "_ids").index(@sub_id.to_i)
245
245
  @associated_record = object.send(attribute)[@associated_record_id]
@@ -293,20 +293,13 @@ module InlineFormsHelper
293
293
  attribute_value = h(attribute_value)
294
294
  spaces = attribute_value.length > 40 ? 0 : 40 - attribute_value.length
295
295
  attribute_value << "&nbsp;".html_safe * spaces
296
- if @Klass == 'Index'
297
- link_to raw(attribute_value),
298
- :url => "/#{@Klass_pluralized}/edit/#{object.id}?field=#{attribute.to_s}&form_element=#{calling_method.sub(/_[a-z]+$/,'')}&values=#{values}",
299
- :update => 'field_' + attribute.to_s + '_' + object.id.to_s,
300
- :method => :get,
301
- :remote => true
302
- else
303
- link_to raw(attribute_value),
304
- :url => "/#{@Klass_pluralized}/#{object.id}/edit?field=#{attribute.to_s}&form_element=#{calling_method.sub(/_[a-z]+$/,'')}&values=#{values}",
305
- :update => 'field_' + attribute.to_s + '_' + object.id.to_s,
306
- :method => :get,
296
+ link_to raw(attribute_value), send('edit_' + @Klass.to_s.underscore + '_path',
297
+ object,
298
+ :field => attribute.to_s,
299
+ :form_element => calling_method.sub(/_[a-z]+$/,''),
300
+ :values => values,
301
+ :update => 'field_' + attribute.to_s + '_' + object.id.to_s ),
307
302
  :remote => true
308
-
309
- end
310
303
  end
311
304
  end
312
305
 
@@ -0,0 +1,23 @@
1
+ <% form_tag send(@Klass.to_s.underscore + '_path', :update => @update_span ,
2
+ #|| @form_element == "associated" ? @sub_id && @sub_id.to_i > 0 ? "field_#{@field.singularize}_#{@sub_id}" : "list_#{@field}_#{@object.id.to_s}" : "field_#{@field}_#{@object.id.to_s}",
3
+ :field => @field,
4
+ :form_element => @form_element,
5
+ :values => @values,
6
+ :sub_id => @sub_id ),
7
+ :method => :put,
8
+ :multipart => true,
9
+ :class => "edit_form",
10
+ :remote => true do -%>
11
+ <div class="edit_form_field">
12
+ <%= send("#{@form_element.to_s}_edit", @object, @field, @values) %>
13
+ </div>
14
+ <%= link_to "nee", send(@Klass.to_s.underscore.pluralize + '_path', :update => @update_span || "field_#{@field}_#{@object.id.to_s}",
15
+ :field => @field,
16
+ :form_element => @form_element,
17
+ :values => @values,
18
+ :sub_id => @sub_id ),
19
+ :method => :get,
20
+ :class => "edit_form_cancel" %>
21
+ <%= submit_tag "ok", :class => "edit_form_submit"-%>
22
+ <div style="clear: both;"></div>
23
+ <% end -%>
@@ -1,9 +1,9 @@
1
- <% form_tag valid_tables_path( :update => @update_span || 'inline_form_list' ),
1
+ <% form_tag send(@Klass.to_s.underscore.pluralize + '_path', :update => @update_span || 'inline_form_list' ),
2
2
  :multipart => true, :remote => true, :class => "edit_form" do -%>
3
3
  <div class="edit_form_field">
4
4
  <%= inline_form_display(@object, @object.respond_to?(:inline_forms_field_list) ? @object.inline_forms_field_list : [ '', :name, :text ], :new) %>
5
5
  </div>
6
- <%= link_to "nee", valid_tables_path(:update => @update_span), :remote => true,
6
+ <%= link_to "nee", send(@Klass.to_s.underscore.pluralize + '_path',:update => @update_span), :remote => true,
7
7
  :class => "edit_form_cancel" %>
8
8
  <%= submit_tag "ok", :class => "edit_form_submit"-%>
9
9
  <div style="clear: both;"></div>
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{inline_forms}
8
- s.version = "0.2.6"
8
+ s.version = "0.3.0"
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"]
@@ -28,12 +28,11 @@ 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/_edit.html.erb",
31
32
  "app/views/inline_forms/_index.html.erb",
32
33
  "app/views/inline_forms/_new.html.erb",
33
34
  "app/views/inline_forms/_subform.html.erb",
34
- "app/views/inline_forms/edit.html.erb",
35
35
  "app/views/inline_forms/index.html.erb",
36
- "app/views/inline_forms/new.html.erb",
37
36
  "app/views/layouts/inline_forms.rhtml",
38
37
  "inline_forms.gemspec",
39
38
  "lib/inline_forms.rb",
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: 27
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 6
10
- version: 0.2.6
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ace Suares
@@ -99,12 +99,11 @@ 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/_edit.html.erb
102
103
  - app/views/inline_forms/_index.html.erb
103
104
  - app/views/inline_forms/_new.html.erb
104
105
  - app/views/inline_forms/_subform.html.erb
105
- - app/views/inline_forms/edit.html.erb
106
106
  - app/views/inline_forms/index.html.erb
107
- - app/views/inline_forms/new.html.erb
108
107
  - app/views/layouts/inline_forms.rhtml
109
108
  - inline_forms.gemspec
110
109
  - lib/inline_forms.rb
@@ -1,17 +0,0 @@
1
- <% form_remote_tag :update => @update_span || @form_element == "associated" ? @sub_id && @sub_id.to_i > 0 ? "field_#{@field.singularize}_#{@sub_id}" : "list_#{@field}_#{@object.id.to_s}" : "field_#{@field}_#{@object.id.to_s}",
2
- :url => "/#{@Klass_pluralized}/#{params[:id]}?field=#{@field}&form_element=#{@form_element}&values=#{@values}&sub_id=#{@sub_id}",
3
- :method => :put,
4
- :multipart => true,
5
- :html => { :class => "edit_form" } do -%>
6
- <div class="edit_form_field">
7
- <%= send("#{@form_element.to_s}_edit", @object, @field, @values) %>
8
- </div>
9
- <%= link_to_remote "nee",
10
- :url => "/#{@Klass_pluralized}/#{params[:id]}?field=#{@field}&form_element=#{@form_element}&values=#{@values}&sub_id=#{@sub_id}",
11
- :method => :get,
12
- :html => { :class => "edit_form_cancel" },
13
- :update => @update_span || "field_#{@field}_#{@object.id.to_s}" -%>
14
- <%= submit_tag "ok", :class => "edit_form_submit"-%>
15
- <div style="clear: both;"></div>
16
- <% end -%>
17
-
@@ -1,18 +0,0 @@
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
- :update => @update_span || 'inline_form_list',
4
- :html => { :class => "edit_form" } do -%>
5
- <div class="edit_form_field">
6
- <%= inline_form_display(@object, @object.respond_to?(:inline_forms_field_list) ? @object.inline_forms_field_list : [ '', :name, :text ], :new) %>
7
- </div>
8
- <%= link_to "nee",
9
- # :url => "/#{@Klass_pluralized}/index?field=#{@attribute.to_s}&form_element=#{@form_element}&values=#{@values}&sub_id=#{@sub_id}",
10
- :url => "/#{@Klass_pluralized}?layout=false",
11
- :html => { :class => "edit_form_cancel" },
12
- :update => 'inline_form_list',
13
- :method => :get,
14
- :remote => true -%>
15
- <%= submit_tag "ok", :class => "edit_form_submit"-%>
16
- <div style="clear: both;"></div>
17
- <% end -%>
18
-