2010-01-14 10:30:53 +00:00
|
|
|
class Admin::LinksController < ApplicationController
|
|
|
|
|
2011-12-05 01:54:41 +00:00
|
|
|
layout "site_editor"
|
2011-05-13 01:08:42 +00:00
|
|
|
|
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?
|
2010-01-14 10:30:53 +00:00
|
|
|
|
|
|
|
def show
|
2011-05-25 06:50:56 +00:00
|
|
|
@item ||= Link.find(params[:id])
|
2010-01-14 10:30:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2011-05-25 06:50:56 +00:00
|
|
|
@item = Link.new
|
2012-02-17 06:54:11 +00:00
|
|
|
@item.parent = Page.find(params[:parent_id]) rescue nil
|
2010-01-14 10:30:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2011-05-25 06:50:56 +00:00
|
|
|
@item = Link.find(params[:id])
|
2010-01-14 10:30:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2011-05-25 06:50:56 +00:00
|
|
|
@item = Link.new(params[:link])
|
2010-01-14 10:30:53 +00:00
|
|
|
|
2011-05-25 06:50:56 +00:00
|
|
|
if @item.save
|
2011-05-13 01:08:42 +00:00
|
|
|
flash.now[:notice] = t('admin.create_success_link')
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
2011-05-25 06:50:56 +00:00
|
|
|
redirect_to admin_link_url(@item)
|
2011-05-13 01:08:42 +00:00
|
|
|
}
|
|
|
|
format.js {}
|
|
|
|
end
|
2010-01-14 10:30:53 +00:00
|
|
|
else
|
2011-05-13 01:08:42 +00:00
|
|
|
flash.now[:error] = t('admin.create_error_link')
|
|
|
|
render :action => "new"
|
2010-01-14 10:30:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2011-05-25 06:50:56 +00:00
|
|
|
@item = Link.find(params[:id])
|
2010-01-14 10:30:53 +00:00
|
|
|
|
2011-05-25 06:50:56 +00:00
|
|
|
if @item.update_attributes(params[:link])
|
2011-05-13 01:08:42 +00:00
|
|
|
flash.now[:notice] = t('admin.update_success_link')
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
2011-05-25 06:50:56 +00:00
|
|
|
redirect_to admin_link_url(@item)
|
2011-05-13 01:08:42 +00:00
|
|
|
}
|
|
|
|
format.js {}
|
|
|
|
end
|
2010-01-14 10:30:53 +00:00
|
|
|
else
|
2011-05-13 01:08:42 +00:00
|
|
|
flash.now[:error] = t('admin.update_error_link')
|
2010-01-14 10:30:53 +00:00
|
|
|
render :action => "edit"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2011-05-25 06:50:56 +00:00
|
|
|
@item = Link.find(params[:id])
|
|
|
|
@item.destroy
|
2011-05-13 01:08:42 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
redirect_to admin_items_url
|
|
|
|
}
|
|
|
|
format.js {}
|
|
|
|
end
|
2010-01-14 10:30:53 +00:00
|
|
|
end
|
|
|
|
|
2011-05-13 01:59:29 +00:00
|
|
|
def delete
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {}
|
|
|
|
format.js { destroy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-14 10:30:53 +00:00
|
|
|
end
|