move closet-hanger-destroy form to JS
This commit is contained in:
parent
2876de2db0
commit
d132567931
6 changed files with 28 additions and 17 deletions
|
@ -74,27 +74,36 @@
|
||||||
// is through the autocompleter, which reinitializes anyway. Geez, this thing
|
// is through the autocompleter, which reinitializes anyway. Geez, this thing
|
||||||
// is begging for a rewrite, but today we're here for performance.
|
// is begging for a rewrite, but today we're here for performance.
|
||||||
$("#closet-hanger-update-tmpl").template("updateFormTmpl");
|
$("#closet-hanger-update-tmpl").template("updateFormTmpl");
|
||||||
|
$("#closet-hanger-destroy-tmpl").template("destroyFormTmpl");
|
||||||
onHangersInit(function () {
|
onHangersInit(function () {
|
||||||
// Super-lame hack to get the user ID from where it already is :/
|
// Super-lame hack to get the user ID from where it already is :/
|
||||||
var currentUserId = itemsSearchForm.data("current-user-id");
|
var currentUserId = itemsSearchForm.data("current-user-id");
|
||||||
$("#closet-hangers div.closet-hangers-group").each(function () {
|
$("#closet-hangers div.closet-hangers-group").each(function () {
|
||||||
var groupEl = $(this);
|
var groupEl = $(this);
|
||||||
var owned = groupEl.data("owned");
|
var owned = groupEl.data("owned");
|
||||||
|
|
||||||
groupEl.find("div.closet-list").each(function () {
|
groupEl.find("div.closet-list").each(function () {
|
||||||
var listEl = $(this);
|
var listEl = $(this);
|
||||||
var listId = listEl.data("id");
|
var listId = listEl.data("id");
|
||||||
|
|
||||||
listEl.find("div.object").each(function () {
|
listEl.find("div.object").each(function () {
|
||||||
var hangerEl = $(this);
|
var hangerEl = $(this);
|
||||||
var hangerId = hangerEl.data("id");
|
var hangerId = hangerEl.data("id");
|
||||||
var quantityEl = hangerEl.find("div.quantity");
|
var quantityEl = hangerEl.find("div.quantity");
|
||||||
var quantity = hangerEl.data("quantity");
|
var quantity = hangerEl.data("quantity");
|
||||||
|
|
||||||
$.tmpl("updateFormTmpl", {
|
$.tmpl("updateFormTmpl", {
|
||||||
|
user_id: currentUserId,
|
||||||
|
closet_hanger_id: hangerId,
|
||||||
quantity: quantity,
|
quantity: quantity,
|
||||||
list_id: listId,
|
list_id: listId,
|
||||||
owned: owned,
|
owned: owned
|
||||||
|
}).appendTo(quantityEl);
|
||||||
|
|
||||||
|
$.tmpl("destroyFormTmpl", {
|
||||||
user_id: currentUserId,
|
user_id: currentUserId,
|
||||||
closet_hanger_id: hangerId
|
closet_hanger_id: hangerId
|
||||||
}).appendTo(quantityEl);
|
}).appendTo(hangerEl);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,10 +17,10 @@ module ClosetListsHelper
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_sorted_hangers(list, show_controls)
|
def render_sorted_hangers(list)
|
||||||
render :partial => 'closet_hanger',
|
# TODO: do we still *need* the sort, now that 99% of items are translated?
|
||||||
:collection => list.hangers.sort { |x,y| x.item.name <=> y.item.name },
|
render partial: 'closet_hanger',
|
||||||
:locals => {:show_controls => show_controls}
|
collection: list.hangers.sort_by(&:item_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ class ClosetHanger < ActiveRecord::Base
|
||||||
|
|
||||||
attr_accessible :list_id, :owned, :quantity
|
attr_accessible :list_id, :owned, :quantity
|
||||||
|
|
||||||
|
delegate :name, to: :item, prefix: true
|
||||||
|
|
||||||
validates :item_id, :uniqueness => {:scope => [:user_id, :owned, :list_id]}
|
validates :item_id, :uniqueness => {:scope => [:user_id, :owned, :list_id]}
|
||||||
validates :quantity, :numericality => {:greater_than => 0}
|
validates :quantity, :numericality => {:greater_than => 0}
|
||||||
validates_presence_of :item, :user
|
validates_presence_of :item, :user
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
- show_controls ||= false # we could do user check here, but may as well do it once
|
|
||||||
%div{'class' => closet_hanger_partial_class(closet_hanger), 'data-item-id' => closet_hanger.item_id, 'data-quantity' => closet_hanger.quantity, 'data-id' => closet_hanger.id}
|
%div{'class' => closet_hanger_partial_class(closet_hanger), 'data-item-id' => closet_hanger.item_id, 'data-quantity' => closet_hanger.quantity, 'data-id' => closet_hanger.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
|
||||||
- if show_controls
|
|
||||||
= form_tag [current_user, closet_hanger], :method => :delete, :class => 'closet-hanger-destroy' do
|
|
||||||
= return_to_field_tag
|
|
||||||
= hidden_field_tag 'closet_hanger[owned]', closet_hanger.owned
|
|
||||||
= submit_tag t('.delete')
|
|
||||||
|
|
|
@ -92,16 +92,22 @@
|
||||||
= t '.autocomplete.already_in_collection_html',
|
= t '.autocomplete.already_in_collection_html',
|
||||||
collection_name: '${collection_name}'
|
collection_name: '${collection_name}'
|
||||||
|
|
||||||
|
|
||||||
|
-# Gotta do this weird subbing in the path, since the braces will be
|
||||||
|
-# escaped if they themselves are inserted. Probably deserves a more legit
|
||||||
|
-# method, especially if we ever need it again.
|
||||||
|
- templated_hanger_path = user_closet_hanger_path(user_id: '$0', id: '$1').sub('$0', '${user_id}').sub('$1', '${closet_hanger_id}')
|
||||||
%script#closet-hanger-update-tmpl{type: 'text/x-jquery-tmpl'}
|
%script#closet-hanger-update-tmpl{type: 'text/x-jquery-tmpl'}
|
||||||
-# Gotta do this weird subbing in the path, since the braces will be
|
= form_tag templated_hanger_path, method: :put, authenticity_token: false, class: 'closet-hanger-update' do
|
||||||
-# escaped if they themselves are inserted. Probably deserves a more
|
|
||||||
-# legit method, especially if we ever need it again.
|
|
||||||
= form_tag user_closet_hanger_path(user_id: '$0', id: '$1').sub('$0', '${user_id}').sub('$1', '${closet_hanger_id}'), method: :put, authenticity_token: false, class: 'closet-hanger-update' do
|
|
||||||
= hidden_field_tag 'closet_hanger[list_id]', '${list_id}'
|
= hidden_field_tag 'closet_hanger[list_id]', '${list_id}'
|
||||||
= hidden_field_tag 'closet_hanger[owned]', '${owned}'
|
= hidden_field_tag 'closet_hanger[owned]', '${owned}'
|
||||||
= number_field_tag 'closet_hanger[quantity]', '${quantity}',
|
= number_field_tag 'closet_hanger[quantity]', '${quantity}',
|
||||||
min: 0, required: true
|
min: 0, required: true
|
||||||
|
|
||||||
|
%script#closet-hanger-destroy-tmpl{type: 'text/x-jquery-tmpl'}
|
||||||
|
= form_tag templated_hanger_path, method: :delete, authenticity_token: false, class: 'closet-hanger-destroy' do
|
||||||
|
= submit_tag t('closet_hangers.closet_hanger.delete')
|
||||||
|
|
||||||
- content_for :stylesheets do
|
- content_for :stylesheets do
|
||||||
= stylesheet_link_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/themes/south-street/jquery-ui.css'
|
= stylesheet_link_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/themes/south-street/jquery-ui.css'
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
.closet-list-hangers
|
.closet-list-hangers
|
||||||
- unless closet_list.hangers.empty?
|
- unless closet_list.hangers.empty?
|
||||||
= render_sorted_hangers(closet_list, show_controls)
|
= render_sorted_hangers(closet_list)
|
||||||
|
|
||||||
%span.empty-list= t('.empty')
|
%span.empty-list= t('.empty')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue