Your Items autocompleter is totally chill with moving items around to different lists

This commit is contained in:
Emi Matchu 2011-07-29 23:26:48 -04:00
parent c76c261444
commit 48ee765505
4 changed files with 74 additions and 36 deletions

View file

@ -177,9 +177,15 @@ body.closet_hangers-index
&:last-child &:last-child
border-bottom: 0 border-bottom: 0
.closet-list-autocomplete-item a .closet-hangers-group-autocomplete-item, .closet-list-autocomplete-item
font-size: 85% span
padding-left: 2em font-style: italic
padding: .2em .4em
.closet-list-autocomplete-item
a, span
font-size: 85%
padding-left: 2em
&.current-user &.current-user
#closet-hangers #closet-hangers

View file

@ -1,5 +1,5 @@
- show_controls ||= false # we could do user check here, but may as well do it once - show_controls ||= false # we could do user check here, but may as well do it once
.object .object{'data-item-id' => closet_hanger.item_id}
= render :partial => 'items/item_link', :locals => {:item => closet_hanger.item} = render :partial => 'items/item_link', :locals => {:item => closet_hanger.item}
.quantity{:class => "quantity-#{closet_hanger.quantity}"} .quantity{:class => "quantity-#{closet_hanger.quantity}"}
%span= closet_hanger.quantity %span= closet_hanger.quantity

View file

@ -189,11 +189,12 @@
itemsSearchField.addClass("loading"); itemsSearchField.addClass("loading");
var closetHanger = { var closetHanger = {
quantity: 1,
owned: group.owned, owned: group.owned,
list_id: ui.item.list ? ui.item.list.id : '' list_id: ui.item.list ? ui.item.list.id : ''
}; };
if(!item.hangerInGroup) closetHanger.quantity = 1;
$.ajax({ $.ajax({
url: "/user/" + itemsSearchForm.data("current-user-id") + "/items/" + item.id + "/closet_hanger", url: "/user/" + itemsSearchForm.data("current-user-id") + "/items/" + item.id + "/closet_hanger",
type: "post", type: "post",
@ -228,21 +229,29 @@
}); });
} else { // item was chosen, now choose a group to insert } else { // item was chosen, now choose a group to insert
var groupInserts = [], group; var groupInserts = [], group;
var item = input.term, itemEl, hangerInGroup, currentListId;
for(var i in hangerGroups) { for(var i in hangerGroups) {
group = hangerGroups[i]; group = hangerGroups[i];
itemEl = $('div.closet-hangers-group[data-owned=' + group.owned + '] div.object[data-item-id=' + item.id + ']');
hangerInGroup = itemEl.length > 0;
currentListId = itemEl.closest('.closet-list').attr('data-id');
groupInserts[groupInserts.length] = { groupInserts[groupInserts.length] = {
group: group, group: group,
item: input.term, item: item,
label: input.term.label label: item.label,
hangerInGroup: hangerInGroup,
hangerInList: !!currentListId
} }
for(var i = 0; i < group.lists.length; i++) { for(var i = 0; i < group.lists.length; i++) {
groupInserts[groupInserts.length] = { groupInserts[groupInserts.length] = {
group: group, group: group,
item: input.term, item: item,
label: input.term.label, label: item.label,
list: group.lists[i] list: group.lists[i],
hangerInGroup: hangerInGroup,
currentListId: currentListId
} }
} }
} }
@ -258,10 +267,28 @@
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 } else if(item.list) { // these are list inserts
li.append("<a>Add to <strong>" + item.list.label + "</strong>"). if(item.hangerInGroup) {
addClass("closet-list-autocomplete-item"); if(item.currentListId == item.list.id) {
li.append("<span>It's in <strong>" + item.list.label + "</strong> now");
} else {
li.append("<a>Move to <strong>" + item.list.label + "</strong>");
}
} else {
li.append("<a>Add to <strong>" + item.list.label + "</strong>");
}
li.addClass("closet-list-autocomplete-item");
} else { // these are group inserts } else { // these are group inserts
li.append("<a>Add to <strong>" + item.group.label + "</strong>"); if(item.hangerInGroup) {
var groupName = item.group.label;
if(item.hangerInList) {
li.append("<a>Move to <strong>" + groupName.replace(/\s+$/, '') + "</strong>, no list");
} else {
li.append("<span>It's in <strong>" + groupName + "</strong> now");
}
} else {
li.append("<a>Add to <strong>" + item.group.label + "</strong>");
}
li.addClass('closet-hangers-group-autocomplete-item');
} }
return li.appendTo(ul); return li.appendTo(ul);
} }

View file

@ -871,22 +871,27 @@ 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 180, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 181, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index .closet-list-autocomplete-item a { body.closet_hangers-index .closet-hangers-group-autocomplete-item span, body.closet_hangers-index .closet-list-autocomplete-item span {
font-style: italic;
padding: 0.2em 0.4em;
}
/* line 186, ../../../app/stylesheets/closet_hangers/_index.sass */
body.closet_hangers-index .closet-list-autocomplete-item a, body.closet_hangers-index .closet-list-autocomplete-item span {
font-size: 85%; font-size: 85%;
padding-left: 2em; padding-left: 2em;
} }
/* line 187, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 193, ../../../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 190, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 196, ../../../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 195, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 201, ../../../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;
@ -927,7 +932,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 198, ../../../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 { body.closet_hangers-index.current-user #closet-hangers .object:hover .quantity {
-moz-opacity: 1; -moz-opacity: 1;
-webkit-opacity: 1; -webkit-opacity: 1;
@ -937,73 +942,73 @@ body.closet_hangers-index.current-user #closet-hangers .object:hover .quantity {
top: 56px; top: 56px;
padding: 0; padding: 0;
} }
/* line 204, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 210, ../../../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 207, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 213, ../../../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 211, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 217, ../../../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 216, ../../../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 { body.closet_hangers-index.current-user.js #closet-hangers .object:hover .quantity {
display: block; display: block;
} }
/* line 219, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 225, ../../../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 222, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 228, ../../../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 225, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 231, ../../../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 229, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 235, ../../../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 232, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 238, ../../../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 236, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 242, ../../../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 239, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 245, ../../../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 243, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 249, ../../../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 246, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 252, ../../../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 251, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 257, ../../../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 254, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 260, ../../../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 258, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 264, ../../../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 261, ../../../app/stylesheets/closet_hangers/_index.sass */ /* line 267, ../../../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;
} }