2009-05-07 18:13:27 +00:00
|
|
|
class Admin::SnippetsController < ApplicationController
|
|
|
|
|
|
|
|
layout "admin"
|
|
|
|
|
|
|
|
def index
|
|
|
|
@snippets = Snippet.all
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@snippet = Snippet.find(params[:id])
|
|
|
|
|
|
|
|
redirect_to "/#{@snippet.name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@snippet = Snippet.new
|
|
|
|
|
2009-05-22 07:16:22 +00:00
|
|
|
if params[:menu]
|
|
|
|
@snippet.name = "#{params[:menu]}_nav"
|
|
|
|
lis = Page.find(:all, :conditions => { :parent_page_id => params[:menu], :is_published => true }, :order => "position" ).map do |page|
|
|
|
|
if page.external_link.blank?
|
|
|
|
"<li><a href='/#{page.name}'>#{page.name}</a></li>\n"
|
|
|
|
else
|
|
|
|
"<li><a href='#{page.external_link}'>#{page.name}</a></li>\n"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-07-06 08:23:34 +00:00
|
|
|
VALID_LOCALES.each do |locale|
|
2010-01-08 07:45:13 +00:00
|
|
|
@snippet.send( :write_attribute, "content_#{locale}", "<ul>\n#{lis}</ul>" )
|
2009-07-06 08:23:34 +00:00
|
|
|
end
|
|
|
|
|
2009-05-22 07:16:22 +00:00
|
|
|
end
|
2010-01-04 09:49:55 +00:00
|
|
|
|
2009-05-07 18:13:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@snippet = Snippet.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@snippet = Snippet.new(params[:snippet])
|
|
|
|
|
2010-01-04 09:49:55 +00:00
|
|
|
if @snippet.save
|
|
|
|
flash[:notice] = 'Snippet was successfully created.'
|
|
|
|
redirect_to admin_snippets_url
|
|
|
|
else
|
|
|
|
render :action => "new"
|
2009-05-07 18:13:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@snippet = Snippet.find(params[:id])
|
|
|
|
|
2010-01-04 09:49:55 +00:00
|
|
|
if @snippet.update_attributes(params[:snippet])
|
|
|
|
flash[:notice] = 'Snippet was successfully updated.'
|
|
|
|
redirect_to admin_snippets_url
|
|
|
|
else
|
|
|
|
render :action => "edit"
|
2009-05-07 18:13:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@snippet = Snippet.find(params[:id])
|
|
|
|
@snippet.destroy
|
|
|
|
|
2010-01-04 09:49:55 +00:00
|
|
|
redirect_to admin_snippets_url
|
2009-05-07 18:13:27 +00:00
|
|
|
end
|
2010-01-04 09:49:55 +00:00
|
|
|
|
2009-05-07 18:13:27 +00:00
|
|
|
end
|