Your Items autocomplete supports lists

This commit is contained in:
Emi Matchu 2011-07-29 11:25:17 -04:00
parent 358840076c
commit d893b0ab41
6 changed files with 68 additions and 31 deletions

View file

@ -40,7 +40,8 @@ class ClosetHangersController < ApplicationController
if @closet_hanger.save if @closet_hanger.save
respond_to do |format| respond_to do |format|
format.html { format.html {
message = "Success! You #{@closet_hanger.verb(:you)} #{@closet_hanger.quantity} #{@item.name.pluralize}" message = "Success! You #{@closet_hanger.verb(:you)} #{@closet_hanger.quantity} "
message << ((@closet_hanger.quantity > 1) ? @item.name.pluralize : @item.name)
message << " in the \"#{@closet_hanger.list.name}\" list" if @closet_hanger.list message << " in the \"#{@closet_hanger.list.name}\" list" if @closet_hanger.list
flash[:success] = "#{message}." flash[:success] = "#{message}."
redirect_back!(@item) redirect_back!(@item)

View file

@ -177,6 +177,10 @@ body.closet_hangers-index
&:last-child &:last-child
border-bottom: 0 border-bottom: 0
.closet-list-autocomplete-item a
font-size: 85%
padding-left: 2em
&.current-user &.current-user
#closet-hangers #closet-hangers
.object:hover .object:hover

View file

@ -49,9 +49,7 @@
.closet-hangers-group{'data-owned' => owned.to_s} .closet-hangers-group{'data-owned' => owned.to_s}
%header %header
%h3 %h3
Items Items #{closet_hanger_subject} #{closet_hanger_verb(owned)}
= closet_hanger_subject
%span.verb= closet_hanger_verb(owned)
%span.toggle.show show %span.toggle.show show
%span.toggle.hide hide %span.toggle.hide hide
= link_to_add_closet_list 'Add new list', :owned => owned, :class => 'add-closet-list' = link_to_add_closet_list 'Add new list', :owned => owned, :class => 'add-closet-list'

View file

@ -1,4 +1,4 @@
.closet-list .closet-list{'data-id' => closet_list.id}
%header %header
- if show_controls - if show_controls
.closet-list-controls .closet-list-controls

View file

@ -9,8 +9,22 @@
$('div.closet-hangers-group').each(function () { $('div.closet-hangers-group').each(function () {
var el = $(this); var el = $(this);
var lists = [];
el.find('div.closet-list').each(function () {
var el = $(this);
var id = el.attr('data-id');
if(id) {
lists[lists.length] = {
id: parseInt(id, 10),
label: el.find('h4').text()
}
}
});
hangerGroups[hangerGroups.length] = { hangerGroups[hangerGroups.length] = {
label: el.find('span.verb').text(), label: el.find('h3').text(),
lists: lists,
owned: (el.attr('data-owned') == 'true') owned: (el.attr('data-owned') == 'true')
}; };
}); });
@ -176,7 +190,8 @@
var closetHanger = { var closetHanger = {
quantity: 1, quantity: 1,
owned: group.owned owned: group.owned,
list_id: ui.item.list ? ui.item.list.id : ''
}; };
$.ajax({ $.ajax({
@ -212,13 +227,24 @@
callback(output); callback(output);
}); });
} else { // item was chosen, now choose a group to insert } else { // item was chosen, now choose a group to insert
var groupInserts = []; var groupInserts = [], group;
for(var i in hangerGroups) { for(var i in hangerGroups) {
group = hangerGroups[i];
groupInserts[groupInserts.length] = { groupInserts[groupInserts.length] = {
group: hangerGroups[i], group: group,
item: input.term, item: input.term,
label: input.term.label label: input.term.label
} }
for(var i = 0; i < group.lists.length; i++) {
groupInserts[groupInserts.length] = {
group: group,
item: input.term,
label: input.term.label,
list: group.lists[i]
}
}
} }
callback(groupInserts); callback(groupInserts);
} }
@ -231,8 +257,11 @@
var li = $("<li></li>").data("item.autocomplete", item); var li = $("<li></li>").data("item.autocomplete", item);
if(item.is_item) { // these are items from the server if(item.is_item) { // these are items from the server
li.append("<a>Add <strong>" + item.label + "</strong>"); li.append("<a>Add <strong>" + item.label + "</strong>");
} else if(item.list) { // these are list inserts
li.append("<a>Add to <strong>" + item.list.label + "</strong>").
addClass("closet-list-autocomplete-item");
} else { // these are group inserts } else { // these are group inserts
li.append("<a>I <strong>" + item.group.label + "</strong> the <strong>" + item.item.label + "</strong>"); li.append("<a>Add to <strong>" + item.group.label + "</strong>");
} }
return li.appendTo(ul); return li.appendTo(ul);
} }

View file

