app/helpers/adminpanel/adminpanel_form_builder.rb in adminpanel-3.1.0 vs app/helpers/adminpanel/adminpanel_form_builder.rb in adminpanel-3.2.0

- old
+ new

@@ -53,11 +53,18 @@ def wysiwyg_field(method, *args) options = args.extract_options! - hidden_field(method, id: "#{self.object.class.to_s.demodulize}-trix-#{method}") + base_layout(method, options, 'trix_field') + hidden_field( + method, + id: "#{self.object.class.to_s.demodulize}-trix-#{method}" + ) + base_layout( + method, + options, + 'trix_field' + ) end def text_area(method, *args) base_layout method, *args, 'text_area_original' end @@ -202,13 +209,32 @@ protected def trix_field(method, *args) options = args.extract_options! options.reverse_merge! input: "#{self.object.class.to_s.demodulize}-trix-#{method}", id: "#{method}-trix-editor" options[:class] << ' trix-content' + options[:data] ||= {} + editor_images = [] + if options['uploader'].present? + options[:data][:uploader_name] = options['uploader'].to_s + options[:data][:uploader_class] = "Adminpanel::#{options['uploader'].to_s.singularize.capitalize}" + relation_name = "#{options['uploader'].to_s.singularize}_ids" + editor_images = self.object.send(options['uploader'].to_s) + empty_uploader_field = @template.hidden_field_tag "#{self.object.class.name.demodulize.underscore}[#{relation_name}][]" + end - @template.content_tag 'trix-editor', options do + editor = @template.content_tag 'trix-editor', options do self.object.send(method) end + editor_images_fields = editor_images.map {|image| + @template.hidden_field_tag( + "#{self.object.class.name.demodulize.underscore}[#{relation_name}][]", + image.id, + data: { + url: image.file_url(:thumb) + } + ) + }.join('').html_safe + editor + empty_uploader_field + editor_images_fields end private def base_layout(method, *args, input_type)