jeffp-wizardly 0.1.8.3 → 0.1.8.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,8 +31,20 @@ module Wizardly
31
31
  self.send(:define_method, sprintf("#{macro.last}", form.to_s), &block )
32
32
  end
33
33
  end
34
+
34
35
  MACRO
35
36
  end
37
+
38
+ global_macros = [
39
+ %w(on_completed after_wizard_save)
40
+ ]
41
+ global_macros.each do |macro|
42
+ mb << <<-GLOBAL
43
+ def self.#{macro.first}(&block)
44
+ self.send(:define_method, :#{macro.last}, &block )
45
+ end
46
+ GLOBAL
47
+ end
36
48
  mb.string
37
49
  end
38
50
 
@@ -97,28 +109,29 @@ MACRO
97
109
  return
98
110
  end
99
111
 
112
+ @do_not_complete = false
100
113
  ONE
101
114
  if self.last_page?(id)
102
115
  mb << <<-TWO
103
116
  callback_performs_action?(:on_#{id}_form_#{finish_button})
104
- complete_wizard
117
+ complete_wizard unless @do_not_complete
105
118
  TWO
106
119
  elsif self.first_page?(id)
107
120
  mb << <<-THREE
108
121
  if button_id == :#{finish_button}
109
122
  callback_performs_action?(:on_#{id}_form_#{finish_button})
110
- complete_wizard
123
+ complete_wizard unless @do_not_complete
111
124
  return
112
125
  end
113
126
  #{model_persist_line}
114
127
  return if callback_performs_action?(:on_#{id}_form_#{next_button})
115
128
  redirect_to :action=>:#{self.next_page(id)}
116
129
  THREE
117
- else
130
+ else
118
131
  mb << <<-FOUR
119
132
  if button_id == :#{finish_button}
120
133
  callback_performs_action?(:on_#{id}_form_#{finish_button})
121
- complete_wizard
134
+ complete_wizard unless @do_not_complete
122
135
  return
123
136
  end
124
137
  #{model_persist_line}
@@ -144,7 +157,7 @@ ENSURE
144
157
  <<-CALLBACKS
145
158
  protected
146
159
  def _on_wizard_#{finish}
147
- @#{self.model}.save_without_validation!
160
+ @#{self.model}.save_without_validation! if @#{self.model}.changed?
148
161
  @wizard_completed_flag = true
149
162
  reset_wizard_form_data
150
163
  _wizard_final_redirect_to(:completed)
@@ -182,6 +195,7 @@ ENSURE
182
195
  mb = StringIO.new
183
196
  mb << <<-PROGRESSION
184
197
  protected
198
+ def do_not_complete; @do_not_complete = true; end
185
199
  def previous_in_progression_from(step)
186
200
  po = #{self.page_order.inspect}
187
201
  p = self.progression
@@ -246,7 +260,9 @@ SANDBOX
246
260
  end
247
261
  mb << <<-HELPERS
248
262
  def complete_wizard(redirect = nil)
249
- redirect_to redirect if redirect
263
+ @#{self.model}.save_without_validation!
264
+ callback_performs_action?(:after_wizard_save)
265
+ redirect_to redirect if (redirect && !self.performed?)
250
266
  _on_wizard_#{finish_button}
251
267
  redirect_to #{Utils.formatted_redirect(self.completed_redirect)} unless self.performed?
252
268
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeffp-wizardly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8.3
4
+ version: 0.1.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Patmon
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-18 00:00:00 -07:00
12
+ date: 2009-08-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15