inline_forms 0.6.3 → 0.6.4

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.6.3
1
+ 0.6.4
@@ -122,10 +122,19 @@ class InlineFormsController < ApplicationController
122
122
  end
123
123
  end
124
124
  @update_span = params[:update]
125
- respond_to do |format|
126
- # found this here: http://www.ruby-forum.com/topic/211467
127
- format.js { render(:update) {|page| page.replace_html @update_span, :inline => '<%= send("#{@form_element}_show", @object, @field, @values) %>' }
128
- }
125
+ if @field.nil?
126
+ respond_to do |format|
127
+ @attributes = @object.respond_to?(:inline_forms_field_list) ? @object.inline_forms_field_list : [ :name, 'name', 'text_field' ]
128
+ # found this here: http://www.ruby-forum.com/topic/211467
129
+ format.js { render(:update) {|page| page.replace_html @update_span, :inline => '<%= send( "inline_forms_show_record", @object, @attributes) %>' }
130
+ }
131
+ end
132
+ else
133
+ respond_to do |format|
134
+ # found this here: http://www.ruby-forum.com/topic/211467
135
+ format.js { render(:update) {|page| page.replace_html @update_span, :inline => '<%= send("#{@form_element}_show", @object, @field, @values) %>' }
136
+ }
137
+ end
129
138
  end
130
139
  end
131
140
 
@@ -134,27 +143,16 @@ class InlineFormsController < ApplicationController
134
143
  #
135
144
  # DELETE /examples/1
136
145
  #
137
- # def destroy
138
- # # @@Klass.constantize = @Klass.constantize.find(params[:id])
139
- # # @@Klass.constantize.destroy
140
- # redirect_to(@Klass.constantizes_url)
141
- # end
146
+ # def destroy
147
+ # # @@Klass.constantize = @Klass.constantize.find(params[:id])
148
+ # # @@Klass.constantize.destroy
149
+ # redirect_to(@Klass.constantizes_url)
150
+ # end
142
151
 
143
152
  private
144
- # If it's not an XhttpRequest, redirect to the index page for this controller.
145
- #
146
- # Used in before_filter as a way to limit access to all actions (except :index)
147
- # def must_be_xhr_request #:doc:
148
- # redirect_to "/#{@Klass_pluralized}" if not request.xhr?
149
- # end
150
-
151
153
  # Get the class
152
154
  # Used in before_filter
153
155
  def getKlass #:doc:
154
156
  @Klass = self.controller_name.classify.constantize
155
- #request.request_uri.split(/[\/?]/)[1].classify
156
- #@Klass_constantized = @Klass.constantize
157
- #@Klass_underscored = @Klass.underscore
158
- #@Klass_pluralized = @Klass_underscored.pluralize
159
157
  end
160
158
  end
@@ -7,7 +7,7 @@ module InlineFormsHelper
7
7
  if @sub_id && @sub_id.to_i > 0
8
8
  # if it's not a new record (sub_id > 0) then just update the list-element
9
9
  out << '<li>'