@ -871,17 +871,22 @@ body.closet_hangers-index .closet-list:hover .closet-list-controls {
body.closet_hangers-index .closet-list:last-child { body.closet_hangers-index .closet-list:last-child {
border-bottom: 0; border-bottom: 0;
} }
/* line 183, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 180, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index .closet-list-autocomplete-item a {
font-size: 85%;
padding-left: 2em;
}
/* line 187, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user #closet-hangers .object:hover form { body.closet_hangers-index.current-user #closet-hangers .object:hover form {
display: inline; display: inline;
} }
/* line 186, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 190, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user #closet-hangers .object:hover .closet-hanger-destroy { body.closet_hangers-index.current-user #closet-hangers .object:hover .closet-hanger-destroy {
position: absolute; position: absolute;
right: 18px; right: 18px;
top: 0; top: 0;
} }
/* line 191, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 195, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user #closet-hangers .object:hover .closet-hanger-destroy input { body.closet_hangers-index.current-user #closet-hangers .object:hover .closet-hanger-destroy input {
/* http://www.zurb.com/blog_uploads/0000/0617/buttons-03.html */ /* http://www.zurb.com/blog_uploads/0000/0617/buttons-03.html */
-moz-border-radius: 5px; -moz-border-radius: 5px;
@ -922,7 +927,7 @@ body.closet_hangers-index.current-user #closet-hangers .object:hover .closet-han
body.closet_hangers-index.current-user #closet-hangers .object:hover .closet-hanger-destroy input:hover { body.closet_hangers-index.current-user #closet-hangers .object:hover .closet-hanger-destroy input:hover {
background-color: #999999; background-color: #999999;
} }
/* line 194, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 198, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user #closet-hangers .object:hover .quantity { body.closet_hangers-index.current-user #closet-hangers .object:hover .quantity {
-moz-opacity: 1; -moz-opacity: 1;
-webkit-opacity: 1; -webkit-opacity: 1;
@ -932,73 +937,73 @@ body.closet_hangers-index.current-user #closet-hangers .object:hover .quantity {
top: 56px; top: 56px;
padding: 0; padding: 0;
} }
/* line 200, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 204, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user #closet-hangers .object:hover .quantity span { body.closet_hangers-index.current-user #closet-hangers .object:hover .quantity span {
display: none; display: none;
} }
/* line 203, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 207, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user #closet-hangers .object:hover .quantity input[type=number] { body.closet_hangers-index.current-user #closet-hangers .object:hover .quantity input[type=number] {
padding: 2px; padding: 2px;
width: 2em; width: 2em;
} }
/* line 207, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 211, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user #closet-hangers .object:hover .quantity input[type=submit] { body.closet_hangers-index.current-user #closet-hangers .object:hover .quantity input[type=submit] {
font-size: 85%; font-size: 85%;
} }
/* line 212, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 216, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user.js #closet-hangers .object:hover .quantity { body.closet_hangers-index.current-user.js #closet-hangers .object:hover .quantity {
display: block; display: block;
} }
/* line 215, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 219, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user.js #closet-hangers .object:hover .quantity input[type=number] { body.closet_hangers-index.current-user.js #closet-hangers .object:hover .quantity input[type=number] {
width: 2.5em; width: 2.5em;
} }
/* line 218, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 222, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user.js #closet-hangers .object:hover .quantity input[type=submit] { body.closet_hangers-index.current-user.js #closet-hangers .object:hover .quantity input[type=submit] {
display: none; display: none;
} }
/* line 221, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 225, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user.js #closet-hangers .object.loading { body.closet_hangers-index.current-user.js #closet-hangers .object.loading {
background: #eeffee; background: #eeffee;
outline: 1px solid #006600; outline: 1px solid #006600;
} }
/* line 225, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 229, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user.js #closet-hangers .object.loading .quantity { body.closet_hangers-index.current-user.js #closet-hangers .object.loading .quantity {
display: block; display: block;
} }
/* line 228, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 232, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user.js #closet-hangers .object.loading .quantity span:after { body.closet_hangers-index.current-user.js #closet-hangers .object.loading .quantity span:after {
content: "…"; content: "…";
} }
/* line 232, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 236, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user.js #closet-hangers-contact form { body.closet_hangers-index.current-user.js #closet-hangers-contact form {
display: none; display: none;
} }
/* line 235, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 239, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user.js #closet-hangers-contact .edit-contact-link, body.closet_hangers-index.current-user.js #closet-hangers-contact #cancel-contact-link { body.closet_hangers-index.current-user.js #closet-hangers-contact .edit-contact-link, body.closet_hangers-index.current-user.js #closet-hangers-contact #cancel-contact-link {
display: inline; display: inline;
} }
/* line 239, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 243, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user.js #closet-hangers-contact.editing form { body.closet_hangers-index.current-user.js #closet-hangers-contact.editing form {
display: block; display: block;
} }
/* line 242, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 246, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user.js #closet-hangers-contact.editing .edit-contact-link { body.closet_hangers-index.current-user.js #closet-hangers-contact.editing .edit-contact-link {
display: none; display: none;
} }
/* line 247, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 251, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user.js .closet-hangers-group header .show, body.closet_hangers-index.current-user.js .closet-hangers-group header .hide { body.closet_hangers-index.current-user.js .closet-hangers-group header .show, body.closet_hangers-index.current-user.js .closet-hangers-group header .hide {
cursor: pointer; cursor: pointer;
} }
/* line 250, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 254, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user.js .closet-hangers-group header .hide { body.closet_hangers-index.current-user.js .closet-hangers-group header .hide {
display: block; display: block;
} }
/* line 254, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 258, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user.js .closet-hangers-group.hidden header .hide, body.closet_hangers-index.current-user.js .closet-hangers-group.hidden .closet-hangers-group-content { body.closet_hangers-index.current-user.js .closet-hangers-group.hidden header .hide, body.closet_hangers-index.current-user.js .closet-hangers-group.hidden .closet-hangers-group-content {
display: none; display: none;
} }
/* line 257, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 261, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index.current-user.js .closet-hangers-group.hidden header .show { body.closet_hangers-index.current-user.js .closet-hangers-group.hidden header .show {
display: block; display: block;
} }