2014-10-27 11:01:37 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
class Admin::RegisteredSitesController < OrbitAdminController
|
2014-12-02 12:21:20 +00:00
|
|
|
before_action ->(module_app = @app_title) { set_variables module_app }
|
2014-10-27 11:01:37 +00:00
|
|
|
def index
|
2014-12-02 12:21:20 +00:00
|
|
|
@registeredsites = RegisteredSite.all.order_by(sort)
|
|
|
|
.with_categories(filters("category"))
|
2014-12-30 12:28:20 +00:00
|
|
|
.with_tags(filters("tag")).desc(:created_at)
|
2014-10-27 11:01:37 +00:00
|
|
|
@table_fields = table_fields
|
2014-12-02 12:21:20 +00:00
|
|
|
@tags = @module_app.tags
|
|
|
|
@categories = @module_app.categories.enabled
|
|
|
|
@filter_fields = filter_fields_without_status(@categories, @tags)
|
2015-08-28 10:10:30 +00:00
|
|
|
@registeredsites = search_data(@registeredsites,[:title,:site_domain]).page(params[:page]).per(10)
|
2014-10-27 11:01:37 +00:00
|
|
|
|
|
|
|
if request.xhr?
|
|
|
|
render :partial => "index"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-12-02 12:21:20 +00:00
|
|
|
def edit
|
|
|
|
@registered_site = RegisteredSite.find(params[:id])
|
|
|
|
if can_edit_or_delete?(@registered_site)
|
|
|
|
else
|
|
|
|
render_401
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
uid = params[:id].split('-').last
|
|
|
|
registered_site = RegisteredSite.find_by(:uid => uid)
|
|
|
|
registered_site.update_attributes(registered_site_params)
|
|
|
|
registered_site.save
|
|
|
|
redirect_to params['referer_url']
|
|
|
|
end
|
|
|
|
|
2014-10-27 11:01:37 +00:00
|
|
|
def change_access_status
|
2014-12-30 13:48:02 +00:00
|
|
|
if !request.xhr?
|
2015-08-28 09:30:12 +00:00
|
|
|
redirect_to admin_registered_sites_path(:page => params[:page], :keywords => params[:keywords])
|
2014-12-30 13:48:02 +00:00
|
|
|
return
|
|
|
|
end
|
2014-10-27 11:01:37 +00:00
|
|
|
status = params[:status]
|
|
|
|
site = RegisteredSite.find_by(:uid => params[:uid])
|
|
|
|
case status
|
|
|
|
when "revoke"
|
|
|
|
site.access_granted = false
|
|
|
|
site.save
|
|
|
|
when "grant"
|
|
|
|
site.access_granted = true
|
|
|
|
site.save
|
|
|
|
end
|
|
|
|
@table_fields = table_fields
|
2015-08-28 09:30:12 +00:00
|
|
|
@registeredsites = RegisteredSite.all.order_by(sort)
|
|
|
|
.with_categories(filters("category"))
|
|
|
|
.with_tags(filters("tag")).desc(:created_at)
|
2015-08-28 10:10:30 +00:00
|
|
|
@registeredsites = search_data(@registeredsites,[:title,:site_domain]).page(params[:page]).per(10)
|
2014-10-27 11:01:37 +00:00
|
|
|
# render :partial => "index"
|
|
|
|
end
|
|
|
|
|
2015-08-28 09:30:12 +00:00
|
|
|
def destroy
|
|
|
|
registeredsite = RegisteredSite.find(params[:id]) rescue nil
|
|
|
|
if !registeredsite.nil?
|
|
|
|
registeredsite.destroy
|
|
|
|
end
|
|
|
|
@table_fields = table_fields
|
2015-08-28 10:10:30 +00:00
|
|
|
|
2015-08-28 09:30:12 +00:00
|
|
|
@registeredsites = RegisteredSite.all.order_by(sort)
|
|
|
|
.with_categories(filters("category"))
|
|
|
|
.with_tags(filters("tag")).desc(:created_at)
|
2015-08-28 10:10:30 +00:00
|
|
|
@registeredsites = search_data(@registeredsites,[:title,:site_domain]).page(params[:page]).per(10)
|
2015-08-28 09:30:12 +00:00
|
|
|
end
|
|
|
|
|
2014-10-27 11:01:37 +00:00
|
|
|
private
|
|
|
|
def table_fields
|
2014-12-02 12:21:20 +00:00
|
|
|
[:domain, :admin_email, :status, :category, :tags, :permission]
|
|
|
|
end
|
|
|
|
|
|
|
|
def registered_site_params
|
|
|
|
params.require(:registered_site).permit!
|
2014-10-27 11:01:37 +00:00
|
|
|
end
|
|
|
|
end
|