inline_forms 0.9.19 → 0.9.20

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.19
1
+ 0.9.20
@@ -54,13 +54,14 @@ class InlineFormsController < ApplicationController
54
54
  @parent_class = params[:parent_class]
55
55
  @parent_id = params[:parent_id]
56
56
  @ul_needed = params[:ul_needed]
57
+ @PER_PAGE = 5 unless @parent_class.nil?
57
58
  # if the parent_class is not nill, we are in associated list and we don't search there.
58
59
  # also, make sure the Model that you want to do a search on has a :name attribute. TODO
59
60
  @parent_class.nil? ? conditions = ["name like ?", "%#{params[:search]}%" ] : conditions = [ "#{@parent_class.foreign_key} = ?", @parent_id ]
60
61
  if cancan_enabled?
61
- @objects = @Klass.accessible_by(current_ability).order(@Klass.order_by_clause).paginate :page => params[:page], :conditions => conditions
62
+ @objects = @Klass.accessible_by(current_ability).order(@Klass.order_by_clause).paginate :page => params[:page], :per_page => @PER_PAGE || 12, :conditions => conditions
62
63
  else
63
- @objects = @Klass.order(@Klass.order_by_clause).paginate :page => params[:page], :conditions => conditions
64
+ @objects = @Klass.order(@Klass.order_by_clause).paginate :page => params[:page], :per_page => @PER_PAGE || 12, :conditions => conditions
64
65
  end
65
66
  respond_to do |format|
66
67
  # found this here: http://www.ruby-forum.com/topic/211467
@@ -118,27 +119,32 @@ class InlineFormsController < ApplicationController
118
119
  end
119
120
  @parent_class = params[:parent_class]
120
121
  @parent_id = params[:parent_id]
122
+ @PER_PAGE = 5 unless @parent_class.nil?
121
123
  # for the logic behind the :conditions see the #index method.
122
124
  @parent_class.nil? ? conditions = ["name like ?", "%#{params[:search]}%" ] : conditions = [ "#{@parent_class.foreign_key} = ?", @parent_id ]
123
125
  object[@parent_class.foreign_key] = @parent_id unless @parent_class.nil?
124
126
  if object.save
125
127
  flash.now[:success] = "Successfully created #{object.class.to_s.underscore}."
128
+ if cancan_enabled?
129
+ @objects = @Klass.accessible_by(current_ability).order(@Klass.order_by_clause).paginate :page => params[:page], :per_page => @PER_PAGE || 12, :conditions => conditions
130
+ else
131
+ @objects = @Klass.order(@Klass.order_by_clause).paginate :page => params[:page], :per_page => @PER_PAGE || 12, :conditions => conditions
132
+ end
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, :partial => 'inline_forms/list'}
136
+ }
137
+ end
126
138
  else
127
139
  flash.now[:error] = "Failed to create #{object.class.to_s.underscore}.".html_safe
128
140
  object.errors.each do |e|
129
141
  flash.now[:error] << '<br />'.html_safe + e[0].to_s + ": " + e[1]
130
142
  end
131
- end
132
- if cancan_enabled?
133
- @objects = @Klass.accessible_by(current_ability).order(@Klass.order_by_clause).paginate :page => params[:page], :conditions => conditions
134
- else
135
- @objects = @Klass.order(@Klass.order_by_clause).paginate :page => params[:page], :conditions => conditions
136
- end
137
-
138
- respond_to do |format|
139
- # found this here: http://www.ruby-forum.com/topic/211467
140
- format.js { render(:update) {|page| page.replace_html @update_span, :partial => 'inline_forms/list'}
141
- }
143
+ respond_to do |format|
144
+ @object = object
145
+ format.js { render(:update) {|page| page.replace_html @update_span, :partial => 'inline_forms/new'}
146
+ }
147
+ end
142
148
  end
143
149
  end
144
150
  # :update updates a specific attribute from an object.
@@ -6,10 +6,11 @@ def date_select_show(object, attribute)
6
6
  end
7
7
 
8
8
  def date_select_edit(object, attribute)
9
- out = text_field_tag attribute, object[attribute]
9
+ css_id = 'datepicker_' + object.class.to_s.underscore + '_' + object.id.to_s + '_' + attribute.to_s
10
+ out = text_field_tag attribute, object[attribute], :id => css_id
10
11
  out << '<SCRIPT>'.html_safe
