Class: BakeryTheme::ToolbarHelper::Toolbar

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/bakery_theme/toolbar_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(template, options = {}) ⇒ Toolbar

Returns a new instance of Toolbar.



13
14
15
16
17
# File 'app/helpers/bakery_theme/toolbar_helper.rb', line 13

def initialize(template, options = {})
  @template = template
  @options  = options
  @items    = []
end

Instance Method Details

#button(url, options = {}) ⇒ Object

Usage:

url - url to link to
options - the following keys can be used:
  :class - adds a css class to the button list item
  :state - sets the jquery UI state on the link
  other options are redirected to icon_link_to, but those include:
  :class - adds a css class for the link
  :label - label to show
  :icon - jquery-ui icon to show. the first part ui-icon- is prefixed automatically
  :remote - boolean. Then true, link_to_remote is used instead
  :function - when set, link_to_function is used instead
  all other options are redirected to the link_to method


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/helpers/bakery_theme/toolbar_helper.rb', line 63

def button(url, options={})
  # new_container_type_path, :label => t(:add), :icon => :plusthick

  # <a title="Toevoegen" class="ui-state-default ui-corner-all" href="">
  #   <span class="ui-icon ui-icon-plusthick"></span> Toevoegen
  # </a>
  options = options.clone.reverse_merge @options[:standard_options] if @options[:standard_options]
  button_class = options.delete :class
  state        = options.delete :state
  state        ||= :default

  add_i18n_support options, state

  button_options = {}
  button_classes = []
  button_classes << "ui-state-default"
  button_classes << "ui-state-#{state}"
  button_classes << "ui-state-transparent" if options.delete :transparent
  button_classes << "ui-corner-all" unless options.delete :no_corner

  options[:class] = button_classes.uniq * " "

  if url == :submit
    button_content = icon_link_content(options)
    link           = (:button, button_content.html_safe, options.merge(:type => "submit"))
  elsif url == :button
    button_content = icon_link_content(options)
    link           = (:button, button_content.html_safe, options.merge(:type => "button"))
  else
    link = icon_link_to url, options
  end
  @items << (:li, link.html_safe, :class => button_class)
end

#choice_dialog(options) {|bar| ... } ⇒ Object

Yields:

  • (bar)


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/helpers/bakery_theme/toolbar_helper.rb', line 97

def choice_dialog(options, &block)
  raise "Block required" unless block_given?
  dialog_settings      = options.delete :dialog
  dialog_settings[:id] ||= (0...6).map { ('a'..'z').to_a[rand(26)] }.join

  bar                  = Interface::Toolbar.new @template, :transparent => true,
                                                :standard_options       => {
                                                    :before_click => "$('##{dialog_settings[:id]}').dialog('destroy'); setTimeout('$(\\'##{dialog_settings[:id]}\\').remove()', 500)"
                                                }
  yield bar
  button_bar  = bar.to_html
  dialog_code = %(<div title="#{dialog_settings[:title]}" id="#{dialog_settings[:id]}">
    <p>#{"<span class=\"ui-icon ui-icon-#{dialog_settings[:icon]}\" style=\"float:left; margin:0 7px 20px 0;\"></span>" if dialog_settings[:icon]}
  #{dialog_settings[:message]}
    </p>
    #{button_bar}
  </div>)
  dialog_code
  javascript_code = "$('#{escape_javascript(dialog_code)}').dialog({ resizable: false, modal: true, position: ['center', 100] })"

  button nil, options.update(:function => javascript_code)
end

#flag(options = {}) ⇒ Object



19
20
21
22
# File 'app/helpers/bakery_theme/toolbar_helper.rb', line 19

def flag(options={})
  options = {:label => options} if options.is_a? String
  button nil, options
end

#panel_header(text) ⇒ Object



24
25
26
27
# File 'app/helpers/bakery_theme/toolbar_helper.rb', line 24

def panel_header text
  contents =  :h3, text, :class => "panel-header"
  @items << (:li, contents.html_safe)
end

#select(options = {}) {|option_list| ... } ⇒ Object

Yields:

  • (option_list)


201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'app/helpers/bakery_theme/toolbar_helper.rb', line 201

def select(options={}, &block)
  raise "Block required" unless block_given?

  state = options.delete :state
  state ||= :default
  add_i18n_support options, state

  button_class   = options.delete :class
  state          = options.delete :state
  state          ||= :default
  button_options = {}
  button_classes = []
  unless options[:transparent]
    button_classes << "ui-state-default"
    button_classes << "ui-state-#{state}"
  else
    button_classes << "ui-state-transparent"
  end
  select_button_classes = button_classes.clone << "ui-corner-all" << "open_options"
  options[:class]       = select_button_classes.uniq * " "
  options[:right_icon]  ||= "triangle-1-s"

  link                  = icon_link_to "#options", options

  #select_options_classes = button_classes.clone << "ui-corner-right" << "open_options"
  #select_options = icon_link_to ,
  #															:class => select_options_classes.uniq * " ",
  #															:icon => "carat-1-s"

  option_list           = Toolbar.new self, :class      => "option_list ui-corner-all ui-widget-content ui-state-default",
                                      :standard_options => {:transparent => true},
                                      :style            => "display: none;",
                                      :transparent      => true
  yield option_list
  select_options = option_list.to_html


  @items << (:li, link + select_options, :class => button_class)
end

#select_button(url, options = {}) {|option_list| ... } ⇒ Object

Yields:

  • (option_list)


162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'app/helpers/bakery_theme/toolbar_helper.rb', line 162

def select_button(url, options={}, &block)
  raise "Block required" unless block_given?

  state = options.delete :state
  state ||= :default
  add_i18n_support options, state

  button_class   = options.delete :class
  state          = options.delete :state
  state          ||= :default
  button_options = {}
  button_classes = []
  unless options[:transparent]
    button_classes << "ui-state-default"
    button_classes << "ui-state-#{state}"
  else
    button_classes << "ui-state-transparent"
  end
  select_button_classes  = button_classes.clone << "ui-corner-left" << "select_button"
  options[:class]        = select_button_classes.uniq * " "

  link                   = icon_link_to url, options

  select_options_classes = button_classes.clone << "ui-corner-right" << "open_options"
  select_options         = icon_link_to "#options",
                                        :class => select_options_classes.uniq * " ",
                                        :icon  => "carat-1-s"

  option_list            = Interface::Toolbar.new self, :class      => "option_list right ui-corner-all ui-widget-content ui-state-default",
                                                  :standard_options => {:transparent => true},
                                                  :style            => "display: none;",
                                                  :transparent      => true
  yield option_list
  select_options += option_list.to_html


  @items << (:li, link + select_options, :class => button_class)
end

#submit_button(form_id, options = {}, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/bakery_theme/toolbar_helper.rb', line 29

def submit_button(form_id, options={}, &block)
  options  = {:primary => true}.reverse_merge options

  contents = ""
  contents = yield if block_given?

  if form_id.nil?
    button :submit, options
  else
    button nil, options.update(:function => "#{contents} " +
        "var submitCode = $(\"##{form_id}\").attr(\"onsubmit\");\n" +
        "if (submitCode) {\n" +
        "eval(\"var test = $.bind(function() { \" + submitCode + \" }, $(\\\"##{form_id}\\\"));\");\n" +
        "var result = test();" +
        "if (result == false) return false;" +
        "}\n" +
        "$(\"##{form_id}\").submit();")
  end
end

#tab(url, options = {}) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'app/helpers/bakery_theme/toolbar_helper.rb', line 141

def tab(url, options={})
  # new_container_type_path, :label => t(:add), :icon => :plusthick

  # <a title="Toevoegen" class="ui-state-default ui-corner-all" href="">
  #   <span class="ui-icon ui-icon-plusthick"></span> Toevoegen
  # </a>
  button_class   = options.delete :class
  state          = options.delete :state
  state          ||= :default
  button_options = {}
  button_classes = []
  button_classes << "ui-state-default"
  button_classes << "ui-state-#{state}"
  button_classes << "ui-corner-top tab"

  options[:class] = button_classes.uniq * " "

  link            = icon_link_to url, options
  @items << (:li, link, :class => button_class)
end

#to_htmlObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'app/helpers/bakery_theme/toolbar_helper.rb', line 120

def to_html
  # <ul class="ui-widget ui-helper-clearfix toolbar">
  #   <li>
  bar_class = @options[:class]
  bar_class ||= "toolbar"

  classes   = []
  classes << "ui-widget"
  classes << "ui-helper-reset"
  classes << "ui-helper-clearfix"
  classes << "ui-widget-header" unless @options[:transparent]
  classes << bar_class

  toolbar_options = {
      :class => classes * " "
  }
  toolbar_options[:id] = @template.dom_id(@options[:object], :tools) if @options[:object]
  toolbar_options[:style] = @options[:style] if @options[:style]
   :ul, (@items * "").html_safe, toolbar_options
end