Skip to content

Commit

Permalink
Add SelectableTable jQuery event
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielePalombo committed Jul 10, 2020
1 parent 3c54fae commit 9fb2dfb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
1 change: 1 addition & 0 deletions backend/app/assets/javascripts/spree/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
//= require spree/backend/progress
//= require spree/backend/promotions
//= require spree/backend/promotions/activation
//= require spree/backend/returns/return_item_selection
//= require spree/backend/routes
//= require spree/backend/shipments
//= require spree/backend/spree-select2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
Spree.ready(function() {
$('table.selectable-table').each(function() {
var selectableTableModel = new Backbone.Model({
allSelected: false,
selectedItems: []
})

new Spree.Views.Tables.SelectableTable({el: this, model: selectableTableModel});

if($(this).hasClass('return-items-table')) {
var tfoot = document.createElement('tfoot')
new Spree.Views.Tables.SelectableTable.SumReturnItemAmount({ el: tfoot, model: selectableTableModel});
$(this).append(tfoot);
}
$(document).trigger("selectableTable:init", [new Spree.Views.Tables.SelectableTable({el: this})]);
})
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$(document).on("selectableTable:init", function(_event, selectableTable) {
if(selectableTable.$el.hasClass('return-items-table')) {
new Spree.Views.Tables.ReturnItems({el: selectableTable.el, model: selectableTable.model});
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//= require 'spree/backend/views/promotions/option_values_rule'
//= require 'spree/backend/views/tables/editable_table'
//= require 'spree/backend/views/tables/editable_table_row'
//= require 'spree/backend/views/tables/return_items'
//= require 'spree/backend/views/tables/selectable_table'
//= require 'spree/backend/views/tables/selectable_table_summary'
//= require 'spree/backend/views/tables/selectable_table_sum_return_item_amount'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Spree.Views.Tables.ReturnItems = Backbone.View.extend({
initialize: function() {
if(this.$el.hasClass('return-items-table')) {
var tfoot = document.createElement('tfoot')
new Spree.Views.Tables.SelectableTable.SumReturnItemAmount({ el: tfoot, model: this.model});
this.$el.append(tfoot);
}
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ Spree.Views.Tables.SelectableTable = Backbone.View.extend({
'change .selectable': 'onSelectedItem',
},

preinitialize({autoRender}) {
this.autoRender = autoRender;
},

initialize: function() {
this.model = new Backbone.Model({
allSelected: false,
selectedItems: []
});

this.listenTo(this.model, 'change', this.detectChanges)
if(this.$el.find('.selectable').length > 0) {
var tr = document.createElement('tr')
Expand All @@ -12,6 +21,7 @@ Spree.Views.Tables.SelectableTable = Backbone.View.extend({
}

this.render();
this.trigger("selectableTable:init", this)
},

onSelectedItem: function(event) {
Expand Down

0 comments on commit 9fb2dfb

Please sign in to comment.