Your Items autocomplete supports lists
This commit is contained in:
parent
358840076c
commit
d893b0ab41
6 changed files with 68 additions and 31 deletions
|
@ -40,7 +40,8 @@ class ClosetHangersController < ApplicationController
|
|||
if @closet_hanger.save
|
||||
respond_to do |format|
|
||||
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
|
||||
flash[:success] = "#{message}."
|
||||
redirect_back!(@item)
|
||||
|
|
|
@ -177,6 +177,10 @@ body.closet_hangers-index
|
|||
&:last-child
|
||||
border-bottom: 0
|
||||
|
||||
.closet-list-autocomplete-item a
|
||||
font-size: 85%
|
||||
padding-left: 2em
|
||||
|
||||
&.current-user
|
||||
#closet-hangers
|
||||
.object:hover
|
||||
|
|
|
@ -49,9 +49,7 @@
|
|||
.closet-hangers-group{'data-owned' => owned.to_s}
|
||||
%header
|
||||
%h3
|
||||
Items
|
||||
= closet_hanger_subject
|
||||
%span.verb= closet_hanger_verb(owned)
|
||||
Items #{closet_hanger_subject} #{closet_hanger_verb(owned)}
|
||||
%span.toggle.show show
|
||||
%span.toggle.hide hide
|
||||
= link_to_add_closet_list 'Add new list', :owned => owned, :class => 'add-closet-list'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.closet-list
|
||||
.closet-list{'data-id' => closet_list.id}
|
||||
%header
|
||||
- if show_controls
|
||||
.closet-list-controls
|
||||
|
|
|
@ -9,8 +9,22 @@
|
|||
|
||||
$('div.closet-hangers-group').each(function () {
|
||||
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] = {
|
||||
label: el.find('span.verb').text(),
|
||||
label: el.find('h3').text(),
|
||||
lists: lists,
|
||||
owned: (el.attr('data-owned') == 'true')
|
||||
};
|
||||
});
|
||||
|
@ -176,7 +190,8 @@
|
|||
|
||||
var closetHanger = {
|
||||
quantity: 1,
|
||||
owned: group.owned
|
||||
owned: group.owned,
|
||||
list_id: ui.item.list ? ui.item.list.id : ''
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
|
@ -212,13 +227,24 @@
|
|||
callback(output);
|
||||
});
|
||||
} else { // item was chosen, now choose a group to insert
|
||||
var groupInserts = [];
|
||||
var groupInserts = [], group;
|
||||
for(var i in hangerGroups) {
|
||||
group = hangerGroups[i];
|
||||
|
||||
groupInserts[groupInserts.length] = {
|
||||
group: hangerGroups[i],
|
||||
group: group,
|
||||
item: input.term,
|
||||
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);
|
||||
}
|
||||
|
@ -231,8 +257,11 @@
|
|||
var li = $("<li></li>").data("item.autocomplete", item);
|
||||
if(item.is_item) { // these are items from the server
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -871,17 +871,22 @@ body.closet_hangers-index .closet-list:hover .closet-list-controls {
|
|||
body.closet_hangers-index .closet-list:last-child {
|
||||
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 {
|
||||
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 {
|
||||
position: absolute;
|
||||
right: 18px;
|
||||
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 {
|
||||
/* http://www.zurb.com/blog_uploads/0000/0617/buttons-03.html */
|
||||
-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 {
|
||||
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 {
|
||||
-moz-opacity: 1;
|
||||
-webkit-opacity: 1;
|
||||
|
@ -932,73 +937,73 @@ body.closet_hangers-index.current-user #closet-hangers .object:hover .quantity {
|
|||
top: 56px;
|
||||
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 {
|
||||
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] {
|
||||
padding: 2px;
|
||||
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] {
|
||||
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 {
|
||||
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] {
|
||||
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] {
|
||||
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 {
|
||||
background: #eeffee;
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
display: block;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue