links/app/controllers/admin/web_resources_controller.rb

67 lines
1.6 KiB
Ruby
Raw Normal View History

2014-05-05 11:33:35 +00:00
class Admin::WebResourcesController < OrbitAdminController
before_action ->(module_app = @app_title) { set_variables module_app }
before_action :set_link, only: [:edit, :update, :destroy]
def index
@tags = @module_app.tags
2014-05-14 02:58:41 +00:00
@categories = @module_app.categories.enabled
@filter_fields = filter_fields(@categories, @tags)
@table_fields = [:status, :category, :title]
2014-05-05 11:33:35 +00:00
2014-08-07 10:48:12 +00:00
@links = WebLink.order_by(sort)
.with_categories(filters("category"))
.with_tags(filters("tag"))
.with_status(filters("status"))
2014-05-05 11:33:35 +00:00
2014-08-07 10:48:12 +00:00
@links = search_data(@links,[:title]).page(params[:page]).per(10)
render :partial => "index" if request.xhr?
2014-05-05 11:33:35 +00:00
end
def new
@tags =@module_app.tags
2014-05-14 02:58:41 +00:00
@categories = @module_app.categories.enabled
2014-05-05 11:33:35 +00:00
@statuses = []
@link = WebLink.new
end
def create
link = WebLink.new(link_params)
link.create_user_id = current_user.id
link.update_user_id = current_user.id
link.save
redirect_to admin_web_resources_path
end
def edit
2014-07-31 12:43:16 +00:00
if can_edit_or_delete?(@link)
@tags =@module_app.tags
@categories = @module_app.categories.enabled
@statuses = []
else
render_401
end
2014-05-05 11:33:35 +00:00
end
def update
@link.update_attributes(link_params)
@link.save
redirect_to admin_web_resources_path
end
def destroy
@link.destroy
redirect_to admin_web_resources_path
end
private
def set_link
@link = WebLink.find(params[:id])
end
def link_params
params.require(:web_link).permit!
end
end