Class: Sibu::SitesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/sibu/sites_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#check_site_ownership!, #conf, #sibu_user

Instance Method Details

#createObject



25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/sibu/sites_controller.rb', line 25

def create
  @site = Sibu::Site.new(site_params)
  if @site.save_and_init
    generate_styles(@site) if conf[:custom_styles]
    redirect_to sites_url, notice: "Le site a bien été créé."
  else
    flash.now[:alert] = "Une erreur s'est produite lors de la création du site."
    render :new
  end
end

#destroyObject



54
55
56
57
# File 'app/controllers/sibu/sites_controller.rb', line 54

def destroy
  @site.destroy
  redirect_to sites_url, notice: "Le site a bien été supprimé."
end

#duplicateObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/sibu/sites_controller.rb', line 59

def duplicate
  new_site = @site.deep_copy
  if new_site.save
    if conf[:custom_styles]
      generate_styles(@site)
      generate_styles(new_site, true)
    end
    redirect_to sites_url, notice: "Le site a bien été copié."
  else
    flash.now[:alert] = "Une erreur s'est produite lors de la copie du site."
    render :index
  end
end

#editObject



36
37
# File 'app/controllers/sibu/sites_controller.rb', line 36

def edit
end

#indexObject



8
9
10
11
12
13
14
# File 'app/controllers/sibu/sites_controller.rb', line 8

def index
  if conf[:admin_filter].call(sibu_user)
    @sites = Sibu::Site.all.order(:name, :version)
  else
    @sites = Sibu::Site.for_user(sibu_user).order(:name, :version)
  end
end

#newObject



21
22
23
# File 'app/controllers/sibu/sites_controller.rb', line 21

def new
  @site = Sibu::Site.new(user_id: sibu_user.id, version: Sibu::Site::DEFAULT_VERSION)
end

#showObject



16
17
18
19
# File 'app/controllers/sibu/sites_controller.rb', line 16

def show
  @page = @site.page('')
  redirect_to site_page_path(@site.id, @page.id)
end

#updateObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/sibu/sites_controller.rb', line 39

def update
  if @site.update(site_params)
    if conf[:custom_styles]
      generate_styles(@site, @site.previous_changes.has_key?(:custom_data))
    end
    if @site.previous_changes.has_key?(:version)
      @site.update_paths
    end
    redirect_to sites_url, notice: "Le site a bien été mis à jour."
  else
    flash.now[:alert] = "Une erreur s'est produite lors de l'enregistrement du site."
    render :edit
  end
end