Module: KirguduBase::GuiHelper
- Included in:
- AdminController, CabinetController, FacadeController, FormBuilder, OldFormBuilder
- Defined in:
- app/helpers/kirgudu_base/gui_helper.rb
Class Method Summary collapse
- .get_value_for_control(property, data_source) ⇒ Object
- .html_options_add_class(html_options, classes_to_add) ⇒ Object
- .html_options_prepare_commons(html_options, property, data_source) ⇒ Object
- .html_options_set_ids(html_options, property, data_source) ⇒ Object
Instance Method Summary collapse
- #autocomplete_field_tag(property, data_source, html_options = {}) ⇒ Object
- #autocomplete_with_id_tag(property, data_source, html_options = {}) ⇒ Object
- #chosen_select_tag(property, data_source, choices_data, html_options = {}) ⇒ Object
- #control_tag(property, data_source, additional_data, html_options = {}) ⇒ Object
- #date_picker_tag(property, data_source, html_options = {}) ⇒ Object
- #file_input_tag(property, data_source, html_options = {}) ⇒ Object
- #left_menu_item_disabled(text, image_path) ⇒ Object
- #left_menu_item_divider ⇒ Object
- #left_menu_item_link(text, path, image_path, html_options = {}) ⇒ Object
- #left_menu_item_title(title) ⇒ Object
- #link_to_cart_add(*args, &block) ⇒ Object
- #link_to_cart_remove(*args, &block) ⇒ Object
- #link_to_delete(*args, &block) ⇒ Object
- #link_to_edit(*args, &block) ⇒ Object
- #link_to_entry(body, opts = {}, html_options = {}) ⇒ Object
- #link_to_leftmenu(*args, &block) ⇒ Object
- #link_to_mass(*args, &block) ⇒ Object
- #link_to_nav(label, url, html_options = {}) ⇒ Object
- #link_to_new(*args, &block) ⇒ Object
- #link_to_paged(*args, &block) ⇒ Object
- #link_to_property(property, entry, html_options = {}) ⇒ Object
- #link_to_search(*args, &block) ⇒ Object
- #link_to_show(*args, &block) ⇒ Object
- #link_to_unless_current_entry(body, opts = {}, html_options = {}) ⇒ Object
- #password_field_tag(property, data_source, html_options = {}) ⇒ Object
- #select_tag(property, data_source, choices_data, html_options = {}) ⇒ Object
- #switcher_tag(label, data, *args) ⇒ Object
- #text_area_tag(property, data_source, html_options = {}) ⇒ Object
- #text_field_tag(property, data_source, html_options = {}) ⇒ Object
Class Method Details
.get_value_for_control(property, data_source) ⇒ Object
616 617 618 619 620 621 622 623 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 616 def self.get_value_for_control(property, data_source) if data_source.is_a?(Hash) #raise "Data Source from HASH: #{data_source.to_json}" data_source[property.name] else data_source.send(property.name) end end |
.html_options_add_class(html_options, classes_to_add) ⇒ Object
576 577 578 579 580 581 582 583 584 585 586 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 576 def self.(, classes_to_add) classes = [:class] ? [:class].split(' ') : [] if classes_to_add.is_a?(Array) classes_to_add.each do |item| classes << item.to_s unless classes.include?(item.to_s) end else classes << classes_to_add.to_s unless classes.include?(classes_to_add.to_s) end [:class] = classes.join(" ") if classes.length > 0 end |
.html_options_prepare_commons(html_options, property, data_source) ⇒ Object
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 625 def self.(, property, data_source) control_value = ::KirguduBase::GuiHelper.get_value_for_control(property, data_source) .merge!(property.) if property. .merge!( value: control_value, :"property-name" => property.name, :"property-value" => control_value, :"parent-property" => (property.parent if property.parent), :"placeholder" => (property.i18n_data_as_string(:placeholder) if property.placeholder) ) # Adding to control attribute value: class = 'error' if error if data_source.respond_to?(:errors) && data_source.errors.is_a?(Hash) ::KirguduBase::GuiHelper.(, ["error"]) if data_source.errors[property.name].present? end ::KirguduBase::GuiHelper.(, property, data_source) end |
.html_options_set_ids(html_options, property, data_source) ⇒ Object
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 589 def self.(, property, data_source) if data_source.is_a?(Hash) .merge!( { id: property.name, name: property.name } ) elsif data_source.class.respond_to?(:for_form_params) .merge!( { id: "#{data_source.class.for_form_params}_#{property.name}", name: "#{data_source.class.for_form_params}[#{property.name}]" } ) else for_form_params = data_source.class.to_s.underscore.gsub('/', '_') .merge!( { id: "#{for_form_params}_#{property.name}", name: "#{for_form_params}[#{property.name}]" } ) end end |
Instance Method Details
#autocomplete_field_tag(property, data_source, html_options = {}) ⇒ Object
157 158 159 160 161 162 163 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 157 def autocomplete_field_tag(property, data_source, = {}) ||= {} (, "error") if @object.errors[property.name].present? #ToDo: Fix it end |
#autocomplete_with_id_tag(property, data_source, html_options = {}) ⇒ Object
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 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 166 def autocomplete_with_id_tag(property, data_source, = {}) ||= {} label_value = if data_source.is_a?(Hash) data_source[property.text_value_property] else data_source.send(property.text_value_property) end .merge!(property.) if property. .merge!( { :"value-property" => property.data_source.value_property, :"label-property" => property.data_source.label_property, url: property.data_source.url, label: label_value } ) ::KirguduBase::GuiHelper.(, "autocomplete-with-id") ::KirguduBase::GuiHelper.(, property, data_source) [:"control-type"] = "autocomplete-with-id" [:type] = "hidden" #raise "HTML OPTIONS in autocomplete: #{html_options.to_json}" content_tag("input", nil, ) end |
#chosen_select_tag(property, data_source, choices_data, html_options = {}) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 232 def chosen_select_tag(property, data_source, choices_data, = {}) #options = {}.merge(params) #options[:id] = SecureRandom.uuid.underscore unless options[:id] # #classes = options[:class] ? options[:class].to_s.split(' ') : [] #classes.push ("chzn-select") unless classes.include?("chzn-select") #options[:class] = classes.join(' ') #options[:'control-type'] = "chosen-select" # #if options[:placeholder] # options[:"data-placeholder"] = options[:placeholder] # options[:placeholder] = nil #end # ######################## BUILDING ONCHANGE COMMANDS ##################### # #if options[:onchange] # options[:onchange] = options[:onchange].to_json #end # ##if options[:onchange] ## commands_set = [] ## if options[:onchange].is_a?(Hash) ## commands_set.push(options[:onchange]) ## elsif options[:onchange].is_a?(Array) ## options[:onchange].each do |command| ## if command.is_a?(Hash) ## commands_set.push(command) ## end ## end ## end ## ## commands_set.each do |cmd_options| ## cmd_options[:id] = "#{options[:id]}_onchange_action" ## cmd_options[:style] = "display: none;" ## result += content_tag("div", "", cmd_options) ## end ##end # # ############################## BUILDING CHOICES ######################### # #choices_html = "" #if choices && choices.is_a?(Array) # # if options[:parent] # if options[:parent_value].nil? # options[:disabled] = "disabled" # end # end # # choices_html = content_tag('option', '', value: '') # choices.each do |chs| # choice_id = chs[1] # choice_label = chs[0] # choice_attributes = Hash.new # choice_attributes[:value] = choice_id # if options[:value] # choice_attributes[:selected] = "selected" if choice_id.to_s == options[:value].to_s # end # # choices_html += content_tag('option', choice_label, choice_attributes) # end #else # options[:disabled] = "disabled" #end # # #content_tag('select', choices_html.html_safe, options) ||= {} ::KirguduBase::GuiHelper.(, ["chzn-select"]) [:'control-type'] = 'chosen-select' select_tag(property, data_source, choices_data, ) end |
#control_tag(property, data_source, additional_data, html_options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 10 def control_tag(property, data_source, additional_data, = {}) if property.input_type == :chosen_select chosen_select_tag(property, data_source, additional_data, ) elsif property.input_type == :select select_tag(property, data_source, additional_data, ) elsif property.input_type == :autocomplete_with_id autocomplete_with_id_tag(property, data_source, ) elsif property.input_type == :autocomplete #autocomplete(property, html_options) elsif property.input_type == :switch_button (property, data_source, ) elsif property.input_type == :date_picker #date_picker_tag(property, html_options) elsif property.input_type == :time_picker time_picker_tag(property, data_source, ) elsif property.input_type == :image_selector image_selector_tag(property, data_source, ) elsif property.input_type == :check_box check_box_tag(property, data_source, ) elsif property.input_type == :radio_button #radio_button(property, html_options) elsif property.input_type == :link link_tag(property, data_source, ) elsif property.input_type == :elastic_text_area elastic_textarea_tag(property, data_source, ) elsif property.input_type == :password elastic_textarea_tag(property, data_source, ) elsif property.input_type == :text_area text_area_tag(property, data_source, ) elsif property.input_type == :file_input #file_input(property, data_source, html_options) elsif property.input_type == :collection_check_boxes else text_field_tag(property, data_source, ) end end |
#date_picker_tag(property, data_source, html_options = {}) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 215 def date_picker_tag(property, data_source, ={}) ||= {} ::KirguduBase::GuiHelper.(, property, data_source) ::KirguduBase::GuiHelper.(, ["date-picker"]) [:"data-date-format"] = "dd-mm-yyyy" #ToDo: Fix for all date formats [:type] = "text" [:"control-type"] = "date-picker" [:id] = SecureRandom.uuid.underscore unless [:id] content_tag("input", '', ) end |
#file_input_tag(property, data_source, html_options = {}) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 200 def file_input_tag(property, data_source, ={}) ||= {} ::KirguduBase::GuiHelper.(, property, data_source) [:type] = "file" [:"control-type"] = "file-input" [:id] = SecureRandom.uuid.underscore unless [:id] content_tag("input", '', ) end |
#left_menu_item_disabled(text, image_path) ⇒ Object
395 396 397 398 399 400 401 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 395 def (text, image_path) raise "Stale method: 'left_menu_item_disabled'" content_tag('li') do tag('img', src: image_path, width: "16", height: "16", valign: "middle") + text end end |
#left_menu_item_divider ⇒ Object
383 384 385 386 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 383 def raise "Stale method: 'left_menu_item_divider'" content_tag('li', "", class: "divider") end |
#left_menu_item_link(text, path, image_path, html_options = {}) ⇒ Object
371 372 373 374 375 376 377 378 379 380 381 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 371 def (text, path, image_path, = {}) raise "Stale method: 'left_menu_item_link'" is_active = "current" if current_page?(path) content_tag('li', class: is_active) do content_tag("a", href: path, target: [:target]) do tag('img', src: image_path, width: "16", height: "16", valign: "middle") + text end end end |
#left_menu_item_title(title) ⇒ Object
388 389 390 391 392 393 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 388 def (title) raise "Stale method: 'left_menu_item_title'" content_tag('li', class: "menuText") do "#{title}:" end end |
#link_to_cart_add(*args, &block) ⇒ Object
508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 508 def link_to_cart_add(*args, &block) raise "Stale method: 'link_to_cart_add'" if block_given? = args.first || {} = args.second link_to_cart_add(capture(&block), , ) else name = args[0] = args[1] || {} = args[2] || {} ['link-type'] = 'cart-add' link_to_nav1(name, , ) end end |
#link_to_cart_remove(*args, &block) ⇒ Object
523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 523 def link_to_cart_remove(*args, &block) raise "Stale method: 'link_to_cart_remove'" if block_given? = args.first || {} = args.second link_to_cart_remove(capture(&block), , ) else name = args[0] = args[1] || {} = args[2] || {} ['link-type'] = 'cart-add' link_to_nav1(name, , ) end end |
#link_to_delete(*args, &block) ⇒ Object
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 491 def link_to_delete(*args, &block) raise "Stale method: 'link_to_delete'" if block_given? = args.first || {} = args.second link_to_delete(capture(&block), , ) else name = args[0] = args[1] || {} = args[2] || {} ['link-type'] = 'delete' ['http-method'] = 'delete' ['confirm-message'] = 'Are You sure You want to delete This Object?' link_to_nav1(name, , ) end end |
#link_to_edit(*args, &block) ⇒ Object
461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 461 def link_to_edit(*args, &block) raise "Stale method: 'link_to_edit'" if block_given? = args.first || {} = args.second link_to_edit(capture(&block), , ) else name = args[0] = args[1] || {} = args[2] || {} ['link-type'] = 'edit' link_to_nav1(name, , ) end end |
#link_to_entry(body, opts = {}, html_options = {}) ⇒ Object
404 405 406 407 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 404 def link_to_entry(body, opts = {}, = {}) raise "Stale method: 'link_to_entry'" link_to body, url_for(:params => build_query_string_params(request.params, opts)), end |
#link_to_leftmenu(*args, &block) ⇒ Object
553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 553 def (*args, &block) raise "Stale method: 'link_to_leftmenu'" if block_given? = args.first || {} = args.second (capture(&block), , ) else name = args[0] = args[1] || {} = args[2] || {} ['link-type'] = 'left-menu' link_to_nav1(name, , ) end end |
#link_to_mass(*args, &block) ⇒ Object
538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 538 def link_to_mass(*args, &block) raise "Stale method: 'link_to_mass'" if block_given? = args.first || {} = args.second link_to_mass(capture(&block), , ) else name = args[0] = args[1] || {} = args[2] || {} ['link-type'] = 'mass-action' link_to_nav1(name, , ) end end |
#link_to_nav(label, url, html_options = {}) ⇒ Object
568 569 570 571 572 573 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 568 def link_to_nav(label, url, = {}) raise "Stale method: 'link_to_nav'" ||= {} ::KirguduBase::GuiHelper.(, "navigate-link") link_to label, url, end |
#link_to_new(*args, &block) ⇒ Object
476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 476 def link_to_new(*args, &block) raise "Stale method: 'link_to_new'" if block_given? = args.first || {} = args.second link_to_new(capture(&block), , ) else name = args[0] = args[1] || {} = args[2] || {} ['link-type'] = 'new' link_to_nav1(name, , ) end end |
#link_to_paged(*args, &block) ⇒ Object
415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 415 def link_to_paged(*args, &block) raise "Stale method: 'link_to_paged'" if block_given? = args.first || {} = args.second link_to_paged(capture(&block), , ) else name = args[0] = args[1] || {} = args[2] || {} ['link-type'] = 'paged' link_to_nav1(name, , ) end end |
#link_to_property(property, entry, html_options = {}) ⇒ Object
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 350 def link_to_property(property, entry, = {}) ||= {} if property.target if property.target == :blank [:target] = "_blank" elsif property.target == :hover_preview elsif property.target == :model_dialog end end [:"control-type"] = "link" [:"link-target"] = property.target if property.target link_value = entry.send(property.name) link_label = property.i18n_data_as_string(:placeholder) || link_value link_to(link_label, link_value, ) unless link_value.nil? && link_value.blank? end |
#link_to_search(*args, &block) ⇒ Object
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 445 def link_to_search(*args, &block) raise "Stale method: 'link_to_search'" if block_given? = args.first || {} = args.second link_to_search(capture(&block), , ) else name = args[0] = args[1] || {} = args[2] || {} ['link-type'] = 'search' link_to_nav1(name, , ) end end |
#link_to_show(*args, &block) ⇒ Object
430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 430 def link_to_show(*args, &block) raise "Stale method: 'link_to_show'" if block_given? = args.first || {} = args.second link_to_show(capture(&block), , ) else name = args[0] = args[1] || {} = args[2] || {} ['link-type'] = 'show' link_to_nav1(name, , ) end end |
#link_to_unless_current_entry(body, opts = {}, html_options = {}) ⇒ Object
409 410 411 412 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 409 def link_to_unless_current_entry(body, opts = {}, = {}) raise "Stale method: 'link_to_unless_current_entry'" link_to_unless_current body, url_for(:params => build_query_string_params(request.params, opts)), end |
#password_field_tag(property, data_source, html_options = {}) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 91 def password_field_tag(property, data_source, = {}) ||= {} ::KirguduBase::GuiHelper.(, property, data_source) .merge!({ type: "password", :"control-type" => "password-field" }) [:id] = SecureRandom.uuid.underscore unless [:id] content_tag("input", '', ) end |
#select_tag(property, data_source, choices_data, html_options = {}) ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 310 def select_tag(property, data_source, choices_data, = {}) ||= {} control_value = ::KirguduBase::GuiHelper.get_value_for_control(property, data_source) [:'control-type'] ||= 'select' if property.data_source.type == :jquery || property.data_source.type == :jquery_db .merge!({ :"ds-method" => property.data_source.http_method, :"ds-url" => property.data_source.url, :"ds-value-property" => property.data_source.value_property, :"ds-label-property" => property.data_source.label_property, #ds_type: property.data_source.type == :jquery ? :jquery : :local :"ds-format" => property.data_source.data_format }) end choices_html = content_tag("option", property.i18n_data_as_string(:placeholder) || "", value: "") choices_data.each do |chs| choice_id = chs[1] choice_label = chs[0] choice_attributes = { value: choice_id } choice_attributes[:selected] = "selected" if control_value && choice_id.to_s == control_value.to_s choices_html += content_tag("option", choice_label, choice_attributes) end if choices_data ::KirguduBase::GuiHelper.(, property, data_source) [:id] = SecureRandom.uuid.underscore unless [:id] content_tag("select", choices_html.html_safe, ) end |
#switcher_tag(label, data, *args) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 108 def switcher_tag(label, data, *args) = args. ||= {} .symbolize_keys! value_off = [:'value-off'] || "0" value_on = [:'value-on'] || "1" = {type: "radio", name: "#{label}", id: "#{label}-off", value: value_off, control_type: "switcher"} = {type: "radio", name: "#{label}", id: "#{label}-on", value: value_on, control_type: "switcher"} if data == true [:'checked'] = true else [:'checked'] = true end = {} [:class] = "toggle" + (data == value_on ? ' on' : ' off') [:class] = "toggle on" control_html = content_tag('div', class: "row-fluid") do content_tag('div', class: "pull-left") do content_tag('label', class: 'radio off') do tag('input', ) end + content_tag('label', class: 'radio on') do tag('input', ) end + content_tag('div', ) do content_tag('div', class: "yes") do ['label-on'] || 'ON' end + content_tag('div', class: "switch") do end + content_tag('div', class: "no") do ['label-off'] || 'OFF' end end end end control_html end |
#text_area_tag(property, data_source, html_options = {}) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 76 def text_area_tag(property, data_source, = {}) ||= {} ::KirguduBase::GuiHelper.(, property, data_source) [:id] = SecureRandom.uuid.underscore unless [:id] [:"control-type"] = "text-area" control_value = [:value] [:value] = nil [:"property-value"] = nil content_tag("textarea", control_value, ) end |
#text_field_tag(property, data_source, html_options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 62 def text_field_tag(property, data_source, = {}) ||= {} ::KirguduBase::GuiHelper.(, property, data_source) [:id] = SecureRandom.uuid.underscore unless [:id] .merge!({ type: "text", :"control-type" => "text-field" }) content_tag("input", '', ) end |