11
12
  out << "$(function() { ".html_safe
12
- out << '$("#'.html_safe + attribute.to_s.html_safe + '").datepicker();'.html_safe
13
+ out << '$("#'.html_safe + css_id.html_safe + '").datepicker();'.html_safe
13
14
  out << '});'.html_safe
14
15
  out << '</SCRIPT>'.html_safe
15
16
  return out
@@ -6,10 +6,11 @@ def datetime_select_show(object, attribute)
6
6
  end
7
7
 
8
8
  def datetime_select_edit(object, attribute)
9
- out = text_field_tag attribute, object[attribute]
9
+ css_id = 'datepicker_' + object.class.to_s.underscore + '_' + object.id.to_s + '_' + attribute.to_s
10
+ out = text_field_tag attribute, object[attribute], :id => css_id
10
11
  out << '<SCRIPT>'.html_safe
11
12
  out << "$(function() { ".html_safe
12
- out << '$("#'.html_safe + attribute.to_s.html_safe + '").datepicker();'.html_safe
13
+ out << '$("#'.html_safe + css_id.html_safe + '").datepicker();'.html_safe
13
14
  out << '});'.html_safe
14
15
  out << '</SCRIPT>'.html_safe
15
16
  return out
@@ -27,29 +27,29 @@ module InlineFormsHelper
27
27
  attribute_value << "&nbsp;".html_safe * spaces
28
28
  css_class_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}"
29
29
  if cancan_disabled? || ( can? :update, object )
30
- link_to attribute_value,
31
- send( 'edit_' + object.class.to_s.underscore + '_path',
32
- object,
33
- :attribute => attribute.to_s,
34
- :form_element => calling_method.sub(/_[a-z]+$/,''),
35
- :update => css_class_id ),
36
- :remote => true
30
+ link_to attribute_value,
31
+ send( 'edit_' + object.class.to_s.underscore + '_path',
32
+ object,
33
+ :attribute => attribute.to_s,
34
+ :form_element => calling_method.sub(/_[a-z]+$/,''),
35
+ :update => css_class_id ),
36
+ :remote => true
37
37
  else
38
- attribute_value
38
+ attribute_value
39
39
  end
40
40
  end
41
41
 
42
42
  # link to inline image edit
43
- def link_to_inline_image_edit(object, attribute)
44
- text= image_tag object.send(attribute).send('url', :thumb)
45
- link_to text,
46
- send('edit_' + @Klass.to_s.underscore + '_path',
47
- object,
48
- :attribute => attribute.to_s,
49
- :form_element => calling_method.sub(/_[a-z]+$/,''),
50
- :update => "attribute_#{attribute}_#{object.id}" ),
51
- :remote => true
52
- end
43
+ # def link_to_inline_image_edit(object, attribute)
44
+ # text= image_tag object.send(attribute).send('url', :thumb)
45
+ # link_to text,
46
+ # send('edit_' + @Klass.to_s.underscore + '_path',
47
+ # object,
48
+ # :attribute => attribute.to_s,
49
+ # :form_element => calling_method.sub(/_[a-z]+$/,''),
50
+ # :update => "attribute_#{attribute}_#{object.id}" ),
51
+ # :remote => true
52
+ # end
53
53
 
54
54
  def link_to_new_record(text, model, path_to_new, update_span, parent_class, parent_id)
55
55
  out = ""
@@ -57,10 +57,17 @@ module InlineFormsHelper
57
57
  out << (link_to text, send(path_to_new, :update => update_span, :parent_class => parent_class, :parent_id => parent_id ), :remote => true)
58
58
  out << "</li>"
59
59
  ""
60
- raw out if cancan_disabled? || ( can? :manage, parent_class.nil? ? Client : parent_class.find(parent_id) )
60
+ if cancan_enabled?
61
+ if can?(:manage, model.constantize)
62
+ if parent_class.nil?
63
+ raw out
64
+ else
65
+ raw out if can?(:update, parent_class.find(parent_id))
66
+ end
67
+ end
68
+ end
61
69
  end
62
70
 
63
-
64
71
  # get the values for an attribute
65
72
  #
66
73
  # values should be a Hash { integer => string, ... }
@@ -1,5 +1,9 @@
1
1
  <% flash.each do |key, value| %>
