hobo 1.3.3 → 1.4.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. data/{CHANGES.txt → CHANGES-1.3.txt} +0 -0
  2. data/CHANGES-1.4.txt +678 -0
  3. data/Rakefile +13 -3
  4. data/TODO-1.4.txt +69 -0
  5. data/VERSION +1 -1
  6. data/app/helpers/hobo_debug_helper.rb +16 -0
  7. data/app/helpers/hobo_deprecated_helper.rb +45 -0
  8. data/app/helpers/hobo_helper_base.rb +8 -0
  9. data/app/helpers/hobo_permissions_helper.rb +136 -0
  10. data/app/helpers/hobo_route_helper.rb +196 -0
  11. data/{lib/hobo/helper/translations.rb → app/helpers/hobo_translations_helper.rb} +4 -7
  12. data/{lib/hobo/helper/translations/normalizer.rb → app/helpers/hobo_translations_normalizer_helper.rb} +3 -10
  13. data/app/helpers/hobo_type_helper.rb +24 -0
  14. data/app/helpers/hobo_view_hint_helper.rb +13 -0
  15. data/hobo.gemspec +3 -3
  16. data/lib/generators/hobo/admin_subsite/admin_subsite_generator.rb +0 -9
  17. data/lib/generators/hobo/admin_subsite/templates/application.dryml +2 -0
  18. data/lib/generators/hobo/admin_subsite/templates/gitkeep +0 -0
  19. data/lib/generators/hobo/admin_subsite/templates/site.css.erb +9 -0
  20. data/lib/generators/hobo/admin_subsite/templates/site.js.erb +10 -0
  21. data/lib/generators/hobo/assets/assets_generator.rb +16 -2
  22. data/lib/generators/hobo/assets/templates/application.css +9 -0
  23. data/lib/generators/hobo/assets/templates/application.dryml.erb +0 -5
  24. data/lib/generators/hobo/assets/templates/application.js +11 -0
  25. data/lib/generators/hobo/assets/templates/front.css +10 -0
  26. data/lib/generators/hobo/assets/templates/front.js +11 -0
  27. data/lib/generators/hobo/assets/templates/front_site.dryml.erb +6 -0
  28. data/lib/generators/hobo/assets/templates/gitkeep +0 -0
  29. data/lib/generators/hobo/dev_tweaks/dev_tweaks_generator.rb +31 -0
  30. data/lib/generators/hobo/i18n/templates/hobo.en.yml +1 -1
  31. data/lib/generators/hobo/install_plugin/USAGE +3 -0
  32. data/lib/generators/hobo/install_plugin/install_plugin_generator.rb +36 -0
  33. data/lib/generators/hobo/plugin.rb +112 -0
  34. data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +31 -14
  35. data/lib/generators/hobo/subsite.rb +16 -2
  36. data/lib/generators/hobo/subsite/templates/gitkeep +0 -0
  37. data/lib/generators/hobo/subsite/templates/site.css.erb +9 -0
  38. data/lib/generators/hobo/subsite/templates/site.js.erb +10 -0
  39. data/lib/generators/hobo/subsite_taglib/templates/taglib.dryml.erb +0 -17
  40. data/lib/generators/hobo/test_framework/test_framework_generator.rb +1 -1
  41. data/lib/hobo.rb +3 -2
  42. data/lib/hobo/controller.rb +43 -24
  43. data/lib/hobo/controller/model.rb +63 -42
  44. data/lib/hobo/controller/user_base.rb +1 -3
  45. data/lib/hobo/engine.rb +1 -1
  46. data/lib/hobo/extensions/active_record/associations/association.rb +36 -0
  47. data/lib/hobo/extensions/active_record/associations/collection.rb +10 -19
  48. data/lib/hobo/extensions/active_record/associations/proxy.rb +3 -15
  49. data/lib/hobo/extensions/active_record/associations/scope.rb +2 -2
  50. data/lib/hobo/extensions/active_record/permissions.rb +32 -38
  51. data/lib/hobo/extensions/active_record/relation_with_origin.rb +5 -5
  52. data/lib/hobo/model.rb +12 -7
  53. data/lib/hobo/model/accessible_associations.rb +8 -15
  54. data/lib/hobo/model/lifecycles/creator.rb +1 -1
  55. data/lib/hobo/model/lifecycles/transition.rb +1 -1
  56. data/lib/hobo/model/permissions.rb +4 -4
  57. data/lib/hobo/model/scopes.rb +4 -17
  58. data/lib/hobo/model/scopes/automatic_scopes.rb +5 -13
  59. data/lib/hobo/rapid/helper.rb +1 -161
  60. data/lib/hobo/rapid/taglibs/rapid.dryml +3 -17
  61. data/test/doctest/hobo/hobo_helper.rdoctest +8 -44
  62. data/{doctests → test/doctest}/hobo/lifecycles.rdoctest +0 -0
  63. data/{doctests → test/doctest}/hobo/model.rdoctest +2 -4
  64. data/{doctests → test/doctest}/hobo/multi_model_forms.rdoctest +3 -24
  65. data/{doctests → test/doctest}/hobo/scopes.rdoctest +3 -53
  66. data/test/doctest/prepare_testapp.rb +11 -0
  67. data/test/irt/generators/admin_subsite.irt +1 -19
  68. data/test/irt/generators/assets.irt +4 -9
  69. data/test/irt/generators/controller.irt +0 -3
  70. data/test/irt/generators/front_controller.irt +0 -5
  71. data/test/irt/generators/{helper.rb → irt_helper.rb} +2 -2
  72. data/test/irt/generators/model.irt +1 -12
  73. data/test/irt/generators/partials/_account_user_model_tests.rb +0 -8
  74. data/test/irt/generators/partials/_accounts_users_controller_tests.rb +0 -2
  75. data/test/irt/generators/partials/_default_user_model_tests.rb +0 -8
  76. data/test/irt/generators/partials/_default_users_controller_tests.rb +0 -2
  77. data/test/irt/generators/partials/_house_controller_tests.rb +0 -2
  78. data/test/irt/generators/partials/_house_model_tests.rb +1 -9
  79. data/test/irt/generators/partials/_subsite_taglib_admin.rb +5 -2
  80. data/test/irt/generators/partials/_subsite_taglib_admin_invite_only.rb +1 -1
  81. data/test/irt/generators/partials/_subsite_taglib_noopt.rb +2 -2
  82. data/test/irt/generators/partials/_subsite_taglib_variables.rb +0 -15
  83. data/test/irt/generators/partials/_user_mailer_tests.rb +1 -3
  84. data/test/irt/generators/resource.irt +0 -3
  85. data/test/irt/generators/subsite.irt +6 -22
  86. data/test/irt/generators/subsite_taglib.irt +0 -18
  87. data/test/irt/generators/test_framework.irt +2 -5
  88. data/test/irt/generators/user_controller.irt +0 -3
  89. data/test/irt/generators/user_mailer.irt +0 -3
  90. data/test/irt/generators/user_model.irt +0 -3
  91. data/test/irt/generators/user_resource.irt +0 -3
  92. data/test/irt/readme.txt +6 -3
  93. metadata +116 -159
  94. data/app/controllers/dev_controller.rb +0 -25
  95. data/app/views/dev/summary.dryml +0 -102
  96. data/doctests/prepare_testapp.rb +0 -8
  97. data/lib/generators/hobo/admin_subsite/templates/admin.css +0 -20
  98. data/lib/generators/hobo/rapid/USAGE +0 -3
  99. data/lib/generators/hobo/rapid/rapid_generator.rb +0 -24
  100. data/lib/generators/hobo/rapid/templates/IE7.js +0 -2
  101. data/lib/generators/hobo/rapid/templates/blank.gif +0 -0
  102. data/lib/generators/hobo/rapid/templates/hobo-rapid.css +0 -94
  103. data/lib/generators/hobo/rapid/templates/hobo-rapid.js +0 -1015
  104. data/lib/generators/hobo/rapid/templates/ie7-recalc.js +0 -166
  105. data/lib/generators/hobo/rapid/templates/lowpro.js +0 -339
  106. data/lib/generators/hobo/rapid/templates/reset.css +0 -95
  107. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/101-3B5F87-ACD3E6.png +0 -0
  108. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/30-3E547A-242E42.png +0 -0
  109. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/30-DBE1E5-FCFEF5.png +0 -0
  110. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/300-ACD3E6-fff.png +0 -0
  111. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/50-ACD3E6-fff.png +0 -0
  112. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/fieldbg.gif +0 -0
  113. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/pencil.png +0 -0
  114. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/small_close.png +0 -0
  115. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/spinner.gif +0 -0
  116. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/clean.css +0 -327
  117. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/rapid-ui.css +0 -102
  118. data/lib/generators/hobo/rapid/templates/themes/clean/views/clean.dryml +0 -10
  119. data/lib/hobo/helper.rb +0 -460
  120. data/lib/hobo/rapid/taglibs/rapid_core.dryml +0 -808
  121. data/lib/hobo/rapid/taglibs/rapid_document_tags.dryml +0 -56
  122. data/lib/hobo/rapid/taglibs/rapid_editing.dryml +0 -287
  123. data/lib/hobo/rapid/taglibs/rapid_forms.dryml +0 -1156
  124. data/lib/hobo/rapid/taglibs/rapid_generics.dryml +0 -48
  125. data/lib/hobo/rapid/taglibs/rapid_i18n.dryml +0 -173
  126. data/lib/hobo/rapid/taglibs/rapid_lifecycles.dryml +0 -96
  127. data/lib/hobo/rapid/taglibs/rapid_navigation.dryml +0 -108
  128. data/lib/hobo/rapid/taglibs/rapid_pages.dryml +0 -259
  129. data/lib/hobo/rapid/taglibs/rapid_plus.dryml +0 -247
  130. data/lib/hobo/rapid/taglibs/rapid_summary.dryml +0 -283
  131. data/lib/hobo/rapid/taglibs/rapid_support.dryml +0 -102
  132. data/lib/hobo/rapid/taglibs/rapid_user_pages.dryml +0 -182
  133. data/test/irt/generators/rapid.irt +0 -29
