From 6af0ac5068d09e963401a25e484906d193c09974 Mon Sep 17 00:00:00 2001 From: Bert Pareyn Date: Tue, 7 Aug 2012 11:55:36 +0100 Subject: [PATCH 1/3] OAEWDGT-58 Implement noscript fallback for user management --- app/assets/javascripts/admin.js | 8 +++++--- app/assets/stylesheets/admin.css.scss | 6 ++++++ app/controllers/admin_controller.rb | 2 +- app/views/admin/_user.html.erb | 14 +++++++++++--- 4 files changed, 23 insertions(+), 7 deletions(-) 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..d181770 100644 --- a/app/assets/stylesheets/admin.css.scss +++ b/app/assets/stylesheets/admin.css.scss @@ -81,6 +81,12 @@ margin-right: 60px; } } + .wl-save-fallback { + height: 15px; + line-height: 16px; + margin-right: 59px; + width: 25px; + } .admin-table { color: #333; tr { diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 61a83a5..813457a 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -35,7 +35,7 @@ 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 options diff --git a/app/views/admin/_user.html.erb b/app/views/admin/_user.html.erb index 5819626..47d9e76 100644 --- a/app/views/admin/_user.html.erb +++ b/app/views/admin/_user.html.erb @@ -1,8 +1,13 @@ -<% @users.each do |user| %> +<% @users.each_with_index do |user, index| %> + <% if index % 3 == 0 %> +
+ <% end %>
  • - <%= form_tag("/admin/users/update", :method => "POST", :remote => true) do %> + <%= form_for user, :url => "/admin/users/update", :method => "POST", :remote => true do |f| %> + <%= button_tag "Save", :class => "wl-no-script wl-button wl-link-button wl-save-fallback wl-right" %> <%= 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" %> +
    <% if user_signed_in? && current_user.id != user.id %> @@ -18,4 +23,7 @@ <% end %> <% end %>
  • + <% if (index + 1) % 3 == 0 %> +
    + <% end %> <% end %> From 61aafb6c42764ca84f482f722dc36c2d76f85d92 Mon Sep 17 00:00:00 2001 From: Dean Angerer Date: Wed, 25 Jul 2012 17:19:24 -0400 Subject: [PATCH 2/3] OAEWDGT-169 Added link to delete users from the system https://jira.sakaiproject.org/browse/OAEWDGT-169 --- app/assets/stylesheets/admin.css.scss | 4 +++- app/controllers/admin_controller.rb | 5 +++++ app/models/user.rb | 9 ++++++--- app/views/admin/_user.html.erb | 1 + config/routes.rb | 1 + 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/admin.css.scss b/app/assets/stylesheets/admin.css.scss index d181770..54b9e1a 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,9 @@ float: right; margin-right: 60px; } + a.wl-button { + margin: auto; + } } .wl-save-fallback { height: 15px; diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 813457a..00c1248 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -38,6 +38,11 @@ def user_update redirect_to request.referer end + def delete_user + User.find(params[:id]).destroy + redirect_to :admin_users + end + def options @results = Language.find(:all, :order => "title") get_used_items(Language) diff --git a/app/models/user.rb b/app/models/user.rb index 876ea60..7bb097e 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,7 @@ 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 + end end diff --git a/app/views/admin/_user.html.erb b/app/views/admin/_user.html.erb index 47d9e76..7d198e2 100644 --- a/app/views/admin/_user.html.erb +++ b/app/views/admin/_user.html.erb @@ -18,6 +18,7 @@ <% if user_signed_in? && current_user.id != user.id %> <%= check_box_tag "chk_user_reviewer#{user.id}", 1, user.reviewer %> + <%= link_to "Remove User", admin_delete_user_path(user), :confirm => "Are you sure you want to delete this user?", :class => "wl-button wl-overlay-button", :method => "delete" %> <% else %> <%= check_box_tag "chk_user_reviewer#{user.id}", 1, user.reviewer, :disabled => true %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 8a11596..9f4f6eb 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 + delete '/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 From a13243c88d762c278d0d2e87272025afc401cbdd Mon Sep 17 00:00:00 2001 From: Bert Pareyn Date: Tue, 7 Aug 2012 16:18:42 +0100 Subject: [PATCH 3/3] OAEWDGT-169 Implement functionality to delete users from the system --- app/assets/stylesheets/admin.css.scss | 4 ++-- app/controllers/admin_controller.rb | 2 +- app/models/user.rb | 1 + app/views/admin/_user.html.erb | 8 +++++--- config/routes.rb | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/admin.css.scss b/app/assets/stylesheets/admin.css.scss index 54b9e1a..3f3e9ae 100644 --- a/app/assets/stylesheets/admin.css.scss +++ b/app/assets/stylesheets/admin.css.scss @@ -84,9 +84,9 @@ } } .wl-save-fallback { + font: 13px/1.231 Arial,Helvetica,sans-serif; + font-weight: bold; height: 15px; - line-height: 16px; - margin-right: 59px; width: 25px; } .admin-table { diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 00c1248..26c4622 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -40,7 +40,7 @@ def user_update def delete_user User.find(params[:id]).destroy - redirect_to :admin_users + redirect_to request.referer end def options diff --git a/app/models/user.rb b/app/models/user.rb index 7bb097e..9c22d32 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -65,5 +65,6 @@ def calculate_fields 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 7d198e2..8d994e4 100644 --- a/app/views/admin/_user.html.erb +++ b/app/views/admin/_user.html.erb @@ -2,11 +2,14 @@ <% if index % 3 == 0 %>
    <% end %> -
  • +
  • <%= form_for user, :url => "/admin/users/update", :method => "POST", :remote => true do |f| %> - <%= button_tag "Save", :class => "wl-no-script wl-button wl-link-button wl-save-fallback wl-right" %> <%= 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 "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" %>
    @@ -18,7 +21,6 @@ <% if user_signed_in? && current_user.id != user.id %> <%= check_box_tag "chk_user_reviewer#{user.id}", 1, user.reviewer %> - <%= link_to "Remove User", admin_delete_user_path(user), :confirm => "Are you sure you want to delete this user?", :class => "wl-button wl-overlay-button", :method => "delete" %> <% else %> <%= check_box_tag "chk_user_reviewer#{user.id}", 1, user.reviewer, :disabled => true %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 9f4f6eb..ea0f03a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -50,7 +50,7 @@ # Admin section match '/admin/users' => 'admin#users', :as => :admin_users match '/admin/users/admin' => 'admin#adminusers', :as => :admin_admin_users - delete '/admin/users/delete/:id' => 'admin#delete_user', :as => :admin_delete_user + 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