2009-05-07 18:13:27 +00:00
|
|
|
class Admin::SnippetsController < ApplicationController
|
|
|
|
|
|
|
|
layout "admin"
|
2010-03-04 08:33:26 +00:00
|
|
|
before_filter :authenticate_user!
|
2010-01-14 10:30:53 +00:00
|
|
|
before_filter :find_parent_item
|
2011-04-13 10:19:51 +00:00
|
|
|
before_filter :is_admin?
|
2009-05-07 18:13:27 +00:00
|
|
|
|
|
|
|
def show
|
2010-01-14 10:30:53 +00:00
|
|
|
#TODO
|
2009-05-07 18:13:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@snippet = Snippet.new
|
2011-04-13 10:19:51 +00:00
|
|
|
@snippet.parent_id = @parent_item.id
|
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
|
2011-04-13 10:19:51 +00:00
|
|
|
flash[:notice] = t('admin.create_success_snippet')
|
|
|
|
redirect_to admin_items_url( :parent_id => @snippet.parent_id )
|
2010-01-04 09:49:55 +00:00
|
|
|
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])
|
2011-04-13 10:19:51 +00:00
|
|
|
flash[:notice] = t('admin.update_success_snippet')
|
|
|
|
redirect_to admin_items_url( :parent_id => @snippet.parent_id )
|
2010-01-04 09:49:55 +00:00
|
|
|
else
|
|
|
|
render :action => "edit"
|
2009-05-07 18:13:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@snippet = Snippet.find(params[:id])
|
|
|
|
@snippet.destroy
|
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
redirect_to admin_items_url( :parent_id => @snippet.parent_id )
|
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
|