hobo 1.4.0.pre8 → 2.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES-1.4.txt +87 -3
- data/TODO-1.4.txt +3 -11
- data/VERSION +1 -1
- data/app/helpers/hobo_route_helper.rb +61 -20
- data/lib/generators/hobo/admin_subsite/USAGE +3 -11
- data/lib/generators/hobo/admin_subsite/admin_subsite_generator.rb +4 -1
- data/lib/generators/hobo/admin_subsite/templates/{site.css.erb → site.scss.erb} +0 -0
- data/lib/generators/hobo/assets/assets_generator.rb +2 -2
- data/lib/generators/hobo/assets/templates/{application.css → application.scss} +0 -0
- data/lib/generators/hobo/assets/templates/{front.css → front.scss} +0 -0
- data/lib/generators/hobo/model/templates/model_injection.rb.erb +1 -0
- data/lib/generators/hobo/plugin.rb +3 -1
- data/lib/generators/hobo/routes/router.rb +115 -0
- data/lib/generators/hobo/routes/templates/hobo_routes.rb.erb +42 -3
- data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +35 -2
- data/lib/generators/hobo/subsite.rb +1 -1
- data/lib/generators/hobo/subsite/USAGE +3 -11
- data/lib/generators/hobo/subsite/subsite_generator.rb +3 -0
- data/lib/generators/hobo/subsite/templates/{site.css.erb → site.scss.erb} +0 -0
- data/lib/generators/hobo/subsite_taglib/subsite_taglib_generator.rb +4 -1
- data/lib/generators/hobo/user_mailer/templates/activation.erb +1 -1
- data/lib/generators/hobo/user_mailer/templates/forgot_password.erb +1 -1
- data/lib/generators/hobo/user_mailer/templates/invite.erb +1 -1
- data/lib/generators/hobo/user_model/templates/model_injection.rb.erb +1 -0
- data/lib/hobo.rb +2 -2
- data/lib/hobo/controller.rb +3 -11
- data/lib/hobo/controller/model.rb +89 -89
- data/lib/hobo/engine.rb +12 -0
- data/lib/hobo/extensions/active_record/permissions.rb +15 -24
- data/lib/hobo/model.rb +3 -0
- data/lib/hobo/model/permissions.rb +1 -1
- data/lib/hobo/rapid/generators/rapid/cards.dryml.erb +10 -3
- data/lib/hobo/rapid/generators/rapid/forms.dryml.erb +9 -2
- data/lib/hobo/rapid/generators/rapid/pages.dryml.erb +11 -4
- data/lib/hobo/routes.rb +2 -0
- data/test/doctest/hobo/hobo_helper.rdoctest +23 -20
- data/test/doctest/hobo/lifecycles.rdoctest +1 -0
- data/test/doctest/hobo/model.rdoctest +4 -0
- data/test/doctest/hobo/multi_model_forms.rdoctest +2 -0
- data/test/doctest/hobo/scopes.rdoctest +18 -5
- data/test/doctest/prepare_testapp.rb +4 -2
- data/test/irt/generators/admin_subsite.irt +2 -6
- data/test/irt/generators/assets.irt +1 -7
- data/test/irt/generators/front_controller.irt +1 -3
- data/test/irt/generators/model.irt +1 -2
- data/test/irt/generators/partials/_account_user_model_tests.rb +1 -3
- data/test/irt/generators/partials/_accounts_users_controller_tests.rb +1 -3
- data/test/irt/generators/partials/_default_user_model_tests.rb +1 -3
- data/test/irt/generators/partials/_default_users_controller_tests.rb +1 -3
- data/test/irt/generators/partials/_house_controller_tests.rb +1 -3
- data/test/irt/generators/partials/_user_mailer_tests.rb +1 -3
- data/test/irt/generators/subsite.irt +5 -6
- data/test/irt/generators/user_mailer.irt +2 -0
- metadata +12 -18
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-ACD3E6-DBE1E5-H.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-DBE1E5-FCFEF5-H.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/300-3B5F87-ACD3E6-H.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/spinner.gif +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/stylesheets/clean-sidemenu.css +0 -81
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/views/clean-sidemenu.dryml +0 -30
@@ -6,18 +6,56 @@
|
|
6
6
|
<% for subsite in subsites -%>
|
7
7
|
<%- if subsite -%>
|
8
8
|
|
9
|
+
<%= "namespace :#{subsite} do" %>
|
10
|
+
<%- end -%>
|
11
|
+
<%- for controller in controllers_for(subsite) -%>
|
12
|
+
<%- router = router_for(subsite, controller) -%>
|
13
|
+
|
14
|
+
|
15
|
+
<%= " #{' ' if subsite}# Resource routes for controller #{controller.controller_path}" %>
|
16
|
+
<%= router.emit_hash(router.resources_hash, subsite ? " " : " ") -%>
|
17
|
+
<%- router.owner_actions.each do |owner_hash| -%>
|
18
|
+
|
19
|
+
<%= " #{' ' if subsite}# Owner routes for controller #{controller.controller_path}" %>
|
20
|
+
<%= router.emit_hash(owner_hash, subsite ? " " : " ") -%>
|
21
|
+
<%- end -%>
|
22
|
+
<%- unless (routes = router.user_routes).blank? -%>
|
23
|
+
|
24
|
+
<%= "#{' ' if subsite} # User routes for controller #{controller.controller_path}" %>
|
25
|
+
<%- for route in routes -%>
|
26
|
+
<%= "#{' ' if subsite} #{route}" %>
|
27
|
+
<%- end -%>
|
28
|
+
<%- end -%>
|
29
|
+
<%- end -%>
|
30
|
+
<%- if subsite -%>
|
31
|
+
|
32
|
+
end
|
33
|
+
<%- end -%>
|
34
|
+
<%- end -%>
|
35
|
+
|
36
|
+
<% unless Rails.configuration.hobo.dont_emit_deprecated_routes %>
|
37
|
+
|
38
|
+
# These are the Hobo 1.3 style routes. They've been included for backwards
|
39
|
+
# compatibility reasons because the names of some named routes have been changed.
|
40
|
+
# Please update your views to use the new named route names and then disable this
|
41
|
+
# section by setting config.hobo.dont_emit_deprecated_routes = true.
|
42
|
+
|
43
|
+
|
44
|
+
<% for subsite in subsites -%>
|
45
|
+
<%- if subsite -%>
|
46
|
+
|
9
47
|
<%= "namespace :#{subsite} do" %>
|
10
48
|
<%- end -%>
|
11
49
|
<%- for controller in controllers_for(subsite) -%>
|
12
50
|
<%- router = router_for(subsite, controller)
|
13
|
-
groups = %w[ index_action lifecycle
|
51
|
+
groups = %w[ index_action lifecycle owner web_method show_action reorder resource ] -%>
|
14
52
|
|
15
53
|
<%- for group in groups -%>
|
16
54
|
<%- gr = "#{group}_routes"
|
17
55
|
routes = gr == 'lifecycle_routes' ? router.send(gr.to_sym, subsite) : router.send(gr.to_sym) -%>
|
18
56
|
<%- unless routes.empty? -%>
|
19
57
|
|
20
|
-
<%= " " if subsite %><%=
|
58
|
+
<%= " " if subsite %><%= "# DEPRECATED #{gr.humanize} for controller #{controller.controller_path}" %>
|
21
59
|
<%- end -%>
|
22
60
|
<%- for route in routes -%>
|
23
61
|
<%= " " if subsite %><%= route %>
|
@@ -28,6 +66,7 @@
|
|
28
66
|
|
29
67
|
end
|
30
68
|
<%- end -%>
|
31
|
-
<%- end -%>
|
69
|
+
<%- end -%>
|
32
70
|
|
71
|
+
<%- end -%>
|
33
72
|
end
|
@@ -25,12 +25,24 @@ module Hobo
|
|
25
25
|
class_option :front_controller_name, :type => :string,
|
26
26
|
:desc => "Front Controller Name", :default => 'front'
|
27
27
|
|
28
|
+
class_option :front_theme, :type => :string,
|
29
|
+
:desc => "Front Theme", :default => 'clean'
|
30
|
+
|
31
|
+
class_option :front_ui_theme, :type => :string,
|
32
|
+
:desc => "Front jQuery-UI Theme", :default => 'redmond'
|
33
|
+
|
28
34
|
class_option :add_admin_subsite, :type => :boolean,
|
29
35
|
:desc => "Add an Admin Subsite"
|
30
36
|
|
31
37
|
class_option :admin_subsite_name, :type => :string,
|
32
38
|
:desc => "Admin Subsite Name", :default => 'admin'
|
33
39
|
|
40
|
+
class_option :admin_theme, :type => :string,
|
41
|
+
:desc => "Admin Theme", :default => 'clean'
|
42
|
+
|
43
|
+
class_option :admin_ui_theme, :type => :string,
|
44
|
+
:desc => "Admin jQuery-UI Theme", :default => 'redmond'
|
45
|
+
|
34
46
|
class_option :invite_only, :type => :boolean,
|
35
47
|
:desc => "Require invitation to join site"
|
36
48
|
|
@@ -154,7 +166,19 @@ EOI
|
|
154
166
|
end
|
155
167
|
|
156
168
|
def install_default_plugins
|
157
|
-
|
169
|
+
if wizard?
|
170
|
+
say_title 'Front Theme'
|
171
|
+
say "The currently available themes are clean, clean_admin, clean_sidemenu and bootstrap."
|
172
|
+
@front_theme = ask("Choose a theme for the front site: [<enter>=clean|<custom_name>]", 'clean')
|
173
|
+
|
174
|
+
say_title 'Front jQuery-UI Theme'
|
175
|
+
say "The currently available jQuery-UI themes are listed here: https://github.com/fatdude/jquery-ui-themes-rails/blob/master/README.markdown"
|
176
|
+
@front_ui_theme = ask("Choose a jQuery-UI theme for the front site: [<enter>=redmond|<custom_name>]", 'redmond')
|
177
|
+
else
|
178
|
+
@front_theme = options[:front_theme]
|
179
|
+
@front_ui_theme = options[:front_ui_theme]
|
180
|
+
end
|
181
|
+
invoke 'hobo:install_default_plugins', [], {:subsite => 'front', :theme => "hobo_#{@front_theme}", :ui_theme => @front_ui_theme, :skip_gem => false}
|
158
182
|
end
|
159
183
|
|
160
184
|
def admin_subsite
|
@@ -162,10 +186,18 @@ EOI
|
|
162
186
|
say_title 'Admin Subsite'
|
163
187
|
if @invite_only || (@add_admin_subsite = yes_no?("Do you want an admin subsite?"))
|
164
188
|
@admin_subsite_name = ask("Choose a name for the admin subsite: [<enter>=admin|<custom_name>]", 'admin')
|
189
|
+
|
190
|
+
say "The currently available themes are clean, clean_admin, clean_sidemenu and bootstrap."
|
191
|
+
@admin_theme = ask("Choose a theme for the #{@admin_subsite_name} site: [<enter>=clean_admin|<custom_name>]", 'clean_admin')
|
192
|
+
|
193
|
+
say "The currently available jQuery-UI themes are listed here: https://github.com/fatdude/jquery-ui-themes-rails/blob/master/README.markdown"
|
194
|
+
@admin_ui_theme = ask("Choose a jQuery-UI theme for the admin site: [<enter>=flick|<custom_name>]", 'flick')
|
165
195
|
end
|
166
196
|
else
|
167
197
|
if @invite_only || (@add_admin_subsite = options[:add_admin_subsite])
|
168
198
|
@admin_subsite_name = options[:admin_subsite_name]
|
199
|
+
@admin_theme = options[:front_theme]
|
200
|
+
@admin_ui_theme = options[:front_ui_theme]
|
169
201
|
end
|
170
202
|
end
|
171
203
|
end
|
@@ -181,7 +213,8 @@ EOI
|
|
181
213
|
invoke 'hobo:admin_subsite', [@admin_subsite_name],
|
182
214
|
:user_resource_name => @user_resource_name,
|
183
215
|
:invite_only => @invite_only,
|
184
|
-
:
|
216
|
+
:theme => @admin_theme,
|
217
|
+
:ui_theme => @admin_ui_theme
|
185
218
|
end
|
186
219
|
end
|
187
220
|
|
@@ -19,7 +19,7 @@ module Generators
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
template "site.
|
22
|
+
template "site.scss.erb", File.join('app/assets/stylesheets', "#{file_name}.scss")
|
23
23
|
copy_file "gitkeep", "app/assets/stylesheets/#{file_name}/.gitkeep"
|
24
24
|
template "site.js.erb", File.join('app/assets/javascripts', "#{file_name}.js")
|
25
25
|
copy_file "gitkeep", "app/assets/javascripts/#{file_name}/.gitkeep"
|
@@ -8,17 +8,9 @@ Description:
|
|
8
8
|
and two different sets of views for the same model.
|
9
9
|
|
10
10
|
The subsite will use app/views/taglibs/<subsite_name>_site.dryml
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
load both application.dryml and front_site.dryml.
|
15
|
-
|
16
|
-
It is thus recommended that you ensure that
|
17
|
-
<subsite_name>_site.dryml and application.dryml do not repeat
|
18
|
-
code, such as the inclusion of rapid or the setting of the theme.
|
19
|
-
One easy way of ensuring this is to use the --make-front-site
|
20
|
-
option. If you have already accounted for this, use
|
21
|
-
--make-front-site=false.
|
11
|
+
for common tags. The assets that the subsite will load are
|
12
|
+
specified in app/assets/javascripts/<subsite_name>.js and
|
13
|
+
app/assets/stylesheets/<subsite_name>.[s]css
|
22
14
|
|
23
15
|
The difference between hobo:admin_site and hobo:subsite is that
|
24
16
|
hobo:admin_site limits the subsite to use by administrators only.
|
@@ -2,6 +2,9 @@ module Hobo
|
|
2
2
|
class SubsiteGenerator < Rails::Generators::NamedBase
|
3
3
|
source_root File.expand_path('../templates', __FILE__)
|
4
4
|
|
5
|
+
class_option :theme, :type => :string, :desc => "Theme", :default => 'clean_admin'
|
6
|
+
class_option :ui_theme, :type => :string, :desc => "jQuery-UI Theme", :default => 'flick'
|
7
|
+
|
5
8
|
def self.banner
|
6
9
|
"rails generate hobo:subsite NAME [options]"
|
7
10
|
end
|
File without changes
|
@@ -4,13 +4,16 @@ module Hobo
|
|
4
4
|
include Generators::Hobo::InviteOnly
|
5
5
|
include Generators::Hobo::Taglib
|
6
6
|
|
7
|
+
class_option :theme, :type => :string, :desc => "Theme", :default => 'clean_admin'
|
8
|
+
class_option :ui_theme, :type => :string, :desc => "jQuery-UI Theme", :default => 'flick'
|
9
|
+
|
7
10
|
def self.banner
|
8
11
|
"rails generate hobo:subsite_taglib NAME [options]"
|
9
12
|
end
|
10
13
|
|
11
14
|
def generate_taglib
|
12
15
|
template "taglib.dryml.erb", File.join('app/views/taglibs', "#{file_name}_site.dryml")
|
13
|
-
Rails::Generators.invoke('hobo:install_default_plugins', ["--subsite=#{file_name}", "--theme=
|
16
|
+
Rails::Generators.invoke('hobo:install_default_plugins', ["--subsite=#{file_name}", "--theme=hobo_#{options[:theme]}", "--ui_theme=#{options[:ui_theme]}"])
|
14
17
|
end
|
15
18
|
|
16
19
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
To activate your account for <%%= @app_name %>, click on this link:
|
4
4
|
|
5
|
-
<%%= <%= name.underscore -%>
|
5
|
+
<%%= activate_<%= name.underscore -%>_url :id => @<%= name.underscore -%>, :key => @key %>
|
6
6
|
|
7
7
|
Thank you,
|
8
8
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
If you have forgotten your password for <%%= @app_name %>, you can choose
|
4
4
|
a new one by clicking on this link:
|
5
5
|
|
6
|
-
<%%= <%= name.underscore -%>
|
6
|
+
<%%= reset_password_<%= name.underscore -%>_url :id => @<%= name.underscore -%>, :key => @key %>
|
7
7
|
|
8
8
|
Thank you,
|
9
9
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
You have been invited to join <%%= @app_name %>. If you wish to accept, please click on the following link
|
4
4
|
|
5
|
-
<%%= <%= name.underscore %>
|
5
|
+
<%%= accept_invitation_<%= name.underscore %>_url :id => @<%= name.underscore %>, :key => @key %>
|
6
6
|
|
7
7
|
Thank you,
|
8
8
|
|
data/lib/hobo.rb
CHANGED
@@ -34,7 +34,7 @@ module Hobo
|
|
34
34
|
|
35
35
|
def find_by_search(query, search_targets=[])
|
36
36
|
if search_targets.empty?
|
37
|
-
search_targets = Hobo::
|
37
|
+
search_targets = Hobo::Model.all_models.select {|m| m.search_columns.any? }
|
38
38
|
end
|
39
39
|
|
40
40
|
query_words = ActiveRecord::Base.connection.quote_string(query).split
|
@@ -44,7 +44,7 @@ module Hobo
|
|
44
44
|
parameters = []
|
45
45
|
like_operator = ActiveRecord::Base.connection.adapter_name =~ /postgres/i ? 'ILIKE' : 'LIKE'
|
46
46
|
query_words.each do |word|
|
47
|
-
column_queries = search_target.search_columns.map { |column| "#{column} #{like_operator} ?" }
|
47
|
+
column_queries = search_target.search_columns.map { |column| column == "id" ? "CAST(#{column} AS varchar) #{like_operator} ?" : "#{column} #{like_operator} ?" }
|
48
48
|
conditions << "(" + column_queries.join(" or ") + ")"
|
49
49
|
parameters.concat(["%#{word}%"] * column_queries.length)
|
50
50
|
end
|
data/lib/hobo/controller.rb
CHANGED
@@ -81,9 +81,9 @@ module Hobo
|
|
81
81
|
|
82
82
|
headers["Content-Type"] = options['content_type'] if options['content_type']
|
83
83
|
|
84
|
-
page = options[:preamble] || "
|
84
|
+
page = options[:preamble] || ""
|
85
85
|
for spec in render_specs
|
86
|
-
function = spec[:function] || "
|
86
|
+
function = spec[:function] || "hjq.ajax.update"
|
87
87
|
dom_id = spec[:id]
|
88
88
|
|
89
89
|
if spec[:part_context]
|
@@ -97,6 +97,7 @@ module Hobo
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
if renderer
|
100
|
+
options[:contexts_function] ||= "hjq.ajax.updatePartContexts" unless options[:no_contexts_function]
|
100
101
|
if options[:contexts_function]
|
101
102
|
storage = renderer.part_contexts_storage_uncoded
|
102
103
|
page << "#{options[:contexts_function]}(#{storage.to_json});\n"
|
@@ -106,15 +107,6 @@ module Hobo
|
|
106
107
|
render :js => page
|
107
108
|
end
|
108
109
|
|
109
|
-
# use this function to send arbitrary bits of javascript
|
110
|
-
def ajax_response(response, options)
|
111
|
-
page = options[:preamble] || "var _update = typeof Hobo == 'undefined' ? Element.update : Hobo.updateElement;\n"
|
112
|
-
page << response
|
113
|
-
page << options[:postamble] if options[:postamble]
|
114
|
-
render :js => page
|
115
|
-
end
|
116
|
-
|
117
|
-
|
118
110
|
# dryml does not use layouts
|
119
111
|
def action_has_layout?
|
120
112
|
false
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Hobo
|
2
2
|
module Controller
|
3
|
-
|
3
|
+
module Model
|
4
4
|
|
5
5
|
include Hobo::Controller
|
6
6
|
|
@@ -32,10 +32,14 @@ module Hobo
|
|
32
32
|
rescue_from Hobo::PermissionDeniedError, :with => :permission_denied
|
33
33
|
rescue_from Hobo::Model::Lifecycles::LifecycleKeyError, :with => :permission_denied
|
34
34
|
|
35
|
+
respond_to :html
|
36
|
+
|
35
37
|
alias_method_chain :render, :hobo_model
|
36
38
|
|
37
39
|
end
|
38
40
|
register_controller(base)
|
41
|
+
subsite = base.name.include?("::") ? base.name.split("::").first.underscore : nil
|
42
|
+
base.model.hobo_controller[subsite] = base
|
39
43
|
|
40
44
|
Hobo::Controller.included_in_class(base)
|
41
45
|
end
|
@@ -385,12 +389,25 @@ module Hobo
|
|
385
389
|
end
|
386
390
|
|
387
391
|
|
388
|
-
def destination_after_submit(
|
392
|
+
def destination_after_submit(*args)
|
393
|
+
options = args.extract_options!
|
394
|
+
destroyed = args[1]
|
389
395
|
after_submit = params[:after_submit]
|
390
396
|
|
391
397
|
# The after_submit post parameter takes priority
|
392
398
|
(after_submit == "stay-here" ? url_for_page_path : after_submit) ||
|
393
399
|
|
400
|
+
# Then try options[:redirect]
|
401
|
+
((o=options[:redirect]) && begin
|
402
|
+
if o.is_a?(Symbol)
|
403
|
+
object_url(@this, o)
|
404
|
+
elsif o.is_a?(String) || o.is_a?(Hash)
|
405
|
+
o
|
406
|
+
else
|
407
|
+
object_url(*Array(o))
|
408
|
+
end
|
409
|
+
end) ||
|
410
|
+
|
394
411
|
# Then try the record's show page
|
395
412
|
(!destroyed && object_url(@this)) ||
|
396
413
|
|
@@ -410,24 +427,6 @@ module Hobo
|
|
410
427
|
end
|
411
428
|
|
412
429
|
|
413
|
-
def redirect_after_submit(*args)
|
414
|
-
options = args.extract_options!
|
415
|
-
o = options[:redirect]
|
416
|
-
if o
|
417
|
-
url = if o.is_a?(Symbol)
|
418
|
-
object_url(this, o)
|
419
|
-
elsif o.is_a?(String) || o.is_a?(Hash)
|
420
|
-
o
|
421
|
-
else
|
422
|
-
object_url(*Array(o))
|
423
|
-
end
|
424
|
-
redirect_to url
|
425
|
-
else
|
426
|
-
redirect_to destination_after_submit(*args)
|
427
|
-
end
|
428
|
-
end
|
429
|
-
|
430
|
-
|
431
430
|
def response_block(&b)
|
432
431
|
if b
|
433
432
|
respond_to do |format|
|
@@ -520,6 +519,8 @@ module Hobo
|
|
520
519
|
if request.xhr? && params[:render]
|
521
520
|
hobo_ajax_response
|
522
521
|
render :nothing => true unless performed?
|
522
|
+
else
|
523
|
+
respond_with(self.this)
|
523
524
|
end
|
524
525
|
end
|
525
526
|
|
@@ -527,6 +528,8 @@ module Hobo
|
|
527
528
|
if request.xhr? && params[:render]
|
528
529
|
hobo_ajax_response(:page => :blah)
|
529
530
|
render :nothing => true unless performed?
|
531
|
+
else
|
532
|
+
respond_with(self.this)
|
530
533
|
end
|
531
534
|
end
|
532
535
|
|
@@ -546,6 +549,7 @@ module Hobo
|
|
546
549
|
self.this = new_for_create(attributes)
|
547
550
|
this.user_save(current_user)
|
548
551
|
end
|
552
|
+
flash_notice (ht( :"#{@this.class.to_s.underscore}.messages.create.success", :default=>["The #{@this.class.model_name.human} was created successfully"])) if valid?
|
549
553
|
response_block(&b) || create_response(:new, options)
|
550
554
|
end
|
551
555
|
|
@@ -560,6 +564,7 @@ module Hobo
|
|
560
564
|
self.this = association.new(attributes)
|
561
565
|
this.save
|
562
566
|
end
|
567
|
+
flash_notice (ht( :"#{@this.class.to_s.underscore}.messages.create.success", :default=>["The #{@this.class.model_name.human} was created successfully"])) if valid?
|
563
568
|
response_block(&b) || create_response(:"new_for_#{name_of_auto_action_for(owner_association)}", options)
|
564
569
|
end
|
565
570
|
|
@@ -586,30 +591,31 @@ module Hobo
|
|
586
591
|
end
|
587
592
|
|
588
593
|
|
589
|
-
def create_response(new_action, options={}
|
590
|
-
|
594
|
+
def create_response(new_action, options={})
|
595
|
+
valid = valid? # valid? can be expensive
|
596
|
+
if params[:render]
|
597
|
+
if (params[:render_options] && params[:render_options][:errors_ok]) || valid
|
598
|
+
hobo_ajax_response
|
591
599
|
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
end
|
612
|
-
end
|
600
|
+
# Maybe no ajax requests were made
|
601
|
+
render :nothing => true unless performed?
|
602
|
+
else
|
603
|
+
errors = @this.errors.full_messages.join('\n')
|
604
|
+
message = ht( :"#{this.class.to_s.underscore}.messages.create.error", :errors=>errors,:default=>["Couldn't create the #{this.class.name.titleize.downcase}.\n #{errors}"])
|
605
|
+
render :js => "alert(#{message.to_json});\n"
|
606
|
+
end
|
607
|
+
else
|
608
|
+
location = destination_after_submit(options)
|
609
|
+
respond_with(self.this, :location => location) do |format|
|
610
|
+
format.html do
|
611
|
+
if valid
|
612
|
+
redirect_to location
|
613
|
+
else
|
614
|
+
re_render_form(new_action)
|
615
|
+
end
|
616
|
+
end
|
617
|
+
end
|
618
|
+
end
|
613
619
|
end
|
614
620
|
|
615
621
|
|
@@ -641,7 +647,7 @@ module Hobo
|
|
641
647
|
#
|
642
648
|
# parameters:
|
643
649
|
# valid is a cache of valid?
|
644
|
-
# options is passed through to
|
650
|
+
# options is passed through to destination_after_submit
|
645
651
|
def update_response(valid=nil, options={})
|
646
652
|
# valid? can be expensive, cache it
|
647
653
|
valid = valid? if valid.nil?
|
@@ -655,15 +661,19 @@ module Hobo
|
|
655
661
|
errors = @this.errors.full_messages.join('\n')
|
656
662
|
message = ht(:"#{@this.class.to_s.underscore}.messages.update.error", :default=>["There was a problem with that change\\n#{errors}"], :errors=>errors)
|
657
663
|
|
658
|
-
|
664
|
+
render :js => "alert(#{message.to_json});\n"
|
659
665
|
end
|
660
666
|
else
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
+
location = destination_after_submit(options)
|
668
|
+
respond_with(self.this, :location => location) do |format|
|
669
|
+
format.html do
|
670
|
+
if valid
|
671
|
+
flash_notice (ht(:"#{@this.class.to_s.underscore}.messages.update.success", :default=>["Changes to the #{@this.class.model_name.human} were saved"]))
|
672
|
+
redirect_to location
|
673
|
+
else
|
674
|
+
re_render_form(:edit)
|
675
|
+
end
|
676
|
+
end
|
667
677
|
end
|
668
678
|
end
|
669
679
|
end
|
@@ -673,16 +683,16 @@ module Hobo
|
|
673
683
|
self.this ||= args.first || find_instance
|
674
684
|
this.user_destroy(current_user)
|
675
685
|
flash_notice ht( :"#{model.to_s.underscore}.messages.destroy.success", :default=>["The #{model.name.titleize.downcase} was deleted"])
|
676
|
-
destroy_response(options, &b)
|
686
|
+
response_block(&b) || destroy_response(options, &b)
|
677
687
|
end
|
678
688
|
|
679
689
|
|
680
|
-
def destroy_response(options={}
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
690
|
+
def destroy_response(options={})
|
691
|
+
if params[:render]
|
692
|
+
hobo_ajax_response || render(:nothing => true)
|
693
|
+
else
|
694
|
+
respond_with(self.this, :location => destination_after_submit(this, true, options))
|
695
|
+
end
|
686
696
|
end
|
687
697
|
|
688
698
|
|
@@ -700,26 +710,32 @@ module Hobo
|
|
700
710
|
def do_creator_action(name, options={}, &b)
|
701
711
|
@creator = model::Lifecycle.creator(name)
|
702
712
|
self.this = @creator.run!(current_user, attribute_parameters)
|
703
|
-
response_block(&b)
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
713
|
+
response_block(&b) || do_creator_response(name, options)
|
714
|
+
end
|
715
|
+
|
716
|
+
def do_creator_response(name, options)
|
717
|
+
if valid?
|
718
|
+
if params[:render]
|
719
|
+
hobo_ajax_response || render(:nothing => true)
|
709
720
|
else
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
721
|
+
location = destination_after_submit(options)
|
722
|
+
respond_with(self.this, :location => location)
|
723
|
+
end
|
724
|
+
else
|
725
|
+
this.exempt_from_edit_checks = true
|
726
|
+
if params[:render] && params[:render_options] && params[:render_options][:errors_ok]
|
727
|
+
hobo_ajax_response
|
728
|
+
render :nothing => true unless performed?
|
729
|
+
else
|
730
|
+
# errors is used by the translation helper, ht, below.
|
731
|
+
errors = this.errors.full_messages.join("\n")
|
732
|
+
respond_with(self.this) do |wants|
|
714
733
|
wants.html { re_render_form(name) }
|
715
|
-
wants.js { render(:status => 500,
|
716
|
-
:text => ht(:"#{@this.class.to_s.underscore}.messages.creator.error", :default=>["Couldn't do creator #{name}.\n#{errors}"], :name=>name, :errors=>errors)
|
717
|
-
)}
|
718
734
|
end
|
719
735
|
end
|
736
|
+
end
|
720
737
|
end
|
721
738
|
|
722
|
-
|
723
739
|
def prepare_transition(name, options)
|
724
740
|
key = options.delete(:key) || params[:key]
|
725
741
|
|
@@ -743,25 +759,9 @@ module Hobo
|
|
743
759
|
options = args.extract_options!
|
744
760
|
@transition = prepare_transition(name, options)
|
745
761
|
@transition.run!(this, current_user, attribute_parameters)
|
746
|
-
response_block(&b)
|
747
|
-
if valid?
|
748
|
-
respond_to do |wants|
|
749
|
-
wants.html { redirect_after_submit(options) }
|
750
|
-
wants.js { hobo_ajax_response || render(:nothing => true) }
|
751
|
-
end
|
752
|
-
else
|
753
|
-
respond_to do |wants|
|
754
|
-
# errors is used by the translation helper, ht, below.
|
755
|
-
errors = this.errors.full_messages.join("\n")
|
756
|
-
wants.html { re_render_form(name) }
|
757
|
-
wants.js { render(:status => 500,
|
758
|
-
:text => ht(:"#{@this.class.to_s.underscore}.messages.transition.error", :default=>["Couldn't do transition #{name}.\n#{errors}"], :name=>name, :errors=>errors)
|
759
|
-
)}
|
760
|
-
end
|
761
|
-
end
|
762
|
+
response_block(&b) || update_response(nil, options)
|
762
763
|
end
|
763
764
|
|
764
|
-
|
765
765
|
# --- Miscelaneous Actions --- #
|
766
766
|
|
767
767
|
# Hobo 1.3's name one uses params[:query], jQuery-UI's autocomplete
|