2
2
  <div id="flash" class="flash <%= key %>"><%= value %></div>
3
+ <script type="text/javascript">
4
+ $(function() { $("#flash").delay(1000).fadeToggle('2000'); } );
5
+ </script>
6
+
3
7
  <% end %>
4
8
 
5
9
  <!-- purpose: list objects. we come here from #index and from #new.
@@ -26,7 +30,7 @@ they are @object. We need this magic here to rewrite all the @variables to varia
26
30
  <% update_span = "#{@parent_class.to_s.underscore}_#{@parent_id}_#{attribute}_list" -%>
27
31
  <% human_readable_class= attribute.to_s.singularize.humanize.downcase %>
28
32
  <% path_to_new='new_' + attribute.to_s.underscore.singularize + '_path' %>
29
- <% parent_class=@parent_class %>
33
+ <% parent_class=@parent_class.constantize %>
30
34
  <% parent_id=@parent_id %>
31
35
  <% objects = @objects %>
32
36
  <% ul_needed = false unless @ul_needed %>
@@ -39,9 +43,9 @@ they are @object. We need this magic here to rewrite all the @variables to varia
39
43
  <% conditions = [ "#{parent_class.name.foreign_key} = ?", parent_id ] %>
40
44
 
41
45
  <% if cancan_enabled? %>
42
- <% objects = parent_class.find(parent_id).send(attribute).accessible_by(current_ability).order(attribute.to_s.singularize.camelcase.constantize.order_by_clause).paginate :page => params[:page], :conditions => conditions %>
46
+ <% objects = parent_class.find(parent_id).send(attribute).accessible_by(current_ability).order(attribute.to_s.singularize.camelcase.constantize.order_by_clause).paginate :page => params[:page], :per_page => @PER_PAGE || 5, :conditions => conditions %>
43
47
  <% else %>
44
- <% objects = parent_class.find(parent_id).send(attribute).order(attribute.to_s.singularize.camelcase.constantize.order_by_clause).paginate :page => params[:page], :conditions => conditions %>
48
+ <% objects = parent_class.find(parent_id).send(attribute).order(attribute.to_s.singularize.camelcase.constantize.order_by_clause).paginate :page => params[:page], :per_page => @PER_PAGE || 5, :conditions => conditions %>
45
49
  <% end %>
46
50
 
47
51
  <% end %>
@@ -66,11 +70,14 @@ they are @object. We need this magic here to rewrite all the @variables to varia
66
70
  :remote => true -%>
67
71
  </li>
68
72
  <% end -%>
69
- <% if parent_id.nil? -%>
70
- <%= will_paginate objects -%>
71
- <% else %>
72
- <%= 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 } -%>
73
- <% end %>
73
+ <!-- # pagination -->
74
+ <li class="even">
75
+ <% if parent_id.nil? -%>
76
+ <%= will_paginate objects -%>
77
+ <% else %>
78
+ <%= 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 } -%>
79
+ <% end %>
80
+ </li>
74
81
  <% if ul_needed %>
75
82
  </ul>
76
83
  <% end %>
