solidus_backend 2.7.4 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_backend might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +12 -8
- data/app/assets/images/favicon.ico +0 -0
- data/app/assets/javascripts/spree/backend.js +0 -2
- data/app/assets/javascripts/spree/backend/adjustments.js +1 -1
- data/app/assets/javascripts/spree/backend/components/tooltips.js +21 -17
- data/app/assets/javascripts/spree/backend/option_type_autocomplete.js +1 -1
- data/app/assets/javascripts/spree/backend/product_picker.js +1 -1
- data/app/assets/javascripts/spree/backend/shipments.js +6 -1
- data/app/assets/javascripts/spree/backend/stock_management.js +9 -0
- data/app/assets/javascripts/spree/backend/store_credits.js +18 -2
- data/app/assets/javascripts/spree/backend/taxons.js +1 -1
- data/app/assets/javascripts/spree/backend/templates/stock_items/stock_location_stock_item.hbs +24 -25
- data/app/assets/javascripts/spree/backend/user_picker.js +1 -1
- data/app/assets/javascripts/spree/backend/variant_autocomplete.js +1 -1
- data/app/assets/javascripts/spree/backend/views/order/customer_select.js +1 -1
- data/app/assets/javascripts/spree/backend/views/order/summary.js +2 -2
- data/app/assets/javascripts/spree/backend/views/stock/add_stock_item.js +15 -4
- data/app/assets/javascripts/spree/backend/views/stock/edit_stock_item_row.js +30 -10
- data/app/assets/stylesheets/spree/backend/globals/_functions.scss +1 -2
- data/app/assets/stylesheets/spree/backend/sections/_orders.scss +8 -0
- data/app/assets/stylesheets/spree/backend/sections/_stock_management.scss +77 -2
- data/app/assets/stylesheets/spree/backend/spree_admin.scss +0 -1
- data/app/controllers/spree/admin/cancellations_controller.rb +2 -2
- data/app/controllers/spree/admin/locale_controller.rb +1 -1
- data/app/controllers/spree/admin/orders/customer_details_controller.rb +8 -1
- data/app/controllers/spree/admin/orders_controller.rb +1 -11
- data/app/controllers/spree/admin/products_controller.rb +10 -6
- data/app/controllers/spree/admin/promotion_codes_controller.rb +19 -1
- data/app/controllers/spree/admin/promotions_controller.rb +1 -1
- data/app/controllers/spree/admin/reimbursements_controller.rb +7 -2
- data/app/controllers/spree/admin/resource_controller.rb +1 -0
- data/app/controllers/spree/admin/store_credit_reasons_controller.rb +8 -0
- data/app/controllers/spree/admin/store_credits_controller.rb +11 -11
- data/app/helpers/spree/admin/navigation_helper.rb +1 -1
- data/app/models/spree/backend_configuration.rb +38 -21
- data/app/views/spree/admin/cancellations/index.html.erb +3 -1
- data/app/views/spree/admin/images/_image_row.html.erb +1 -1
- data/app/views/spree/admin/images/edit.html.erb +3 -3
- data/app/views/spree/admin/images/index.html.erb +2 -2
- data/app/views/spree/admin/log_entries/index.html.erb +2 -2
- data/app/views/spree/admin/orders/_carton_manifest.html.erb +3 -1
- data/app/views/spree/admin/orders/_shipment_manifest.html.erb +3 -1
- data/app/views/spree/admin/orders/confirm/_line_items.html.erb +3 -2
- data/app/views/spree/admin/orders/confirm/_shipment_manifest.html.erb +3 -1
- data/app/views/spree/admin/orders/index.html.erb +1 -1
- data/app/views/spree/admin/products/_form.html.erb +7 -7
- data/app/views/spree/admin/products/edit.html.erb +5 -0
- data/app/views/spree/admin/products/index.html.erb +3 -1
- data/app/views/spree/admin/promotion_categories/index.html.erb +1 -1
- data/app/views/spree/admin/promotion_code_batches/index.html.erb +1 -1
- data/app/views/spree/admin/promotion_codes/index.html.erb +5 -1
- data/app/views/spree/admin/promotion_codes/new.html.erb +31 -0
- data/app/views/spree/admin/promotions/_actions.html.erb +1 -1
- data/app/views/spree/admin/promotions/_activations_edit.html.erb +1 -1
- data/app/views/spree/admin/promotions/_form.html.erb +4 -3
- data/app/views/spree/admin/promotions/_rules.html.erb +1 -1
- data/app/views/spree/admin/promotions/edit.html.erb +3 -1
- data/app/views/spree/admin/refunds/new.html.erb +1 -1
- data/app/views/spree/admin/shared/_address_form.html.erb +10 -3
- data/app/views/spree/admin/shared/_edit_resource_links.html.erb +1 -1
- data/app/views/spree/admin/shared/_head.html.erb +1 -0
- data/app/views/spree/admin/shared/_image.html.erb +2 -2
- data/app/views/spree/admin/shared/_product_sub_menu.html.erb +1 -1
- data/app/views/spree/admin/shared/_settings_checkout_tabs.html.erb +4 -0
- data/app/views/spree/admin/shared/_settings_sub_menu.html.erb +3 -3
- data/app/views/spree/admin/shared/_tabs.html.erb +3 -2
- data/app/views/spree/admin/shared/_variant_search.html.erb +1 -1
- data/app/views/spree/admin/stock_items/_stock_management.html.erb +56 -38
- data/app/views/spree/admin/stock_locations/_form.html.erb +133 -121
- data/app/views/spree/admin/stock_locations/edit.html.erb +4 -2
- data/app/views/spree/admin/store_credit_reasons/edit.html.erb +15 -0
- data/app/views/spree/admin/store_credit_reasons/index.html.erb +56 -0
- data/app/views/spree/admin/store_credit_reasons/new.html.erb +18 -0
- data/app/views/spree/admin/store_credit_reasons/shared/_form.html.erb +15 -0
- data/app/views/spree/admin/store_credits/_store_credit_reason_field.html.erb +7 -0
- data/app/views/spree/admin/store_credits/edit_amount.html.erb +1 -1
- data/app/views/spree/admin/store_credits/edit_validity.html.erb +1 -1
- data/app/views/spree/admin/store_credits/show.html.erb +2 -2
- data/app/views/spree/admin/users/items.html.erb +3 -1
- data/app/views/spree/admin/users/orders.html.erb +1 -1
- data/config/routes.rb +2 -8
- data/lib/spree/backend.rb +1 -1
- data/solidus_backend.gemspec +3 -4
- data/spec/controllers/spree/admin/base_controller_spec.rb +1 -1
- data/spec/controllers/spree/admin/cancellations_controller_spec.rb +7 -3
- data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +50 -2
- data/spec/controllers/spree/admin/orders_controller_spec.rb +23 -11
- data/spec/controllers/spree/admin/payments_controller_spec.rb +1 -1
- data/spec/controllers/spree/admin/products_controller_spec.rb +72 -0
- data/spec/controllers/spree/admin/promotion_codes_controller_spec.rb +13 -1
- data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +11 -0
- data/spec/controllers/spree/admin/resource_controller_spec.rb +22 -0
- data/spec/controllers/spree/admin/stock_items_controller_spec.rb +1 -1
- data/spec/controllers/spree/admin/store_credits_controller_spec.rb +7 -7
- data/spec/features/admin/configuration/payment_methods_spec.rb +2 -2
- data/spec/features/admin/configuration/shipping_methods_spec.rb +2 -2
- data/spec/features/admin/homepage_spec.rb +1 -6
- data/spec/features/admin/orders/listing_spec.rb +1 -1
- data/spec/features/admin/orders/new_order_spec.rb +117 -0
- data/spec/features/admin/orders/new_refund_spec.rb +35 -0
- data/spec/features/admin/orders/order_details_spec.rb +2 -2
- data/spec/features/admin/orders/payments_spec.rb +2 -2
- data/spec/features/admin/orders/return_payment_state_spec.rb +3 -0
- data/spec/features/admin/orders/shipments_spec.rb +28 -0
- data/spec/features/admin/products/products_spec.rb +1 -1
- data/spec/features/admin/products/stock_management_spec.rb +10 -13
- data/spec/features/admin/promotion_adjustments_spec.rb +12 -12
- data/spec/features/admin/promotions/option_value_rule_spec.rb +2 -2
- data/spec/features/admin/promotions/product_rule_spec.rb +1 -1
- data/spec/features/admin/promotions/tiered_calculator_spec.rb +1 -1
- data/spec/features/admin/promotions/user_rule_spec.rb +2 -2
- data/spec/features/admin/reimbursements_spec.rb +1 -1
- data/spec/features/admin/store_credits_spec.rb +51 -2
- data/spec/features/admin/taxons_spec.rb +35 -0
- data/spec/features/admin/users_spec.rb +22 -11
- data/spec/helpers/admin/navigation_helper_spec.rb +4 -2
- data/spec/helpers/admin/store_credit_events_helper_spec.rb +2 -2
- data/spec/javascripts/spec_helper.js +2 -0
- data/spec/models/spree/backend_configuration/menu_item_spec.rb +17 -0
- data/spec/models/spree/backend_configuration_spec.rb +22 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/feature/order_feature_helper.rb +1 -1
- data/spec/views/spree/admin/shared/navigation_footer_spec.rb +1 -1
- data/vendor/assets/javascripts/solidus_admin/select2_locales/select2_locale_en-US.js +10 -0
- metadata +26 -34
- data/app/controllers/spree/admin/reports_controller.rb +0 -82
- data/app/views/spree/admin/reports/index.html.erb +0 -19
- data/app/views/spree/admin/reports/sales_total.html.erb +0 -35
- data/app/views/spree/admin/shared/_report_order_criteria.html.erb +0 -19
- data/app/views/spree/admin/store_credits/_update_reason_field.html.erb +0 -7
- data/spec/controllers/spree/admin/reports_controller_spec.rb +0 -133
- data/spec/features/admin/reports_spec.rb +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dbcdf9e9703176fcce09d9a18c80c599bef4e00cad4596227147ecaf10e87d8
|
4
|
+
data.tar.gz: ea64fd9b016d984994fb3c5cf85a1c9686238e40e866a6dbdc1c78886330bdc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c75cb7b2700aa34e75d7089661ee78f7dd0d242982bd8c8690d56b99a65ea2698ed4fe37f4343a3d64c16770295afc5e3e6a1d89af3df7256a37c36df900888
|
7
|
+
data.tar.gz: 248117bd08c0e93f947b3fb742a3184970454cd9b6ebe7589c91eacc9826fba287866756e9342f196e5cf7d0211e41608b6583676423ee82339c9ed3206abdfb
|
data/README.md
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
# solidus\_backend
|
2
2
|
|
3
|
-
Backend contains the controllers, views, and assets making up the admin interface of
|
3
|
+
Backend contains the controllers, views, and assets making up the admin interface of Solidus.
|
4
4
|
|
5
5
|
## Assets
|
6
6
|
|
7
|
-
###
|
7
|
+
### JavaScript
|
8
8
|
|
9
9
|
Can be found in [app/assets/javascripts/spree/backend/](./app/assets/javascripts/spree/backend/)
|
10
10
|
|
11
|
-
Our scripts are written in a mix of
|
11
|
+
Our scripts are written in a mix of CoffeeScript and JavaScript (ES5). We can't
|
12
12
|
easily use a transpiler for ECMAScript >= 6 without adding additional steps for
|
13
13
|
applications using solidus\_admin.
|
14
14
|
|
15
15
|
Though we have existing CoffeeScript files, any new files should be in
|
16
|
-
|
16
|
+
JavaScript (ES5).
|
17
17
|
|
18
18
|
### Stylesheets
|
19
19
|
|
20
20
|
Can be found in [app/assets/stylesheets/spree/backend/](./app/assets/stylesheets/spree/backend/)
|
21
21
|
|
22
|
-
The stylesheets are written in SCSS and include all of [
|
22
|
+
The stylesheets are written in SCSS and include all of [Bourbon](http://bourbon.io/docs/) and [Bootstrap 4 alpha](http://v4-alpha.getbootstrap.com/).
|
23
23
|
|
24
24
|
When running the application there is a styleguide available at:
|
25
25
|
|
@@ -31,8 +31,12 @@ When running the application there is a styleguide available at:
|
|
31
31
|
|
32
32
|
Run the tests
|
33
33
|
|
34
|
-
|
34
|
+
```bash
|
35
|
+
bundle exec rspec
|
36
|
+
```
|
35
37
|
|
36
|
-
Run the
|
38
|
+
Run the JavaScript tests (must have [ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/) installed)
|
37
39
|
|
38
|
-
|
40
|
+
```bash
|
41
|
+
bundle exec teaspoon
|
42
|
+
```
|
Binary file
|
@@ -3,26 +3,30 @@ Spree.ready(function(){
|
|
3
3
|
|
4
4
|
$('body').tooltip({selector: '.with-tip'});
|
5
5
|
|
6
|
+
/*
|
7
|
+
* Poll tooltips to hide them if they are no longer being hovered.
|
8
|
+
*
|
9
|
+
* This is necessary to fix tooltips hanging around after their attached
|
10
|
+
* element has been removed from the DOM (and will therefore receive no
|
11
|
+
* mouseleave event). This may be unnecessary in a future version of
|
12
|
+
* bootstrap, which intends to solve this using MutationObserver.
|
13
|
+
*/
|
14
|
+
var removeDesyncedTooltip = function(tooltip) {
|
15
|
+
var interval = setInterval(function(){
|
16
|
+
if(!$(tooltip.element).is(":hover")) {
|
17
|
+
tooltip.dispose();
|
18
|
+
clearInterval(interval);
|
19
|
+
}
|
20
|
+
}, 200);
|
21
|
+
$(tooltip.element).on('hidden.bs.tooltip', function(){
|
22
|
+
clearInterval(interval);
|
23
|
+
});
|
24
|
+
};
|
25
|
+
|
6
26
|
$('body').on('inserted.bs.tooltip', function(e){
|
7
27
|
var $target = $(e.target);
|
8
28
|
var tooltip = $target.data('bs.tooltip');
|
9
|
-
|
10
|
-
/*
|
11
|
-
* Observe target changes to understand if we need to remove tooltips.
|
12
|
-
*
|
13
|
-
* This is necessary to fix tooltips hanging around after their attached
|
14
|
-
* element has been removed from the DOM (and will therefore receive no
|
15
|
-
* mouseleave event).
|
16
|
-
*/
|
17
|
-
var observer = new MutationObserver(function(mutations) {
|
18
|
-
// disconnect itself when content is changed, a new observer will
|
19
|
-
// be attached to this element when the new tooltip is created.
|
20
|
-
this.disconnect();
|
21
|
-
|
22
|
-
tooltip.hide();
|
23
|
-
});
|
24
|
-
observer.observe($target.get(0), { attributes: true });
|
25
|
-
|
29
|
+
removeDesyncedTooltip(tooltip);
|
26
30
|
var $tooltip = $("#" + $target.attr("aria-describedby"));
|
27
31
|
$tooltip.addClass("action-" + $target.data("action"));
|
28
32
|
});
|
@@ -23,7 +23,7 @@ Spree.ready(function () {
|
|
23
23
|
url: Spree.routes.option_type_search,
|
24
24
|
quietMillis: 200,
|
25
25
|
datatype: 'json',
|
26
|
-
params: { "headers": {
|
26
|
+
params: { "headers": { 'Authorization': 'Bearer ' + Spree.api_key } },
|
27
27
|
data: function (term) {
|
28
28
|
return {
|
29
29
|
q: { name_cont: term }
|
@@ -23,7 +23,7 @@ $.fn.productAutocomplete = function (options) {
|
|
23
23
|
ajax: {
|
24
24
|
url: Spree.routes.admin_product_search,
|
25
25
|
datatype: 'json',
|
26
|
-
params: { "headers": {
|
26
|
+
params: { "headers": { 'Authorization': 'Bearer ' + Spree.api_key } },
|
27
27
|
data: function (term, page) {
|
28
28
|
return {
|
29
29
|
q: {
|
@@ -85,7 +85,12 @@ adjustShipmentItems = function(shipment_number, variant_id, quantity){
|
|
85
85
|
window.location.reload();
|
86
86
|
},
|
87
87
|
error: function(response) {
|
88
|
-
|
88
|
+
json = response.responseJSON;
|
89
|
+
message = json.error;
|
90
|
+
for (error in json.errors) {
|
91
|
+
message += '<br />' + json.errors[error].join();
|
92
|
+
}
|
93
|
+
window.show_flash('error', message);
|
89
94
|
}
|
90
95
|
});
|
91
96
|
}
|
@@ -2,11 +2,20 @@ Spree.ready(function() {
|
|
2
2
|
$('.js-edit-stock-item').each(function() {
|
3
3
|
var $el = $(this);
|
4
4
|
var model = new Spree.Models.StockItem($el.data('stock-item'));
|
5
|
+
var trackInventory = $el.data('track-inventory');
|
5
6
|
new Spree.Views.Stock.EditStockItemRow({
|
6
7
|
el: $el,
|
7
8
|
stockLocationName: $el.data('stock-location-name'),
|
8
9
|
model: model
|
9
10
|
});
|
11
|
+
|
12
|
+
if (trackInventory === false) {
|
13
|
+
$('.js-edit-stock-item input').attr({
|
14
|
+
disabled: true,
|
15
|
+
class: 'with-tip',
|
16
|
+
title: '"Track inventory" option disabled for this variant'
|
17
|
+
});
|
18
|
+
}
|
10
19
|
});
|
11
20
|
|
12
21
|
$('.js-add-stock-item').each(function() {
|
@@ -9,9 +9,25 @@ Spree.ready(function() {
|
|
9
9
|
field.defaultValue = field.value;
|
10
10
|
textDisplay.textContent = field.value;
|
11
11
|
|
12
|
-
|
12
|
+
if (typeof data !== "undefined") {
|
13
|
+
// we are using jquery_ujs
|
14
|
+
message = data.message
|
15
|
+
} else {
|
16
|
+
// we are using rails-ujs
|
17
|
+
message = event.detail[0].message
|
18
|
+
}
|
19
|
+
|
20
|
+
show_flash('success', message);
|
13
21
|
}).on('ajax:error', function(event, xhr, status, error) {
|
14
|
-
|
22
|
+
if (typeof xhr !== "undefined") {
|
23
|
+
// we are using jquery_ujs
|
24
|
+
message = xhr.responseJSON.message
|
25
|
+
} else {
|
26
|
+
// we are using rails-ujs
|
27
|
+
message = event.detail[0].message
|
28
|
+
}
|
29
|
+
|
30
|
+
show_flash('error', message);
|
15
31
|
});
|
16
32
|
|
17
33
|
row.querySelector('.edit-memo').addEventListener('click', function() {
|
data/app/assets/javascripts/spree/backend/templates/stock_items/stock_location_stock_item.hbs
CHANGED
@@ -1,36 +1,35 @@
|
|
1
|
-
<td>{{stockLocationName}}</td>
|
2
|
-
<td>
|
1
|
+
<td class="stock-location-name">{{stockLocationName}}</td>
|
2
|
+
<td class="align-center">
|
3
3
|
<input id="backorderable-{{id}}"
|
4
4
|
name="backorderable"
|
5
5
|
type="checkbox"
|
6
6
|
value="backorderable"
|
7
|
-
{{#unless editing}} disabled="disabled" {{/unless}}
|
8
7
|
{{#if backorderable}} checked="checked" {{/if}}
|
9
8
|
>
|
10
9
|
</td>
|
10
|
+
<td class="align-center">
|
11
|
+
<span
|
12
|
+
{{#if negative}}
|
13
|
+
class="negative count-on-hand-display"
|
14
|
+
{{else}}
|
15
|
+
class="count-on-hand-display"
|
16
|
+
{{/if}}
|
17
|
+
>{{count_on_hand}}</span>
|
18
|
+
</td>
|
11
19
|
<td>
|
12
|
-
|
13
|
-
<
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
>
|
24
|
-
</form>
|
25
|
-
{{else}}
|
26
|
-
<span {{#if negative}}class="negative"{{/if}}>{{count_on_hand}}</span>
|
27
|
-
{{/if}}
|
20
|
+
<form>
|
21
|
+
<input
|
22
|
+
{{#if negative}}
|
23
|
+
class="fullwidth negative"
|
24
|
+
{{else}}
|
25
|
+
class="fullwidth"
|
26
|
+
{{/if}}
|
27
|
+
name="count_on_hand"
|
28
|
+
type="number"
|
29
|
+
value="0">
|
30
|
+
</form>
|
28
31
|
</td>
|
29
32
|
<td class="actions">
|
30
|
-
|
31
|
-
|
32
|
-
<a class="cancel fa fa-cancel icon_link with-tip no-text" data-action="cancel" href="#"></a>
|
33
|
-
{{else}}
|
34
|
-
<a class="edit fa fa-edit icon_link with-tip no-text" data-action="edit" href="#"></a>
|
35
|
-
{{/if}}
|
33
|
+
<a class="submit fa fa-check icon_link with-tip no-text" data-action="save" href="#"></a>
|
34
|
+
<a class="cancel fa fa-cancel icon_link with-tip no-text" data-action="cancel" href="#"></a>
|
36
35
|
</td>
|
@@ -22,7 +22,7 @@ $.fn.userAutocomplete = function () {
|
|
22
22
|
ajax: {
|
23
23
|
url: Spree.routes.users_api,
|
24
24
|
datatype: 'json',
|
25
|
-
params: { "headers": {
|
25
|
+
params: { "headers": { 'Authorization': 'Bearer ' + Spree.api_key } },
|
26
26
|
data: function (term) {
|
27
27
|
return {
|
28
28
|
q: {
|
@@ -27,7 +27,7 @@ Spree.Views.Order.CustomerSelect = Backbone.View.extend({
|
|
27
27
|
placeholder: Spree.translations.choose_a_customer,
|
28
28
|
ajax: {
|
29
29
|
url: Spree.routes.users_api,
|
30
|
-
params: { "headers": {
|
30
|
+
params: { "headers": { 'Authorization': 'Bearer ' + Spree.api_key } },
|
31
31
|
datatype: 'json',
|
32
32
|
data: function(term, page) {
|
33
33
|
return {
|
@@ -20,10 +20,10 @@ Spree.Views.Order.Summary = Backbone.View.extend({
|
|
20
20
|
this.$('dd.order-additional_tax_total').text(this.model.get("display_additional_tax_total"))
|
21
21
|
|
22
22
|
this.$('.order-shipment_state').toggleClass("hidden", !this.model.get("completed_at"))
|
23
|
-
this.$('dd.order-shipment_state').html(this.renderState('
|
23
|
+
this.$('dd.order-shipment_state').html(this.renderState('shipment_states', this.model.get("shipment_state")))
|
24
24
|
|
25
25
|
this.$('.order-payment_state').toggleClass("hidden", !this.model.get("completed_at"))
|
26
|
-
this.$('dd.order-payment_state').html(this.renderState('
|
26
|
+
this.$('dd.order-payment_state').html(this.renderState('payment_states', this.model.get("payment_state")))
|
27
27
|
},
|
28
28
|
|
29
29
|
renderState: function(translation_key, value) {
|
@@ -6,14 +6,23 @@ Spree.Views.Stock.AddStockItem = Backbone.View.extend({
|
|
6
6
|
},
|
7
7
|
|
8
8
|
events: {
|
9
|
-
"click .submit": "onSubmit"
|
9
|
+
"click .submit": "onSubmit",
|
10
|
+
"submit form": "onSubmit",
|
11
|
+
'input [name="count_on_hand"]': "onChange",
|
12
|
+
'change [name="stock_location_id"]': "onChange",
|
13
|
+
'click [name="backorderable"]': "onChange"
|
10
14
|
},
|
11
15
|
|
12
16
|
validate: function() {
|
13
|
-
|
14
|
-
locationSelectContainer.toggleClass('error', !this.$locationSelect.val());
|
17
|
+
this.$locationSelect.toggleClass('error', !this.$locationSelect.val());
|
15
18
|
this.$countInput.toggleClass('error', !this.$countInput.val());
|
16
|
-
return
|
19
|
+
return this.$locationSelect.hasClass('error') || this.$countInput.hasClass('error');
|
20
|
+
},
|
21
|
+
|
22
|
+
onChange: function (event) {
|
23
|
+
var $target = $(event.target)
|
24
|
+
if ($target.val() !== '') $target.removeClass('error');
|
25
|
+
this.$el.addClass('changed');
|
17
26
|
},
|
18
27
|
|
19
28
|
onSuccess: function() {
|
@@ -25,6 +34,7 @@ Spree.Views.Stock.AddStockItem = Backbone.View.extend({
|
|
25
34
|
stockLocationName: stockLocationName
|
26
35
|
});
|
27
36
|
editView.$el.insertBefore(this.$el);
|
37
|
+
editView.$el.addClass('stock-item-edit-row');
|
28
38
|
this.model = new Spree.Models.StockItem({
|
29
39
|
variant_id: this.model.get('variant_id'),
|
30
40
|
stock_location_id: this.model.get('stock_location_id')
|
@@ -58,6 +68,7 @@ Spree.Views.Stock.AddStockItem = Backbone.View.extend({
|
|
58
68
|
success: this.onSuccess.bind(this),
|
59
69
|
error: this.onError.bind(this)
|
60
70
|
};
|
71
|
+
this.$el.removeClass('changed');
|
61
72
|
this.model.save(null, options);
|
62
73
|
}
|
63
74
|
});
|
@@ -3,16 +3,17 @@ Spree.Views.Stock.EditStockItemRow = Backbone.View.extend({
|
|
3
3
|
|
4
4
|
initialize: function(options) {
|
5
5
|
this.stockLocationName = options.stockLocationName;
|
6
|
-
this.editing = false;
|
7
6
|
this.negative = this.model.attributes.count_on_hand < 0;
|
7
|
+
this.previousAttributes = _.clone(this.model.attributes);
|
8
|
+
this.listenTo(this.model, 'sync', this.onSuccess);
|
8
9
|
this.render();
|
9
10
|
},
|
10
11
|
|
11
12
|
events: {
|
12
|
-
"click .edit": "onEdit",
|
13
13
|
"click .submit": "onSubmit",
|
14
14
|
"submit form": "onSubmit",
|
15
|
-
"click .cancel": "onCancel"
|
15
|
+
"click .cancel": "onCancel",
|
16
|
+
'input [name="count_on_hand"]': "countOnHandChanged"
|
16
17
|
},
|
17
18
|
|
18
19
|
template: HandlebarsTemplates['stock_items/stock_location_stock_item'],
|
@@ -26,26 +27,43 @@ Spree.Views.Stock.EditStockItemRow = Backbone.View.extend({
|
|
26
27
|
_.extend(renderAttr, this.model.attributes);
|
27
28
|
this.$el.attr("data-variant-id", this.model.get('variant_id'));
|
28
29
|
this.$el.html(this.template(renderAttr));
|
30
|
+
this.$count_on_hand_display = this.$('.count-on-hand-display');
|
29
31
|
return this;
|
30
32
|
},
|
31
33
|
|
32
34
|
onEdit: function(ev) {
|
33
35
|
ev.preventDefault();
|
34
|
-
this.editing = true;
|
35
36
|
this.render();
|
36
37
|
},
|
37
38
|
|
38
39
|
onCancel: function(ev) {
|
39
40
|
ev.preventDefault();
|
40
|
-
this.model.set(this.
|
41
|
-
this.
|
41
|
+
this.model.set(this.previousAttributes);
|
42
|
+
this.$el.removeClass('changed');
|
42
43
|
this.render();
|
43
44
|
},
|
44
45
|
|
46
|
+
countOnHandChanged: function(ev) {
|
47
|
+
var diff = parseInt(ev.currentTarget.value), newCount;
|
48
|
+
if (isNaN(diff)) diff = 0;
|
49
|
+
newCount = this.previousAttributes.count_on_hand + diff;
|
50
|
+
ev.preventDefault();
|
51
|
+
// Do not allow negative stock values
|
52
|
+
if (newCount < 0) {
|
53
|
+
ev.currentTarget.value = -1 * this.previousAttributes.count_on_hand;
|
54
|
+
this.$count_on_hand_display.text(0);
|
55
|
+
} else {
|
56
|
+
this.model.set("count_on_hand", newCount);
|
57
|
+
this.$count_on_hand_display.text(newCount);
|
58
|
+
}
|
59
|
+
this.$el.toggleClass('changed', diff !== 0);
|
60
|
+
},
|
61
|
+
|
45
62
|
onSuccess: function() {
|
46
|
-
this.
|
63
|
+
this.$el.removeClass('changed');
|
64
|
+
this.previousAttributes = _.clone(this.model.attributes);
|
47
65
|
this.render();
|
48
|
-
|
66
|
+
this.$('[name="count_on_hand"]').focus();
|
49
67
|
},
|
50
68
|
|
51
69
|
onError: function(model, response, options) {
|
@@ -62,9 +80,11 @@ Spree.Views.Stock.EditStockItemRow = Backbone.View.extend({
|
|
62
80
|
backorderable: backorderable
|
63
81
|
});
|
64
82
|
var options = {
|
65
|
-
success:
|
83
|
+
success: function() {
|
84
|
+
show_flash("success", Spree.translations.updated_successfully);
|
85
|
+
},
|
66
86
|
error: this.onError.bind(this)
|
67
87
|
};
|
68
|
-
this.model.save({
|
88
|
+
this.model.save({}, options);
|
69
89
|
}
|
70
90
|
});
|