@@ -1,4 +1,5 @@
1
1
  require 'generators/hobo_support/thor_shell'
2
+ require 'bundler/cli'
2
3
  module Hobo
3
4
  class SetupWizardGenerator < Rails::Generators::Base
4
5
 
@@ -9,6 +10,7 @@ module Hobo
9
10
  include Generators::Hobo::ActivationEmail
10
11
  include Generators::Hobo::TestOptions
11
12
  include Generators::Hobo::Taglib
13
+ include Generators::Hobo::Plugin
12
14
 
13
15
  def self.banner
14
16
  "rails generate hobo:setup_wizard [options]"
@@ -29,9 +31,6 @@ module Hobo
29
31
  class_option :admin_subsite_name, :type => :string,
30
32
  :desc => "Admin Subsite Name", :default => 'admin'
31
33
 
32
- class_option :make_front_site, :type => :boolean,
33
- :desc => "Rename application.dryml to front_site.dryml", :default => 'true'
34
-
35
34
  class_option :private_site, :type => :boolean,
36
35
  :desc => "Make the site unaccessible to non-members"
37
36
 
@@ -140,14 +139,6 @@ EOI
140
139
  end
141
140
  end
142
141
 
143
- def rapid
144
- if wizard?
145
- say_title 'Hobo Rapid'
146
- say 'Installing Hobo Rapid and default theme...'
147
- end
148
- invoke 'hobo:rapid'
149
- end
150
-
151
142
  def front_controller
