Commit 8c66d3773b03b2f7cd97ec61aeca220bef0a098e

Authored by Daniela Feitosa
1 parent e2854d1b

Fixed problem with NaN on progressbar

app/controllers/my_profile/manage_products_controller.rb
... ... @@ -138,7 +138,7 @@ class ManageProductsController < ApplicationController
138 138  
139 139 def display_inputs_cost
140 140 @product = @profile.products.find(params[:id])
141   - render :partial => 'inputs_cost'
  141 + render :inline => "<%= float_to_currency(@product.inputs_cost) %>"
142 142 end
143 143  
144 144 def destroy
... ...
app/views/manage_products/_display_price_details.rhtml
... ... @@ -5,7 +5,7 @@
5 5 <li>
6 6 <div class='price-detail-name'><%= _('Inputs:') %></div>
7 7 <div class='price-detail-price inputs-cost'>
8   - <%= render :partial => 'inputs_cost' %>
  8 + <span><%= float_to_currency(@product.inputs_cost) %></span>
9 9 </div>
10 10 </li>
11 11 <% @product.price_details.each do |price_detail| %>
... ...
app/views/manage_products/_inputs_cost.rhtml
... ... @@ -1,5 +0,0 @@
1   -<span><%= float_to_currency(@product.inputs_cost) %></span>
2   -
3   -<div id='price-described-notice' style='display:none;'>
4   - <%= _("Congratulations! Now the product's price is open to the public") %>
5   -</div>
app/views/manage_products/_manage_product_details.rhtml
... ... @@ -7,8 +7,12 @@
7 7 <table id='display-product-price-details'>
8 8 <tr>
9 9 <td><%= _('Inputs') %></td>
10   - <td class='inputs-cost'><%= float_to_currency(@product.inputs_cost) %></td>
11   - <td><small><%= _('This value is composed by the total value of registered inputs') %></small></td>
  10 + <td class='inputs-cost'>
  11 + <span><%= float_to_currency(@product.inputs_cost) %></span>
  12 + </td>
  13 + <td>
  14 + <small><%= _('This value is composed by the total value of registered inputs') %></small>
  15 + </td>
12 16 </tr>
13 17 <%= render :partial => 'edit_price_details', :locals => {:price_details => @product.price_details} %>
14 18 </table>
... ...
app/views/manage_products/_price_composition_bar.rhtml
... ... @@ -17,7 +17,6 @@
17 17 <%= price_composition_progressbar_text(@product) %>
18 18 </div>
19 19 </div>
20   - <div id='progressbar-icon' class='ui-icon ui-icon-info'></div>
21   - <span id='price-not-described-message' style='display:none'><%= _("The production cost of your product is not described yet. If you want to display the price composition, please add all the costs") %></span>
22   - <span id='price-described-message' style='display:none'><%= _("The production cost of your product is fully described and will be displayed on your product's page") %></span>
  20 + <div id='progressbar-icon' class='ui-icon ui-icon-info' data-price-not-described-message='<%= _("The production cost of your product is not described yet. If you want to display the price composition, please add all the costs") %>' data-price-described-message='<%= _("The production cost of your product is fully described and will be displayed on your product's page") %>' data-price-described-notice='<%= _("Congratulations! Now the price is open to the public") %>'>
  21 +</div>
23 22 </div>
... ...
public/javascripts/manage-products.js
... ... @@ -32,7 +32,7 @@
32 32 $("#manage-product-details-button").show();
33 33 });
34 34 if ($('#progressbar-icon').hasClass('ui-icon-check')) {
35   - display_notice($('#price-described-notice').show());
  35 + display_notice($('#progressbar-icon').attr('data-price-described-notice'));
36 36 }
37 37 return false;
38 38 });
... ... @@ -55,11 +55,11 @@
55 55  
56 56 $("form.edit_input").live('submit', function(data) {
57 57 var form = this;
58   - updatePriceCompositionBar(form);
59 58 inputs_cost_update_url = $(form).find('#inputs-cost-update-url').val();
60 59 $.get(inputs_cost_update_url, function(data){
61 60 $(".inputs-cost span").html(data);
62 61 });
  62 + updatePriceCompositionBar(form);
63 63 return false;
64 64 });
65 65  
... ... @@ -71,18 +71,18 @@
71 71 $("#display-manage-price-details").html('');
72 72 };
73 73  
74   - function updatePriceCompositionBar(form) {
75   - bar_url = $(form).find('.bar-update-url').val();
76   - $.get(bar_url, function(data){
77   - $("#price-composition-bar").html(data);
78   - $('form #product_price').val(currencyToFloat($('#progressbar-text .product_price').html(), currency_format.separator, currency_format.delimiter));
79   - $('form #product_inputs_cost').val(currencyToFloat($('#display-product-price-details .inputs-cost span').html(), currency_format.separator, currency_format.delimiter, currency_format.unit));
80   - calculateValuesForBar();
81   - });
82   - };
83   -
84 74 })(jQuery);
85 75  
  76 +function updatePriceCompositionBar(form) {
  77 + bar_url = jQuery(form).find('.bar-update-url').val();
  78 + jQuery.get(bar_url, function(data){
  79 + jQuery("#price-composition-bar").html(data);
  80 + jQuery('form #product_price').val(currencyToFloat(jQuery('#progressbar-text .product_price').html(), currency_format.separator, currency_format.delimiter));
  81 + jQuery('form #product_inputs_cost').val(currencyToFloat(jQuery('#display-product-price-details .inputs-cost span').html(), currency_format.separator, currency_format.delimiter, currency_format.unit));
  82 + calculateValuesForBar();
  83 + });
  84 +};
  85 +
86 86 function enablePriceDetailSubmit() {
87 87 jQuery('#manage-product-details-form input.submit').removeAttr("disabled").removeClass('disabled');
88 88 }
... ... @@ -125,7 +125,7 @@ function floatToCurrency(value, sep, del, cur) {
125 125  
126 126 function currencyToFloat(value, sep, del, cur) {
127 127 var val = value;
128   - if (cur) val.replace(cur + ' ', '');
  128 + if (cur) val = val.replace(cur + ' ', '');
129 129 if (!sep) sep = '.';
130 130 if (!del) del = ',';
131 131 return parseFloat(val.replace(del, '').replace(sep, '.'));
... ... @@ -166,11 +166,11 @@ function priceCompositionBar(value, described, total_cost, price) {
166 166 $(bar_area).find('.product_price').html(floatToCurrency(price, currency_format.separator, currency_format.delimiter));
167 167 if (described) {
168 168 $(bar_area).find('#progressbar-icon').addClass('ui-icon-check');
169   - $(bar_area).find('#progressbar-icon').attr('title', $('#price-described-message').html());
  169 + $(bar_area).find('#progressbar-icon').attr('title', $('#progressbar-icon').attr('data-price-described-message'));
170 170 $(bar_area).find('div.ui-progressbar-value').addClass('price-described');
171 171 } else {
172 172 $(bar_area).find('#progressbar-icon').removeClass('ui-icon-check');
173   - $(bar_area).find('#progressbar-icon').attr('title', $('#price-not-described-message').html());
  173 + $(bar_area).find('#progressbar-icon').attr('title', $('#progressbar-icon').attr('data-price-not-described-message'));
174 174 $(bar_area).find('div.ui-progressbar-value').removeClass('price-described');
175 175  
176 176 }
... ...