Class: AdminWidgets::WizardWidget

Inherits:
BaseFormWidget show all
Defined in:
lib/admin_widgets/wizard_widget.rb

Instance Attribute Summary collapse

Attributes inherited from BaseFormWidget

#form

Instance Method Summary collapse

Methods inherited from BaseFormWidget

#around_form, #autofocus!, #autofocus_done?, #builder, #content, #field

Methods inherited from BaseWidget

#capture, #content_block, #helper, #method_missing, #root

Methods included from Memoization

#memoize

Methods included from Delegation

#delegate

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class AdminWidgets::BaseWidget

Instance Attribute Details

#current_stepObject (readonly)

Returns the value of attribute current_step.



9
10
11
# File 'lib/admin_widgets/wizard_widget.rb', line 9

def current_step
  @current_step
end

Instance Method Details

#buttonsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/admin_widgets/wizard_widget.rb', line 41

def buttons
  div :class => ['group', 'navform', 'wat-cf'] do
    rawtext helper.button_tag(:class => 'big button finish', :name => 'change_step', :value => @steps.size + 1) {
      helper.image_tag('icons/tick.png') +
      helper.t('resources.actions.finish')
    } if display_finish_button && @current_step == @steps.count
    rawtext helper.button_tag(:class => 'big button next', :name => 'change_step', :value => @current_step + 1) {
      helper.image_tag('icons/next.png') +
      helper.t('resources.actions.next')
    } if @current_step < @steps.count
    rawtext helper.button_tag(:class => 'big button previous', :name => 'change_step', :value => @current_step - 1) {
      helper.image_tag('icons/previous.png') +
      helper.t('resources.actions.previous')
    } if @current_step > 1
  end
end

#fieldset(name, options = {}, &block) ⇒ Object

DSL methods



13
14
15
# File 'lib/admin_widgets/wizard_widget.rb', line 13

def fieldset(name, options = {}, &block)
  widget AdminWidgets::Form::FieldsetWidget.new(options.merge(:name => name, :parent => self, :block => block))
end

#form_contentObject



34
35
36
37
38
39
# File 'lib/admin_widgets/wizard_widget.rb', line 34

def form_content
  content_block
  steps_header
  rawtext @content_buffer
  buttons
end

#step(name, &block) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/admin_widgets/wizard_widget.rb', line 58

def step(name, &block)
  @current_step ||= 1
  @content_buffer ||= ''
  @steps = [] if !@steps
  @steps << name
  @content_buffer += capture do
    div :class => 'step' do
      instance_eval &block if block
    end if @current_step == @steps.count
  end
end

#steps_headerObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/admin_widgets/wizard_widget.rb', line 17

def steps_header

  # Default button
  rawtext helper.button_tag(:class => "default-step-button", :style => 'border:0;display:block;height:0;overflow:hidden;padding:0;', :name => 'change_step', :value => (@current_step.to_i + 1)) { 'Next' }

  ul :class => 'steps' do
    @steps.each_with_index do |step, index|
      li do
        active = @current_step == index + 1 ? ' active' : ''
        rawtext helper.button_tag(:class => "step#{active}", :name => 'change_step', :value => index + 1) {
          helper.t(step, :scope => "wizards.#{resource_plural_name}.steps", :index => index + 1)
        }
      end
    end
  end
end

#view(&block) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/admin_widgets/wizard_widget.rb', line 70

def view(&block)
  @content_buffer ||= ''

  @content_buffer += capture do
    instance_eval &block if block
  end
end