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 108 end
109 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 153 private
112 154  
113 155 def validate_same_enterprise
... ...
plugins/shopping_cart/public/cart.js
... ... @@ -6,13 +6,26 @@ function Cart(config) {
6 6 this.contentBox = $("#cart1 .cart-content");
7 7 this.itemsBox = $("#cart1 .cart-items");
8 8 this.items = {};
  9 + this.empty = !config.hasProducts;
9 10 this.visible = false;
10 11 $(".cart-buy", this.cartElem).button({ icons: { primary: 'ui-icon-cart'} });
11   - if (config.hasProducts) {
  12 + if (!this.empty) {
12 13 $(this.cartElem).show();
13 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 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 76 input.onchange = function() {
64 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 82 var liBg = li.css("background-color");
70 83 li[0].style.backgroundColor = "#FF0";
71 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 89 this.contentBox.hide();
75 90 this.show();
76 91 }
  92 + this.empty = false;
77 93 }
78 94  
79 95 Cart.prototype.updateQuantity = function(input, itemId, quantity) {
... ... @@ -135,7 +151,7 @@ function Cart(config) {
135 151 if(!this.enterprise) {
136 152 this.enterprise = enterprise;
137 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 156 var me = this;
141 157 $.ajax({
... ... @@ -183,6 +199,14 @@ function Cart(config) {
183 199 }
184 200  
185 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 210 this.visible = true;
187 211 this.contentBox.slideDown(500);
188 212 $(".cart-toggle .str-show", this.cartElem).hide();
... ... @@ -190,6 +214,14 @@ function Cart(config) {
190 214  
191 215 }
192 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 225 this.visible = false;
194 226 this.contentBox.slideUp(500);
195 227 $(".cart-toggle .str-show", this.cartElem).show();
... ... @@ -231,6 +263,7 @@ function Cart(config) {
231 263 me.hide();
232 264 me.enterprise = null;
233 265 me.updateTotal();
  266 + me.empty = true;
234 267 });
235 268 }
236 269 },
... ...