10
- out << link_to( @associated_record.presentation,
10
+ out << link_to( @associated_record._presentation,
11
11
  send('edit_' + @Klass.to_s.underscore + '_path', object,
12
12
  :field => attribute,
13
13
  :sub_id => @sub_id,
@@ -36,7 +36,7 @@ module InlineFormsHelper
36
36
  object.send(attribute.to_s.pluralize).each do |m|
37
37
  out << "<span id='field_#{attribute.to_s.singularize}_#{m.id.to_s}'>"
38
38
  out << '<li>'
39
- out << link_to( m.presentation, send('edit_' + @Klass.to_s.underscore + '_path',
39
+ out << link_to( m._presentation, send('edit_' + @Klass.to_s.underscore + '_path',
40
40
  object,
41
41
  :field => attribute,
42
42
  :sub_id => m.id,
@@ -2,14 +2,14 @@ module InlineFormsHelper
2
2
  InlineForms::SPECIAL_MIGRATION_TYPES[:dropdown]=:integer
3
3
  # dropdown
4
4
  def dropdown_show(object, attribute, values)
5
- attribute_value = object.send(attribute).presentation rescue nil
5
+ attribute_value = object.send(attribute)._presentation rescue nil
6
6
  link_to_inline_edit object, attribute, attribute_value, nil
7
7
  end
8
8
  def dropdown_edit(object, attribute, values)
9
9
  object.send('build_' + attribute.to_s) unless object.send(attribute)
10
10
  values = object.send(attribute).class.name.constantize.find(:all) # TODO bring order!
11
11
  # 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!
12
- collection_select( ('_' + object.class.to_s.downcase).to_sym, attribute.to_s.foreign_key.to_sym, values, 'id', 'presentation', :selected => object.send(attribute).id)
12
+ collection_select( ('_' + object.class.to_s.downcase).to_sym, attribute.to_s.foreign_key.to_sym, values, 'id', '_presentation', :selected => object.send(attribute).id)
13
13
  end
14
14
  def dropdown_update(object, attribute, values)
15
15
  object[attribute.to_s.foreign_key.to_sym] = params[('_' + object.class.to_s.downcase).to_sym][attribute.to_s.foreign_key.to_sym]
@@ -2,7 +2,7 @@ module InlineFormsHelper
2
2
  InlineForms::SPECIAL_MIGRATION_TYPES[:geo_code_curacao]=:string
3
3
  # geo_code_curacao
4
4
  def geo_code_curacao_show(object, attribute, values)
5
- attribute_value = object.send(attribute).presentation rescue nil
5
+ attribute_value = object.send(attribute)._presentation rescue nil
6
6
  link_to_inline_edit object, attribute, attribute_value, nil
7
7
  end
8
8
  def geo_code_curacao_edit(object, attribute, values)
@@ -5,44 +5,28 @@ Dir[INLINE_FORMS_PATH + "*.rb"].each do |form_element|
5
5
  end
6
6
 
7
7
  module InlineFormsHelper
8
- def inline_form(object, attributes) #, collapsed=true)
8
+ def inline_forms_show_record(object, attributes)
9
9
  attributes = [ attributes ] if not attributes[0].is_a?(Array) # make sure we have an array of arrays
10
- out = String.new #ugly as hell but that's how content_tag works...
11
- # if collapsed
12
- # then
13
- # name_cell = content_tag :td, :valign=>'top' do
14
- # content_tag :div, :class=> "field_name" do
15
- # h(object.presentation)
16
- # end
17
- # end
18
- # value_cell = content_tag :td, :valign=>'top' do
19
- # content_tag :div, :class=> "field_value" do
20
- # link_to 'edit', send( @Klass.to_s.underscore + '_path', object, :update => 'inline_form_list'), :remote => true
21
- # end
22
- # end
23
- # out += content_tag :tr, name_cell + value_cell
24
- # out += "\n"
25
- # else
26
- out << h(object._presentation)
27
- attributes.each do | attribute, name, form_element, values |
28
- #css_class_id = form_element == :associated ? "subform_#{attribute.to_s}_#{object.id}" : "field_#{attribute.to_s}_#{object.id}"
29
- css_class_id = "field_#{attribute.to_s}_#{object.id}"
30
- name_cell = content_tag :td, :valign=>'top' do
31
- content_tag :div, :class=> "field_name field_#{attribute.to_s} form_element_#{form_element.to_s}" do
32
- h(name)
33
- end
10
+ out = String.new
11
+ attributes.each do | attribute, name, form_element, values |
12
+ #css_class_id = form_element == :associated ? "subform_#{attribute.to_s}_#{object.id}" : "field_#{attribute.to_s}_#{object.id}"
13
+ css_class_id = "field_#{attribute.to_s}_#{object.id}"
14
+ name_cell = content_tag :td, :valign=>'top' do
15
+ content_tag :div, :class=> "field_name field_#{attribute.to_s} form_element_#{form_element.to_s}" do
16
+ h(name)
34
17
  end
35
- value_cell = content_tag :td, :valign=>'top' do
36
- content_tag :div, :class=> "field_value field_#{attribute.to_s} form_element_#{form_element.to_s}" do
37
- content_tag :span, :id => css_class_id do
38
- send("#{form_element.to_s}_show", object, attribute, values)
39
- end
18
+ end
19
+ value_cell = content_tag :td, :valign=>'top' do
20
+ content_tag :div, :class=> "field_value field_#{attribute.to_s} form_element_#{form_element.to_s}" do
21
+ content_tag :span, :id => css_class_id do
22
+ send("#{form_element.to_s}_show", object, attribute, values)
40
23
  end
41
24
  end
42
- out += content_tag :tr, name_cell + value_cell
43
- out += "\n"
44
25
  end
45
- # end
26
+ out += content_tag :tr, name_cell + value_cell
27
+ out += "\n"
28
+ end
29
+ # end
46
30
  return content_tag :table, raw(out), :cellspacing => 0, :cellpadding => 0
47
31
  end
48
32
 
@@ -74,8 +58,10 @@ out << h(object._presentation)
74
58
  def inline_form_display_list(objects, tag=:li)
75
59
  t = ''
76
60
  objects.each do |object|
77
- t += content_tag tag do
78
- inline_form object, object.respond_to?(:inline_forms_field_list) ? object.inline_forms_field_list : [ :name, 'name', 'text_field' ]
61
+ css_class_id = @Klass.to_s.underscore + '_' + object.id.to_s
62
+ t += content_tag tag, :id => css_class_id do
63
+ #inline_forms_show_record object, object.respond_to?(:inline_forms_field_list) ? object.inline_forms_field_list : [ :name, 'name', 'text_field' ]
64
+ link_to( h( object._presentation ), send( @Klass.to_s.underscore + '_path', object, :update => css_class_id), :remote => true )
79
65
  end
80
66
  end
81
67
  return raw(t)
data/inline_forms.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{inline_forms}
8
- s.version = "0.6.3"
8
+ s.version = "0.6.4"
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"]
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: 1
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 3
10
- version: 0.6.3
9
+ - 4
10
+ version: 0.6.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ace Suares