Commit 9a2d62543f4d019f55bbae8d7ac4f456816edcda

Authored by Rodrigo Souto
1 parent eb68553a

[shopping-cart-plugin] Fixing Chromium problem

  * The history.go used to revert the url don't work properly on
    chromium. We're commenting it for now to avoid problems.
  * Also fixing the show/hide feature.
plugins/shopping_cart/controllers/shopping_cart_plugin_profile_controller.rb
@@ -108,6 +108,48 @@ class ShoppingCartPluginProfileController < ProfileController @@ -108,6 +108,48 @@ class ShoppingCartPluginProfileController < ProfileController
108 end 108 end
109 end 109 end
110 110
  111 + def visibility
  112 + render :text => session[:cart].has_key?(:visibility) ? session[:cart][:visibility].to_json : true.to_json
  113 + end
  114 +
  115 + def show
  116 + begin
  117 + session[:cart][:visibility] = true
  118 + render :text => {
  119 + :ok => true,
  120 + :message => _('Cart displayed.'),
  121 + :error => {:code => 0}
  122 + }.to_json
  123 + rescue Exception => exception
  124 + render :text => {
  125 + :ok => false,
  126 + :error => {
  127 + :code => 7,
  128 + :message => exception.message
  129 + }
  130 + }.to_json
  131 + end
  132 + end
  133 +
  134 + def hide
  135 + begin
  136 + session[:cart][:visibility] = false
  137 + render :text => {
  138 + :ok => true,
  139 + :message => _('Cart Hidden.'),
  140 + :error => {:code => 0}
  141 + }.to_json
  142 + rescue Exception => exception
  143 + render :text => {
  144 + :ok => false,
  145 + :error => {
  146 + :code => 8,
  147 + :message => exception.message
  148 + }
  149 + }.to_json
  150 + end
  151 + end
  152 +
111 private 153 private
112 154
113 def validate_same_enterprise 155 def validate_same_enterprise
plugins/shopping_cart/public/cart.js
@@ -6,13 +6,26 @@ function Cart(config) { @@ -6,13 +6,26 @@ function Cart(config) {
6 this.contentBox = $("#cart1 .cart-content"); 6 this.contentBox = $("#cart1 .cart-content");
7 this.itemsBox = $("#cart1 .cart-items"); 7 this.itemsBox = $("#cart1 .cart-items");
8 this.items = {}; 8 this.items = {};
  9 + this.empty = !config.hasProducts;
9 this.visible = false; 10 this.visible = false;
10 $(".cart-buy", this.cartElem).button({ icons: { primary: 'ui-icon-cart'} }); 11 $(".cart-buy", this.cartElem).button({ icons: { primary: 'ui-icon-cart'} });
11 - if (config.hasProducts) { 12 + if (!this.empty) {
12 $(this.cartElem).show(); 13 $(this.cartElem).show();
13 this.enterprise = config.enterprise; 14 this.enterprise = config.enterprise;
  15 + me = this;
  16 + $.ajax({
  17 + url: '/profile/'+ this.enterprise +'/plugins/shopping_cart/visibility',
  18 + dataType: 'json',
  19 + success: function(data, status, ajax){
  20 + me.visible = /^true$/i.test(data);
  21 + me.listProducts();
  22 + },
  23 + cache: false,
  24 + error: function(ajax, status, errorThrown) {
  25 + alert('Visibility - HTTP '+status+': '+errorThrown);
  26 + }
  27 + });
14 $(".cart-buy", this.cartElem).colorbox({href: '/profile/' + this.enterprise + '/plugins/shopping_cart/buy'}); 28 $(".cart-buy", this.cartElem).colorbox({href: '/profile/' + this.enterprise + '/plugins/shopping_cart/buy'});
15 - this.listProducts();  
16 } 29 }
17 } 30 }
18 31
@@ -63,17 +76,20 @@ function Cart(config) { @@ -63,17 +76,20 @@ function Cart(config) {
63 input.onchange = function() { 76 input.onchange = function() {
64 me.updateQuantity(this, this.itemId, this.value); 77 me.updateQuantity(this, this.itemId, this.value);
65 }; 78 };
66 - document.location.href = "#"+liId;  
67 - document.location.href = "#"+this.cartElem.id;  
68 - history.go(-2); 79 +// document.location.href = "#"+liId;
  80 +// document.location.href = "#"+this.cartElem.id;
  81 +// history.go(-2);
69 var liBg = li.css("background-color"); 82 var liBg = li.css("background-color");
70 li[0].style.backgroundColor = "#FF0"; 83 li[0].style.backgroundColor = "#FF0";
71 li.animate({ backgroundColor: liBg }, 1000); 84 li.animate({ backgroundColor: liBg }, 1000);
72 } 85 }
73 - if( !this.visible ) { 86 +
  87 + if (!clear && this.empty) $(this.cartElem).show();
  88 + if((!clear && this.empty) || (this.visible && clear)) {
74 this.contentBox.hide(); 89 this.contentBox.hide();
75 this.show(); 90 this.show();
76 } 91 }
  92 + this.empty = false;