152
143
  if wizard?
153
144
  say_title 'Front Controller'
@@ -164,12 +155,10 @@ EOI
164
155
  say_title 'Admin Subsite'
165
156
  if @invite_only || (@add_admin_subsite = yes_no?("Do you want an admin subsite?"))
166
157
  @admin_subsite_name = ask("Choose a name for the admin subsite: [<enter>=admin|<custom_name>]", 'admin')
167
- @make_front_site = yes_no?("Do you want to use a separate front_site.dryml?")
168
158
  end
169
159
  else
170
160
  if @invite_only || (@add_admin_subsite = options[:add_admin_subsite])
171
161
  @admin_subsite_name = options[:admin_subsite_name]
172
- @make_front_site = options[:make_front_site]
173
162
  end
174
163
  end
175
164
  end
@@ -185,10 +174,38 @@ EOI
185
174
  invoke 'hobo:admin_subsite', [@admin_subsite_name],
186
175
  :user_resource_name => @user_resource_name,
187
176
  :invite_only => @invite_only,
188
- :make_front_site => @make_front_site
177
+ :make_front_site => false
189
178
  end
190
179
  end
191
180
 
181
+ def installing_plugins
182
+ say "Installing hobo_rapid plugin..."
183
+ install_plugin_helper('hobo_rapid', nil, :version => Hobo::VERSION)
184
+ say "Installing hobo_jquery plugin..."
185
+ install_plugin_helper('hobo_jquery', nil, :version => Hobo::VERSION)
186
+ say "Installing hobo_jquery_ui plugin..."
187
+ install_plugin_helper('hobo_jquery_ui', nil, :version => Hobo::VERSION)
188
+
189
+ say "Installing hobo_clean theme..."
190
+ inject_css_require("jquery-ui/redmond", "front", nil, true)
191
+ inject_css_require("jquery-ui/flick", "admin", nil, true) if @add_admin_subsite
192
+ if @add_admin_subsite
193
+ install_plugin_helper('hobo_clean', nil, :version => Hobo::VERSION, :subsite => "front", :comments => "The default Hobo theme", :css_top => true)
194
+ install_plugin_helper('hobo_clean_admin', nil, :version => Hobo::VERSION, :subsite => @admin_subsite_name, :css_top => true)
195
+ else
196
+ install_plugin_helper('hobo_clean', nil, :version => Hobo::VERSION, :comments => "The default Hobo theme", :subsite => "front", :css_top => true)
197
+ end
198
+
199
+ gem_with_comments("jquery-ui-themes", "~> 0.0.4")
200
+ Bundler.with_clean_env do
201
+ run "bundle install"
202
+ end
203
+ end
204
+
205
+ def add_dev_tweaks
206
+ invoke 'hobo:dev_tweaks'
207
+ end
208
+
192
209
  def generate_migration
