forked from solidusio/solidus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix searching discarded products in admin by SKU
Now that we've got a new scope we can use that will correctly return products with discarded variants, we've updated the admin interface to use it. This meant adding a new Backbone view to help control the two inputs we now have on the page, one for each scope. It will hide and disable the appropriate input based on the value of the "with deleted" checkbox.
- Loading branch information
1 parent
defac40
commit 18762f7
Showing
7 changed files
with
91 additions
and
5 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
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
7 changes: 7 additions & 0 deletions
7
backend/app/assets/javascripts/spree/backend/products/index.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,7 @@ | ||
Spree.ready(function() { | ||
if ($('[data-hook="admin_products_index_search"]').length) { | ||
new Spree.Views.Product.Search({ | ||
el: $('[data-hook="admin_products_index_search"]') | ||
}) | ||
} | ||
}); |
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
44 changes: 44 additions & 0 deletions
44
backend/app/assets/javascripts/spree/backend/views/product/search.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,44 @@ | ||
Spree.Views.Product.Search = Backbone.View.extend({ | ||
initialize: function() { | ||
this.render(); | ||
}, | ||
|
||
events: { | ||
"change .js-with-discarded-input": "onChange" | ||
}, | ||
|
||
onChange: function(e) { | ||
const withDiscarded = $(e.target).is(":checked"); | ||
|
||
var keptInput = this.$el.find(".js-kept-variant-sku-input input"); | ||
var allInput = this.$el.find(".js-all-variant-sku-input input"); | ||
|
||
if (withDiscarded) { | ||
allInput.val(keptInput.val()); | ||
keptInput.val(""); | ||
} else { | ||
keptInput.val(allInput.val()); | ||
allInput.val(""); | ||
} | ||
|
||
allInput.prop("disabled", !withDiscarded) | ||
keptInput.prop("disabled", withDiscarded) | ||
|
||
this.render(); | ||
}, | ||
|
||
render: function() { | ||
var withDiscarded = this.$el.find(".js-with-discarded-input").is(":checked"); | ||
|
||
var keptContainer = this.$el.find(".js-kept-variant-sku-input"); | ||
var allContainer = this.$el.find(".js-all-variant-sku-input"); | ||
|
||
if (withDiscarded) { | ||
keptContainer.hide(); | ||
allContainer.show(); | ||
} else { | ||
keptContainer.show(); | ||
allContainer.hide(); | ||
} | ||
}, | ||
}); |
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