diff --git a/app/assets/javascripts/admin.js b/app/assets/javascripts/admin.js index 753b3f1..63043aa 100644 --- a/app/assets/javascripts/admin.js +++ b/app/assets/javascripts/admin.js @@ -1,9 +1,11 @@ $(function() { + $('.wl-no-script').hide(); + var reject_widget = function() { - $( "#admin_action_buttons" ).hide(); - $(".widget_confirmation").hide(); - $("#reject_confirm").show(); + $('#admin_action_buttons').hide(); + $('.widget_confirmation').hide(); + $('#reject_confirm').show(); }; var finalize_rejection = function( versionid ) { diff --git a/app/assets/stylesheets/admin.css.scss b/app/assets/stylesheets/admin.css.scss index 5b27d11..3f3e9ae 100644 --- a/app/assets/stylesheets/admin.css.scss +++ b/app/assets/stylesheets/admin.css.scss @@ -67,7 +67,6 @@ margin: 0; li { display: inline-block; - float: left; margin: 12px 0; width: 33%; } @@ -80,6 +79,15 @@ float: right; margin-right: 60px; } + a.wl-button { + margin: auto; + } + } + .wl-save-fallback { + font: 13px/1.231 Arial,Helvetica,sans-serif; + font-weight: bold; + height: 15px; + width: 25px; } .admin-table { color: #333; diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 61a83a5..26c4622 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -35,7 +35,12 @@ def user_update user.admin = params["chk_user_admin" + params[:user_id]] user.reviewer = params["chk_user_reviewer" + params[:user_id]] user.save - head :ok + redirect_to request.referer + end + + def delete_user + User.find(params[:id]).destroy + redirect_to request.referer end def options diff --git a/app/models/user.rb b/app/models/user.rb index 876ea60..9c22d32 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,7 @@ class User < ActiveRecord::Base include ValidatesAsImage before_save :calculate_fields + after_destroy :destroy_inactive_widgets has_attached_file :avatar, :styles => { @@ -8,8 +9,8 @@ class User < ActiveRecord::Base :medium => ["100x100!", :png], :large => ["800x800", :png] }, :default_url => "register_default_image.jpg" - has_many :widgets - has_many :downloads + has_many :widgets, :dependent => :destroy + has_many :downloads, :dependent => :destroy # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, @@ -62,5 +63,8 @@ def calculate_fields self.name = "#{self.first_name} #{self.last_name}" self.url_title = "#{self.first_name.to_s.downcase}-#{self.last_name.to_s.downcase}" end - + def destroy_inactive_widgets + Widget.where("user_id = ?", self.id).destroy_all + Rating.where("user_id = ?", self.id).destroy_all + end end diff --git a/app/views/admin/_user.html.erb b/app/views/admin/_user.html.erb index 5819626..8d994e4 100644 --- a/app/views/admin/_user.html.erb +++ b/app/views/admin/_user.html.erb @@ -1,8 +1,16 @@ -<% @users.each do |user| %> -
  • - <%= form_tag("/admin/users/update", :method => "POST", :remote => true) do %> +<% @users.each_with_index do |user, index| %> + <% if index % 3 == 0 %> +
    + <% end %> +
  • + <%= form_for user, :url => "/admin/users/update", :method => "POST", :remote => true do |f| %> <%= image_tag user.avatar.url(:thumb), :alt => "#{user.name}'s Photo", :class => "wl-left"%> - <%= link_to user.name, user_path(:id => user.id, :url_title => user.url_title), :class => "wl-bold wl-regular-link", :target => "_blank" %>
    + <%= link_to user.name, user_path(:id => user.id, :url_title => user.url_title), :class => "wl-bold wl-regular-link", :target => "_blank" %> + - + <%= link_to "Delete", admin_delete_user_path(user), :confirm => "Are you sure you want to delete this user?", :class => "wl-bold wl-regular-link", :method => "delete" %> + - + <%= button_tag "Save", :class => "wl-no-script wl-button wl-link-button wl-regular-link wl-save-fallback" %> +
    <% if user_signed_in? && current_user.id != user.id %> @@ -18,4 +26,7 @@ <% end %> <% end %>
  • + <% if (index + 1) % 3 == 0 %> + + <% end %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 8a11596..ea0f03a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -50,6 +50,7 @@ # Admin section match '/admin/users' => 'admin#users', :as => :admin_users match '/admin/users/admin' => 'admin#adminusers', :as => :admin_admin_users + match '/admin/users/delete/:id' => 'admin#delete_user', :as => :admin_delete_user match '/admin/options' => 'admin#options', :as => :admin_options match '/admin/languages/edit/:id' => 'admin#edit_language', :as => :admin_edit_language post '/admin/languages/save' => 'admin#save_language', :as => :admin_add_edit_language