193
210
  if wizard?
194
211
  say_title 'DB Migration'
@@ -29,15 +29,29 @@ module Generators
29
29
  say "Cannot rename application.dryml to #{file_name}_site.dryml"
30
30
  exit 1
31
31
  end
32
- say "Renaming app/views/taglibs/application.dryml to app/views/taglibs/front_site.dryml" \
33
- unless options[:quiet]
32
+ say "Renaming app/views/taglibs/application.dryml to app/views/taglibs/front_site.dryml" unless options[:quiet]
34
33
  unless options[:pretend]
35
34
  FileUtils.mv('app/views/taglibs/application.dryml', "app/views/taglibs/front_site.dryml")
36
35
  copy_file "application.dryml", 'app/views/taglibs/application.dryml'
36
+
37
+ # remove lines from front_site.dryml that exist in both front_site.dryml & application.dryml
38
+ front_site = File.readlines('app/views/taglibs/front_site.dryml') - File.readlines('app/views/taglibs/application.dryml').reject{|l| l.blank?}
39
+ File.open('app/views/taglibs/front_site.dryml', 'wb') do |file|
40
+ front_site.each do
41
+ |line| file.write(line)
42
+ end
43
+ end
37
44
  end
38
45
  end
39
46
 
47
+ template "site.css.erb", File.join('app/assets/stylesheets', "#{file_name}.css")
48
+ copy_file "gitkeep", "app/assets/stylesheets/#{file_name}/.gitkeep"
49
+ template "site.js.erb", File.join('app/assets/javascripts', "#{file_name}.js")
50
+ copy_file "gitkeep", "app/assets/javascripts/#{file_name}/.gitkeep"
51
+
40
52
  template "controller.rb.erb", File.join('app/controllers', file_name, "#{file_name}_site_controller.rb")
