Module: DcImageControl
- Defined in:
- app/controls/dc_image_control.rb
Overview
DrgcmsControls for DcImage data entry.
Instance Method Summary collapse
-
#dc_after_save ⇒ Object
Prepare additional images.
-
#dc_before_save ⇒ Object
Save uploaded file if selected and extract properties data.
-
#dc_new_record ⇒ Object
Set some default values when new record.
-
#images_search ⇒ Object
Invoke images search.
- #search_filter ⇒ Object
Instance Method Details
#dc_after_save ⇒ Object
Prepare additional images
94 95 96 |
# File 'app/controls/dc_image_control.rb', line 94 def dc_after_save %w[l m s o].each { |size| image_convert(size) } end |
#dc_before_save ⇒ Object
Save uploaded file if selected and extract properties data
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controls/dc_image_control.rb', line 73 def dc_before_save return if @record.size_o.present? || !params[:upload_file] input_file_name = params[:upload_file].original_filename type = File.extname(input_file_name).to_s.downcase.gsub('.', '').strip unless %w(jpg jpeg png gif svg webp).include?(type) flash[:error] = t 'drgcms.dc_image.wrong_type' return false end name = File.basename(input_file_name) path = File.dirname(params[:upload_file].tempfile) @record.img_type = dc_get_site.params.dig('dc_image', 'img_type') || type @record.short = File.basename(input_file_name, '.*') if @record.short.blank? @record.name = File.join(path, name) FileUtils.mv(params[:upload_file].tempfile, @record.name, force: nil) end |
#dc_new_record ⇒ Object
Set some default values when new record
63 64 65 66 67 68 |
# File 'app/controls/dc_image_control.rb', line 63 def dc_new_record default_sizes = dc_get_site.params.dig('dc_image', 'sizes').to_s.split(',') @record.size_ls = default_sizes.shift @record.size_ms = default_sizes.shift @record.size_ss = default_sizes.shift end |
#images_search ⇒ Object
Invoke images search. Just forward parameters and reload form. Filter parameters will be taken into account on reload.
50 51 52 53 54 55 56 57 58 |
# File 'app/controls/dc_image_control.rb', line 50 def images_search flash[:record] = {} flash[:record][:short] = params[:record][:short] flash[:record][:created_by] = params[:record][:created_by] flash[:record][:categories] = params[:record][:categories] url = url_for(controller: :cmsedit, table: :dc_image, form_name: :dc_image_search, field_name: params[:field_name]) render json: { url: url } end |
#search_filter ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controls/dc_image_control.rb', line 32 def search_filter flash[:record] ||= {} created_by = flash[:record][:created_by] qry = created_by.present? ? DcImage.where(created_by: created_by) : DcImage.all short_name = flash[:record][:short] qry = qry.and(short: /#{short_name}/i) if short_name.present? category = flash[:record][:categories] qry = qry.and(categories: category) if category.present? qry.limit(30).order_by(created_at: -1) end |