From 48ee76550579a19b0a48cafd3d31b1ad7e9bf367 Mon Sep 17 00:00:00 2001 From: Matchu Date: Fri, 29 Jul 2011 23:26:48 -0400 Subject: [PATCH] Your Items autocompleter is totally chill with moving items around to different lists --- app/stylesheets/closet_hangers/_index.sass | 12 +++-- .../closet_hangers/_closet_hanger.html.haml | 2 +- public/javascripts/closet_hangers/index.js | 45 ++++++++++++---- public/stylesheets/compiled/screen.css | 51 ++++++++++--------- 4 files changed, 74 insertions(+), 36 deletions(-) diff --git a/app/stylesheets/closet_hangers/_index.sass b/app/stylesheets/closet_hangers/_index.sass index d758fc9c..cda8d60b 100644 --- a/app/stylesheets/closet_hangers/_index.sass +++ b/app/stylesheets/closet_hangers/_index.sass @@ -177,9 +177,15 @@ body.closet_hangers-index &:last-child border-bottom: 0 - .closet-list-autocomplete-item a - font-size: 85% - padding-left: 2em + .closet-hangers-group-autocomplete-item, .closet-list-autocomplete-item + span + font-style: italic + padding: .2em .4em + + .closet-list-autocomplete-item + a, span + font-size: 85% + padding-left: 2em &.current-user #closet-hangers diff --git a/app/views/closet_hangers/_closet_hanger.html.haml b/app/views/closet_hangers/_closet_hanger.html.haml index 44a20148..ad7d3bec 100644 --- a/app/views/closet_hangers/_closet_hanger.html.haml +++ b/app/views/closet_hangers/_closet_hanger.html.haml @@ -1,5 +1,5 @@ - 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} .quantity{:class => "quantity-#{closet_hanger.quantity}"} %span= closet_hanger.quantity diff --git a/public/javascripts/closet_hangers/index.js b/public/javascripts/closet_hangers/index.js index 897863ff..74047135 100644 --- a/public/javascripts/closet_hangers/index.js +++ b/public/javascripts/closet_hangers/index.js @@ -189,11 +189,12 @@ itemsSearchField.addClass("loading"); var closetHanger = { - quantity: 1, owned: group.owned, list_id: ui.item.list ? ui.item.list.id : '' }; + if(!item.hangerInGroup) closetHanger.quantity = 1; + $.ajax({ url: "/user/" + itemsSearchForm.data("current-user-id") + "/items/" + item.id + "/closet_hanger", type: "post", @@ -228,21 +229,29 @@ }); } else { // item was chosen, now choose a group to insert var groupInserts = [], group; + var item = input.term, itemEl, hangerInGroup, currentListId; for(var i in hangerGroups) { 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] = { group: group, - item: input.term, - label: input.term.label + item: item, + label: item.label, + hangerInGroup: hangerInGroup, + hangerInList: !!currentListId } 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] + item: item, + label: item.label, + list: group.lists[i], + hangerInGroup: hangerInGroup, + currentListId: currentListId } } } @@ -258,10 +267,28 @@ if(item.is_item) { // these are items from the server li.append("Add " + item.label + ""); } else if(item.list) { // these are list inserts - li.append("Add to " + item.list.label + ""). - addClass("closet-list-autocomplete-item"); + if(item.hangerInGroup) { + if(item.currentListId == item.list.id) { + li.append("It's in " + item.list.label + " now"); + } else { + li.append("Move to " + item.list.label + ""); + } + } else { + li.append("Add to " + item.list.label + ""); + } + li.addClass("closet-list-autocomplete-item"); } else { // these are group inserts - li.append("Add to " + item.group.label + ""); + if(item.hangerInGroup) { + var groupName = item.group.label; + if(item.hangerInList) { + li.append("Move to " + groupName.replace(/\s+$/, '') + ", no list"); + } else { + li.append("It's in " + groupName + " now"); + } + } else { + li.append("Add to " + item.group.label + ""); + } + li.addClass('closet-hangers-group-autocomplete-item'); } return li.appendTo(ul); } diff --git a/public/stylesheets/compiled/screen.css b/public/stylesheets/compiled/screen.css index f1c41c04..746f4c08 100644 --- a/public/stylesheets/compiled/screen.css +++ b/public/stylesheets/compiled/screen.css @@ -871,22 +871,27 @@ body.closet_hangers-index .closet-list:hover .closet-list-controls { body.closet_hangers-index .closet-list:last-child { border-bottom: 0; } -/* line 180, ../../../app/stylesheets/closet_hangers/_index.sass */ -body.closet_hangers-index .closet-list-autocomplete-item a { +/* line 181, ../../../app/stylesheets/closet_hangers/_index.sass */ +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%; 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 { 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 { position: absolute; right: 18px; 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 { /* http://www.zurb.com/blog_uploads/0000/0617/buttons-03.html */ -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 { 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 { -moz-opacity: 1; -webkit-opacity: 1; @@ -937,73 +942,73 @@ body.closet_hangers-index.current-user #closet-hangers .object:hover .quantity { top: 56px; 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 { 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] { padding: 2px; 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] { 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 { 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] { 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] { 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 { background: #eeffee; 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { display: block; }