77 } 93 }
78 94
79 Cart.prototype.updateQuantity = function(input, itemId, quantity) { 95 Cart.prototype.updateQuantity = function(input, itemId, quantity) {
@@ -135,7 +151,7 @@ function Cart(config) { @@ -135,7 +151,7 @@ function Cart(config) {
135 if(!this.enterprise) { 151 if(!this.enterprise) {
136 this.enterprise = enterprise; 152 this.enterprise = enterprise;
137 $(".cart-buy", this.cartElem).colorbox({href: '/profile/' + this.enterprise + '/plugins/shopping_cart/buy'}); 153 $(".cart-buy", this.cartElem).colorbox({href: '/profile/' + this.enterprise + '/plugins/shopping_cart/buy'});
138 - if( !this.visible ) $(this.cartElem).show(); 154 +// $(this.cartElem).show();
139 } 155 }
140 var me = this; 156 var me = this;
141 $.ajax({ 157 $.ajax({
@@ -183,6 +199,14 @@ function Cart(config) { @@ -183,6 +199,14 @@ function Cart(config) {
183 } 199 }
184 200
185 Cart.prototype.show = function() { 201 Cart.prototype.show = function() {
  202 + $.ajax({
  203 + url: '/profile/'+ this.enterprise +'/plugins/shopping_cart/show',
  204 + dataType: 'json',
  205 + cache: false,
  206 + error: function(ajax, status, errorThrown) {
  207 + alert('Show - HTTP '+status+': '+errorThrown);
  208 + }
  209 + });
186 this.visible = true; 210 this.visible = true;
187 this.contentBox.slideDown(500); 211 this.contentBox.slideDown(500);
188 $(".cart-toggle .str-show", this.cartElem).hide(); 212 $(".cart-toggle .str-show", this.cartElem).hide();
@@ -190,6 +214,14 @@ function Cart(config) { @@ -190,6 +214,14 @@ function Cart(config) {
190 214
191 } 215 }
192 Cart.prototype.hide = function() { 216 Cart.prototype.hide = function() {
  217 + $.ajax({
  218 + url: '/profile/'+ this.enterprise +'/plugins/shopping_cart/hide',
  219 + dataType: 'json',
  220 + cache: false,
  221 + error: function(ajax, status, errorThrown) {
  222 + alert('Hide - HTTP '+status+': '+errorThrown);
  223 + }
  224 + });
193 this.visible = false; 225 this.visible = false;
194 this.contentBox.slideUp(500); 226 this.contentBox.slideUp(500);
195 $(".cart-toggle .str-show", this.cartElem).show(); 227 $(".cart-toggle .str-show", this.cartElem).show();
@@ -231,6 +263,7 @@ function Cart(config) { @@ -231,6 +263,7 @@ function Cart(config) {
231 me.hide(); 263 me.hide();
232 me.enterprise = null; 264 me.enterprise = null;
233 me.updateTotal(); 265 me.updateTotal();
  266 + me.empty = true;
234 }); 267 });
235 } 268 }
236 }, 269 },