53
+
54
+ application "config.assets.precompile += %w(#{file_name}.css #{file_name}.js)"
41
55
  end
42
56
 
43
57
  hook_for :test_framework, :as => :controller do | instance, controller_test |
File without changes
@@ -0,0 +1,9 @@
1
+ /*
2
+ * This is the stylesheet manifest file for the <%= name %> subsite.
3
+ * Files or plugins referenced from here or placed in the <%= name %>/
4
+ * directory will be included.
5
+ *
6
+ *= require_self
7
+ *= require application
8
+ *= require_tree ./<%= name %>
9
+ */
@@ -0,0 +1,10 @@
1
+ // This is a manifest file for the <%= name %> subsite. It will be
2
+ // compiled into including all the files listed below. Add new
3
+ // JavaScript/Coffee code in separate files in the <%= name %>
4
+ // directory and they'll automatically be included in the compiled
5
+ // file accessible from http://example.com/assets/<%= name %>.js It's
6
+ // not advisable to add code directly here, but if you do, it'll
7
+ // appear at the bottom of the the compiled file.
8
+ //
9
+ //= require application
10
+ //= require_tree ./<%= name %>
@@ -1,26 +1,9 @@
1
1
  <!-- Tag definitions for the <%= file_name %> subsite -->
2
2
 
3
- <include src="rapid" gem="hobo"/>
4
-
5
3
  <include src="taglibs/auto/<%= file_name %>/rapid/cards"/>
6
4
  <include src="taglibs/auto/<%= file_name %>/rapid/pages"/>
7
5
  <include src="taglibs/auto/<%= file_name %>/rapid/forms"/>
8
6
 
9
- <set-theme name="clean"/>
10
-
11
- <% if options[:admin]%>
12
-
13
- <extend tag="page">
14
- <old-page merge>
15
- <append-stylesheets:>
16
- <stylesheet name="<%= file_name %>"/>
17
- </append-stylesheets:>
18
- <footer:>
19
- <a href="#{base_url}/"><t key="hobo.subsite.back_link">View Site</t></a>
20
- </footer:>
21
- </old-page>
22
- </extend>
23
- <% end -%>
24
7
  <% if invite_only? -%>
25
8
 
26
9
  <extend tag="card" for="<%= options[:user_resource_name].camelcase %>">
@@ -32,7 +32,7 @@ module Hobo
32
32
  def finalize_installation
33
33
  # add the block only if it's not the default
34
34
  add_generators_block unless (name == 'test_unit' && options[:fixtures] && options[:fixture_replacement].blank?)
35
- invoke Bundler::CLI, :update if options[:update] && @should_update
35
+ invoke(Bundler::CLI, :update, [], {}) if options[:update] && @should_update
36
36
  @finalize_hooks.each {|h| h.call }
37
37
  end
38
38
 
data/lib/hobo.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'hobo_support'
2
2
  require 'hobo_fields'
3
3
  require 'dryml'
4
+ gem 'will_paginate', ">= 3.0"
4
5
  require 'will_paginate'
5
6
  require 'hobo/extensions/enumerable'
6
7
  require 'hobo/extensions/array'
@@ -25,7 +26,7 @@ module Hobo
25
26
 
26
27
  class << self
27
28
 
