-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1793 from jhawthorn/currency_selector
Number with currency widget
- Loading branch information
Showing
18 changed files
with
140 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
backend/app/assets/javascripts/spree/backend/components/number_with_currency.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Spree.initNumberWithCurrency = function() { | ||
$('.js-number-with-currency').each(function() { | ||
var view = new Spree.Views.NumberWithCurrency({ | ||
el: this, | ||
}); | ||
view.render(); | ||
}); | ||
} | ||
|
||
$(function() { | ||
Spree.initNumberWithCurrency() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
backend/app/assets/javascripts/spree/backend/views/number_with_currency.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Spree.Views.NumberWithCurrency = Backbone.View.extend({ | ||
events: { | ||
'change input,select': "render" | ||
}, | ||
|
||
initialize: function() { | ||
this.$currencySelector = this.$('.number-with-currency-select select'); | ||
}, | ||
|
||
getCurrency: function() { | ||
if (this.$currencySelector.length) { | ||
return this.$currencySelector.find('option:selected').val(); | ||
} else { | ||
return this.$('[data-currency]').data("currency"); | ||
} | ||
}, | ||
|
||
getCurrencySymbol: function() { | ||
var currency = this.getCurrency(); | ||
if (currency) { | ||
var currencyInfo = Spree.currencyInfo[currency]; | ||
return currencyInfo[0]; | ||
} else { | ||
return ''; | ||
} | ||
}, | ||
|
||
render: function() { | ||
this.$('.number-with-currency-symbol').text(this.getCurrencySymbol()); | ||
} | ||
}); |
32 changes: 32 additions & 0 deletions
32
backend/app/assets/stylesheets/spree/backend/components/_number_with_currency.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.number-with-currency { | ||
&-symbol { | ||
min-width: 2.5em; | ||
} | ||
|
||
&-amount { | ||
text-align: right; | ||
} | ||
|
||
&-addon { | ||
width: 5.5rem; | ||
text-align: left; | ||
} | ||
|
||
& &-select { | ||
padding: 0; | ||
background: $input-bg; | ||
|
||
select { | ||
@extend .c-select; | ||
|
||
width: 100%; | ||
height: $input-height; | ||
border: 0; | ||
|
||
&::-ms-expand { | ||
// Required to see full text of selected value on IE11 | ||
display: none; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
backend/app/views/spree/admin/promotions/calculators/flat_rate/_fields.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%= fields_for "#{prefix}[calculator_attributes]", calculator do |f| %> | ||
<%= f.label :preferred_amount %> | ||
<%= render "spree/admin/shared/number_with_currency", f: f, amount_attr: :preferred_amount, currency_attr: :preferred_currency %> | ||
<% end %> |
13 changes: 5 additions & 8 deletions
13
backend/app/views/spree/admin/promotions/rules/_item_total.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
backend/app/views/spree/admin/shared/_number_with_currency.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<% amount_attr ||= :amount %> | ||
<% currency_attr ||= :currency %> | ||
<% currency ||= nil %> | ||
<% required ||= nil %> | ||
|
||
<div class="input-group number-with-currency js-number-with-currency"> | ||
<div class="input-group-addon number-with-currency-symbol"></div> | ||
<%= f.text_field amount_attr, value: number_to_currency(f.object.public_send(amount_attr), unit: ''), class: 'form-control number-with-currency-amount', required: required %> | ||
<% if currency %> | ||
<div class="input-group-addon number-with-currency-addon" data-currency="<%= currency %>"> | ||
<%= ::Money::Currency.find(currency).iso_code %> | ||
</div> | ||
<% else %> | ||
<div class="input-group-addon number-with-currency-addon number-with-currency-select"> | ||
<%= f.select currency_attr, ::Money::Currency.all.map(&:iso_code), {include_blank: true}, {required: required} %> | ||
</div> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters