Class: BakeryTheme::ToolbarHelper::Toolbar
- Inherits:
-
Object
- Object
- BakeryTheme::ToolbarHelper::Toolbar
- Defined in:
- app/helpers/bakery_theme/toolbar_helper.rb
Instance Method Summary collapse
-
#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.
- #choice_dialog(options) {|bar| ... } ⇒ Object
- #flag(options = {}) ⇒ Object
-
#initialize(template, options = {}) ⇒ Toolbar
constructor
A new instance of Toolbar.
- #panel_header(text) ⇒ Object
- #select(options = {}) {|option_list| ... } ⇒ Object
- #select_button(url, options = {}) {|option_list| ... } ⇒ Object
- #submit_button(form_id, options = {}, &block) ⇒ Object
- #tab(url, options = {}) ⇒ Object
- #to_html ⇒ Object
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, = {}) @template = template @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 (url, ={}) # 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> = .clone.reverse_merge @options[:standard_options] if @options[:standard_options] = .delete :class state = .delete :state state ||= :default add_i18n_support , state = {} = [] << "ui-state-default" << "ui-state-#{state}" << "ui-state-transparent" if .delete :transparent << "ui-corner-all" unless .delete :no_corner [:class] = .uniq * " " if url == :submit = icon_link_content() link = content_tag(:button, .html_safe, .merge(:type => "submit")) elsif url == :button = icon_link_content() link = content_tag(:button, .html_safe, .merge(:type => "button")) else link = icon_link_to url, end @items << content_tag(:li, link.html_safe, :class => ) end |
#choice_dialog(options) {|bar| ... } ⇒ Object
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(, &block) raise "Block required" unless block_given? dialog_settings = .delete :dialog dialog_settings[:id] ||= (0...6).map { ('a'..'z').to_a[rand(26)] }.join = Interface::Toolbar.new @template, :transparent => true, :standard_options => { :before_click => "$('##{dialog_settings[:id]}').dialog('destroy'); setTimeout('$(\\'##{dialog_settings[:id]}\\').remove()', 500)" } yield = .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> #{} </div>) dialog_code javascript_code = "$('#{escape_javascript(dialog_code)}').dialog({ resizable: false, modal: true, position: ['center', 100] })" nil, .update(:function => javascript_code) end |
#flag(options = {}) ⇒ Object
19 20 21 22 |
# File 'app/helpers/bakery_theme/toolbar_helper.rb', line 19 def flag(={}) = {:label => } if .is_a? String nil, end |
#panel_header(text) ⇒ Object
24 25 26 27 |
# File 'app/helpers/bakery_theme/toolbar_helper.rb', line 24 def panel_header text contents = content_tag :h3, text, :class => "panel-header" @items << content_tag(:li, contents.html_safe) end |
#select(options = {}) {|option_list| ... } ⇒ Object
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(={}, &block) raise "Block required" unless block_given? state = .delete :state state ||= :default add_i18n_support , state = .delete :class state = .delete :state state ||= :default = {} = [] unless [:transparent] << "ui-state-default" << "ui-state-#{state}" else << "ui-state-transparent" end = .clone << "ui-corner-all" << "open_options" [:class] = .uniq * " " [:right_icon] ||= "triangle-1-s" link = icon_link_to "#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 = option_list.to_html @items << content_tag(:li, link + , :class => ) end |
#select_button(url, options = {}) {|option_list| ... } ⇒ Object
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 (url, ={}, &block) raise "Block required" unless block_given? state = .delete :state state ||= :default add_i18n_support , state = .delete :class state = .delete :state state ||= :default = {} = [] unless [:transparent] << "ui-state-default" << "ui-state-#{state}" else << "ui-state-transparent" end = .clone << "ui-corner-left" << "select_button" [:class] = .uniq * " " link = icon_link_to url, = .clone << "ui-corner-right" << "open_options" = icon_link_to "#options", :class => .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 += option_list.to_html @items << content_tag(:li, link + , :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 (form_id, ={}, &block) = {:primary => true}.reverse_merge contents = "" contents = yield if block_given? if form_id.nil? :submit, else nil, .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, ={}) # 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> = .delete :class state = .delete :state state ||= :default = {} = [] << "ui-state-default" << "ui-state-#{state}" << "ui-corner-top tab" [:class] = .uniq * " " link = icon_link_to url, @items << content_tag(:li, link, :class => ) end |
#to_html ⇒ Object
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> = @options[:class] ||= "toolbar" classes = [] classes << "ui-widget" classes << "ui-helper-reset" classes << "ui-helper-clearfix" classes << "ui-widget-header" unless @options[:transparent] classes << = { :class => classes * " " } [:id] = @template.dom_id(@options[:object], :tools) if @options[:object] [:style] = @options[:style] if @options[:style] content_tag :ul, (@items * "").html_safe, end |