Class: Cms::ComponentsController

Inherits:
MainController show all
Defined in:
app/controllers/cms/components_controller.rb

Instance Method Summary collapse

Methods inherited from MainController

#index

Methods included from RoleAuthentication

#authenticate_user

Methods inherited from SetupController

#authorize_role, #current_user

Instance Method Details

#destroyObject



36
37
38
39
40
41
42
43
44
# File 'app/controllers/cms/components_controller.rb', line 36

def destroy
  if @path.present? && Cms::Component.new(@context, @path).delete
    flash[:notice] = 'The component has been removed.'
  else
    flash[:error] = 'The component path was invalid.'
  end

  redirect_to cms_root_path
end

#editObject



6
7
8
9
10
11
12
13
# File 'app/controllers/cms/components_controller.rb', line 6

def edit
  if Cms::Component.editable?(@path)
    @component = Cms::Component.new(@context, @path)
  else
    flash[:error] = "Not an editable component."
    redirect_to cms_root_path
  end
end

#updateObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/cms/components_controller.rb', line 15

def update
  edit_url = {:controller => 'cms/components', :action => 'edit', :url => @path}

  if Cms::Component.editable?(@path)
    @component = Cms::Component.new(@context, @path)
    @component.write params[:file_content]

    respond_to do |format|
      format.html {
        redirect_to edit_url, :notice => t('components.flash.updated')
      }
      format.js {
        flash.now[:notice] = t('components.flash.updated')
      }
    end
  else
    flash[:error] = "Not an editable component."
    redirect_to edit_url
  end
end

#uploadObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/cms/components_controller.rb', line 46

def upload
  component_zip = params[:zip_file]

  if component_zip.present? && File.extname(component_zip.original_filename) == '.zip'
    Cms::Component.expand @context, component_zip.path
    flash[:notice] = 'The component has been uploaded.'
  else
    flash[:error] = 'The component file must be a zip archive.'
  end

  redirect_to cms_root_path
end