Class: DrgcmsFormFields::Elfinder

Inherits:
DrgcmsField
  • Object
show all
Defined in:
app/models/drgcms_form_fields/elfinder.rb

Overview

Class for creating ElFinder file manager enabled form field.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.file_manager_url(parent) ⇒ Object

Return html url code required for FileManager icon on CMS menu.



77
78
79
80
81
82
# File 'app/models/drgcms_form_fields/elfinder.rb', line 77

def self.file_manager_url(parent)
  url = "/assets/elfinder/elfinder.legacy.html?langCode=#{I18n.locale}"

  parent.link_to( parent.fa_icon('inventory_2-o', title: parent.t('drgcms.file_manager')), '#',
                  { onclick: "window.open('#{url}', '#{parent.t('drgcms.file_manager')}','width=700,height=500')"} )
end

Instance Method Details

#renderObject

Return code required to render elfinder DRG CMS form field.



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
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/drgcms_form_fields/elfinder.rb', line 34

def render
  return ro_standard if @readonly

  set_initial_value
  record = record_text_for(@yaml['name'])
  @js << <<EOJS
  $('##{record}_#{@yaml['name']}').dblclick(function(){
    $('##{record}_div_#{@yaml['name']}').show();
    let f = $('##{record}_div_#{@yaml['name']}').elfinder({
      url : '/elfinder',
      baseUrl : '/assets/elfinder/',
      transport : new elFinderSupportVer1(),
      rememberLastDir: true,
      height: 490,
      docked: false,
      dialog: { width: 400, modal: true },
      lang: '#{I18n.locale}',
      getFileCallback : function(files) {
        $('##{record}_#{@yaml['name']}').val(files.url);
        $('##{record}_div_#{@yaml['name']}').hide();
      },
    });
  });
EOJS

  @html << @parent.text_field(record, @yaml['name'], @yaml['html'])
  @html << @parent.dc_image_invoke("record_#{@yaml['name']}") if @parent.respond_to?(:dc_image_invoke)
  @html << @parent.agile_image_invoke("record_#{@yaml['name']}") if @parent.respond_to?(:agile_image_invoke)
  unless @record[@yaml['name']].blank? || @parent.dc_dont?(@yaml['preview'], false)
    @html << %(
  <span class="dc-image-preview">
    #{(@parent.image_tag(@record[@yaml['name']], title: t('drgcms.img_large') ) unless @record[@yaml['name']].match('<i ')) rescue ''}
  </span><div id="dc-image-preview"></div>
  )
  end
  @html << "<div id='#{record}_div_#{@yaml['name']}'></div>"

  self
end