From dcf254a78dcb45ef95b80387d005a222d55e296e Mon Sep 17 00:00:00 2001 From: Matchu Date: Sun, 19 Jul 2015 12:35:49 -0400 Subject: [PATCH] finally let people remove all items from the list at once. I've been doing this manually via email for a long time, since building new stuff in the logged-in world was a pain in the old env. But now here we are! Finally, finally :) --- app/controllers/closet_hangers_controller.rb | 21 +++++++++++++++---- app/models/user.rb | 21 ++++++++++++++++++- app/views/closet_hangers/index.html.haml | 4 ++++ app/views/closet_lists/_closet_list.html.haml | 3 +++ config/locales/en.yml | 17 +++++++++++---- config/routes.rb | 1 + 6 files changed, 58 insertions(+), 9 deletions(-) diff --git a/app/controllers/closet_hangers_controller.rb b/app/controllers/closet_hangers_controller.rb index c5aef510..7d273729 100644 --- a/app/controllers/closet_hangers_controller.rb +++ b/app/controllers/closet_hangers_controller.rb @@ -4,10 +4,23 @@ class ClosetHangersController < ApplicationController before_filter :find_user, :only => [:index, :petpage, :update_quantities] def destroy - @closet_hanger = current_user.closet_hangers.find params[:id] - @closet_hanger.destroy - @item = @closet_hanger.item - closet_hanger_destroyed + if params[:list_id] + @closet_list = current_user.find_closet_list_by_id_or_null_owned params[:list_id] + @closet_list.hangers.destroy_all + respond_to do |format| + format.html { + flash[:success] = t("closet_hangers.destroy_all.success") + redirect_back!(user_closet_hangers_path(current_user)) + } + + format.json { render :json => true } + end + else + @closet_hanger = current_user.closet_hangers.find params[:id] + @closet_hanger.destroy + @item = @closet_hanger.item + closet_hanger_destroyed + end end def index diff --git a/app/models/user.rb b/app/models/user.rb index b52260a5..c709dc6a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -89,7 +89,26 @@ class User < ActiveRecord::Base end def null_closet_list(owned) - owned ? ClosetList::NullOwned.new(self) : ClosetList::NullWanted.new(self) + owned ? null_owned_list : null_wanted_list + end + + def null_owned_list + ClosetList::NullOwned.new(self) + end + + def null_wanted_list + ClosetList::NullWanted.new(self) + end + + def find_closet_list_by_id_or_null_owned(id_or_owned) + id_or_owned_str = id_or_owned.to_s + if id_or_owned_str == 'true' + null_owned_list + elsif id_or_owned_str == 'false' + null_wanted_list + else + self.closet_lists.find id_or_owned + end end def neopets_usernames diff --git a/app/views/closet_hangers/index.html.haml b/app/views/closet_hangers/index.html.haml index e563e3db..f58950d5 100644 --- a/app/views/closet_hangers/index.html.haml +++ b/app/views/closet_hangers/index.html.haml @@ -73,6 +73,10 @@ closet_visibility_choices(:human_name) = f.submit t('.unlisted.submit') = closet_visibility_descriptions + .closet-list-controls + = form_tag user_closet_hangers_path(@user), method: :delete do + = hidden_field_tag :list_id, owned + = submit_tag t('.remove_all.submit'), confirm: t('.remove_all.confirm') - if has_lists?(owned) %h4= t '.unlisted.header' - if !@public_perspective diff --git a/app/views/closet_lists/_closet_list.html.haml b/app/views/closet_lists/_closet_list.html.haml index 02835634..05833317 100644 --- a/app/views/closet_lists/_closet_list.html.haml +++ b/app/views/closet_lists/_closet_list.html.haml @@ -9,6 +9,9 @@ = link_to t('.edit'), edit_user_closet_list_path(closet_list.user_id, closet_list) = form_tag user_closet_list_path(closet_list.user_id, closet_list), :method => 'delete' do = submit_tag t('.delete'), :confirm => closet_list_delete_confirmation(closet_list) + = form_tag user_closet_hangers_path(@user), method: :delete do + = hidden_field_tag :list_id, closet_list.id + = submit_tag t('.remove_all.submit'), confirm: t('.remove_all.confirm') %h4= closet_list.name - if show_controls diff --git a/config/locales/en.yml b/config/locales/en.yml index 77eafc94..fc4caf22 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -95,6 +95,9 @@ en: success: owned: Success! You do not own the %{item_name}. wanted: Success! You do not want the %{item_name}. + + destroy_all: + success: Success! Removed all items from the list. index: title_for: @@ -124,6 +127,9 @@ en: submit: Save header: (Not in a list) empty: There aren't any items here. + remove_all: + confirm: 'Remove all items from this list?' + submit: Remove all autocomplete: add_item_html: Add %{item_name} add_to_list_html: Add to %{list_name} @@ -179,11 +185,14 @@ en: delete: Delete delete_confirmation: owned: - Are you sure you want to delete "%{list_name}"? Even if you do, we'll - remember that you own these items. + Are you sure you want to delete "%{list_name}"? + If you do, we'll move these items into Items You Own, not in a list. wanted: - Are you sure you want to delete "%{list_name}"? Even if you do, we'll - remember that you want these items. + Are you sure you want to delete "%{list_name}"? + If you do, we'll move these items into Items You Want, not in a list. + remove_all: + confirm: 'Remove all items from this list?' + submit: Remove all empty: This list is empty. trading_neomail_warning_html: You've marked this list as Trading, so folks will discover it via Dress diff --git a/config/routes.rb b/config/routes.rb index 68f87c82..17d0a821 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -66,6 +66,7 @@ OpenneoImpressItems::Application.routes.draw do resources :closet_hangers, :only => [:index, :update, :destroy], :path => 'closet' do collection do get :petpage + delete :destroy end end resources :closet_lists, :only => [:new, :create, :edit, :update, :destroy], :path => 'closet/lists'