Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative coh red #2682

Merged
merged 1 commit into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/app/assets/javascripts/spree/backend/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//= require spree/backend/product_picker
//= require spree/backend/option_value_picker
//= require spree/backend/taxons
//= require spree/backend/highlight_negative_numbers

/**
This is a collection of javascript functions and whatnot
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Spree.ready(function() {
// Highlight negative numbers in red.
document.querySelector('body').addEventListener('input', function(e){
var el = e.target;
var isInputNumber = el instanceof HTMLInputElement && el.type == 'number';
if (isInputNumber) {
if (el.value < 0) {
el.classList.add("negative");
} else {
el.classList.remove("negative");
}
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@
<td>
{{#if editing}}
<form>
<input class="fullwidth" name="count_on_hand" type="number" value="{{count_on_hand}}">
<input
{{#if negative}}
class="fullwidth negative"
{{else}}
class="fullwidth"
{{/if}}
name="count_on_hand"
type="number"
value="{{count_on_hand}}"
>
</form>
{{else}}
<span>{{count_on_hand}}</span>
<span {{#if negative}}class="negative"{{/if}}>{{count_on_hand}}</span>
{{/if}}
</td>
<td class="actions">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Spree.Views.Stock.EditStockItemRow = Backbone.View.extend({
initialize: function(options) {
this.stockLocationName = options.stockLocationName;
this.editing = false;
this.negative = this.model.attributes.count_on_hand < 0;
this.render();
},

Expand All @@ -19,7 +20,8 @@ Spree.Views.Stock.EditStockItemRow = Backbone.View.extend({
render: function() {
var renderAttr = {
stockLocationName: this.stockLocationName,
editing: this.editing
editing: this.editing,
negative: this.negative
};
_.extend(renderAttr, this.model.attributes);
this.$el.attr("data-variant-id", this.model.get('variant_id'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ dl {
.red { color: $color-5 }
.yellow { color: $color-6 }

.negative { color: $red }
input[type="number"].negative { color: $red } // needed to override blue style that is more specific than '.negative'

.no-objects-found {
text-align: center;
font-size: 120%;
Expand Down