@@ -1,47 +1,56 @@
1
- <li>
2
- <% form_tag send(@Klass.to_s.underscore.pluralize + '_path', :update => @update_span,
3
- :parent_class => @parent_class,
4
- :parent_id => @parent_id ),
5
- :multipart => true, :remote => true, :class => "edit_form" do -%>
6
- <div class="edit_form_field">
7
- <table cellspacing="0" cellpadding="0">
8
- <tr>
9
- <th colspan="2" valign="top">
10
- <div class="object_presentation" >
11
- Add a new <%= @object.class.to_s.singularize.downcase -%>
12
- </div>
13
- </th>
14
- </tr>
15
- <% attributes ||= @object.inline_forms_attribute_list -%>
16
- <% attributes.each do | attribute, name, form_element | -%>
17
- <% unless form_element.to_sym == :associated -%>
18
- <% css_class_id = "attribute_#{attribute}_#{@object.id}" -%>
19
- <tr>
20
- <td valign="top">
21
- <div class='<%= "attribute_name attribute_#{attribute} form_element_#{form_element}" -%>' >
22
- <%= h(name) -%>
23
- </div>
24
- </td>
25
- <td valign="top">
26
- <div class='<%= "attribute_value attribute_#{attribute} form_element_#{form_element}" -%>' >
27
- <span id="<%= css_class_id -%>" >
28
- <%= send("#{form_element}_edit", @object, attribute) -%>
29
- </span>
30
- </div>
31
- </td>
32
- </tr>
1
+ <li id="newnew">
2
+ <% flash.each do |key, value| %>
3
+ <div id="flash" class="flash <%= key %>"><%= value %></div>
4
+ <% end %>
5
+ <script type="text/javascript">
6
+ $(function() { $("#flash").delay(1000).fadeTo('slow', 0.33); } );
7
+ </script>
8
+ <% form_tag send(@Klass.to_s.underscore.pluralize + '_path', :update => @update_span,
9
+ :parent_class => @parent_class,
10
+ :parent_id => @parent_id ),
11
+ :multipart => true, :remote => true, :class => "edit_form" do -%>
12
+ <div class="edit_form_field">
13
+ <table cellspacing="0" cellpadding="0">
14
+ <tr>
15
+ <th colspan="2" valign="top">
16
+ <div class="object_presentation" >
17
+ Add a new <%= @object.class.to_s.singularize.downcase -%>
18
+ </div>
19
+ </th>
20
+ </tr>
21
+ <% attributes ||= @object.inline_forms_attribute_list -%>
22
+ <% attributes.each do | attribute, name, form_element | -%>
23
+ <% unless form_element.to_sym == :associated -%>
24
+ <% css_class_id = "attribute_#{attribute}_#{@object.id}" -%>
25
+ <tr>
26
+ <td valign="top">
27
+ <div class='<%= "attribute_name attribute_#{attribute} form_element_#{form_element}" -%>' >
28
+ <%= h(name) -%>
29
+ </div>
30
+ </td>
31
+ <td valign="top">
32
+ <div class='<%= "attribute_value attribute_#{attribute} form_element_#{form_element}" -%>' >
33
+ <span id="<%= css_class_id -%>" >
34
+ <%= send("#{form_element}_edit", @object, attribute) -%>
35
+ </span>
36
+ </div>
37
+ </td>
38
+ </tr>
39
+ <% end -%>
33
40
  <% end -%>
34
- <% end -%>
35
- </table>
36
- </div>
37
- <%= link_to( send(@Klass.to_s.underscore.pluralize + '_path', :update => @update_span,
38
- :parent_class => @parent_class,
39
- :parent_id => @parent_id ),
40
- :remote => true,
41
- :class => "edit_form_cancel" ) do %>
42
- <input type="button" name="cancel" value="cancel" />
41
+ </table>
42
+ </div>
43
+ <%= link_to( send(@Klass.to_s.underscore.pluralize + '_path', :update => @update_span,
44
+ :parent_class => @parent_class,
45
+ :parent_id => @parent_id ),
46
+ :remote => true,
47
+ :class => "edit_form_cancel" ) do %>
48
+ <input type="button" name="cancel" value="cancel" />
49
+ <% end %>
50
+ <%= submit_tag "ok", :class => "edit_form_submit"-%>
51
+ <div style="clear: both;"></div>
43
52
  <% end %>
44
- <%= submit_tag "ok", :class => "edit_form_submit"-%>
45
- <div style="clear: both;"></div>
46
- <% end %>
47
- </li>
53
+ </li>
54
+ <script type="text/javascript">
55
+ $(function() { $("#newnew").slideDown(4000); } );
56
+ </script>
@@ -1,4 +1,4 @@
1
- <table cellspacing="0" cellpadding="0">
1
+ <table cellspacing="0" cellpadding="0" style="height: 0">
2
2
  <tr>
3
3
  <th valign="top">
4
4
  <div class="object_presentation" >
@@ -25,6 +25,8 @@
25
25
  <body>
26
26
  <%= render "inline_forms/header" %>
27
27
  <%= render "/inline_forms_tabs" %>
28
- <%= yield %>
28
+ <div id="inline_forms_main_list">
29
+ <%= yield %>
30
+ </div>
29
31
  </body>
30
32
  </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.9.19"
8
+ s.version = "0.9.20"
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-06-21}
12
+ s.date = %q{2011-06-28}
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: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 19
10
- version: 0.9.19
9
+ - 20
10
+ version: 0.9.20
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-06-21 00:00:00 -04:00
18
+ date: 2011-06-28 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency