inline_forms 1.1.12 → 1.1.13
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/app/controllers/inline_forms_controller.rb +28 -36
- data/app/views/inline_forms/_list.html.erb +26 -31
- data/lib/inline_forms.rb +24 -18
- data/lib/inline_forms/version.rb +1 -1
- metadata +3 -3
@@ -45,10 +45,8 @@ class InlineFormsController < ApplicationController
|
|
45
45
|
|
46
46
|
include InlineFormsHelper
|
47
47
|
|
48
|
-
# shows a list of all objects from class @Klass, using will_paginate
|
49
|
-
#
|
50
|
-
# The link to 'new' allows you to create a new record.
|
51
|
-
#
|
48
|
+
# :index shows a list of all objects from class @Klass, using will_paginate,
|
49
|
+
# including a link to 'new', that allows you to create a new record.
|
52
50
|
def index
|
53
51
|
@update_span = params[:update]
|
54
52
|
@parent_class = params[:parent_class]
|
@@ -57,11 +55,22 @@ class InlineFormsController < ApplicationController
|
|
57
55
|
@PER_PAGE = 5 unless @parent_class.nil?
|
58
56
|
# if the parent_class is not nill, we are in associated list and we don't search there.
|
59
57
|
# also, make sure the Model that you want to do a search on has a :name attribute. TODO
|
60
|
-
@parent_class.nil?
|
58
|
+
if @parent_class.nil?
|
59
|
+
conditions = [ @Klass.order_by_clause.to_s + " like ?", "%#{params[:search]}%" ]
|
60
|
+
else
|
61
|
+
conditions = [ "#{@parent_class.foreign_key} = ?", @parent_id ]
|
62
|
+
end
|
63
|
+
# if we are using cancan, then make sure to select only accessible records
|
61
64
|
if cancan_enabled?
|
62
|
-
@objects = @Klass.accessible_by(current_ability).order(@Klass.order_by_clause).paginate
|
65
|
+
@objects = @Klass.accessible_by(current_ability).order(@Klass.order_by_clause).paginate(
|
66
|
+
:page => params[:page],
|
67
|
+
:per_page => @PER_PAGE || 12,
|
68
|
+
:conditions => conditions )
|
63
69
|
else
|
64
|
-
@objects = @Klass.order(@Klass.order_by_clause).paginate
|
70
|
+
@objects = @Klass.order(@Klass.order_by_clause).paginate(
|
71
|
+
:page => params[:page],
|
72
|
+
:per_page => @PER_PAGE || 12,
|
73
|
+
:conditions => conditions )
|
65
74
|
end
|
66
75
|
respond_to do |format|
|
67
76
|
format.html { render 'inline_forms/_list', :layout => 'inline_forms' } unless @Klass.not_accessible_through_html?
|
@@ -69,10 +78,9 @@ class InlineFormsController < ApplicationController
|
|
69
78
|
end
|
70
79
|
end
|
71
80
|
|
72
|
-
# :new prepares a new object, updates the
|
73
|
-
# empty form. After pressing OK or Cancel, the list of objects is retrieved
|
74
|
-
#
|
75
|
-
# GET /examples/new
|
81
|
+
# :new prepares a new object, updates the list of objects and replaces it with
|
82
|
+
# an empty form. After pressing OK or Cancel, the list of objects is retrieved
|
83
|
+
# in the same way as :index
|
76
84
|
def new
|
77
85
|
@object = @Klass.new
|
78
86
|
@update_span = params[:update]
|
@@ -87,9 +95,6 @@ class InlineFormsController < ApplicationController
|
|
87
95
|
end
|
88
96
|
|
89
97
|
# :edit presents a form to edit one specific attribute from an object
|
90
|
-
#
|
91
|
-
# GET /examples/1/edit
|
92
|
-
#
|
93
98
|
def edit
|
94
99
|
@object = @Klass.find(params[:id])
|
95
100
|
@attribute = params[:attribute]
|
@@ -101,10 +106,8 @@ class InlineFormsController < ApplicationController
|
|
101
106
|
end
|
102
107
|
end
|
103
108
|
|
104
|
-
# :create creates the object made with :new.
|
105
|
-
#
|
106
|
-
# POST /examples
|
107
|
-
#
|
109
|
+
# :create creates the object made with :new.
|
110
|
+
# It then presents the list of objects.
|
108
111
|
def create
|
109
112
|
object = @Klass.new
|
110
113
|
@update_span = params[:update]
|
@@ -139,10 +142,8 @@ class InlineFormsController < ApplicationController
|
|
139
142
|
end
|
140
143
|
end
|
141
144
|
end
|
145
|
+
|
142
146
|
# :update updates a specific attribute from an object.
|
143
|
-
#
|
144
|
-
# PUT /examples/1
|
145
|
-
#
|
146
147
|
def update
|
147
148
|
@object = @Klass.find(params[:id])
|
148
149
|
@attribute = params[:attribute]
|
@@ -157,11 +158,8 @@ class InlineFormsController < ApplicationController
|
|
157
158
|
end
|
158
159
|
end
|
159
160
|
|
160
|
-
# :show shows one attribute (attribute) from a record (object).
|
161
|
-
#
|
162
|
-
# GET /examples/1?attribute=name&form_element=text
|
163
|
-
#
|
164
|
-
|
161
|
+
# :show shows one attribute (attribute) from a record (object).
|
162
|
+
# It includes the link to 'edit'
|
165
163
|
def show
|
166
164
|
@object = @Klass.find(params[:id])
|
167
165
|
@attribute = params[:attribute]
|
@@ -191,6 +189,7 @@ class InlineFormsController < ApplicationController
|
|
191
189
|
end
|
192
190
|
end
|
193
191
|
|
192
|
+
# :destroy destroys the record, but also shows an undo link (with paper_trail)
|
194
193
|
def destroy
|
195
194
|
@update_span = params[:update]
|
196
195
|
@object = @Klass.find(params[:id])
|
@@ -200,8 +199,9 @@ class InlineFormsController < ApplicationController
|
|
200
199
|
end
|
201
200
|
end
|
202
201
|
|
202
|
+
# :revert works like undo.
|
203
|
+
# Thanks Ryan Bates: http://railscasts.com/episodes/255-undo-with-paper-trail
|
203
204
|
def revert
|
204
|
-
# http://railscasts.com/episodes/255-undo-with-paper-trail
|
205
205
|
@update_span = params[:update]
|
206
206
|
@version = Version.find(params[:id])
|
207
207
|
@version.reify.save!
|
@@ -209,19 +209,11 @@ class InlineFormsController < ApplicationController
|
|
209
209
|
respond_to do |format|
|
210
210
|
format.js { render :close }
|
211
211
|
end
|
212
|
-
|
213
|
-
# if @version.reify
|
214
|
-
# @version.reify.save!
|
215
|
-
# else
|
216
|
-
# @version.item.destroy
|
217
|
-
# end
|
218
|
-
# link_name = params[:redo] == "true" ? "undo" : "redo"
|
219
|
-
# link = view_context.link_to(link_name, revert_version_path(@version.next, :redo => !params[:redo]), :method => :post)
|
220
|
-
# redirect_to :back, :notice => "Undid #{@version.event}. #{link}"
|
221
212
|
end
|
222
213
|
|
223
214
|
private
|
224
215
|
# Get the class from the controller name.
|
216
|
+
# CountryController < InlineFormsController, so what class are we?
|
225
217
|
def getKlass #:doc:
|
226
218
|
@Klass = self.controller_name.classify.constantize
|
227
219
|
end
|
@@ -3,7 +3,6 @@
|
|
3
3
|
<script type="text/javascript">
|
4
4
|
$(function() { $("#flash").delay(1000).fadeToggle('2000'); } );
|
5
5
|
</script>
|
6
|
-
|
7
6
|
<% end %>
|
8
7
|
|
9
8
|
<!-- purpose: list objects. we come here from #index and from #new.
|
@@ -53,35 +52,31 @@ they are @object. We need this magic here to rewrite all the @variables to varia
|
|
53
52
|
|
54
53
|
<% end %>
|
55
54
|
|
56
|
-
|
57
|
-
|
55
|
+
<%= "<ul id=\"#{update_span}\" class=\"inline_forms_list\">" if ul_needed -%>
|
56
|
+
<!-- # link to new -->
|
57
|
+
<%= link_to_new_record("Add a new #{human_readable_class}", model_name, path_to_new, update_span, parent_class, parent_id) -%>
|
58
|
+
<!-- # list of objects -->
|
59
|
+
<% for object in objects %>
|
60
|
+
<% if parent_class.nil? %>
|
61
|
+
<% css_class_id = object.class.to_s.underscore + '_' + object.id.to_s -%>
|
62
|
+
<% path_to_object = object.class.to_s.underscore + '_path' %>
|
63
|
+
<% else %>
|
64
|
+
<% css_class_id = parent_class.to_s.underscore + '_' + parent_id.to_s + '_' + attribute.to_s.singularize.underscore + "_" + object.id.to_s -%>
|
65
|
+
<% path_to_object = attribute.to_s.singularize.underscore + "_path" %>
|
58
66
|
<% end %>
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
<% css_class_id = object.class.to_s.underscore + '_' + object.id.to_s -%>
|
65
|
-
<% path_to_object = object.class.to_s.underscore + '_path' %>
|
66
|
-
<% else %>
|
67
|
-
<% css_class_id = parent_class.to_s.underscore + '_' + parent_id.to_s + '_' + attribute.to_s.singularize.underscore + "_" + object.id.to_s -%>
|
68
|
-
<% path_to_object = attribute.to_s.singularize.underscore + "_path" %>
|
69
|
-
<% end %>
|
70
|
-
<li id="<%= css_class_id -%>" class="<%= cycle('odd', 'even') -%>" >
|
71
|
-
<%= link_to_destroy('del',object, css_class_id) -%>
|
72
|
-
<%= link_to h(object._presentation),
|
73
|
-
send( path_to_object, object, :update => css_class_id),
|
74
|
-
:remote => true -%>
|
75
|
-
</li>
|
76
|
-
<% end -%>
|
77
|
-
<!-- # pagination -->
|
78
|
-
<li class="even">
|
79
|
-
<% if parent_id.nil? -%>
|
80
|
-
<%= will_paginate objects -%>
|
81
|
-
<% else %>
|
82
|
-
<%= will_paginate objects, :ajax => true, :params => {:controller => attribute, :action => :index, :id => nil, :parent_class => parent_class, :parent_id => parent_id, :update => "#{parent_class.to_s.underscore}_#{parent_id}_#{attribute}", :ul_needed => true } -%>
|
83
|
-
<% end %>
|
67
|
+
<li id="<%= css_class_id -%>" class="<%= cycle('odd', 'even') -%>" >
|
68
|
+
<%= link_to_destroy('del',object, css_class_id) -%>
|
69
|
+
<%= link_to h(object._presentation),
|
70
|
+
send( path_to_object, object, :update => css_class_id),
|
71
|
+
:remote => true -%>
|
84
72
|
</li>
|
85
|
-
|
86
|
-
|
87
|
-
|
73
|
+
<% end -%>
|
74
|
+
<!-- # pagination -->
|
75
|
+
<li class="even">
|
76
|
+
<% if parent_id.nil? -%>
|
77
|
+
<%= will_paginate objects -%>
|
78
|
+
<% else %>
|
79
|
+
<%= will_paginate objects, :ajax => true, :params => {:controller => attribute, :action => :index, :id => nil, :parent_class => parent_class, :parent_id => parent_id, :update => "#{parent_class.to_s.underscore}_#{parent_id}_#{attribute}", :ul_needed => true } -%>
|
80
|
+
<% end %>
|
81
|
+
</li>
|
82
|
+
<%= "</ul>" if ul_needed -%>
|
data/lib/inline_forms.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require ('inline_forms/version.rb')
|
2
|
-
#
|
2
|
+
# InlineForms is a Rails Engine that let you setup an admin interface quick and
|
3
|
+
# easy. Please install it as a gem or include it in your Gemfile.
|
3
4
|
module InlineForms
|
4
|
-
|
5
|
-
#
|
6
|
-
#
|
5
|
+
# DEFAULT_COLUMN_TYPES holds the standard ActiveRecord::Migration column types.
|
6
|
+
# This list provides compatability with the standard types, but we add our own
|
7
|
+
# later in 'Special Column Types'.
|
7
8
|
#
|
8
|
-
# These types will override
|
9
|
-
# types with these names as Special Column Types!
|
9
|
+
# These types will override Special Column Types of the same name.\
|
10
10
|
#
|
11
11
|
# Example:
|
12
|
-
#
|
12
|
+
# rails g inline_forms Example name:string price:integer
|
13
13
|
# will result in:
|
14
14
|
# class InlineFormsCreateExamples < ActiveRecord::Migration
|
15
15
|
# def self.up
|
@@ -40,7 +40,9 @@ module InlineForms
|
|
40
40
|
# :belongs_to => :belongs_to,
|
41
41
|
}
|
42
42
|
|
43
|
-
#
|
43
|
+
# DEFAULT_FORM_ELEMENTS holds a mapping from Default Column Types to
|
44
|
+
# Form Elements. Form Elements are defined in app/helpers/form_elements
|
45
|
+
# and are pieces of code that display a form for a field.
|
44
46
|
#
|
45
47
|
# Example:
|
46
48
|
# rails g inline_forms Example name:string price:integer
|
@@ -70,12 +72,11 @@ module InlineForms
|
|
70
72
|
:boolean => :check_box,
|
71
73
|
}
|
72
74
|
|
73
|
-
#
|
74
|
-
# ActiveRecord::Migration
|
75
|
+
# SPECIAL_COLUMN_TYPES maps the column types that we define here and in
|
76
|
+
# app/helpers/form_elements to the standard ActiveRecord::Migration column
|
77
|
+
# types
|
75
78
|
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
# Usage example: in app/helpers/form_elements/dropdown.rb
|
79
|
+
# Example: in app/helpers/form_elements/dropdown.rb
|
79
80
|
# InlineForms::SPECIAL_COLUMN_TYPES[:dropdown]=:belongs_to
|
80
81
|
# this maps the :dropdown form element to the :belongs_to column type.
|
81
82
|
#
|
@@ -89,6 +90,9 @@ module InlineForms
|
|
89
90
|
SPECIAL_COLUMN_TYPES = {
|
90
91
|
:associated => :no_migration
|
91
92
|
}
|
93
|
+
|
94
|
+
# RELATIONS defines a mapping between AR::Migrations columns and the Model.
|
95
|
+
#
|
92
96
|
# When a column has the type of :references or :belongs_to, then
|
93
97
|
# there will be a line in the migration reflecting that, but not in the model.
|
94
98
|
# == Why?
|
@@ -115,7 +119,9 @@ module InlineForms
|
|
115
119
|
:references => :belongs_to,
|
116
120
|
}
|
117
121
|
|
118
|
-
#
|
122
|
+
# SPECIAL_RELATIONS maps AR relations to migrations.
|
123
|
+
# In most cases, these relations have no migration at all, but they do need
|
124
|
+
# a line in the model.
|
119
125
|
SPECIAL_RELATIONS = {
|
120
126
|
:has_many => :no_migration,
|
121
127
|
:has_many_destroy => :no_migration,
|
@@ -125,10 +131,10 @@ module InlineForms
|
|
125
131
|
}
|
126
132
|
|
127
133
|
# Declare as a Rails::Engine, see http://www.ruby-forum.com/topic/211017#927932
|
128
|
-
class
|
129
|
-
initializer 'inline_forms.helper' do |app|
|
130
|
-
ActionView::Base.send :include, InlineFormsHelper
|
131
|
-
end
|
134
|
+
class Engine < Rails::Engine
|
135
|
+
# initializer 'inline_forms.helper' do |app|
|
136
|
+
# ActionView::Base.send :include, InlineFormsHelper
|
137
|
+
# end
|
132
138
|
end
|
133
139
|
end
|
134
140
|
|
data/lib/inline_forms/version.rb
CHANGED
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: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 13
|
10
|
+
version: 1.1.13
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ace Suares
|