Module: Alchemy::Custom::Model::Admin::BaseHelper
- Defined in:
- app/helpers/alchemy/custom/model/admin/base_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
- #base_container ⇒ Object
- #base_form_container ⇒ Object
- #check_presence_polymorphic_path(record_or_hash_or_array, method = :get, options = {}) ⇒ Object
- #exist_order_path?(obj = nil) ⇒ Boolean
-
#fa_icon(icon, title: nil) ⇒ Object
rimpiazzo helper per icone.
-
#gallery_input(form, field, partial_url:, partial_identifier:, tags: []) ⇒ Object
Costruisce il necessario per la generazione della struttura della gallery e per selezione ed upload immagini.
- #mime2class(mimeType) ⇒ Object
- #order_path(obj = nil, options = {}) ⇒ Object
- #print_order_tree(sort: false) ⇒ Object
- #printelement_to_order(el) ⇒ Object
- #render_obj(obj, field) ⇒ Object
- #rich_text_editor(form, field) ⇒ Object
- #search_panel(options = {}, &block) ⇒ Object
- #single_attachment_input(form, field) ⇒ Object
- #single_image_input(form, field) ⇒ Object
- #subobject(label, form, field, to_load:, url_partial:, active_record_modifier: ->(relation) {relation}) ⇒ Object
Class Method Details
.included(mod) ⇒ Object
3 4 5 6 7 8 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 3 def self.included(mod) if ::Rails.application.config.action_controller.include_all_helpers!=false raise "Devi definire in config/application.rb config.action_controller.include_all_helpers=false in modo da far funzionare correttamente l'override degli helper come per i controller" end end |
Instance Method Details
#base_container ⇒ Object
179 180 181 182 183 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 179 def base_container content_tag :div, class: "base_container #{controller_name}" do yield end end |
#base_form_container ⇒ Object
11 12 13 14 15 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 11 def base_form_container content_tag :div, class: "base_form_container #{controller_name}" do yield end end |
#check_presence_polymorphic_path(record_or_hash_or_array, method = :get, options = {}) ⇒ Object
378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 378 def check_presence_polymorphic_path(record_or_hash_or_array, method = :get, = {}) begin url = polymorphic_path record_or_hash_or_array, route_hash = Rails.application.routes.recognize_path(url, :method => method) if route_hash[:controller] != "alchemy/pages" true else false end rescue NoMethodError, ActionController::RoutingError false end end |
#exist_order_path?(obj = nil) ⇒ Boolean
401 402 403 404 405 406 407 408 409 410 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 401 def exist_order_path?(obj = nil) if obj.nil? order_path else order_path obj end true rescue NoMethodError false end |
#fa_icon(icon, title: nil) ⇒ Object
rimpiazzo helper per icone
102 103 104 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 102 def fa_icon(icon, title: nil) content_tag(:i, nil, class: "fas fa-#{icon} fa-lg fa-fw", title: title) end |
#gallery_input(form, field, partial_url:, partial_identifier:, tags: []) ⇒ Object
Costruisce il necessario per la generazione della struttura della gallery e per selezione ed upload immagini
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 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 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 202 def gallery_input(form, field, partial_url:, partial_identifier:, tags: []) return '' unless form.object.persisted? obj_cls = form.object.class hint_helper = '' chiave_i18n = "#{obj_cls.i18n_scope}.attributes.#{obj_cls.model_name.i18n_key}.#{field}_hint" hint_helper = hint_with_tooltip(t(chiave_i18n), icon: 'question-circle') if I18n.exists?(chiave_i18n) form.input(field, label: obj_cls.human_attribute_name(field).html_safe + hint_helper) do content_tag(:div, class: 'elfinder_picture_gallery') do bf2 = ActiveSupport::SafeBuffer.new container_images = SecureRandom.hex bf2 << content_tag(:div, class: 'blk_container_immagini', id: container_images) do bf = ActiveSupport::SafeBuffer.new component_id = SecureRandom.hex(10) bf << form.fields_for(field) do |join_record_form| render(layout: 'gallery_item', locals: {picture: join_record_form.object.picture, jr: join_record_form.object}) do sb = ActiveSupport::SafeBuffer.new sb << join_record_form.hidden_field(:position, class: 'gallery_position_counter') sb << join_record_form.hidden_field(:_destroy, class: 'gallery_item_destroy_input') sb end end bf << content_tag(:div, class: 'gallery_item_blk') do link_to("#", class: 'open_el_finder', data: { "elfinder-mode": 'multiple_selection', "elfinder-target_upgrader": partial_url, "elfinder-target": partial_identifier, "elfinder-volumes": 'AlchemyImages,GalleryVolume', "elfinder-volumes_cfgs": Base64.strict_encode64({ "GalleryVolume": { volume: 'ComponentAttribute', attribute: field, object: form.object.to_signed_global_id.to_s, file_link_ref: 'picture', tags: } }.to_json) }) do fa_icon("images") end end bf end bf2 << content_tag(:script, :type => "text/javascript") do raw "(function(){ $('##{container_images}').nested_attributes_sortable({field:'.gallery_position_counter'}); })(); " end bf2 end end end |
#mime2class(mimeType) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 107 def mime2class(mimeType) prefix = 'elfinder-cwd-icon-' mime = mimeType.downcase # isText = this.textMimes[mime] # mime = mime.split('/') # if (isText) { # mime[0] += ' ' + prefix + 'text'; # } prefix + mime[0] + (mime[1] ? ' ' + prefix + mime[1].gsub(/(\.|\+)/, '-') : '') end |
#order_path(obj = nil, options = {}) ⇒ Object
393 394 395 396 397 398 399 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 393 def order_path(obj = nil, = {}) if obj.nil? new_polymorphic_path([:admin, base_class.to_s.pluralize.underscore.to_sym, :order]) else new_polymorphic_path([:admin, obj, :order]) end end |
#print_order_tree(sort: false) ⇒ Object
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 418 def print_order_tree(sort: false) sortable_class = "sortable_tree" if sort content_tag(:ol, class: "order_tree margined #{sortable_class}", id: "sort_tree") do el_buf = ActiveSupport::SafeBuffer.new @elements.each do |el| el_buf << content_tag(:li, id: print_order_identify(el)) do sb = ActiveSupport::SafeBuffer.new sb << content_tag(:div, class: "el_block") do div = ActiveSupport::SafeBuffer.new div << print_sort_icon(el) div << content_tag(:div, class: "el_value") do printelement_to_order el end end sb end end el_buf end end |
#printelement_to_order(el) ⇒ Object
412 413 414 415 416 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 412 def printelement_to_order(el) content_tag(:span, class: "el_title name") do el.name end end |
#render_obj(obj, field) ⇒ Object
185 186 187 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 185 def render_obj(obj, field) obj.send field end |
#rich_text_editor(form, field) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 17 def rich_text_editor(form, field) editor_idenfier = "#{field}_#{form.object_id}" bf = ActiveSupport::SafeBuffer.new bf << form.input(field) do content_tag(:div, class: 'tinymce_container') do form.text_area field, class: 'has_tinymce', id: "tinymce_#{editor_idenfier}" end end bf << content_tag(:script, :type => "text/javascript") do raw "(function(){ CustomTinyMce.initEditor('#{editor_idenfier}') })(); " end bf end |
#search_panel(options = {}, &block) ⇒ Object
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 440 def search_panel( = {}, &block) = .fetch(:enable_submit, true) klass = .delete(:class) || [] content_tag(:div, class: "search_panel #{klass.join(" ")}", ** ) do sb = ActiveSupport::SafeBuffer.new if @query sb << content_tag(:div, class:"title") do spt = ActiveSupport::SafeBuffer.new spt << content_tag(:span, t("search_panel_title"), class:"title_label") #TODO: toggle pannello #spt << content_tag(:span, class:"button_toggle") do # content_tag(:a,class:"icon_button") do # content_tag(:i, nil, class:"icon fa-fw fa-bars fas") # end #end spt end sb << simple_form_for(@query, url: polymorphic_path([:admin, @query.klass]), method: :get) do |f| sff = ActiveSupport::SafeBuffer.new sff << content_tag(:div, class: "search_fields_group") do search_fields = ActiveSupport::SafeBuffer.new search_fields << capture do block.call(f) end search_fields end if sff << content_tag(:div, class: "action_buttons") do f.submit(::I18n.t('alchemy_ajax_form.submit_search')) end end sff end end sb end end |
#single_attachment_input(form, field) ⇒ Object
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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 121 def (form, field) form.input(field) do content_tag(:div, class: "elfinder_attachment") do bf = ActiveSupport::SafeBuffer.new component_id = SecureRandom.hex(10) ref_id = nil mime_class = '' unless form.object.send(field).blank? ref_id = form.object.send(field).to_signed_global_id.to_s mime_class = "elfinder-cwd-icon #{mime2class(form.object.send(field).file_mime_type)}" end bf << form.hidden_field(field, id: component_id, value: ref_id) id_icone = "#{component_id}_mime_icon" bf << content_tag(:div, class: 'container_icon_container') do content_tag(:div, nil, id: id_icone, class: mime_class) end bf << content_tag(:div, class: "edit_file_bottom") do bf2 = ActiveSupport::SafeBuffer.new bf2 << link_to("#", class: 'open_el_finder', title: t("elfinder.edit_attachment_button"), data: { "elfinder-mode": 'single_selection', "elfinder-target": "##{component_id}", "elfinder-mime_icon_updater": "##{id_icone}", "elfinder-volumes": 'AlchemyFiles' }) do fa_icon("file") end bf2 << link_to("#", class: 'clear_selection', title: t("elfinder.clear_attachment_button"), data: { "clearfield-target": "##{component_id}", "clearfield-icon": "##{id_icone}" }) do fa_icon("times") end bf2 end bf end end end |
#single_image_input(form, field) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 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 96 97 98 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 41 def single_image_input(form, field) form.input(field) do content_tag(:div, class: "elfinder_picture_thumbnail") do bf = ActiveSupport::SafeBuffer.new component_id = SecureRandom.hex(10) component_id_image = "#{component_id}_image" ref_id = nil unless form.object.send(field).blank? ref_id = form.object.send(field).to_signed_global_id.to_s end bf << form.hidden_field(field, id: component_id, value: ref_id) image_path = no_image_path = image_url("alchemy-custom-model/no_image.png") image_path = form.object.send(field).image_file.thumb("100x100#").url if form.object.send(field) and form.object.send(field).image_file_stored? bf << content_tag(:div, image_tag(image_path, id: component_id_image, class: "picture_image")) bf << content_tag(:div, class: "edit_images_bottom") do bf2 = ActiveSupport::SafeBuffer.new bf2 << link_to("#", class: 'open_el_finder', title: t("elfinder.edit_image_button"), data: { "elfinder-mode": 'single_selection', "elfinder-target": "##{component_id}", "elfinder-thumb-target": "##{component_id_image}", "elfinder-volumes": 'AlchemyImages' }) do fa_icon("file-image") end bf2 << link_to("#", class: 'clear_selection', title: t("elfinder.clear_image_button"), data: { "clearfield-target": "##{component_id}", "clearfield-thumb-target": "##{component_id_image}", "clearfield-thumb-target-replace": no_image_path }) do fa_icon("times") end bf2 end bf end end end |
#subobject(label, form, field, to_load:, url_partial:, active_record_modifier: ->(relation) {relation}) ⇒ Object
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 308 309 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 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'app/helpers/alchemy/custom/model/admin/base_helper.rb', line 281 def subobject(label, form, field, to_load:, url_partial:, active_record_modifier: ->(relation) {relation}) ui_identify = "subobjects_container_#{SecureRandom.hex}" interface = ActiveSupport::SafeBuffer.new interface = content_tag(:fieldset, class: "subobjects #{ui_identify}") do sb = ActiveSupport::SafeBuffer.new sb << content_tag(:legend, label) sb << content_tag(:div, class: "sub_objects_container sub_object_#{field}") do sub_obj = ActiveSupport::SafeBuffer.new active_record_modifier.call(form.object.send(field)).each_with_index do |subo, index| sub_obj << form.simple_fields_for(field, subo, child_index: subo.new_record? ? Time.now.getutc.strftime("%9N") : index) do |subform| form_attrs = subform.object.attributes.reject do |attr, val| attr == form.object.class.reflect_on_association(field).foreign_key end is_sample = form_attrs.all? {|attr, val| val.blank?} content_tag(:div, id: "#{subform.object.class.name.demodulize.underscore}_#{subform.object.id}", class: "subobject_row row_#{field.to_s.singularize} #{"sample" if is_sample}") do form_html = ActiveSupport::SafeBuffer.new form_html << content_tag(:div, class: "buttons toolbar_button") do = ActiveSupport::SafeBuffer.new << content_tag(:div, class: "button_with_label maximize") do link_to "#", class: "icon_button" do fa_icon "window-maximize" end end << content_tag(:div, class: "button_with_label minimize") do link_to "#", class: "icon_button" do fa_icon "window-minimize" end end << content_tag(:div, class: "button_with_label remove") do content_tag(:span, class: "icon_button") do = ActiveSupport::SafeBuffer.new << fa_icon("trash", title: t(:remove)) << subform.input(:_destroy, as: :hidden, input_html: {class: "destroy"}) end end end form_html << content_tag(:div, class: "fields") do yield subform end form_html end end end #sub_obj << content_for(:"sample_#{field}") sub_obj end sb << content_tag(:div, class: "buttons") do = ActiveSupport::SafeBuffer.new << (type: "button", class: "minimize_all", title: acm_t(:minimize_all, scope: 'sub_objects')) do fa_icon("window-minimize") end << (type: "button", class: "maximize_all", title: acm_t(:maxzimize_all, scope: 'sub_objects')) do fa_icon("window-maximize") end << (type: "button", class: "add", title: acm_t(:title_add, scope: 'sub_objects'), data: {to_load: to_load, url: url_partial}) do fa_icon("plus") end end sb end interface << content_tag(:script, :type => "text/javascript") do raw "(function(){ $('.#{ui_identify}').subobjects(); })(); " end interface end |