delivery.js
2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
delivery = {
order: {
select: {
onChange: function(input) {
var input = jQuery(input)
var deliverySelect = input.parents('.order-delivery-select')
var option = input.find('option:selected')
var typeData = option.attr('data-type')
var isPickup = typeData == 'pickup'
var instructionsData = option.attr('data-instructions')
var labelData = option.attr('data-label')
var instructions = deliverySelect.find('.instructions')
instructions.html(instructionsData)
var consumerData = deliverySelect.find('.consumer-delivery-data')
if (isPickup) {
consumerData.slideUp('fast')
} else {
consumerData.slideDown('fast')
}
},
},
},
option: {
},
method: {
view: {
edition: function() {
return jQuery('#delivery-method-edition')
},
listing: function() {
return jQuery('#delivery-method-list')
},
toggle: function () {
jQuery('#delivery-method-list, #delivery-method-edition').fadeToggle();
},
},
changeType: function(select) {
select = jQuery(select)
},
new: function(newUrl) {
this.edit(newUrl)
},
edit: function(editUrl) {
var listing = this.view.listing()
var edition = this.view.edition()
loading_overlay.show(listing)
jQuery.get(editUrl, function(data) {
edition.html(data)
delivery.method.view.toggle();
loading_overlay.hide(listing)
});
},
save: function(form) {
var listing = this.view.listing()
var edition = this.view.edition()
jQuery(form).ajaxSubmit({
beforeSubmit: function() {
loading_overlay.show(edition)
}, success: function(data) {
listing.html(data);
delivery.method.view.toggle();
loading_overlay.hide(edition)
},
})
return false;
},
destroy: function(id, confirmText, destroy_url) {
if (!confirm(confirmText))
return
var method = jQuery('#delivery-method-'+id)
jQuery.post(destroy_url, function() {
method.fadeOut(function() {
method.remove()
})
})
},
},
option: {
add: function(newUrl) {
$.getScript(newUrl)
},
},
};