28
- attr_accessor :current_theme, :engines
29
+ attr_accessor :engines
29
30
 
30
31
  def raw_js(s)
31
32
  RawJs.new(s)
@@ -43,7 +44,7 @@ module Hobo
43
44
  parameters = []
44
45
  like_operator = ActiveRecord::Base.connection.adapter_name =~ /postgres/i ? 'ILIKE' : 'LIKE'
45
46
  query_words.each do |word|
46
- column_queries = search_target.search_columns.map { |column| column == "id" ? "CAST(#{column} AS varchar) #{like_operator} ?" : "#{column} #{like_operator} ?" }
47
+ column_queries = search_target.search_columns.map { |column| "#{column} #{like_operator} ?" }
47
48
  conditions << "(" + column_queries.join(" or ") + ")"
48
49
  parameters.concat(["%#{word}%"] * column_queries.length)
49
50
  end
@@ -14,7 +14,6 @@ module Hobo
14
14
 
15
15
  def included_in_class(klass)
16
16
  klass.extend(ClassMethods)
17
- klass.send(:include, Hobo::Helper::Translations)
18
17
  klass.class_eval do
19
18
  before_filter :login_from_cookie
20
19
  alias_method_chain :redirect_to, :object_url
@@ -29,7 +28,10 @@ module Hobo
29
28
  @included_taglibs = []
30
29
  rescue_from ActionController::RoutingError, :with => :not_found unless Rails.env.development?
31
30
  end
32
- Hobo::Helper.add_to_controller(klass)
31
+ HoboRouteHelper.add_to_controller(klass)
32
+ HoboTranslationsHelper.add_to_controller(klass)
33
+ HoboTranslationsNormalizerHelper.add_to_controller(klass)
34
+ HoboPermissionsHelper.add_to_controller(klass)
33
35
  end
34
36
 
35
37
  end
@@ -56,11 +58,10 @@ module Hobo
56
58
  end
57
59
 
58
60
 
59
- def hobo_ajax_response(*args)
60
- results = args.extract_options!
61
+ def hobo_ajax_response(options={})
61
62
  r = params[:render]
62
63
  if r
63
- ajax_update_response(r.values, results)
64
+ ajax_update_response(r.values, options[:results] || {}, options || params[:render_options])
64
65
  true
65
66
  else
66
67
  false
@@ -75,26 +76,41 @@ module Hobo
75
76
  false,
76
77
  view_context.lookup_context.instance_variable_get('@details')).identifier
77
78
  renderer = Dryml.page_renderer(view_context, identifier, [], controller)
78
-
79
- render :update do |page|
80
- page << (options[:preamble] || "var _update = typeof Hobo == 'undefined' ? Element.update : Hobo.updateElement;")
81
- for spec in render_specs
82
- function = spec[:function] || "_update"
83
- dom_id = spec[:id]
84
-
85
- if spec[:part_context]
86
- part_content = renderer.refresh_part(spec[:part_context], session, dom_id)
87
- page.call(function, dom_id, part_content)
88
- elsif spec[:result]
89
- result = results[spec[:result].to_sym]
90
- page.call(function, dom_id, result)
91
- else
92
- # spec didn't specify any action :-/
93
- end
79
+ options = options.with_indifferent_access
80
+
81
+ headers["Content-Type"] = options['content_type'] if options['content_type']
82
+
83
+ page = options[:preamble] || "var _update = typeof Hobo == 'undefined' ? Element.update : Hobo.updateElement;\n"
84
+ for spec in render_specs
85
+ function = spec[:function] || "_update"
86
+ dom_id = spec[:id]
87
+
88
+ if spec[:part_context]
89
+ part_content = renderer.refresh_part(spec[:part_context], session, dom_id)
90
+ page << "#{function}(#{dom_id.to_json}, #{part_content.to_json})\n"
91
+ elsif spec[:result]
92
+ result = results[spec[:result].to_sym]
93
+ page << "#{function}(#{dom_id.to_json}, #{result.to_json})\n"
94
+ else
95
+ page << "alert('ajax_update_response: render_spec did not provide action');\n"
96
+ end
97
+ end
98
+ if renderer
99
+ if options[:contexts_function]
100
+ storage = renderer.part_contexts_storage_uncoded
101
+ page << "#{options[:contexts_function]}(#{storage.to_json});\n"
94
102
  end
