fat_free_crm 0.11.0 → 0.11.1

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.

Potentially problematic release.


This version of fat_free_crm might be problematic. Click here for more details.

Files changed (212) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +2 -2
  3. data/Gemfile +15 -2
  4. data/Gemfile.lock +34 -14
  5. data/README.md +37 -124
  6. data/app/assets/javascripts/application.js.erb +1 -1
  7. data/app/assets/javascripts/crm.js +22 -1
  8. data/app/assets/javascripts/crm_fields.js +2 -3
  9. data/app/assets/javascripts/jquery-noconflict.js +17 -0
  10. data/app/assets/stylesheets/application.css.erb +1 -0
  11. data/app/assets/stylesheets/common.scss +26 -0
  12. data/app/assets/stylesheets/ffcrm_chosen.scss +1 -1
  13. data/app/controllers/admin/application_controller.rb +1 -1
  14. data/app/controllers/application_controller.rb +0 -8
  15. data/app/controllers/{accounts_controller.rb → entities/accounts_controller.rb} +1 -13
  16. data/app/controllers/{campaigns_controller.rb → entities/campaigns_controller.rb} +1 -13
  17. data/app/controllers/{contacts_controller.rb → entities/contacts_controller.rb} +1 -7
  18. data/app/controllers/{leads_controller.rb → entities/leads_controller.rb} +1 -1
  19. data/app/controllers/{opportunities_controller.rb → entities/opportunities_controller.rb} +1 -7
  20. data/app/controllers/{tasks_controller.rb → entities/tasks_controller.rb} +1 -1
  21. data/app/controllers/{base_controller.rb → entities_controller.rb} +32 -1
  22. data/app/controllers/home_controller.rb +9 -9
  23. data/app/controllers/lists_controller.rb +17 -0
  24. data/app/helpers/admin/tags_helper.rb +1 -1
  25. data/app/helpers/application_helper.rb +14 -14
  26. data/app/helpers/crm_tags_helper.rb +1 -1
  27. data/app/helpers/home_helper.rb +13 -15
  28. data/app/helpers/lists_helper.rb +17 -0
  29. data/app/inputs/date_time_input.rb +17 -0
  30. data/app/inputs/text_input.rb +17 -1
  31. data/app/models/{base → entities}/account.rb +0 -1
  32. data/app/models/{base → entities}/account_contact.rb +0 -0
  33. data/app/models/{base → entities}/account_opportunity.rb +0 -0
  34. data/app/models/{base → entities}/campaign.rb +0 -1
  35. data/app/models/{base → entities}/contact.rb +0 -1
  36. data/app/models/{base → entities}/contact_opportunity.rb +0 -0
  37. data/app/models/{base → entities}/lead.rb +0 -1
  38. data/app/models/{base → entities}/opportunity.rb +0 -1
  39. data/app/models/{base → entities}/task.rb +5 -6
  40. data/app/models/list.rb +17 -0
  41. data/app/models/observers/lead_observer.rb +39 -0
  42. data/app/models/observers/opportunity_observer.rb +54 -0
  43. data/app/models/observers/task_observer.rb +41 -0
  44. data/app/models/polymorphic/address.rb +1 -3
  45. data/app/models/polymorphic/avatar.rb +0 -5
  46. data/app/models/polymorphic/comment.rb +2 -11
  47. data/app/models/polymorphic/email.rb +2 -9
  48. data/app/models/polymorphic/tag.rb +17 -0
  49. data/app/models/polymorphic/tagging.rb +17 -0
  50. data/app/models/users/ability.rb +13 -0
  51. data/app/models/users/user.rb +1 -4
  52. data/app/views/accounts/_account.html.haml +10 -6
  53. data/app/views/accounts/index.html.haml +1 -1
  54. data/app/views/accounts/show.html.haml +6 -24
  55. data/app/views/admin/fields/_field.html.haml +6 -6
  56. data/app/views/admin/tags/_tag.html.haml +2 -2
  57. data/app/views/admin/tags/index.html.haml +1 -1
  58. data/app/views/admin/users/_user.html.haml +3 -3
  59. data/app/views/admin/users/index.html.haml +1 -1
  60. data/app/views/campaigns/_campaign.html.haml +9 -5
  61. data/app/views/campaigns/index.html.haml +1 -1
  62. data/app/views/campaigns/show.html.haml +4 -24
  63. data/app/views/comments/_comment.html.haml +17 -14
  64. data/app/views/comments/_edit.html.haml +1 -1
  65. data/app/views/comments/_new.html.haml +3 -3
  66. data/app/views/contacts/_contact.html.haml +33 -15
  67. data/app/views/contacts/_contacts.html.haml +6 -0
  68. data/app/views/contacts/_sidebar_show.html.haml +1 -1
  69. data/app/views/contacts/index.html.haml +1 -1
  70. data/app/views/contacts/show.html.haml +3 -19
  71. data/app/views/emails/_email.html.haml +24 -21
  72. data/app/views/{base → entities}/_advanced_search.html.haml +0 -0
  73. data/app/views/{base → entities}/_condition_fields.html.haml +0 -0
  74. data/app/views/{base → entities}/_grouping_fields.html.haml +0 -0
  75. data/app/views/{base → entities}/_sort_fields.html.haml +0 -0
  76. data/app/views/{base → entities}/advanced_search.js.rjs +0 -0
  77. data/app/views/entities/contacts.js.rjs +3 -0
  78. data/app/views/entities/leads.js.rjs +3 -0
  79. data/app/views/entities/opportunities.js.rjs +3 -0
  80. data/app/views/entities/versions.js.rjs +3 -0
  81. data/app/views/home/_activity.html.haml +19 -18
  82. data/app/views/home/_events_menu.html.haml +8 -0
  83. data/app/views/home/_options.html.haml +2 -3
  84. data/app/views/home/index.html.haml +1 -1
  85. data/app/views/leads/_lead.html.haml +42 -23
  86. data/app/views/leads/_leads.html.haml +6 -0
  87. data/app/views/leads/_sidebar_show.html.haml +1 -1
  88. data/app/views/leads/index.html.haml +1 -1
  89. data/app/views/leads/show.html.haml +3 -13
  90. data/app/views/opportunities/_opportunities.html.haml +6 -0
  91. data/app/views/opportunities/_opportunity.html.haml +23 -11
  92. data/app/views/opportunities/index.html.haml +1 -1
  93. data/app/views/opportunities/show.html.haml +4 -18
  94. data/app/views/shared/_comment.html.haml +3 -3
  95. data/app/views/shared/_edit_comment.html.haml +1 -1
  96. data/app/views/shared/_recent.html.haml +4 -4
  97. data/app/views/shared/_recently.html.haml +3 -3
  98. data/app/views/shared/_timeline.html.haml +2 -3
  99. data/app/views/tasks/_assigned.html.haml +4 -4
  100. data/app/views/tasks/_completed.html.haml +2 -2
  101. data/app/views/tasks/_pending.html.haml +2 -2
  102. data/app/views/tasks/_related.html.haml +4 -5
  103. data/app/views/tasks/_tasks.html.haml +3 -0
  104. data/app/views/tasks/_title.html.haml +1 -1
  105. data/app/views/tasks/index.html.haml +1 -1
  106. data/app/views/users/_avatar.html.haml +2 -2
  107. data/app/views/versions/_version.html.haml +9 -12
  108. data/app/views/versions/_versions.html.haml +11 -0
  109. data/config/application.rb +3 -2
  110. data/config/environments/development.rb +2 -2
  111. data/config/environments/production.rb +0 -4
  112. data/config/environments/staging.rb +1 -1
  113. data/config/initializers/action_mailer.rb +9 -0
  114. data/config/initializers/paper_trail.rb +80 -0
  115. data/config/initializers/relative_url_root.rb +23 -0
  116. data/config/locales/cz_fat_free_crm.yml +1 -1
  117. data/config/locales/en-US_fat_free_crm.yml +22 -17
  118. data/config/locales/fr_fat_free_crm.yml +349 -134
  119. data/config/routes.rb +144 -140
  120. data/config/settings.default.yml +14 -2
  121. data/db/demo/addresses.yml +2 -2
  122. data/db/demo/emails.yml +2 -2
  123. data/db/migrate/20120216042541_is_paranoid_to_paper_trail.rb +1 -2
  124. data/db/migrate/20120309070209_add_versions_related.rb +6 -0
  125. data/db/migrate/20120316045804_activities_to_versions.rb +35 -0
  126. data/db/schema.rb +79 -53
  127. data/fat_free_crm.gemspec +8 -4
  128. data/lib/development_tasks/gem.rake +18 -1
  129. data/lib/development_tasks/license.rake +2 -4
  130. data/lib/development_tasks/rdoc.rake +17 -0
  131. data/lib/development_tasks/rspec.rake +17 -0
  132. data/lib/fat_free_crm.rb +20 -14
  133. data/lib/fat_free_crm/core_ext/array.rb +0 -27
  134. data/lib/fat_free_crm/dropbox.rb +11 -1
  135. data/lib/fat_free_crm/engine.rb +21 -3
  136. data/lib/fat_free_crm/gem_dependencies.rb +26 -0
  137. data/lib/fat_free_crm/gem_ext.rb +18 -1
  138. data/lib/fat_free_crm/gem_ext/active_record/schema_dumper.rb +18 -1
  139. data/lib/fat_free_crm/gem_ext/authlogic/session/cookies.rb +17 -0
  140. data/lib/fat_free_crm/gem_ext/rails/engine.rb +17 -0
  141. data/lib/fat_free_crm/gem_ext/rails/text_helper.rb +17 -0
  142. data/lib/fat_free_crm/gem_ext/rake/task.rb +17 -0
  143. data/lib/fat_free_crm/gem_ext/simple_form/action_view_extensions/form_helper.rb +18 -1
  144. data/lib/fat_free_crm/plugin_dependencies.rb +23 -5
  145. data/lib/fat_free_crm/renderers.rb +17 -0
  146. data/lib/fat_free_crm/syck_yaml.rb +17 -0
  147. data/lib/fat_free_crm/version.rb +1 -1
  148. data/lib/{country_select → plugins/country_select}/MIT-LICENSE +0 -0
  149. data/lib/{country_select → plugins/country_select}/README +0 -0
  150. data/lib/{country_select → plugins/country_select}/init.rb +0 -0
  151. data/lib/{country_select → plugins/country_select}/install.rb +0 -0
  152. data/lib/{country_select → plugins/country_select}/lib/country_select.rb +0 -0
  153. data/lib/{country_select → plugins/country_select}/uninstall.rb +0 -0
  154. data/lib/{gravatar_image_tag → plugins/gravatar_image_tag}/Gemfile +0 -0
  155. data/lib/{gravatar_image_tag → plugins/gravatar_image_tag}/README.textile +0 -0
  156. data/lib/{gravatar_image_tag → plugins/gravatar_image_tag}/ROADMAP.textile +0 -0
  157. data/lib/{gravatar_image_tag → plugins/gravatar_image_tag}/Rakefile +0 -0
  158. data/lib/{gravatar_image_tag → plugins/gravatar_image_tag}/VERSION +0 -0
  159. data/lib/{gravatar_image_tag → plugins/gravatar_image_tag}/gravatar_image_tag.gemspec +0 -0
  160. data/lib/{gravatar_image_tag → plugins/gravatar_image_tag}/init.rb +0 -0
  161. data/lib/{gravatar_image_tag → plugins/gravatar_image_tag}/lib/gravatar_image_tag.rb +0 -0
  162. data/lib/{gravatar_image_tag → plugins/gravatar_image_tag}/spec/gravatar_image_tag_spec.rb +0 -0
  163. data/lib/{gravatar_image_tag → plugins/gravatar_image_tag}/spec/test_helper.rb +0 -0
  164. data/lib/tasks/demo.rake +32 -29
  165. data/lib/tasks/dropbox.rake +1 -1
  166. data/lib/tasks/fat_free_crm.rake +3 -2
  167. data/lib/tasks/plugins.rake +1 -0
  168. data/spec/controllers/accounts_controller_spec.rb +7 -5
  169. data/spec/controllers/campaigns_controller_spec.rb +11 -9
  170. data/spec/controllers/contacts_controller_spec.rb +7 -5
  171. data/spec/controllers/home_controller_spec.rb +2 -2
  172. data/spec/controllers/leads_controller_spec.rb +7 -5
  173. data/spec/controllers/opportunities_controller_spec.rb +7 -5
  174. data/spec/factories/shared_factories.rb +8 -11
  175. data/spec/lib/dropbox_spec.rb +1 -0
  176. data/spec/models/polymorphic/version_spec.rb +247 -0
  177. data/spec/models/users/user_spec.rb +0 -9
  178. data/spec/spec_helper.rb +4 -0
  179. data/spec/views/home/index.haml_spec.rb +1 -1
  180. data/spec/views/home/index.rjs_spec.rb +4 -4
  181. data/spec/views/tasks/new.rjs_spec.rb +2 -2
  182. data/vendor/assets/javascripts/calendar_date_select/format_french.js +24 -0
  183. metadata +167 -126
  184. data/app/models/observers/activity_observer.rb +0 -84
  185. data/app/models/polymorphic/activity.rb +0 -106
  186. data/app/views/accounts/contacts.js.rjs +0 -3
  187. data/app/views/accounts/opportunities.js.rjs +0 -3
  188. data/app/views/campaigns/leads.js.rjs +0 -3
  189. data/app/views/campaigns/opportunities.js.rjs +0 -3
  190. data/app/views/contacts/opportunities.js.rjs +0 -3
  191. data/app/views/home/_actions_menu.html.haml +0 -8
  192. data/lib/dynamic_form/MIT-LICENSE +0 -20
  193. data/lib/dynamic_form/README +0 -13
  194. data/lib/dynamic_form/Rakefile +0 -10
  195. data/lib/dynamic_form/dynamic_form.gemspec +0 -12
  196. data/lib/dynamic_form/init.rb +0 -2
  197. data/lib/dynamic_form/lib/action_view/helpers/dynamic_form.rb +0 -301
  198. data/lib/dynamic_form/lib/action_view/locale/en-US.yml +0 -8
  199. data/lib/dynamic_form/lib/dynamic_form.rb +0 -6
  200. data/lib/dynamic_form/test/dynamic_form_i18n_test.rb +0 -42
  201. data/lib/dynamic_form/test/dynamic_form_test.rb +0 -370
  202. data/lib/dynamic_form/test/test_helper.rb +0 -10
  203. data/lib/responds_to_parent/MIT-LICENSE +0 -20
  204. data/lib/responds_to_parent/README +0 -47
  205. data/lib/responds_to_parent/Rakefile +0 -22
  206. data/lib/responds_to_parent/init.rb +0 -2
  207. data/lib/responds_to_parent/install.rb +0 -2
  208. data/lib/responds_to_parent/lib/responds_to_parent.rb +0 -70
  209. data/lib/responds_to_parent/test/responds_to_parent_test.rb +0 -11
  210. data/lib/responds_to_parent/test/test_helper.rb +0 -7
  211. data/lib/responds_to_parent/uninstall.rb +0 -2
  212. data/spec/models/polymorphic/activity_spec.rb +0 -303
