Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More abstract interaction with front end application

  • Loading branch information...
commit 2ad17e813790cdd6b9aef567e3e8cee3d523b23d 1 parent a45844b
@alexshuhin alexshuhin authored
View
29 app/views/compare_products/add.js.erb
@@ -1,29 +1,16 @@
-showComparePopup();
<% if @added_product %>
- $("#comparable_products").append("<%= escape_javascript(render(:partial => "shared/comparable_line_item", :object => @added_product)) %>");
- $("#comp_item_<%= @added_product.id %>").hide().slideDown();
- $("#compare_products").html("<%= t(:compare_products, :scope => :compare_products, :count => @comparable_products.count + 1) %>");
+var line_item = "<%= escape_javascript(render(:partial => "shared/comparable_line_item", :object => @added_product)) %>";
+var product_id = <%= @added_product.id %>
+onAddCompareProduct(line_item, product_id);
<% end %>
-notice_div = $("div.notice");
-error_div = $("div.errors");
<% notice = flash.delete(:notice)
if notice %>
- error_div.hide();
- if (notice_div.length > 0) {
- notice_div.html("<%= notice %>");
- notice_div.show();
- } else {
- $("#content").prepend('<div class="flash notice"><%= notice %></div>');
- } <%
-end
+ var notice = "<%= notice %>";
+ onCompareProductNotice(notice);
+<% end
error = flash.delete(:error)
if error %>
- notice_div.hide();
- if (error_div.length > 0) {
- error_div.html("<%= notice %>");
- error_div.show();
- } else {
- $("#content").prepend('<div class="flash errors"><%= error %></div>');
- }
+ var error = "<%= error %>";
+ onCompareProductError(error);
<% end %>
View
27 app/views/compare_products/remove.js.erb
@@ -1,28 +1,15 @@
-showComparePopup();
<% if @deleted_product %>
- $("#comp_item_<%= @deleted_product.id %>").slideUp(function() { $(this).remove() });
- $("#compare_products").html("<%= t(:compare_products, :scope => :compare_products, :count => @comparable_products.count - 1) %>");
+var product_id = <%= @deleted_product.id %>
+onRemoveCompareProduct(product_id);
<% end %>
-notice_div = $("div.notice");
-error_div = $("div.errors");
<% notice = flash.delete(:notice)
if notice %>
- error_div.hide();
- if (notice_div.length > 0) {
- notice_div.html("<%= notice %>");
- notice_div.show();
- } else {
- $("#content").prepend('<div class="flash notice"><%= notice %></div>');
- } <%
-end
+ var notice = "<%= notice %>";
+ onCompareProductNotice(notice);
+<% end
error = flash.delete(:error)
if error %>
- notice_div.hide();
- if (error_div.length > 0) {
- error_div.html("<%= notice %>");
- error_div.show();
- } else {
- $("#content").prepend('<div class="flash errors"><%= error %></div>');
- }
+ var error = "<%= error %>";
+ onCompareProductError(error);
<% end %>
View
1  app/views/shared/_comparable_products.html.erb
@@ -3,6 +3,7 @@
<ul id="comparable_products">
<%= render :partial => 'shared/comparable_line_item', :collection => @comparable_products %>
</ul>
+ <div style="display: none" class="no_products_message"><%= t(:no_products_to_compare, :scope => :compare_products) %></div>
<div id="compare_products_link"><%= link_to t(:compare, :scope => :compare_products), compare_products_path %></div>
<div id="clear_comparable_products_link"><%= link_to t(:compare_clear, :scope => :compare_products), destroy_comparison_path %></div>
</div>
View
8 app/views/shared/_compare_product_javascript.html.erb
@@ -8,4 +8,12 @@
function onRemoveCompareProduct() {
// override in your application
}
+
+ function onCompareProductNotice() {
+ // override in your application
+ }
+
+ function onCompareProductError() {
+ // override in your application
+ }
</script>
View
1  config/locales/en-US.yml
@@ -9,3 +9,4 @@ en:
product_comparison: Product comparison
taxon_not_comparable: "Products inside this taxon can't be compared"
add_to_comparison: "Compare"
+ no_products_to_compare: "There is no products to compare"
View
3  config/locales/ru.yml
@@ -16,4 +16,5 @@ ru:
limit_is_reached: "Вы можете сравнить не более %{count} товаров одновременно."
product_comparison: "Сравнение товаров"
removed_from_comparsion: "%{product} убран из сравнения"
- taxon_not_comparable: "Товары данной категории не могут быть сравнены."
+ taxon_not_comparable: "Товары данной категории не могут быть сравнены."
+ no_products_to_compare: "Вы можете добавить товары к сравнению, воспользовавшись соответствующей ссылкой на странице просмотра товара."
View
8 public/javascripts/product_comparison.js
@@ -97,11 +97,3 @@ var ProductComparison = function(params) {
_init(); // Initialize product comparison
}
-
-
-$(document).ready(function() {
- var productComparison = new ProductComparison();
- $('#comparable_products li a').live('ajax:before', function() {
- $(this).parent('li').fadeOut();
- });
-});

0 comments on commit 2ad17e8

Please sign in to comment.
Something went wrong with that request. Please try again.