95
- page << renderer.part_contexts_storage if renderer
96
- page << options[:postamble] if options[:postamble]
97
103
  end
104
+ page << options[:postamble] if options[:postamble]
105
+ render :js => page
106
+ end
107
+
108
+ # use this function to send arbitrary bits of javascript
109
+ def ajax_response(response, options)
110
+ page = options[:preamble] || "var _update = typeof Hobo == 'undefined' ? Element.update : Hobo.updateElement;\n"
111
+ page << response
112
+ page << options[:postamble] if options[:postamble]
113
+ render :js => page
98
114
  end
99
115
 
100
116
 
@@ -134,7 +150,10 @@ module Hobo
134
150
  def site_search(query)
135
151
  results_hash = Hobo.find_by_search(query)
136
152
  all_results = results_hash.values.flatten.select { |r| r.viewable_by?(current_user) }
137
- if all_results.empty?
153
+ if params["search_version"]
154
+ @search_results = all_results
155
+ hobo_ajax_response
156
+ elsif all_results.empty?
138
157
  render :text => "<p>"+ t("hobo.live_search.no_results", :default=>["Your search returned no matches."]) + "</p>"
139
158
  else
140
159
  # TODO: call one tag that renders all the search results with headings for each model
@@ -475,8 +475,8 @@ module Hobo
475
475
  def hobo_index(*args, &b)
476
476
  options = args.extract_options!
477
477
  finder = args.first || model
478
- self.this = find_or_paginate(finder, options)
479
- response_block(&b)
478
+ self.this ||= find_or_paginate(finder, options)
479
+ index_response(&b)
480
480
  end
481
481
 
482
482
 
@@ -484,15 +484,21 @@ module Hobo
484
484
  options = args.extract_options!
485
485
  owner, association = find_owner_and_association(owner)
486
486
  finder = args.first || association
487
- self.this = find_or_paginate(finder, options)
488
- response_block(&b)
487
+ self.this ||= find_or_paginate(finder, options)
488
+ index_response(&b)
489
489
  end
490
490
 
491
491
 
492
492
  def hobo_show(*args, &b)
493
493
  options = args.extract_options!
494
- self.this ||= args.first || find_instance(options)
495
- response_block(&b)
494
+ self.this ||= args.first
495
+ if this.nil?
496
+ self.this = find_instance(options)
497
+ unless (parms=attribute_parameters).blank?
498
+ this.with_acting_user(current_user) { this.attributes = parms }
499
+ end
500
+ end
501
+ show_response(&b)
496
502
  end
497
503
 
498
504
  def hobo_edit(*args, &b)
@@ -500,15 +506,34 @@ module Hobo
500
506
  end
501
507
 
502
508
  def hobo_new(record=nil, &b)
503
- self.this = record || model.user_new(current_user)
504
- response_block(&b)
509
+ self.this = record || model.user_new(current_user, attribute_parameters)
510
+ show_response(&b)
511
+ end
512
+
513
+ def show_response(&b)
514
+ response_block(&b) or
515
+ begin
516
+ if request.xhr? && params[:render]
517
+ hobo_ajax_response
518
+ render :nothing => true unless performed?
519
+ end
520
+ end
505
521
  end
506
522
 
523
+ def index_response(&b)
524
+ response_block(&b) or
525
+ begin
526
+ if request.xhr? && params[:render]
527
+ hobo_ajax_response(:page => :blah)
528
+ render :nothing => true unless performed?
529
+ end
530
+ end
531
+ end
507
532
 
508
533
  def hobo_new_for(owner, record=nil, &b)
509
534
  owner, association = find_owner_and_association(owner)
510
- self.this = record || association.user_new(current_user)
511
- response_block(&b)
535
+ self.this = record || association.user_new(current_user, attribute_parameters)
536
+ show_response(&b)
512
537
  end
513
538
 
514
539
 
@@ -603,38 +628,29 @@ module Hobo
603
628
 
604
629
  flash_notice (ht(:"#{@this.class.to_s.underscore}.messages.update.success", :default=>["Changes to the #{@this.class.model_name.human} were saved"])) if valid?
605
630
 
606
- response_block(&b) or
607
- if valid?
608
- respond_to do |wants|
609
- wants.html do
610
- redirect_after_submit options
611
- end
612
- wants.js do
613
- if in_place_edit_field
614
- # Decreasingly hacky support for the scriptaculous in-place-editor
615
- new_val = call_dryml_tag("view", :field => in_place_edit_field, :no_wrapper => true)
616
- hobo_ajax_response(this, :new_field_value => new_val)
617
- else
618
- hobo_ajax_response(this)
619
- end
620
-
621
- # Maybe no ajax requests were made
622
- render :nothing => true unless performed?
623
- end
624
- end
625
- else
626
- respond_to do |wants|
627
- # errors is used by the translation helper, ht, below.
628
- errors = @this.errors.full_messages.join("\n")
629
- wants.html { re_render_form(:edit) }
630
- wants.js { render(:status => 500,
631
- :text => ht(:"#{@this.class.to_s.underscore}.messages.update.error",:default=>["There was a problem with that change.\n#{errors}"], :errors=>errors)
632
- ) }
633
- end
634
- end
631
+ response_block(&b) or begin
632
+ valid = valid? # valid? can be expensive
633
+ if params[:render]
634
+ if (params[:render_options] && params[:render_options][:errors_ok]) || valid
635
+ hobo_ajax_response
636
+
637
+ # Maybe no ajax requests were made
638
+ render :nothing => true unless performed?
639
+ else
640
+ errors = @this.errors.full_messages.join('\n')
641
+ message = ht(:"#{@this.class.to_s.underscore}.messages.update.error",:default=>["There was a problem with that change\\n#{errors}"], :errors=>errors)
642
+ ajax_response("alert('#{message}');", params[:render_options])
643
+ end
644
+ else
645
+ if valid
646
+ redirect_after_submit options
647
+ else
648
+ re_render_form(:edit)
649
+ end
650
+ end
651
+ end
635
652
  end
636
653
 
637
-
638
654
  def hobo_destroy(*args, &b)
639
655
  options = args.extract_options!
640
656
  self.this ||= args.first || find_instance
@@ -732,7 +748,8 @@ module Hobo
732
748
  # --- Miscelaneous Actions --- #
733
749
 
734
750
  def hobo_completions(attribute, finder, options={})
735
- options = options.reverse_merge(:limit => 10, :param => :query, :query_scope => "#{attribute}_contains")
751
+ options = options.reverse_merge(:limit => 10, :query_scope => "#{attribute}_contains")
752
+ options[:param] ||= params[:query].nil? ? :term : :query
736
753
  finder = finder.limit(options[:limit]) unless finder.try.limit_value
737
754
 
738
755
  begin
@@ -745,7 +762,11 @@ module Hobo
745
762
  items += finder2.find(:all).select { |r| r.viewable_by?(current_user) }
746
763
  end
747
764
  end
748
- render :text => "<ul>\n" + items.map {|i| "<li>#{i.send(attribute)}</li>\n"}.join + "</ul>"
765
+ if request.xhr?
766
+ render :json => items.map {|i| i.send(attribute)}
767
+ else
768
+ render :text => "<ul>\n" + items.map {|i| "<li>#{i.send(attribute)}</li>\n"}.join + "</ul>"
769
+ end
749
770
  end
750
771
 
751
772