Class: BcmsKcfinder::BrowseController

Inherits:
Cms::BaseController
  • Object
show all
Defined in:
app/controllers/bcms_kcfinder/browse_controller.rb

Instance Method Summary collapse

Instance Method Details

#change_dirObject

Change to a directory and return the files for that directory



53
54
55
# File 'app/controllers/bcms_kcfinder/browse_controller.rb', line 53

def change_dir
  render :json => {files: list_files(), dirWritable: true}.to_json
end

#commandObject



59
60
61
# File 'app/controllers/bcms_kcfinder/browse_controller.rb', line 59

def command
  raise "Error: The command '#{params[:command]}' is not implemented yet."
end

#create_new(klass) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/bcms_kcfinder/browse_controller.rb', line 41

def create_new(klass)
  uploaded_file = params[:upload].first
  f = klass.new(:name => uploaded_file.original_filename, :publish_on_save => true)
  a = f.attachments.build(:parent => @section,
                          :data_file_path => uploaded_file.original_filename,
                          :attachment_name => 'file',
                          :data => uploaded_file)
  f.save!
  f
end

#indexObject



11
12
# File 'app/controllers/bcms_kcfinder/browse_controller.rb', line 11

def index
end

#initObject

At the start, the entire Sitemap tree has to be defined, though pages below the top level do not need to be included until a ‘chDir’ command is issued.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/bcms_kcfinder/browse_controller.rb', line 16

def init
  logger.warn "Use the right root section"
  @root_section = Cms::Section.root.first
  @section = Cms::Section.find_by_name_path("/")
  render :json => {tree: {name: @root_section.name,
                          readable: true,
                          writable: true,
                          removable: false,
                          current: true,
                          hasDirs: !@section.child_sections.empty?,
                          dirs: child_sections_to_dirs(@section)},
                   files: list_files(),
                   dirWritable: true}.to_json
end

#uploadObject



31
32
33
34
35
36
37
38
39
# File 'app/controllers/bcms_kcfinder/browse_controller.rb', line 31

def upload
  content_block = case params[:type].downcase
    when "files"
      create_new(Cms::FileBlock)
    when "images"
      create_new(Cms::ImageBlock)
  end
  render :text => content_block.path
end