Skip to content

Commit

Permalink
Rewrite zones.js.coffee using Backbone.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jhawthorn committed Mar 16, 2017
1 parent 7bade4c commit 07f6179
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 45 deletions.
3 changes: 2 additions & 1 deletion backend/app/assets/javascripts/spree/backend/namespaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ _.extend(window.Spree, {
Collections: {},
Views: {
Order: {},
Cart: {}
Cart: {},
Zones: {}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
//= require 'spree/backend/views/order/customer_select'
//= require 'spree/backend/views/order/summary'
//= require 'spree/backend/views/state_select'
//= require 'spree/backend/views/zones/form'
16 changes: 16 additions & 0 deletions backend/app/assets/javascripts/spree/backend/views/zones/form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Spree.Views.Zones.Form = Backbone.View.extend({
events: {
'click [name="zone[kind]"]': 'render'
},

render: function() {
var kind = this.$('[name="zone[kind]"]:checked').val() || 'state';
this.$('[name="zone[kind]"]').val([kind]);

$('#state_members').toggleClass('hidden', kind !== 'state');
$('#state_members :input').prop('disabled', kind !== 'state');

$('#country_members').toggleClass('hidden', kind !== 'country');
$('#country_members :input').prop('disabled', kind !== 'country');
}
})
8 changes: 8 additions & 0 deletions backend/app/assets/javascripts/spree/backend/zone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$(function(){
if($('.js-zones-form').length) {
var view = new Spree.Views.Zones.Form({
el: $('.js-zones-form')
});
view.render()
}
});
43 changes: 0 additions & 43 deletions backend/app/assets/javascripts/spree/backend/zone.js.coffee

This file was deleted.

2 changes: 1 addition & 1 deletion backend/app/views/spree/admin/zones/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="row">
<div class="row js-zones-form">
<div class="col-xs-5">

<div data-hook="admin_zone_form_fields">
Expand Down

0 comments on commit 07f6179

Please sign in to comment.