From 081dea82bad7eaad2778993ab8e2cd62bcb3eee4 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Fri, 28 Aug 2015 17:30:12 +0800 Subject: [PATCH] user friendly revoke and delete --- .../admin/registered_sites_controller.rb | 20 +++++++++++++++++-- .../admin/registered_sites/_index.html.erb | 7 +++++-- .../admin/registered_sites/destroy.js.erb | 1 + 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 app/views/admin/registered_sites/destroy.js.erb diff --git a/app/controllers/admin/registered_sites_controller.rb b/app/controllers/admin/registered_sites_controller.rb index 0981d53..590257f 100644 --- a/app/controllers/admin/registered_sites_controller.rb +++ b/app/controllers/admin/registered_sites_controller.rb @@ -34,7 +34,7 @@ class Admin::RegisteredSitesController < OrbitAdminController def change_access_status if !request.xhr? - redirect_to admin_registered_sites_path(:page => params[:page]) + redirect_to admin_registered_sites_path(:page => params[:page], :keywords => params[:keywords]) return end status = params[:status] @@ -48,10 +48,26 @@ class Admin::RegisteredSitesController < OrbitAdminController site.save end @table_fields = table_fields - @registeredsites = RegisteredSite.all.desc(:created_at).page(params[:page]).per(10) + @registeredsites = RegisteredSite.all.order_by(sort) + .with_categories(filters("category")) + .with_tags(filters("tag")).desc(:created_at) + @registeredsites = search_data(@registeredsites,[:title]).page(params[:page]).per(10) # render :partial => "index" end + def destroy + registeredsite = RegisteredSite.find(params[:id]) rescue nil + if !registeredsite.nil? + registeredsite.destroy + end + @table_fields = table_fields + + @registeredsites = RegisteredSite.all.order_by(sort) + .with_categories(filters("category")) + .with_tags(filters("tag")).desc(:created_at) + @registeredsites = search_data(@registeredsites,[:title]).page(params[:page]).per(10) + end + private def table_fields [:domain, :admin_email, :status, :category, :tags, :permission] diff --git a/app/views/admin/registered_sites/_index.html.erb b/app/views/admin/registered_sites/_index.html.erb index bca042f..4a691c2 100644 --- a/app/views/admin/registered_sites/_index.html.erb +++ b/app/views/admin/registered_sites/_index.html.erb @@ -44,10 +44,13 @@ <% if !site.site_confirmed %> Grant <% elsif !site.access_granted %> - " class="btn btn-success" data-remote="true">Grant + <%= "&keywords=#{params[:keywords]}" if params[:keywords] %>" class="btn btn-success" data-remote="true">Grant <% else %> - " class="btn btn-danger" data-remote="true">Revoke + <%= "&keywords=#{params[:keywords]}" if params[:keywords] %>" class="btn btn-warning" data-remote="true">Revoke <% end %> + <%# if current_user.is_admin? %> + <%= "&keywords=#{params[:keywords]}" if params[:keywords] %>" class="btn btn-danger" data-remote="true" data-method="delete"> + <%# end %> <% end %> diff --git a/app/views/admin/registered_sites/destroy.js.erb b/app/views/admin/registered_sites/destroy.js.erb new file mode 100644 index 0000000..e4ac3a7 --- /dev/null +++ b/app/views/admin/registered_sites/destroy.js.erb @@ -0,0 +1 @@ +$("#index_table").html("<%= j render 'index' %>"); \ No newline at end of file