@@ -1,84 +0,0 @@
1
- # Fat Free CRM
2
- # Copyright (C) 2008-2011 by Michael Dvorkin
3
- #
4
- # This program is free software: you can redistribute it and/or modify
5
- # it under the terms of the GNU Affero General Public License as published by
6
- # the Free Software Foundation, either version 3 of the License, or
7
- # (at your option) any later version.
8
- #
9
- # This program is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- # GNU Affero General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU Affero General Public License
15
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- #------------------------------------------------------------------------------
17
-
18
- class ActivityObserver < ActiveRecord::Observer
19
- observe :account, :campaign, :contact, :lead, :opportunity, :task
20
-
21
- @@tasks = {}
22
- @@leads = {}
23
- @@opportunities = {}
24
-
25
- def after_create(subject)
26
- log_activity(subject, :created)
27
- if subject.is_a?(Opportunity) && subject.campaign && subject.stage == "won"
28
- update_campaign_revenue(subject.campaign, (subject.amount || 0) - (subject.discount || 0))
29
- end
30
- end
31
-
32
- def before_update(subject)
33
- if subject.is_a?(Task)
34
- @@tasks[subject.id] = Task.find(subject.id).freeze
35
- elsif subject.is_a?(Lead)
36
- @@leads[subject.id] = Lead.find(subject.id).freeze
37
- elsif subject.is_a?(Opportunity)
38
- @@opportunities[subject.id] = Opportunity.find(subject.id).freeze
39
- end
40
- end
41
-
42
- def after_update(subject)
43
- if subject.is_a?(Task)
44
- original = @@tasks.delete(subject.id)
45
- if original
46
- return log_activity(subject, :completed) if subject.completed_at && original.completed_at.nil?
47
- return log_activity(subject, :reassigned) if subject.assigned_to != original.assigned_to
48
- return log_activity(subject, :rescheduled) if subject.bucket != original.bucket
49
- end
50
- elsif subject.is_a?(Lead)
51
- original = @@leads.delete(subject.id)
52
- if original && original.status != "rejected" && subject.status == "rejected"
53
- return log_activity(subject, :rejected)
54
- end
55
- elsif subject.is_a?(Opportunity)
56
- original = @@opportunities.delete(subject.id)
57
- if original
58
- if original.stage != "won" && subject.stage == "won" # :other to :won -- add to total campaign revenue.
59
- update_campaign_revenue(subject.campaign, (subject.amount || 0) - (subject.discount || 0))
60
- return log_activity(subject, :won)
61
- elsif original.stage == "won" && subject.stage != "won" # :won to :other -- substract from total campaign revenue.
62
- update_campaign_revenue(original.campaign, -((original.amount || 0) - (original.discount || 0)))
63
- end
64
- end
65
- end
66
- log_activity(subject, :updated)
67
- end
68
-
69
- def before_destroy(subject)
70
- log_activity(subject, :deleted)
71
- end
72
-
73
- private
74
- def log_activity(subject, action)
75
- current_user = User.current_user
76
- Activity.log(current_user, subject, action) if current_user
77
- end
78
-
79
- def update_campaign_revenue(campaign, revenue)
80
- campaign.update_attribute(:revenue, (campaign.revenue || 0) + revenue) if campaign
81
- end
82
-
83
- end
84
-
@@ -1,106 +0,0 @@
1
- # Fat Free CRM
2
- # Copyright (C) 2008-2011 by Michael Dvorkin
3
- #
4
- # This program is free software: you can redistribute it and/or modify
5
- # it under the terms of the GNU Affero General Public License as published by
6
- # the Free Software Foundation, either version 3 of the License, or
7
- # (at your option) any later version.
8
- #
9
- # This program is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- # GNU Affero General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU Affero General Public License
15
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- #------------------------------------------------------------------------------
17
-
18
- # == Schema Information
19
- #
20
- # Table name: activities
21
- #
22
- # id :integer not null, primary key
23
- # user_id :integer
24
- # subject_id :integer
25
- # subject_type :string(255)
26
- # action :string(32) default("created")
27
- # info :string(255) default("")
28
- # private :boolean default(FALSE)
29
- # created_at :datetime
30
- # updated_at :datetime
31
- #
32
-
33
- class Activity < ActiveRecord::Base
34
- belongs_to :user
35
- belongs_to :subject, :polymorphic => true
36
- scope :recent, where(:action => 'viewed').order('activities.updated_at DESC').limit(10)
37
- scope :for, lambda { |user| where(:user_id => user.id) }
38
- scope :with_actions, lambda { |*actions| where('action IN (?)', actions) }
39
- scope :without_actions, lambda { |*actions| where('action NOT IN (?)', actions) }
40
- scope :latest, lambda { |options|
41
- includes(:user).
42
- where(options[:asset] ? {:subject_type => options[:asset]} : nil).
43
- where(options[:action] ? {:action => options[:action]} : nil).
44
- where(options[:user] ? {:user_id => options[:user]} : nil).
45
- where('activities.created_at >= ?', Time.zone.now - (options[:duration] || 2.days)).
46
- order('activities.created_at DESC')
47
- }
48
-
49
- validates_presence_of :user, :subject
50
- exportable
51
-
52
- ASSETS = %w(all tasks campaigns leads accounts contacts opportunities)
53
- ACTIONS = %w(all_actions created viewed updated deleted commented email)
54
- DURATION = %w(one_hour one_day two_days one_week two_weeks one_month)
55
-
56
- #----------------------------------------------------------------------------
57
- def self.log(user, subject, action)
58
- if action != :viewed
59
- create_activity(user, subject, action)
60
- if action == :created
61
- create_activity(user, subject, :viewed)
62
- elsif action == :deleted
63
- # Remove the subject from recently viewed list. Note that we don't
64
- # specify an user since we want to delete :viewed activity for all users.
65
- delete_activity(nil, subject, :viewed)
66
- end
67
- end
68
- if [:viewed, :updated, :commented].include?(action)
69
- update_activity(user, subject, :viewed)
70
- end
71
- end
72
-
73
- private
74
- #----------------------------------------------------------------------------
75
- def self.create_activity(user, subject, action)
76
- unless subject.is_a?(Task) && action == :viewed # Tasks don't have landing pages, so technically they can't be "viewed".
77
- create(
78
- :user => user,
79
- :subject => subject,
80
- :action => action.to_s,
81
- :info => subject.respond_to?(:full_name) ? subject.full_name : subject.name
82
- )
83
- end
84
- end
85
-
86
- #----------------------------------------------------------------------------
87
- def self.update_activity(user, subject, action)
88
- activity = Activity.where('user_id = ? AND subject_id = ? AND subject_type = ? AND action = ?', user.id, subject.id, subject.class.name, action.to_s).first
89
- if activity
90
- activity.update_attribute(:updated_at, Time.now)
91
- else
92
- create_activity(user, subject, action)
93
- end
94
- end
95
-
96
- #----------------------------------------------------------------------------
97
- def self.delete_activity(user, subject, action)
98
- unless user
99
- delete_all([ 'subject_id = ? AND subject_type = ? AND action = ?', subject.id, subject.class.name, action.to_s ])
100
- else
101
- delete_all([ 'user_id = ? AND subject_id = ? AND subject_type = ? AND action = ?', user.id, subject.id, subject.class.name, action.to_s ])
102
- end
103
- end
104
-
105
- end
106
-
@@ -1,3 +0,0 @@
1
- @contacts = @account.contacts.paginate(:page => params[:page], :per_page => 20)
2
- page['contacts'].replace_html :partial => 'contacts/contact', :collection => @contacts
3
- page['contacts_pagination'].replace will_paginate(@contacts, :id => true, :params => {:action => :contacts})
@@ -1,3 +0,0 @@
1
- @opportunities = @account.opportunities.paginate(:page => params[:page], :per_page => 20)
2
- page['opportunities'].replace_html :partial => 'opportunities/opportunity', :collection => @opportunities
3
- page['opportunities_pagination'].replace will_paginate(@opportunities, :id => true, :params => {:action => :opportunities})
@@ -1,3 +0,0 @@
1
- @leads = @campaign.leads.paginate(:page => params[:page], :per_page => 20)
2
- page['leads'].replace_html :partial => 'leads/lead', :collection => @leads
3
- page['leads_pagination'].replace will_paginate(@leads, :id => true, :params => {:action => :leads})
@@ -1,3 +0,0 @@
1
- @opportunities = @campaign.opportunities.paginate(:page => params[:page], :per_page => 20)
2
- page['opportunities'].replace_html :partial => 'opportunities/opportunity', :collection => @opportunities
3
- page['opportunities_pagination'].replace will_paginate(@opportunities, :id => true, :params => {:action => :opportunities})
@@ -1,3 +0,0 @@
1
- @opportunities = @contact.opportunities.paginate(:page => params[:page], :per_page => 20)
2
- page['opportunities'].replace_html :partial => 'opportunities/contact', :collection => @opportunities
3
- page['opportunities_pagination'].replace will_paginate(@opportunities, :id => true, :params => {:action => :opportunities})
@@ -1,8 +0,0 @@
1
- :plain
2
- new crm.Menu({
3
- trigger : "action_type",
4
- fade : 0.5,
5
- appear : 0.5,
6
- menu_items: [ #{sort_by_actions.join(",")} ]
7
- });
8
-
@@ -1,20 +0,0 @@
1
- Copyright (c) 2010 David Heinemeier Hansson
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,13 +0,0 @@
1
- DynamicForm
2
- ===========
3
-
4
- DynamicForm holds a few helpers method to help you deal with your models, they are:
5
-
6
- * input(record, method, options = {})
7
- * form(record, options = {})
8
- * error_message_on(object, method, options={})
9
- * error_messages_for(record, options={})
10
-
11
- It also adds f.error_messages and f.error_messages_on to your form builders.
12
-
13
- Copyright (c) 2010 David Heinemeier Hansson, released under the MIT license
@@ -1,10 +0,0 @@
1
- require 'rake/testtask'
2
-
3
- desc 'Default: run unit tests.'
4
- task :default => :test
5
-
6
- desc 'Test the active_model_helper plugin.'
7
- Rake::TestTask.new(:test) do |t|
8
- t.libs << 'test'
9
- t.pattern = 'test/**/*_test.rb'
10
- end
@@ -1,12 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'dynamic_form'
3
- s.version = '1.0.0'
4
- s.author = 'David Heinemeier Hansson'
5
- s.email = 'david@loudthinking.com'
6
- s.summary = 'Deprecated dynamic form helpers: input, form, error_messages_for, error_messages_on'
7
-
8
- s.add_dependency('rails', '>= 3.0.0')
9
-
10
- s.files = Dir['lib/**/*']
11
- s.require_path = 'lib'
12
- end
@@ -1,2 +0,0 @@
1
- require 'dynamic_form'
2
-
@@ -1,301 +0,0 @@
1
- require 'action_view/helpers'
2
- require 'active_support/i18n'
3
- require 'active_support/core_ext/enumerable'
4
- require 'active_support/core_ext/object/blank'
5
-
6
- module ActionView
7
- module Helpers
8
- # The Active Record Helper makes it easier to create forms for records kept in instance variables. The most far-reaching is the +form+
9
- # method that creates a complete form for all the basic content types of the record (not associations or aggregations, though). This
10
- # is a great way of making the record quickly available for editing, but likely to prove lackluster for a complicated real-world form.
11
- # In that case, it's better to use the +input+ method and the specialized +form+ methods in link:classes/ActionView/Helpers/FormHelper.html
12
- module DynamicForm
13
- # Returns a default input tag for the type of object returned by the method. For example, if <tt>@post</tt>
14
- # has an attribute +title+ mapped to a +VARCHAR+ column that holds "Hello World":
15
- #
16
- # input("post", "title")
17
- # # => <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />
18
- def input(record_name, method, options = {})
19
- InstanceTag.new(record_name, method, self).to_tag(options)
20
- end
21
-
22
- # Returns an entire form with all needed input tags for a specified Active Record object. For example, if <tt>@post</tt>
23
- # has attributes named +title+ of type +VARCHAR+ and +body+ of type +TEXT+ then
24
- #
25
- # form("post")
26
- #
27
- # would yield a form like the following (modulus formatting):
28
- #
29
- # <form action='/posts/create' method='post'>
30
- # <p>
31
- # <label for="post_title">Title</label><br />
32
- # <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />
33
- # </p>
34
- # <p>
35
- # <label for="post_body">Body</label><br />
36
- # <textarea cols="40" id="post_body" name="post[body]" rows="20"></textarea>
37
- # </p>
38
- # <input name="commit" type="submit" value="Create" />
39
- # </form>
40
- #
41
- # It's possible to specialize the form builder by using a different action name and by supplying another
42
- # block renderer. For example, if <tt>@entry</tt> has an attribute +message+ of type +VARCHAR+ then
43
- #
44
- # form("entry",
45
- # :action => "sign",
46
- # :input_block => Proc.new { |record, column|
47
- # "#{column.human_name}: #{input(record, column.name)}<br />"
48
- # })
49
- #
50
- # would yield a form like the following (modulus formatting):
51
- #
52
- # <form action="/entries/sign" method="post">
53
- # Message:
54
- # <input id="entry_message" name="entry[message]" size="30" type="text" /><br />
55
- # <input name="commit" type="submit" value="Sign" />
56
- # </form>
57
- #
58
- # It's also possible to add additional content to the form by giving it a block, such as:
59
- #
60
- # form("entry", :action => "sign") do |form|
61
- # form << content_tag("b", "Department")
62
- # form << collection_select("department", "id", @departments, "id", "name")
63
- # end
64
- #
65
- # The following options are available:
66
- #
67
- # * <tt>:action</tt> - The action used when submitting the form (default: +create+ if a new record, otherwise +update+).
68
- # * <tt>:input_block</tt> - Specialize the output using a different block, see above.
69
- # * <tt>:method</tt> - The method used when submitting the form (default: +post+).
70
- # * <tt>:multipart</tt> - Whether to change the enctype of the form to "multipart/form-data", used when uploading a file (default: +false+).
71
- # * <tt>:submit_value</tt> - The text of the submit button (default: "Create" if a new record, otherwise "Update").
72
- def form(record_name, options = {})
73
- record = instance_variable_get("@#{record_name}")
74
- record = convert_to_model(record)
75
-
76
- options = options.symbolize_keys
77
- options[:action] ||= record.persisted? ? "update" : "create"
78
- action = url_for(:action => options[:action], :id => record)
79
-
80
- submit_value = options[:submit_value] || options[:action].gsub(/[^\w]/, '').capitalize
81
-
82
- contents = form_tag({:action => action}, :method =>(options[:method] || 'post'), :enctype => options[:multipart] ? 'multipart/form-data': nil)
83
- contents.safe_concat hidden_field(record_name, :id) if record.persisted?
84
- contents.safe_concat all_input_tags(record, record_name, options)
85
- yield contents if block_given?
86
- contents.safe_concat submit_tag(submit_value)
87
- contents.safe_concat('</form>')
88
- end
89
-
90
- # Returns a string containing the error message attached to the +method+ on the +object+ if one exists.
91
- # This error message is wrapped in a <tt>DIV</tt> tag by default or with <tt>:html_tag</tt> if specified,
92
- # which can be extended to include a <tt>:prepend_text</tt> and/or <tt>:append_text</tt> (to properly explain
93
- # the error), and a <tt>:css_class</tt> to style it accordingly. +object+ should either be the name of an
94
- # instance variable or the actual object. The method can be passed in either as a string or a symbol.
95
- # As an example, let's say you have a model <tt>@post</tt> that has an error message on the +title+ attribute:
96
- #
97
- # <%= error_message_on "post", "title" %>
98
- # # => <div class="formError">can't be empty</div>
99
- #
100
- # <%= error_message_on @post, :title %>
101
- # # => <div class="formError">can't be empty</div>
102
- #
103
- # <%= error_message_on "post", "title",
104
- # :prepend_text => "Title simply ",
105
- # :append_text => " (or it won't work).",
106
- # :html_tag => "span",
107
- # :css_class => "inputError" %>
108
- # # => <span class="inputError">Title simply can't be empty (or it won't work).</span>
109
- def error_message_on(object, method, *args)
110
- options = args.extract_options!
111
- unless args.empty?
112
- ActiveSupport::Deprecation.warn('error_message_on takes an option hash instead of separate ' +
113
- 'prepend_text, append_text, html_tag, and css_class arguments', caller)
114
-
115
- options[:prepend_text] = args[0] || ''
116
- options[:append_text] = args[1] || ''
117
- options[:html_tag] = args[2] || 'div'
118
- options[:css_class] = args[3] || 'formError'
119
- end
120
- options.reverse_merge!(:prepend_text => '', :append_text => '', :html_tag => 'div', :css_class => 'formError')
121
-
122
- object = convert_to_model(object)
123
-
124
- if (obj = (object.respond_to?(:errors) ? object : instance_variable_get("@#{object}"))) &&
125
- (errors = obj.errors[method]).presence
126
- content_tag(options[:html_tag],
127
- (options[:prepend_text].html_safe << errors.first).safe_concat(options[:append_text]),
128
- :class => options[:css_class]
129
- )
130
- else
131
- ''
132
- end
133
- end
134
-
135
- # Returns a string with a <tt>DIV</tt> containing all of the error messages for the objects located as instance variables by the names
136
- # given. If more than one object is specified, the errors for the objects are displayed in the order that the object names are
137
- # provided.
138
- #
139
- # This <tt>DIV</tt> can be tailored by the following options:
140
- #
141
- # * <tt>:header_tag</tt> - Used for the header of the error div (default: "h2").
142
- # * <tt>:id</tt> - The id of the error div (default: "errorExplanation").
143
- # * <tt>:class</tt> - The class of the error div (default: "errorExplanation").
144
- # * <tt>:object</tt> - The object (or array of objects) for which to display errors,
145
- # if you need to escape the instance variable convention.
146
- # * <tt>:object_name</tt> - The object name to use in the header, or any text that you prefer.
147
- # If <tt>:object_name</tt> is not set, the name of the first object will be used.
148
- # * <tt>:header_message</tt> - The message in the header of the error div. Pass +nil+
149
- # or an empty string to avoid the header message altogether. (Default: "X errors
150
- # prohibited this object from being saved").
151
- # * <tt>:message</tt> - The explanation message after the header message and before
152
- # the error list. Pass +nil+ or an empty string to avoid the explanation message
153
- # altogether. (Default: "There were problems with the following fields:").
154
- #
155
- # To specify the display for one object, you simply provide its name as a parameter.
156
- # For example, for the <tt>@user</tt> model:
157
- #
158
- # error_messages_for 'user'
159
- #
160
- # You can also supply an object:
161
- #
162
- # error_messages_for @user
163
- #
164
- # This will use the last part of the model name in the presentation. For instance, if
165
- # this is a MyKlass::User object, this will use "user" as the name in the String. This
166
- # is taken from MyKlass::User.model_name.human, which can be overridden.
167
- #
168
- # To specify more than one object, you simply list them; optionally, you can add an extra <tt>:object_name</tt> parameter, which
169
- # will be the name used in the header message:
170
- #
171
- # error_messages_for 'user_common', 'user', :object_name => 'user'
172
- #
173
- # You can also use a number of objects, which will have the same naming semantics
174
- # as a single object.
175
- #
176
- # error_messages_for @user, @post
177
- #
178
- # If the objects cannot be located as instance variables, you can add an extra <tt>:object</tt> parameter which gives the actual
179
- # object (or array of objects to use):
180
- #
181
- # error_messages_for 'user', :object => @question.user
182
- #
183
- # NOTE: This is a pre-packaged presentation of the errors with embedded strings and a certain HTML structure. If what
184
- # you need is significantly different from the default presentation, it makes plenty of sense to access the <tt>object.errors</tt>
185
- # instance yourself and set it up. View the source of this method to see how easy it is.
186
- def error_messages_for(*params)
187
- options = params.extract_options!.symbolize_keys
188
-
189
- objects = Array.wrap(options.delete(:object) || params).map do |object|
190
- object = instance_variable_get("@#{object}") unless object.respond_to?(:to_model)
191
- object = convert_to_model(object)
192
-
193
- if object.class.respond_to?(:model_name)
194
- options[:object_name] ||= object.class.model_name.human.downcase
195
- end
196
-
197
- object
198
- end
199
-
200
- objects.compact!
201
- count = objects.inject(0) {|sum, object| sum + object.errors.count }
202
-
203
- unless count.zero?
204
- html = {}
205
- [:id, :class].each do |key|
206
- if options.include?(key)
207
- value = options[key]
208
- html[key] = value unless value.blank?
209
- else
210
- html[key] = 'errorExplanation'
211
- end
212
- end
213
- options[:object_name] ||= params.first
214
-
215
- I18n.with_options :locale => options[:locale], :scope => [:activerecord, :errors, :template] do |locale|
216
- header_message = if options.include?(:header_message)
217
- options[:header_message]
218
- else
219
- locale.t :header, :count => count, :model => options[:object_name].to_s.gsub('_', ' ')
220
- end
221
-
222
- message = options.include?(:message) ? options[:message] : locale.t(:body)
223
-
224
- error_messages = objects.sum do |object|
225
- object.errors.full_messages.map do |msg|
226
- content_tag(:li, msg)
227
- end
228
- end.join.html_safe
229
-
230
- contents = ''
231
- contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank?
232
- contents << content_tag(:p, message) unless message.blank?
233
- contents << content_tag(:ul, error_messages)
234
-
235
- content_tag(:div, contents.html_safe, html)
236
- end
237
- else
238
- ''
239
- end
240
- end
241
-
242
- private
243
-
244
- def all_input_tags(record, record_name, options)
245
- input_block = options[:input_block] || default_input_block
246
- record.class.content_columns.collect{ |column| input_block.call(record_name, column) }.join("\n")
247
- end
248
-
249
- def default_input_block
250
- Proc.new { |record, column| %(<p><label for="#{record}_#{column.name}">#{column.human_name}</label><br />#{input(record, column.name)}</p>) }
251
- end
252
-
253
- module InstanceTagMethods
254
- def to_tag(options = {})
255
- case column_type
256
- when :string
257
- field_type = @method_name.include?("password") ? "password" : "text"
258
- to_input_field_tag(field_type, options)
259
- when :text
260
- to_text_area_tag(options)
261
- when :integer, :float, :decimal
262
- to_input_field_tag("text", options)
263
- when :date
264
- to_date_select_tag(options)
265
- when :datetime, :timestamp
266
- to_datetime_select_tag(options)
267
- when :time
268
- to_time_select_tag(options)
269
- when :boolean
270
- to_boolean_select_tag(options)
271
- end
272
- end
273
-
274
- def column_type
275
- object.send(:column_for_attribute, @method_name).type
276
- end
277
- end
278
-
279
- module FormBuilderMethods
280
- def error_message_on(method, *args)
281
- @template.error_message_on(@object || @object_name, method, *args)
282
- end
283
-
284
- def error_messages(options = {})
285
- @template.error_messages_for(@object_name, objectify_options(options))
286
- end
287
- end
288
- end
289
-
290
- class InstanceTag
291
- include DynamicForm::InstanceTagMethods
292
- end
293
-
294
- class FormBuilder
295
- include DynamicForm::FormBuilderMethods
296
- end
297
- end
298
- end
299
-
300
- I18n.load_path << File.expand_path("../../locale/en-US.yml", __FILE__)
301
-